checkout.js 33 KB

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