checkout.js 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. var util = require('../../../utils/util.js');
  2. var api = require('../../../config/api.js');
  3. var app = getApp();
  4. var dateArray = [];
  5. Page({
  6. data: {
  7. checkedGoodsList: [],
  8. addressVo: {},
  9. checkedCoupon00: [],
  10. checkedCoupon02: [],
  11. checkedCoupon10: [],
  12. checkedCoupon11: [],
  13. couponList00: [],
  14. couponList02: [],
  15. couponList10: [],
  16. couponList11: [],
  17. goodsBizTypeList: ['00', '02', '10', '11'],
  18. goodsTotalPrice: 0.00, //商品总价
  19. freightPrice00: 0.00, //备货业务快递费
  20. freightPrice02: 0.00, //补货业务快递费
  21. freightPrice10: 0.00, //现场发包快递费
  22. freightPrice11: 0.00, //普通商品快递费
  23. couponPrice: 0.00, //优惠券的价格
  24. orderTotalPrice: 0.00, //订单总价
  25. actualPrice: 0.00, //实际需要支付的总价
  26. // userCouponId: 0,
  27. fullCutCouponId: 0,
  28. fullCutCouponDec: 0, //满减优惠券
  29. goodsTotalByType00: 0, //备货业务商品总计
  30. goodsTotalByType02: 0, //补货业务商品总计
  31. goodsTotalByType10: 0, //现场发包商品总计
  32. goodsTotalByType11: 0, //普通商品商品总计
  33. goodsTotalPrice00: 0,
  34. goodsTotalPrice02: 0,
  35. goodsTotalPrice10: 0,
  36. goodsTotalPrice11: 0,
  37. postscript: "",
  38. postscript00: '', //备货业务备注
  39. postscript02: '', //补货业务备注
  40. postscript10: '', //现场发包备注
  41. postscript11: '', //普通商品备注
  42. checkStore: false,
  43. storeVo: {},
  44. delivery_date: '',
  45. delivery_remark: '尽快送达',
  46. multiArray: [],
  47. multiIndex: [0, 0],
  48. timeArray: util.getNowTimeArray(),
  49. idNo: '',
  50. userName: '',
  51. idNoM: '',
  52. idNoDisabled: false,
  53. checkCart: '',
  54. ticketDiscountList: [],
  55. tickDiscId00: 0,
  56. tickDiscId02: 0,
  57. tickDiscId10: 0,
  58. tickDiscId11: 0,
  59. checkTickDiscId: 0,
  60. actualPrice00: 0.00,
  61. actualPrice02: 0.00,
  62. actualPrice10: 0.00,
  63. actualPrice11: 0.00,
  64. campId00: 0,
  65. campId02: 0,
  66. campId10: 0,
  67. campId11: 0,
  68. campList00: '',
  69. campList02: '',
  70. campList10: '',
  71. campList11: '',
  72. campMinusDto00: '',
  73. campMinusDto02: '',
  74. campMinusDto10: '',
  75. campMinusDto11: '',
  76. checkCampId: 0,
  77. storeCampMinusList: [],
  78. openCampMinusAttr: false,
  79. goodsId: '',
  80. number: '',
  81. isAgreed: false
  82. },
  83. onLoad: function(options) {
  84. // 页面初始化 options为页面跳转所带来的参数
  85. // console.log(options.checkCart);
  86. this.setData({
  87. checkCart: options.checkCart
  88. });
  89. if (options.isAgreed) {
  90. this.setData({
  91. isAgreed: options.isAgreed
  92. });
  93. }
  94. if (options.goodsId) {
  95. this.setData({
  96. goodsId: options.goodsId,
  97. number: options.number
  98. });
  99. console.log(this.data.goodsId);
  100. console.log(this.data.number);
  101. }
  102. },
  103. onReady: function() {
  104. // 页面渲染完成
  105. },
  106. onShow: function() {
  107. let that = this;
  108. // 页面显示
  109. wx.showLoading({
  110. title: '加载中...',
  111. })
  112. if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
  113. if (wx.getStorageSync('storeId')) {
  114. util.request(api.ChooseStoreId, {
  115. storeId: wx.getStorageSync('storeId'),
  116. merchSn: wx.getStorageSync('merchSn')
  117. }, 'POST').then(function(res) {
  118. if (res.errno === 0) {
  119. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  120. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  121. that.reLoad();
  122. }
  123. });
  124. that.getCheckoutInfo();
  125. that.initPicker()
  126. }
  127. } else {
  128. wx.navigateTo({
  129. url: '/pages/auth/btnAuth/btnAuth',
  130. })
  131. }
  132. },
  133. onHide: function() {
  134. // 页面隐藏
  135. console.log('页面隐藏');
  136. },
  137. onUnload: function() {
  138. // 页面关闭
  139. console.log('页面关闭');
  140. },
  141. bindMultiPickerColumnChange: function(e) {
  142. let that = this;
  143. // console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
  144. var data = {
  145. multiArray: this.data.multiArray,
  146. multiIndex: this.data.multiIndex
  147. };
  148. data.multiIndex[e.detail.column] = e.detail.value
  149. if (e.detail.column == 0) {
  150. data.multiIndex[1] = 0
  151. }
  152. let timeArray = that.data.timeArray;
  153. if (data.multiIndex[0] == 1) {
  154. timeArray = util.timeArray.slice(0);
  155. } else {
  156. timeArray = util.getNowTimeArray();
  157. }
  158. data.timeArray = timeArray;
  159. data.multiArray[1] = timeArray;
  160. this.setData(data)
  161. },
  162. bindMultiPickerChange: function(e) {
  163. let that = this;
  164. // console.log('picker发送选择改变,携带值为', e.detail.value)
  165. this.setData({
  166. multiIndex: e.detail.value,
  167. delivery_date: dateArray[e.detail.value[0]],
  168. delivery_remark: e.detail.value[0] == 0 ? that.data.timeArray[e.detail.value[1]] : that.data.timeArray[e.detail.value[1]]
  169. })
  170. // console.log('delivery_date', this.data.delivery_date, ',delivery_remark', this.data.delivery_remark)
  171. },
  172. initPicker() {
  173. let that = this;
  174. let date = new Date();
  175. let hours = date.getHours();
  176. let minutes = date.getMinutes();
  177. let index = 0;
  178. var today = util.getNowTime();
  179. var tomorrow = util.getDateStr(new Date(), 1);
  180. dateArray = [today, tomorrow];
  181. this.setData({
  182. 'multiArray[0]': dateArray,
  183. 'multiArray[1]': that.data.timeArray,
  184. })
  185. },
  186. formatidcard(idcard) {
  187. if (idcard.length == 15) {
  188. return idcard.replace(/(\d{6})\d{6}(\d{3})/, "$1******$2");
  189. } else {
  190. return idcard.replace(/(\d{5})\d{6}(\d{6})/, "$1******$2");
  191. }
  192. },
  193. getCheckoutInfo: function() {
  194. let that = this;
  195. util.request(api.CartCheckout, {
  196. tickDiscId00: that.data.tickDiscId00,
  197. tickDiscId02: that.data.tickDiscId02,
  198. tickDiscId10: that.data.tickDiscId10,
  199. tickDiscId11: that.data.tickDiscId11,
  200. campId00: that.data.campId00,
  201. campId02: that.data.campId02,
  202. campId10: that.data.campId10,
  203. campId11: that.data.campId11,
  204. merchSn: wx.getStorageSync('merchSn'),
  205. checkCart: that.data.checkCart,
  206. isLoadStatus: 0, //是首次加载
  207. goodsId: that.data.goodsId,
  208. number: that.data.number
  209. }, 'POST').then(function(res) {
  210. if (res.errno === 0) {
  211. console.log(res.data);
  212. that.setData({
  213. checkedGoodsList: res.data.checkedGoodsList,
  214. actualPrice: res.data.actualPrice,
  215. actualPrice00: res.data.actualPrice00,
  216. actualPrice02: res.data.actualPrice02,
  217. actualPrice10: res.data.actualPrice10,
  218. actualPrice11: res.data.actualPrice11,
  219. addressVo: res.data.addressVo,
  220. checkedCoupon00: res.data.checkedCoupon00,
  221. checkedCoupon02: res.data.checkedCoupon02,
  222. checkedCoupon10: res.data.checkedCoupon10,
  223. checkedCoupon11: res.data.checkedCoupon11,
  224. couponList00: res.data.couponList00,
  225. couponList02: res.data.couponList02,
  226. couponList10: res.data.couponList10,
  227. couponList11: res.data.couponList11,
  228. // fullCutCouponId: res.data.fullCutCouponId,
  229. // fullCutCouponDec: res.data.fullCutCouponDec,
  230. couponPrice: res.data.couponPrice,
  231. freightPrice00: res.data.freightPrice00,
  232. freightPrice02: res.data.freightPrice02,
  233. freightPrice10: res.data.freightPrice10,
  234. freightPrice11: res.data.freightPrice11,
  235. goodsTotalPrice: res.data.goodsTotalPrice,
  236. orderTotalPrice: res.data.orderTotalPrice,
  237. userName: res.data.userName,
  238. idNo: res.data.idNo,
  239. campList00: res.data.campList00,
  240. campList02: res.data.campList02,
  241. campList10: res.data.campList10,
  242. campList11: res.data.campList11,
  243. campMinusDto00: res.data.campMinusDto00,
  244. campMinusDto02: res.data.campMinusDto02,
  245. campMinusDto10: res.data.campMinusDto10,
  246. campMinusDto11: res.data.campMinusDto11,
  247. campId00: res.data.campId00,
  248. campId02: res.data.campId02,
  249. campId10: res.data.campId10,
  250. campId11: res.data.campId11,
  251. tickDiscId00: res.data.tickDiscId00,
  252. tickDiscId02: res.data.tickDiscId02,
  253. tickDiscId10: res.data.tickDiscId10,
  254. tickDiscId11: res.data.tickDiscId11,
  255. isLoadStatus: 0
  256. });
  257. if (that.data.idNo) {
  258. that.setData({
  259. idNoM: that.formatidcard(that.data.idNo)
  260. });
  261. }
  262. if (that.data.idNo) {
  263. that.setData({
  264. idNoDisabled: true
  265. });
  266. }
  267. let num00 = 0;
  268. let num02 = 0;
  269. let num10 = 0;
  270. let num11 = 0;
  271. let goodsTotalPrice00 = 0;
  272. let goodsTotalPrice02 = 0;
  273. let goodsTotalPrice10 = 0;
  274. let goodsTotalPrice11 = 0;
  275. for (var i = 0; i < that.data.checkedGoodsList.length; i++) {
  276. if ('00' == that.data.checkedGoodsList[i].goodsBizType) {
  277. num00 = num00 + that.data.checkedGoodsList[i].number;
  278. goodsTotalPrice00 = goodsTotalPrice00 +
  279. (that.data.checkedGoodsList[i].retail_price * that.data.checkedGoodsList[i].number);
  280. }
  281. if ('02' == that.data.checkedGoodsList[i].goodsBizType) {
  282. num02 = num02 + that.data.checkedGoodsList[i].number;
  283. goodsTotalPrice02 = goodsTotalPrice02 +
  284. (that.data.checkedGoodsList[i].retail_price * that.data.checkedGoodsList[i].number);
  285. }
  286. if ('10' == that.data.checkedGoodsList[i].goodsBizType) {
  287. num10 = num10 + that.data.checkedGoodsList[i].number;
  288. goodsTotalPrice10 = goodsTotalPrice10 +
  289. (that.data.checkedGoodsList[i].retail_price * that.data.checkedGoodsList[i].number);
  290. }
  291. if ('11' == that.data.checkedGoodsList[i].goodsBizType) {
  292. num11 = num11 + that.data.checkedGoodsList[i].number;
  293. goodsTotalPrice11 = goodsTotalPrice11 +
  294. (that.data.checkedGoodsList[i].retail_price * that.data.checkedGoodsList[i].number);
  295. }
  296. }
  297. that.setData({
  298. goodsTotalByType00: num00,
  299. goodsTotalByType02: num02,
  300. goodsTotalByType10: num10,
  301. goodsTotalByType11: num11,
  302. goodsTotalPrice00: (goodsTotalPrice00 + that.data.freightPrice00).toFixed(2),
  303. goodsTotalPrice02: (goodsTotalPrice02 + that.data.freightPrice02).toFixed(2),
  304. goodsTotalPrice10: (goodsTotalPrice10 + that.data.freightPrice10).toFixed(2),
  305. goodsTotalPrice11: (goodsTotalPrice11 + that.data.freightPrice11).toFixed(2)
  306. });
  307. // console.log(that.data.goodsTotalByType00);
  308. // console.log(that.data.goodsTotalByType02);
  309. // console.log(that.data.goodsTotalByType10);
  310. // console.log(that.data.goodsTotalByType11);
  311. //选择促销
  312. that.setCampMinus();
  313. //选择优惠券
  314. that.setTickDisc();
  315. }
  316. wx.hideLoading();
  317. that.checkStore();
  318. });
  319. },
  320. selectAddress() {
  321. this.setData({
  322. checkStore: false,
  323. openTicketAttr: false
  324. });
  325. wx.navigateTo({
  326. url: '/pages/shopping/address/address',
  327. })
  328. },
  329. addAddress() {
  330. wx.navigateTo({
  331. url: '/pages/shopping/addressAdd/addressAdd',
  332. })
  333. },
  334. bindPostscriptBlur(e) {
  335. let goodsType = e.target.dataset.goodsType;
  336. if (goodsType == '00') {
  337. this.setData({
  338. postscript00: e.detail.value
  339. });
  340. }
  341. if (goodsType == '02') {
  342. this.setData({
  343. postscript02: e.detail.value
  344. });
  345. }
  346. if (goodsType == '10') {
  347. this.setData({
  348. postscript10: e.detail.value
  349. });
  350. }
  351. if (goodsType == '11') {
  352. this.setData({
  353. postscript11: e.detail.value
  354. });
  355. }
  356. },
  357. submitOrder: function (e) {
  358. let that = this;
  359. // console.log(e.detail.formId);
  360. wx.showModal({
  361. title: '消费者告知书',
  362. content: '为了您更好地选择境外商品,请您在下单前务必认真详细阅读并完全理解本告知书相关内容,对自身风险做出客观判断,完全同意本告知书内容后再下单。\r\n1、按照跨境电商进口税收政策(财关税[2018]49号)要求,跨境电子商务零售进口商品的单笔交易限额为人民币5000元,个人年底交易限额为人民币26000元。\r\n2、本平台所售境外商品是用户最终支付的金额,无需额外再支付税费。\r\n3、根据相关法律政策,您选购的境外商品仅限于个人自用,不得进行再次销售。\r\n4、您知晓商品的订购人(即支付人)将被记录为进口方,必须遵守中国的法律法规。\r\n5、跨境电商相关法律法规规定“合法的报关清关手续需验证个人身份信息”,提交订单时,需要用户填写个人真实身份信息。\r\n6、您购买的所有境外商品适用的品质、健康、安全、卫生、环保、标示等项目标准可能与我国质量安全标准不同,由此可能产生的危害和损失以及法律责任或其他风险,将由您个人承担。\r\n7、您在本网站购买的境外商品等同于原产地直接销售商品,因此商品本身可能无中文标签或者说明书,请在下单前认真阅读平台提供的物品信息。\r\n8、建议您对境外商品有一定了解并评估是否适合自己使用后再下单,感谢您的配合。\r\n9、您购买的跨境商品订单经海关清关成功放行后,便不可退单及修改收件地址,请确认信息后再下单,感谢您的理解和配合。',
  363. cancelText:'拒绝',
  364. confirmText:'同意',
  365. success(res) {
  366. if (res.confirm) {
  367. if (wx.getStorageSync('storeId')) {} else {
  368. wx.switchTab({
  369. url: '/pages/cart/cart'
  370. })
  371. }
  372. if (!that.data.addressVo) {
  373. util.showErrorToast('请选择收货地址');
  374. return false;
  375. }
  376. if (!e.detail.value.idNo) {
  377. util.showErrorToast('身份证号不能为空');
  378. return false;
  379. }
  380. if (!e.detail.value.userName) {
  381. util.showErrorToast('姓名不能为空');
  382. return false;
  383. }
  384. if (that.data.idNoM == '') {
  385. that.setData({
  386. idNo: e.detail.value.idNo,
  387. userName: e.detail.value.userName
  388. });
  389. }
  390. if (!that.checkIdcard(that.data.idNo)) {
  391. wx.showModal({
  392. title: '提示信息',
  393. content: '请输入正确的身份证号',
  394. showCancel: false
  395. });
  396. return false;
  397. }
  398. // if (!this.data.checkStore || !this.data.checkStore) {
  399. // util.showErrorToast('超过门店配送范围');
  400. // return false;
  401. // }
  402. // console.log(that.data.postscript00);
  403. // console.log(that.data.postscript02);
  404. // console.log(that.data.postscript10);
  405. // console.log(that.data.postscript11);
  406. wx.showLoading({
  407. title: '加载中...',
  408. });
  409. util.request(api.OrderSubmit, {
  410. checkedAddress: that.data.addressVo,
  411. tickDiscId00: that.data.tickDiscId00,
  412. tickDiscId02: that.data.tickDiscId02,
  413. tickDiscId10: that.data.tickDiscId10,
  414. tickDiscId11: that.data.tickDiscId11,
  415. // fullCutCouponId: that.data.fullCutCouponId,
  416. postscript00: that.data.postscript00,
  417. postscript02: that.data.postscript02,
  418. postscript10: that.data.postscript10,
  419. postscript11: that.data.postscript11,
  420. delivery_date: that.data.delivery_date,
  421. delivery_remark: that.data.delivery_remark,
  422. idNo: that.data.idNo,
  423. userName: that.data.userName,
  424. merchSn: wx.getStorageSync("merchSn"),
  425. checkCart: that.data.checkCart,
  426. campId00: that.data.campId00,
  427. campId02: that.data.campId02,
  428. campId10: that.data.campId10,
  429. campId11: that.data.campId11,
  430. isLoadStatus: that.data.isLoadStatus,
  431. goodsId: that.data.goodsId,
  432. number: that.data.number
  433. }, 'POST').then(function(res) {
  434. if (res.errno === 0) {
  435. let actualPrice = that.data.actualPrice;
  436. let orderIds = [];
  437. for (let i = 0; i < res.data.orderInfo.length; i++) {
  438. orderIds[i] = res.data.orderInfo[i].id;
  439. }
  440. wx.redirectTo({
  441. url: '/pages/pay/pay?orderIds=' + orderIds + '&actualPrice=' + actualPrice + '&isMergePay=1' //此处提交支付属于合并支付
  442. })
  443. } else {
  444. wx.showModal({
  445. title: '提示信息',
  446. content: res.errmsg,
  447. showCancel: false
  448. });
  449. }
  450. wx.hideLoading();
  451. });
  452. } else if (res.cancel) {
  453. console.log('用户点击取消')
  454. }
  455. }
  456. });
  457. },
  458. // 校验门店
  459. checkStore: function() {
  460. let that = this;
  461. util.request(api.CheckStore, {
  462. checkedAddress: that.data.addressVo,
  463. storeId: wx.getStorageSync('storeId')
  464. }, 'POST').then(function(res) {
  465. if (res.errno === 0) {
  466. that.setData({
  467. storeVo: res.data,
  468. checkStore: true
  469. });
  470. } else {
  471. // console.log(res.errmsg);
  472. // util.showErrorToast(res.errmsg);
  473. that.setData({
  474. checkStore: false
  475. });
  476. }
  477. });
  478. },
  479. reLoad: function() {
  480. let that = this;
  481. if (wx.getStorageSync('storeId')) {
  482. if (wx.getStorageSync('userId')) {
  483. wx.request({
  484. url: api.updateLoginUser,
  485. data: {
  486. userId: wx.getStorageSync('userId'),
  487. storeId: wx.getStorageSync('storeId'),
  488. merchSn: wx.getStorageSync('merchSn')
  489. },
  490. method: 'POST',
  491. header: {
  492. 'Content-Type': 'application/json'
  493. },
  494. success: function(wxRes) {
  495. if (wxRes.data.errno === 0) {
  496. // console.log("用户信息更新成功");
  497. }
  498. },
  499. fail: function(err) {
  500. console.log("failed");
  501. }
  502. });
  503. }
  504. }
  505. },
  506. // 校验身份证号
  507. //校验码校验
  508. checkCode: function(val) {
  509. var p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
  510. var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  511. var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
  512. var code = val.substring(17);
  513. if (p.test(val)) {
  514. var sum = 0;
  515. for (var i = 0; i < 17; i++) {
  516. sum += val[i] * factor[i];
  517. }
  518. if (parity[sum % 11] == code.toUpperCase()) {
  519. return true;
  520. }
  521. }
  522. return false;
  523. },
  524. //省份校验
  525. checkProv: function(val) {
  526. var pattern = /^[1-9][0-9]/;
  527. var provs = {
  528. 11: "北京",
  529. 12: "天津",
  530. 13: "河北",
  531. 14: "山西",
  532. 15: "内蒙古",
  533. 21: "辽宁",
  534. 22: "吉林",
  535. 23: "黑龙江 ",
  536. 31: "上海",
  537. 32: "江苏",
  538. 33: "浙江",
  539. 34: "安徽",
  540. 35: "福建",
  541. 36: "江西",
  542. 37: "山东",
  543. 41: "河南",
  544. 42: "湖北 ",
  545. 43: "湖南",
  546. 44: "广东",
  547. 45: "广西",
  548. 46: "海南",
  549. 50: "重庆",
  550. 51: "四川",
  551. 52: "贵州",
  552. 53: "云南",
  553. 54: "西藏 ",
  554. 61: "陕西",
  555. 62: "甘肃",
  556. 63: "青海",
  557. 64: "宁夏",
  558. 65: "新疆",
  559. 71: "台湾",
  560. 81: "香港",
  561. 82: "澳门"
  562. };
  563. if (pattern.test(val)) {
  564. if (provs[val]) {
  565. return true;
  566. }
  567. }
  568. return false;
  569. },
  570. //出生日期码校验
  571. checkDate: function(val) {
  572. var pattern = /^(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)$/;
  573. if (pattern.test(val)) {
  574. var year = val.substring(0, 4);
  575. var month = val.substring(4, 6);
  576. var date = val.substring(6, 8);
  577. var date2 = new Date(year + "-" + month + "-" + date);
  578. if (date2 && date2.getMonth() == (parseInt(month) - 1)) {
  579. return true;
  580. }
  581. }
  582. return false;
  583. },
  584. checkIdcard: function(val) {
  585. if (this.checkCode(val)) {
  586. var date = val.substring(6, 14);
  587. if (this.checkDate(date)) {
  588. if (this.checkProv(val.substring(0, 2))) {
  589. return true;
  590. }
  591. }
  592. }
  593. // this.isError("请输入正确身份证号");
  594. return false;
  595. },
  596. // 通过身份证号获取出生日期和性别
  597. getBirthAndSex: function(idCard) {
  598. var that = this;
  599. var info = {};
  600. var birth = (idCard.length === 18) ? idCard.slice(6, 14) : idCard.slice(6, 12);
  601. var order = (idCard.length === 18) ? idCard.slice(-2, -1) : idCard.slice(-1);
  602. info.birthDay = (idCard.length === 18) ? ([birth.slice(0, 4), birth.slice(4, 6), birth.slice(-2)]).join('-') : (['19' + birth.slice(0, 2), birth.slice(2, 4), birth.slice(-2)]).join('-');
  603. info.sex = (order % 2 === 0 ? 2 : 0);
  604. return info;
  605. },
  606. selectCoupon(e) {
  607. let goodsBizType = e.currentTarget.dataset.goodsType;
  608. let that = this;
  609. // wx.navigateTo({
  610. // url: '/pages/shopping/coupon/coupon',
  611. // })
  612. that.setData({
  613. openTicketAttr: !that.data.openTicketAttr,
  614. openCampMinusAttr: false
  615. })
  616. if (that.data.openTicketAttr) {
  617. that.getTicketDiscountList(goodsBizType);
  618. }
  619. },
  620. hideSwitchTicketPop: function() {
  621. this.setData({
  622. openTicketAttr: false
  623. })
  624. },
  625. /**
  626. * 查看当前用户已领取的且购订单商品所支持的优惠券列表
  627. */
  628. getTicketDiscountList: function(bizType) {
  629. wx.showLoading({
  630. title: '加载中...',
  631. });
  632. let that = this;
  633. util.request(api.DiscountByCheckCartList, {
  634. storeId: wx.getStorageSync('storeId'),
  635. checkCart: that.data.checkCart,
  636. bizType: bizType,
  637. goodsId: that.data.goodsId,
  638. number: that.data.number
  639. }).then(function(res) {
  640. if (res.errno === 0) {
  641. that.setData({
  642. ticketDiscountList: res.data
  643. });
  644. wx.hideLoading();
  645. }
  646. });
  647. },
  648. selectTicket(e) {
  649. let that = this;
  650. let id = e.currentTarget.dataset.ticketId;
  651. let goodsBizType = e.currentTarget.dataset.goodsType;
  652. // console.log(id);
  653. if (id != null) {
  654. if (goodsBizType == '00') {
  655. that.setData({
  656. tickDiscId00: id,
  657. checkTickDiscId: id
  658. });
  659. }
  660. if (goodsBizType == '02') {
  661. that.setData({
  662. tickDiscId02: id,
  663. checkTickDiscId: id
  664. });
  665. }
  666. if (goodsBizType == '10') {
  667. that.setData({
  668. tickDiscId10: id,
  669. checkTickDiscId: id
  670. });
  671. }
  672. if (goodsBizType == '11') {
  673. that.setData({
  674. tickDiscId11: id,
  675. checkTickDiscId: id
  676. });
  677. }
  678. }
  679. },
  680. submitTicket() {
  681. let that = this;
  682. that.setData({
  683. openTicketAttr: false
  684. });
  685. wx.showLoading({
  686. title: '加载中...',
  687. });
  688. util.request(api.CartCheckout, {
  689. tickDiscId00: that.data.tickDiscId00,
  690. tickDiscId02: that.data.tickDiscId02,
  691. tickDiscId10: that.data.tickDiscId10,
  692. tickDiscId11: that.data.tickDiscId11,
  693. campId00: that.data.campId00,
  694. campId02: that.data.campId02,
  695. campId10: that.data.campId10,
  696. campId11: that.data.campId11,
  697. merchSn: wx.getStorageSync('merchSn'),
  698. checkCart: that.data.checkCart,
  699. isLoadStatus: 2, //2代表选择优惠券加载
  700. goodsId: that.data.goodsId,
  701. number: that.data.number
  702. }, 'POST').then(function(res) {
  703. console.log(res.data);
  704. if (res.errno === 0) {
  705. that.setData({
  706. checkedGoodsList: res.data.checkedGoodsList,
  707. actualPrice: res.data.actualPrice,
  708. actualPrice00: res.data.actualPrice00,
  709. actualPrice02: res.data.actualPrice02,
  710. actualPrice10: res.data.actualPrice10,
  711. actualPrice11: res.data.actualPrice11,
  712. checkedCoupon00: res.data.checkedCoupon00,
  713. checkedCoupon02: res.data.checkedCoupon02,
  714. checkedCoupon10: res.data.checkedCoupon10,
  715. checkedCoupon11: res.data.checkedCoupon11,
  716. couponList00: res.data.couponList00,
  717. couponList02: res.data.couponList02,
  718. couponList10: res.data.couponList10,
  719. couponList11: res.data.couponList11,
  720. goodsTotalPrice: res.data.goodsTotalPrice,
  721. orderTotalPrice: res.data.orderTotalPrice,
  722. // fullCutCouponDec: res.data.fullCutCouponDec,
  723. // fullCutCouponId: res.data.fullCutCouponId,
  724. campList00: res.data.campList00,
  725. campList02: res.data.campList02,
  726. campList10: res.data.campList10,
  727. campList11: res.data.campList11,
  728. campMinusDto00: res.data.campMinusDto00,
  729. campMinusDto02: res.data.campMinusDto02,
  730. campMinusDto10: res.data.campMinusDto10,
  731. campMinusDto11: res.data.campMinusDto11,
  732. campId00: res.data.campId00,
  733. campId02: res.data.campId02,
  734. campId10: res.data.campId10,
  735. campId11: res.data.campId11,
  736. tickDiscId00: res.data.tickDiscId00,
  737. tickDiscId02: res.data.tickDiscId02,
  738. tickDiscId10: res.data.tickDiscId10,
  739. tickDiscId11: res.data.tickDiscId11,
  740. isLoadStatus: 2
  741. });
  742. //选择促销
  743. that.setCampMinus();
  744. //选择优惠券
  745. that.setTickDisc();
  746. }
  747. wx.hideLoading();
  748. });
  749. },
  750. selectCamp(e) {
  751. let goodsBizType = e.currentTarget.dataset.goodsType;
  752. let that = this;
  753. // wx.navigateTo({
  754. // url: '/pages/shopping/coupon/coupon',
  755. // })
  756. that.setData({
  757. openCampMinusAttr: !that.data.openCampMinusAttr,
  758. openTicketAttr: false
  759. })
  760. if (that.data.openCampMinusAttr) {
  761. that.getStoreCampMinusList(goodsBizType);
  762. }
  763. },
  764. hideSwitchTicketPop: function() {
  765. this.setData({
  766. openTicketAttr: false,
  767. openCampMinusAttr: false
  768. })
  769. },
  770. /**
  771. * 查看满减满折列表
  772. */
  773. getStoreCampMinusList(goodsBizType) {
  774. wx.showLoading({
  775. title: '加载中...',
  776. });
  777. let that = this;
  778. util.request(api.CampminusByCheckCartList, {
  779. storeId: wx.getStorageSync('storeId'),
  780. checkCart: that.data.checkCart,
  781. bizType: goodsBizType,
  782. goodsId: that.data.goodsId,
  783. number: that.data.number
  784. }).then(function(res) {
  785. if (res.errno === 0) {
  786. that.setData({
  787. storeCampMinusList: res.data
  788. });
  789. wx.hideLoading();
  790. }
  791. });
  792. },
  793. selectUserCamp(e) {
  794. let that = this;
  795. let campId = e.currentTarget.dataset.campId;
  796. let goodsBizType = e.currentTarget.dataset.goodsType;
  797. if (campId != null) {
  798. if (goodsBizType == '00') {
  799. that.setData({
  800. campId00: campId,
  801. checkCampId: campId
  802. });
  803. }
  804. if (goodsBizType == '02') {
  805. that.setData({
  806. campId02: campId,
  807. checkCampId: campId
  808. });
  809. }
  810. if (goodsBizType == '10') {
  811. that.setData({
  812. campId10: campId,
  813. checkCampId: campId
  814. });
  815. }
  816. if (goodsBizType == '11') {
  817. that.setData({
  818. campId11: campId,
  819. checkCampId: campId
  820. });
  821. }
  822. }
  823. },
  824. submitCampMinus() {
  825. let that = this;
  826. that.hideSwitchTicketPop();
  827. wx.showLoading({
  828. title: '加载中...',
  829. });
  830. util.request(api.CartCheckout, {
  831. tickDiscId00: that.data.tickDiscId00,
  832. tickDiscId02: that.data.tickDiscId02,
  833. tickDiscId10: that.data.tickDiscId10,
  834. tickDiscId11: that.data.tickDiscId11,
  835. campId00: that.data.campId00,
  836. campId02: that.data.campId02,
  837. campId10: that.data.campId10,
  838. campId11: that.data.campId11,
  839. merchSn: wx.getStorageSync('merchSn'),
  840. checkCart: that.data.checkCart,
  841. isLoadStatus: 1, //1代表选择促销活动加载
  842. goodsId: that.data.goodsId,
  843. number: that.data.number
  844. }, 'POST').then(function(res) {
  845. console.log(res.data);
  846. if (res.errno === 0) {
  847. that.setData({
  848. checkedGoodsList: res.data.checkedGoodsList,
  849. actualPrice: res.data.actualPrice,
  850. actualPrice00: res.data.actualPrice00,
  851. actualPrice02: res.data.actualPrice02,
  852. actualPrice10: res.data.actualPrice10,
  853. actualPrice11: res.data.actualPrice11,
  854. checkedCoupon00: res.data.checkedCoupon00,
  855. checkedCoupon02: res.data.checkedCoupon02,
  856. checkedCoupon10: res.data.checkedCoupon10,
  857. checkedCoupon11: res.data.checkedCoupon11,
  858. couponList00: res.data.couponList00,
  859. couponList02: res.data.couponList02,
  860. couponList10: res.data.couponList10,
  861. couponList11: res.data.couponList11,
  862. goodsTotalPrice: res.data.goodsTotalPrice,
  863. orderTotalPrice: res.data.orderTotalPrice,
  864. // fullCutCouponDec: res.data.fullCutCouponDec,
  865. // fullCutCouponId: res.data.fullCutCouponId,
  866. campList00: res.data.campList00,
  867. campList02: res.data.campList02,
  868. campList10: res.data.campList10,
  869. campList11: res.data.campList11,
  870. campMinusDto00: res.data.campMinusDto00,
  871. campMinusDto02: res.data.campMinusDto02,
  872. campMinusDto10: res.data.campMinusDto10,
  873. campMinusDto11: res.data.campMinusDto11,
  874. campId00: res.data.campId00,
  875. campId02: res.data.campId02,
  876. campId10: res.data.campId10,
  877. campId11: res.data.campId11,
  878. tickDiscId00: res.data.tickDiscId00,
  879. tickDiscId02: res.data.tickDiscId02,
  880. tickDiscId10: res.data.tickDiscId10,
  881. tickDiscId11: res.data.tickDiscId11,
  882. isLoadStatus: 1
  883. });
  884. //选择促销
  885. that.setCampMinus();
  886. //选择优惠券
  887. that.setTickDisc();
  888. }
  889. wx.hideLoading();
  890. });
  891. },
  892. /**
  893. * 选择促销
  894. */
  895. setCampMinus() {
  896. let that = this;
  897. // console.log(that.data.campMinusDto00);
  898. // console.log(that.data.campList00);
  899. // console.log(that.data.campId00);
  900. if (that.data.campMinusDto00 != null && that.data.campList00 != null && that.data.campList00.length > 0) {
  901. for (var i = 0; i < that.data.campList00.length; i++) {
  902. if (that.data.campId00 == that.data.campList00[i].campMinusId) {
  903. that.setData({
  904. campMinusDto00: that.data.campList00[i],
  905. checkCampId: that.data.campId00
  906. });
  907. break;
  908. }
  909. }
  910. }
  911. if (that.data.campMinusDto02 != null && that.data.campList02 != null && that.data.campList02.length > 0) {
  912. for (var i = 0; i < that.data.campList02.length; i++) {
  913. if (that.data.campId02 == that.data.campList02[i].campMinusId) {
  914. that.setData({
  915. campMinusDto02: that.data.campList02[i],
  916. checkCampId: that.data.campId02
  917. });
  918. break;
  919. }
  920. }
  921. }
  922. if (that.data.campMinusDto10 != null && that.data.campList10 != null && that.data.campList10.length > 0) {
  923. for (var i = 0; i < that.data.campList10.length; i++) {
  924. if (that.data.campId10 == that.data.campList10[i].campMinusId) {
  925. that.setData({
  926. campMinusDto10: that.data.campList10[i],
  927. checkCampId: that.data.campId10
  928. });
  929. break;
  930. }
  931. }
  932. }
  933. if (that.data.campMinusDto11 != null && that.data.campList11 != null && that.data.campList11.length > 0) {
  934. for (var i = 0; i < that.data.campList11.length; i++) {
  935. if (that.data.campId11 == that.data.campList11[i].campMinusId) {
  936. that.setData({
  937. campMinusDto11: that.data.campList11[i],
  938. checkCampId: that.data.campId11
  939. });
  940. break;
  941. }
  942. }
  943. }
  944. },
  945. /**
  946. * 选择优惠券
  947. */
  948. setTickDisc() {
  949. let that = this;
  950. if (that.data.tickDiscId00 != null && that.data.couponList00 != null && that.data.couponList00.length > 0) {
  951. for (var i = 0; i < that.data.couponList00.length; i++) {
  952. if (that.data.tickDiscId00 == that.data.couponList00[i].id) {
  953. that.setData({
  954. checkedCoupon00: that.data.couponList00[i],
  955. checkTickDiscId: that.data.tickDiscId00
  956. });
  957. break;
  958. }
  959. }
  960. }
  961. if (that.data.tickDiscId02 != null && that.data.couponList02 != null && that.data.couponList02.length > 0) {
  962. for (var i = 0; i < that.data.couponList02.length; i++) {
  963. if (that.data.tickDiscId02 == that.data.couponList02[i].id) {
  964. that.setData({
  965. checkedCoupon02: that.data.couponList02[i],
  966. checkTickDiscId: that.data.tickDiscId02
  967. });
  968. break;
  969. }
  970. }
  971. }
  972. if (that.data.tickDiscId10 != null && that.data.couponList10 != null && that.data.couponList10.length > 0) {
  973. for (var i = 0; i < that.data.couponList10.length; i++) {
  974. if (that.data.tickDiscId10 == that.data.couponList10[i].id) {
  975. that.setData({
  976. checkedCoupon10: that.data.couponList10[i],
  977. checkTickDiscId: that.data.tickDiscId10
  978. });
  979. break;
  980. }
  981. }
  982. }
  983. if (that.data.tickDiscId11 != null && that.data.couponList11 != null && that.data.couponList11.length > 0) {
  984. for (var i = 0; i < that.data.couponList11.length; i++) {
  985. if (that.data.tickDiscId11 == that.data.couponList11[i].id) {
  986. that.setData({
  987. checkedCoupon11: that.data.couponList11[i],
  988. checkTickDiscId: that.data.tickDiscId11
  989. });
  990. break;
  991. }
  992. }
  993. }
  994. }
  995. })