Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. import md5 from '../sys/md5.js';
  2. import sha1 from '../sys/sha1.js';
  3. import datas from './datas.js';
  4. import ksort from '../sys/ksort.js';
  5. import theme from '../../config/theme.js';
  6. import config from '../../config/config.js';
  7. import urlConfig from '../../config/urlConfig.js';
  8. import http from './http.js'; //身份类型
  9. const identityData = [
  10. {
  11. id: 101,
  12. name: '身份证(含临时身份证)'
  13. },
  14. {
  15. id: 102,
  16. name: '护照(限外籍人士)'
  17. },
  18. {
  19. id: 103,
  20. name: '港澳居民来往内地通行证'
  21. },
  22. {
  23. id: 104,
  24. name: '台湾居民来往大陆通行证'
  25. },
  26. {
  27. id: 105,
  28. name: '军官证'
  29. },
  30. {
  31. id: 106,
  32. name: '武警警察身份证'
  33. },
  34. {
  35. id: 201,
  36. name: '统一社会信用代码证书'
  37. },
  38. {
  39. id: 202,
  40. name: '组织机构代码证'
  41. },
  42. {
  43. id: 203,
  44. name: '营业执照'
  45. },
  46. {
  47. id: 204,
  48. name: '事业单位法人证书'
  49. },
  50. {
  51. id: 205,
  52. name: '社会团体法人登记证书'
  53. },
  54. {
  55. id: 206,
  56. name: '律师事务所执业许可证'
  57. },
  58. {
  59. id: 217,
  60. name: '公司商业登记副本(3个月内)'
  61. },
  62. {
  63. id: 218,
  64. name: '公司营业税单M8副本'
  65. },
  66. {
  67. id: 219,
  68. name: '公司营业税开业/更改M1副本'
  69. }
  70. ];
  71. const deviceModel = [
  72. {
  73. name: '万集',
  74. value: 'WJ'
  75. },
  76. {
  77. name: '聚利',
  78. value: 'JL'
  79. },
  80. {
  81. name: '金溢',
  82. value: 'JY'
  83. },
  84. {
  85. name: '埃特斯',
  86. value: 'AT'
  87. },
  88. {
  89. name: '建投',
  90. value: 'JT'
  91. },
  92. {
  93. name: '握奇',
  94. value: 'WQ'
  95. },
  96. {
  97. name: '成谷',
  98. value: 'CG'
  99. },
  100. {
  101. name: '天地融',
  102. value: 'TD'
  103. },
  104. {
  105. name: '智载',
  106. value: 'ZZ'
  107. }
  108. ];
  109. /********************** 路由跳转 **********************/
  110. //保留当前页面,跳转到应用内的某个页面
  111. function toUrl(url) {
  112. uni.showToast({
  113. //显示消息提示框 此处是提升用户体验的作用
  114. title: '加载中',
  115. icon: 'loading'
  116. }); // if (url.indexOf("?")==-1){
  117. // url += '?rand=' + datas.randomNum(1000,9999)
  118. // }else{
  119. // url += '&rand=' + datas.randomNum(1000,9999)
  120. // }
  121. console.log('url:*****' + url);
  122. uni.navigateTo({
  123. url: url,
  124. complete: function (response) {
  125. uni.hideToast();
  126. }
  127. });
  128. } //关闭当前页面,返回上一页面或多级页面。
  129. function navigateBack(delta, successFunc = null, failFunc = null) {
  130. uni.navigateBack({
  131. delta: delta,
  132. success: function (res) {
  133. //接口调用成功的回调函数
  134. if (successFunc != null) {
  135. successFunc(res);
  136. }
  137. },
  138. fail: function (res) {
  139. //接口调用失败的回调函数
  140. if (failFunc != null) {
  141. failFunc(res);
  142. }
  143. },
  144. complete: function (res) {} //接口调用结束的回调函数(调用成功、失败都会执行)
  145. });
  146. }
  147. /********************** showModalAlert ************************/
  148. function showModalAlert(content, successFunc = null, failFunc = null, title = '温馨提示', showCancel = false) {
  149. uni.showModal({
  150. title: title,
  151. content: content,
  152. showCancel: showCancel,
  153. //是否显示取消按钮
  154. cancelText: '取消',
  155. //默认是“取消”
  156. cancelColor: theme.cancelModalColor,
  157. //取消文字的颜色
  158. confirmText: '确定',
  159. //默认是“确定”
  160. confirmColor: theme.modalColor,
  161. //确定文字的颜色
  162. success: function (res) {
  163. //接口调用成功的回调函数
  164. if (successFunc != null) {
  165. successFunc(res);
  166. }
  167. },
  168. fail: function (res) {
  169. //接口调用失败的回调函数
  170. if (failFunc != null) {
  171. failFunc(res);
  172. }
  173. },
  174. complete: function (res) {} //接口调用结束的回调函数(调用成功、失败都会执行)
  175. });
  176. }
  177. /*******************showToastAlert********************/
  178. function showToastAlert(title = '成功', icon = 'none', image = '', duration = 2000, mask = true, successFunc = null, failFunc = null, completeFun = null) {
  179. uni.showToast({
  180. title: title,
  181. icon: icon,
  182. //success显示成功图标,loading显示加载图标,none不显示图标
  183. image: image,
  184. duration: duration,
  185. mask: mask,
  186. ////是否显示透明蒙层,防止触摸穿透
  187. success: function (res) {
  188. //接口调用成功的回调函数
  189. if (successFunc != null) {
  190. successFunc(res);
  191. }
  192. },
  193. fail: function (res) {
  194. //接口调用失败的回调函数
  195. if (failFunc != null) {
  196. failFunc(res);
  197. }
  198. },
  199. complete: function (res) {
  200. //接口调用结束的回调函数(调用成功、失败都会执行)
  201. if (completeFun != null) {
  202. completeFun(res);
  203. }
  204. }
  205. });
  206. }
  207. /******************showLoadingAlert************************/
  208. function showLoadingAlert(title = '加载中...', mask = true, successFunc = null, failFunc = null, completeFun = null) {
  209. uni.showLoading({
  210. title: title,
  211. mask: mask,
  212. //是否显示透明蒙层,防止触摸穿透
  213. success: function (res) {
  214. //接口调用成功的回调函数
  215. if (successFunc != null) {
  216. successFunc(res);
  217. }
  218. },
  219. fail: function (res) {
  220. //接口调用失败的回调函数
  221. if (failFunc != null) {
  222. failFunc(res);
  223. }
  224. },
  225. complete: function (res) {
  226. //接口调用结束的回调函数(调用成功、失败都会执行)
  227. if (completeFun != null) {
  228. completeFun(res);
  229. }
  230. }
  231. });
  232. }
  233. function hideLoadingAlert(successFunc = null, failFunc = null, completeFun = null) {
  234. uni.hideLoading({
  235. success: function (res) {
  236. //接口调用成功的回调函数
  237. if (successFunc != null) {
  238. successFunc(res);
  239. }
  240. },
  241. fail: function (res) {
  242. //接口调用失败的回调函数
  243. if (failFunc != null) {
  244. failFunc(res);
  245. }
  246. },
  247. complete: function (res) {
  248. //接口调用结束的回调函数(调用成功、失败都会执行)
  249. if (completeFun != null) {
  250. completeFun(res);
  251. }
  252. }
  253. });
  254. } //签名
  255. function sign(data, signCode) {
  256. data = ksort.ksort(data);
  257. var signStr = '';
  258. var requestId = false;
  259. for (let k in data) {
  260. if (k != 'sign') {
  261. if (k == 'requestId') {
  262. requestId = data[k];
  263. }
  264. signStr += k + '=' + data[k] + '&';
  265. }
  266. }
  267. signStr += 'signCode=' + signCode; // console.log("signStr*************"+signStr);
  268. if (!requestId) {
  269. return false;
  270. }
  271. signStr = md5.i(signStr);
  272. signStr = signStr.toUpperCase(); // console.log('MD5**************' + signStr);
  273. signStr += requestId; // console.log('requestId**************' + signStr);
  274. signStr = sha1.i(signStr);
  275. signStr = signStr.toUpperCase(); // console.log('SHA1**************' + signStr);
  276. return signStr;
  277. } //字符串加密
  278. function md5Str(str) {
  279. var _str = md5.i(str);
  280. return _str;
  281. }
  282. function sha1Str(str) {
  283. var _str = sha1.i(str);
  284. return _str;
  285. } //加载
  286. // function loading(msg = "加载中") {
  287. // wx.showToast({ //显示消息提示框 此处是提升用户体验的作用
  288. // title: msg,
  289. // icon: 'loading',
  290. // duration: 60000, //提示的延迟时间
  291. // mask: true, //是否显示透明蒙层,防止触摸穿透
  292. // });
  293. // }
  294. //对话
  295. // function showAlertv2(content, func = nu l l, titl e = "温馨提示") {
  296. // wx.hideLoading();
  297. // wx.showModal({
  298. // title: title,
  299. // content: content,
  300. // showCancel : false,//是否显示取消按钮
  301. // cancelTex "否",//默认是“取消”
  302. // cancelColor: theme.modalColo//取消文字的颜色
  303. // confirmText: "确定",//默认是“确定”
  304. // confirmColor: theme.modalColor,//确定文字的颜色
  305. // success: function (res) {
  306. // if (func != null) {
  307. // func(res);
  308. // }
  309. // },
  310. // fail: function (res) { },//接口调用失败的回调函数
  311. // complete: function (res) { },//接口调用结束的回调函数(调用成功、失败都会执行)
  312. // })
  313. // }
  314. //公用的获取车牌颜色
  315. function getVehicleColor(callback) {
  316. http.sendPostv2(config.serviceMiniURL + urlConfig.vehiclePlateColor, {}, function (res) {
  317. if (res.rc != '00') {
  318. return;
  319. }
  320. if (callback != null) {
  321. callback(res);
  322. }
  323. });
  324. }
  325. function getVehicleColorBYcode(code, callback) {
  326. getVehicleColor(function (res) {
  327. callback(
  328. res.rd.filter((item) => {
  329. return item.code == code;
  330. })[0].name
  331. );
  332. });
  333. } //获取开户行
  334. function getEtcBankList(callback) {
  335. http.sendPostv2(config.aftersaleURL + urlConfig.etcBankList, {}, function (res) {
  336. if (res.rc != '00') {
  337. alertF(res.rm);
  338. return;
  339. }
  340. if (callback != null) {
  341. callback(res.rd);
  342. }
  343. });
  344. }
  345. /**
  346. * 判断用户是否关注公众号
  347. */
  348. function isFollow(callback) {
  349. var requestData = new Array();
  350. requestData['openId'] = datas.getData('wxOpenId');
  351. var requestData = datas.arrayToJson(requestData);
  352. http.sendPostv2(config.etcNewUrl + urlConfig.isFollow, requestData, function (res) {
  353. if (res.rc != '00') {
  354. alertF(res.rm);
  355. return;
  356. }
  357. if (callback != null) {
  358. callback(res.rd.subscribe);
  359. }
  360. });
  361. }
  362. function alertF(msg) {
  363. //隐藏加载框
  364. hideLoadingAlert(); //提示对话框
  365. showModalAlert(msg);
  366. }
  367. function alertFback(msg, backcall) {
  368. //隐藏加载框
  369. hideLoadingAlert(); //提示对话框
  370. showModalAlert(msg, backcall);
  371. }
  372. /*
  373. 调用核心接口,外层接口共用(暂用于发票模块)
  374. */
  375. function coreInter(url, param, successFun, failFun) {
  376. var initSignUrl = config.zeusURL + urlConfig.htlUrl;
  377. var requestData = new Array();
  378. requestData['requestId'] = datas.getDate() + datas.generateMixed(10);
  379. requestData['accessCode'] = 'etc';
  380. requestData['distinction'] = url;
  381. requestData['data'] = JSON.stringify(param);
  382. requestData['sign'] = sign(requestData, config._signCode);
  383. var requestData = datas.arrayToJson(requestData);
  384. showLoadingAlert('加载中');
  385. http.sendPostv2(initSignUrl, requestData, function (res) {
  386. hideLoadingAlert();
  387. if (res.rc != '00') {
  388. alertF(res.rm);
  389. return;
  390. }
  391. if (!res.rd.success) {
  392. failFun ? failFun() : alertF(res.rd.msg);
  393. return;
  394. }
  395. successFun(res);
  396. });
  397. }
  398. /**
  399. * 车牌数字转车牌中文
  400. */
  401. function vehiclePlateStr(num, successFun) {
  402. var vehicleColorStr;
  403. switch (num) {
  404. case 0:
  405. vehicleColorStr = '蓝色';
  406. successFun(vehicleColorStr);
  407. break;
  408. case 1:
  409. vehicleColorStr = '黄色';
  410. successFun(vehicleColorStr);
  411. break;
  412. case 2:
  413. vehicleColorStr = '黑色';
  414. successFun(vehicleColorStr);
  415. break;
  416. case 3:
  417. vehicleColorStr = '白色';
  418. successFun(vehicleColorStr);
  419. break;
  420. case 4:
  421. vehicleColorStr = '渐变绿色';
  422. successFun(vehicleColorStr);
  423. break;
  424. case 5:
  425. vehicleColorStr = '黄绿双拼色';
  426. successFun(vehicleColorStr);
  427. break;
  428. case 6:
  429. vehicleColorStr = '蓝白渐变色';
  430. successFun(vehicleColorStr);
  431. break;
  432. case 7:
  433. vehicleColorStr = '临时牌照';
  434. successFun(vehicleColorStr);
  435. break;
  436. case 9:
  437. vehicleColorStr = '未确定';
  438. successFun(vehicleColorStr);
  439. break;
  440. case 11:
  441. vehicleColorStr = '绿色';
  442. successFun(vehicleColorStr);
  443. break;
  444. case 12:
  445. vehicleColorStr = '红色';
  446. successFun(vehicleColorStr);
  447. break;
  448. default:
  449. vehicleColorStr = '未知';
  450. successFun(vehicleColorStr);
  451. break;
  452. }
  453. }
  454. module.exports = {
  455. coreInter,
  456. toUrl,
  457. navigateBack,
  458. showModalAlert,
  459. showToastAlert,
  460. showLoadingAlert,
  461. hideLoadingAlert,
  462. sign,
  463. getVehicleColor,
  464. getVehicleColorBYcode,
  465. getEtcBankList,
  466. // showAlertv2,
  467. // loading,
  468. md5Str,
  469. sha1Str,
  470. alertF,
  471. alertFback,
  472. identityData,
  473. deviceModel,
  474. isFollow,
  475. vehiclePlateStr
  476. };