1
0

checkout.js 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  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{6})\d{6}(\d{3})/, "$1******$2");
  190. } else {
  191. return idcard.replace(/(\d{5})\d{6}(\d{6})/, "$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. }, 'POST').then(function(res) {
  435. if (res.errno === 0) {
  436. let actualPrice = that.data.actualPrice;
  437. let orderIds = [];
  438. for (let i = 0; i < res.data.orderInfo.length; i++) {
  439. orderIds[i] = res.data.orderInfo[i].id;
  440. }
  441. wx.redirectTo({
  442. url: '/pages/pay/pay?orderIds=' + orderIds + '&actualPrice=' + actualPrice + '&isMergePay=1' //此处提交支付属于合并支付
  443. })
  444. } else {
  445. wx.showModal({
  446. title: '提示信息',
  447. content: res.errmsg,
  448. showCancel: false
  449. });
  450. }
  451. wx.hideLoading();
  452. });
  453. } else if (res.cancel) {
  454. console.log('用户点击取消')
  455. }
  456. }
  457. });
  458. },
  459. // 校验门店
  460. checkStore: function() {
  461. let that = this;
  462. util.request(api.CheckStore, {
  463. checkedAddress: that.data.addressVo,
  464. storeId: wx.getStorageSync('storeId')
  465. }, 'POST').then(function(res) {
  466. if (res.errno === 0) {
  467. that.setData({
  468. storeVo: res.data,
  469. checkStore: true
  470. });
  471. } else {
  472. // console.log(res.errmsg);
  473. // util.showErrorToast(res.errmsg);
  474. that.setData({
  475. checkStore: false
  476. });
  477. }
  478. });
  479. },
  480. reLoad: function() {
  481. let that = this;
  482. if (wx.getStorageSync('storeId')) {
  483. if (wx.getStorageSync('userId')) {
  484. wx.request({
  485. url: api.updateLoginUser,
  486. data: {
  487. userId: wx.getStorageSync('userId'),
  488. storeId: wx.getStorageSync('storeId'),
  489. merchSn: wx.getStorageSync('merchSn')
  490. },
  491. method: 'POST',
  492. header: {
  493. 'Content-Type': 'application/json'
  494. },
  495. success: function(wxRes) {
  496. if (wxRes.data.errno === 0) {
  497. // console.log("用户信息更新成功");
  498. }
  499. },
  500. fail: function(err) {
  501. console.log("failed");
  502. }
  503. });
  504. }
  505. }
  506. },
  507. // 校验身份证号
  508. //校验码校验
  509. checkCode: function(val) {
  510. 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]$/;
  511. var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  512. var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
  513. var code = val.substring(17);
  514. if (p.test(val)) {
  515. var sum = 0;
  516. for (var i = 0; i < 17; i++) {
  517. sum += val[i] * factor[i];
  518. }
  519. if (parity[sum % 11] == code.toUpperCase()) {
  520. return true;
  521. }
  522. }
  523. return false;
  524. },
  525. //省份校验
  526. checkProv: function(val) {
  527. var pattern = /^[1-9][0-9]/;
  528. var provs = {
  529. 11: "北京",
  530. 12: "天津",
  531. 13: "河北",
  532. 14: "山西",
  533. 15: "内蒙古",
  534. 21: "辽宁",
  535. 22: "吉林",
  536. 23: "黑龙江 ",
  537. 31: "上海",
  538. 32: "江苏",
  539. 33: "浙江",
  540. 34: "安徽",
  541. 35: "福建",
  542. 36: "江西",
  543. 37: "山东",
  544. 41: "河南",
  545. 42: "湖北 ",
  546. 43: "湖南",
  547. 44: "广东",
  548. 45: "广西",
  549. 46: "海南",
  550. 50: "重庆",
  551. 51: "四川",
  552. 52: "贵州",
  553. 53: "云南",
  554. 54: "西藏 ",
  555. 61: "陕西",
  556. 62: "甘肃",
  557. 63: "青海",
  558. 64: "宁夏",
  559. 65: "新疆",
  560. 71: "台湾",
  561. 81: "香港",
  562. 82: "澳门"
  563. };
  564. if (pattern.test(val)) {
  565. if (provs[val]) {
  566. return true;
  567. }
  568. }
  569. return false;
  570. },
  571. //出生日期码校验
  572. checkDate: function(val) {
  573. var pattern = /^(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)$/;
  574. if (pattern.test(val)) {
  575. var year = val.substring(0, 4);
  576. var month = val.substring(4, 6);
  577. var date = val.substring(6, 8);
  578. var date2 = new Date(year + "-" + month + "-" + date);
  579. if (date2 && date2.getMonth() == (parseInt(month) - 1)) {
  580. return true;
  581. }
  582. }
  583. return false;
  584. },
  585. checkIdcard: function(val) {
  586. if (this.checkCode(val)) {
  587. var date = val.substring(6, 14);
  588. if (this.checkDate(date)) {
  589. if (this.checkProv(val.substring(0, 2))) {
  590. return true;
  591. }
  592. }
  593. }
  594. // this.isError("请输入正确身份证号");
  595. return false;
  596. },
  597. // 通过身份证号获取出生日期和性别
  598. getBirthAndSex: function(idCard) {
  599. var that = this;
  600. var info = {};
  601. var birth = (idCard.length === 18) ? idCard.slice(6, 14) : idCard.slice(6, 12);
  602. var order = (idCard.length === 18) ? idCard.slice(-2, -1) : idCard.slice(-1);
  603. 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('-');
  604. info.sex = (order % 2 === 0 ? 2 : 0);
  605. return info;
  606. },
  607. selectCoupon(e) {
  608. let goodsBizType = e.currentTarget.dataset.goodsType;
  609. let that = this;
  610. // wx.navigateTo({
  611. // url: '/pages/shopping/coupon/coupon',
  612. // })
  613. that.setData({
  614. openTicketAttr: !that.data.openTicketAttr,
  615. openCampMinusAttr: false
  616. })
  617. if (that.data.openTicketAttr) {
  618. that.getTicketDiscountList(goodsBizType);
  619. }
  620. },
  621. hideSwitchTicketPop: function() {
  622. this.setData({
  623. openTicketAttr: false
  624. })
  625. },
  626. /**
  627. * 查看当前用户已领取的且购订单商品所支持的优惠券列表
  628. */
  629. getTicketDiscountList: function(bizType) {
  630. wx.showLoading({
  631. title: '加载中...',
  632. });
  633. let that = this;
  634. util.request(api.DiscountByCheckCartList, {
  635. storeId: wx.getStorageSync('storeId'),
  636. checkCart: that.data.checkCart,
  637. bizType: bizType,
  638. goodsId: that.data.goodsId,
  639. number: that.data.number
  640. }).then(function(res) {
  641. if (res.errno === 0) {
  642. that.setData({
  643. ticketDiscountList: res.data
  644. });
  645. wx.hideLoading();
  646. }
  647. });
  648. },
  649. selectTicket(e) {
  650. let that = this;
  651. let id = e.currentTarget.dataset.ticketId;
  652. let goodsBizType = e.currentTarget.dataset.goodsType;
  653. // console.log(id);
  654. if (id != null) {
  655. if (goodsBizType == '00') {
  656. that.setData({
  657. tickDiscId00: id,
  658. checkTickDiscId: id
  659. });
  660. }
  661. if (goodsBizType == '02') {
  662. that.setData({
  663. tickDiscId02: id,
  664. checkTickDiscId: id
  665. });
  666. }
  667. if (goodsBizType == '10') {
  668. that.setData({
  669. tickDiscId10: id,
  670. checkTickDiscId: id
  671. });
  672. }
  673. if (goodsBizType == '11') {
  674. that.setData({
  675. tickDiscId11: id,
  676. checkTickDiscId: id
  677. });
  678. }
  679. }
  680. },
  681. submitTicket() {
  682. let that = this;
  683. that.setData({
  684. openTicketAttr: false
  685. });
  686. wx.showLoading({
  687. title: '加载中...',
  688. });
  689. util.request(api.CartCheckout, {
  690. tickDiscId00: that.data.tickDiscId00,
  691. tickDiscId02: that.data.tickDiscId02,
  692. tickDiscId10: that.data.tickDiscId10,
  693. tickDiscId11: that.data.tickDiscId11,
  694. campId00: that.data.campId00,
  695. campId02: that.data.campId02,
  696. campId10: that.data.campId10,
  697. campId11: that.data.campId11,
  698. merchSn: wx.getStorageSync('merchSn'),
  699. checkCart: that.data.checkCart,
  700. isLoadStatus: 2, //2代表选择优惠券加载
  701. goodsId: that.data.goodsId,
  702. number: that.data.number
  703. }, 'POST').then(function(res) {
  704. console.log(res.data);
  705. if (res.errno === 0) {
  706. that.setData({
  707. checkedGoodsList: res.data.checkedGoodsList,
  708. actualPrice: res.data.actualPrice,
  709. actualPrice00: res.data.actualPrice00,
  710. actualPrice02: res.data.actualPrice02,
  711. actualPrice10: res.data.actualPrice10,
  712. actualPrice11: res.data.actualPrice11,
  713. checkedCoupon00: res.data.checkedCoupon00,
  714. checkedCoupon02: res.data.checkedCoupon02,
  715. checkedCoupon10: res.data.checkedCoupon10,
  716. checkedCoupon11: res.data.checkedCoupon11,
  717. couponList00: res.data.couponList00,
  718. couponList02: res.data.couponList02,
  719. couponList10: res.data.couponList10,
  720. couponList11: res.data.couponList11,
  721. goodsTotalPrice: res.data.goodsTotalPrice,
  722. orderTotalPrice: res.data.orderTotalPrice,
  723. // fullCutCouponDec: res.data.fullCutCouponDec,
  724. // fullCutCouponId: res.data.fullCutCouponId,
  725. campList00: res.data.campList00,
  726. campList02: res.data.campList02,
  727. campList10: res.data.campList10,
  728. campList11: res.data.campList11,
  729. campMinusDto00: res.data.campMinusDto00,
  730. campMinusDto02: res.data.campMinusDto02,
  731. campMinusDto10: res.data.campMinusDto10,
  732. campMinusDto11: res.data.campMinusDto11,
  733. campId00: res.data.campId00,
  734. campId02: res.data.campId02,
  735. campId10: res.data.campId10,
  736. campId11: res.data.campId11,
  737. tickDiscId00: res.data.tickDiscId00,
  738. tickDiscId02: res.data.tickDiscId02,
  739. tickDiscId10: res.data.tickDiscId10,
  740. tickDiscId11: res.data.tickDiscId11,
  741. isLoadStatus: 2
  742. });
  743. //选择促销
  744. that.setCampMinus();
  745. //选择优惠券
  746. that.setTickDisc();
  747. }
  748. wx.hideLoading();
  749. });
  750. },
  751. selectCamp(e) {
  752. let goodsBizType = e.currentTarget.dataset.goodsType;
  753. let that = this;
  754. // wx.navigateTo({
  755. // url: '/pages/shopping/coupon/coupon',
  756. // })
  757. that.setData({
  758. openCampMinusAttr: !that.data.openCampMinusAttr,
  759. openTicketAttr: false
  760. })
  761. if (that.data.openCampMinusAttr) {
  762. that.getStoreCampMinusList(goodsBizType);
  763. }
  764. },
  765. hideSwitchTicketPop: function() {
  766. this.setData({
  767. openTicketAttr: false,
  768. openCampMinusAttr: false
  769. })
  770. },
  771. /**
  772. * 查看满减满折列表
  773. */
  774. getStoreCampMinusList(goodsBizType) {
  775. wx.showLoading({
  776. title: '加载中...',
  777. });
  778. let that = this;
  779. util.request(api.CampminusByCheckCartList, {
  780. storeId: wx.getStorageSync('storeId'),
  781. checkCart: that.data.checkCart,
  782. bizType: goodsBizType,
  783. goodsId: that.data.goodsId,
  784. number: that.data.number
  785. }).then(function(res) {
  786. if (res.errno === 0) {
  787. that.setData({
  788. storeCampMinusList: res.data
  789. });
  790. wx.hideLoading();
  791. }
  792. });
  793. },
  794. selectUserCamp(e) {
  795. let that = this;
  796. let campId = e.currentTarget.dataset.campId;
  797. let goodsBizType = e.currentTarget.dataset.goodsType;
  798. if (campId != null) {
  799. if (goodsBizType == '00') {
  800. that.setData({
  801. campId00: campId,
  802. checkCampId: campId
  803. });
  804. }
  805. if (goodsBizType == '02') {
  806. that.setData({
  807. campId02: campId,
  808. checkCampId: campId
  809. });
  810. }
  811. if (goodsBizType == '10') {
  812. that.setData({
  813. campId10: campId,
  814. checkCampId: campId
  815. });
  816. }
  817. if (goodsBizType == '11') {
  818. that.setData({
  819. campId11: campId,
  820. checkCampId: campId
  821. });
  822. }
  823. }
  824. },
  825. submitCampMinus() {
  826. let that = this;
  827. that.hideSwitchTicketPop();
  828. wx.showLoading({
  829. title: '加载中...',
  830. });
  831. util.request(api.CartCheckout, {
  832. tickDiscId00: that.data.tickDiscId00,
  833. tickDiscId02: that.data.tickDiscId02,
  834. tickDiscId10: that.data.tickDiscId10,
  835. tickDiscId11: that.data.tickDiscId11,
  836. campId00: that.data.campId00,
  837. campId02: that.data.campId02,
  838. campId10: that.data.campId10,
  839. campId11: that.data.campId11,
  840. merchSn: wx.getStorageSync('merchSn'),
  841. checkCart: that.data.checkCart,
  842. isLoadStatus: 1, //1代表选择促销活动加载
  843. goodsId: that.data.goodsId,
  844. number: that.data.number
  845. }, 'POST').then(function(res) {
  846. console.log(res.data);
  847. if (res.errno === 0) {
  848. that.setData({
  849. checkedGoodsList: res.data.checkedGoodsList,
  850. actualPrice: res.data.actualPrice,
  851. actualPrice00: res.data.actualPrice00,
  852. actualPrice02: res.data.actualPrice02,
  853. actualPrice10: res.data.actualPrice10,
  854. actualPrice11: res.data.actualPrice11,
  855. checkedCoupon00: res.data.checkedCoupon00,
  856. checkedCoupon02: res.data.checkedCoupon02,
  857. checkedCoupon10: res.data.checkedCoupon10,
  858. checkedCoupon11: res.data.checkedCoupon11,
  859. couponList00: res.data.couponList00,
  860. couponList02: res.data.couponList02,
  861. couponList10: res.data.couponList10,
  862. couponList11: res.data.couponList11,
  863. goodsTotalPrice: res.data.goodsTotalPrice,
  864. orderTotalPrice: res.data.orderTotalPrice,
  865. // fullCutCouponDec: res.data.fullCutCouponDec,
  866. // fullCutCouponId: res.data.fullCutCouponId,
  867. campList00: res.data.campList00,
  868. campList02: res.data.campList02,
  869. campList10: res.data.campList10,
  870. campList11: res.data.campList11,
  871. campMinusDto00: res.data.campMinusDto00,
  872. campMinusDto02: res.data.campMinusDto02,
  873. campMinusDto10: res.data.campMinusDto10,
  874. campMinusDto11: res.data.campMinusDto11,
  875. campId00: res.data.campId00,
  876. campId02: res.data.campId02,
  877. campId10: res.data.campId10,
  878. campId11: res.data.campId11,
  879. tickDiscId00: res.data.tickDiscId00,
  880. tickDiscId02: res.data.tickDiscId02,
  881. tickDiscId10: res.data.tickDiscId10,
  882. tickDiscId11: res.data.tickDiscId11,
  883. isLoadStatus: 1
  884. });
  885. //选择促销
  886. that.setCampMinus();
  887. //选择优惠券
  888. that.setTickDisc();
  889. }
  890. wx.hideLoading();
  891. });
  892. },
  893. /**
  894. * 选择促销
  895. */
  896. setCampMinus() {
  897. let that = this;
  898. // console.log(that.data.campMinusDto00);
  899. // console.log(that.data.campList00);
  900. // console.log(that.data.campId00);
  901. if (that.data.campMinusDto00 != null && that.data.campList00 != null && that.data.campList00.length > 0) {
  902. for (var i = 0; i < that.data.campList00.length; i++) {
  903. if (that.data.campId00 == that.data.campList00[i].campMinusId) {
  904. that.setData({
  905. campMinusDto00: that.data.campList00[i],
  906. checkCampId: that.data.campId00
  907. });
  908. break;
  909. }
  910. }
  911. }
  912. if (that.data.campMinusDto02 != null && that.data.campList02 != null && that.data.campList02.length > 0) {
  913. for (var i = 0; i < that.data.campList02.length; i++) {
  914. if (that.data.campId02 == that.data.campList02[i].campMinusId) {
  915. that.setData({
  916. campMinusDto02: that.data.campList02[i],
  917. checkCampId: that.data.campId02
  918. });
  919. break;
  920. }
  921. }
  922. }
  923. if (that.data.campMinusDto10 != null && that.data.campList10 != null && that.data.campList10.length > 0) {
  924. for (var i = 0; i < that.data.campList10.length; i++) {
  925. if (that.data.campId10 == that.data.campList10[i].campMinusId) {
  926. that.setData({
  927. campMinusDto10: that.data.campList10[i],
  928. checkCampId: that.data.campId10
  929. });
  930. break;
  931. }
  932. }
  933. }
  934. if (that.data.campMinusDto11 != null && that.data.campList11 != null && that.data.campList11.length > 0) {
  935. for (var i = 0; i < that.data.campList11.length; i++) {
  936. if (that.data.campId11 == that.data.campList11[i].campMinusId) {
  937. that.setData({
  938. campMinusDto11: that.data.campList11[i],
  939. checkCampId: that.data.campId11
  940. });
  941. break;
  942. }
  943. }
  944. }
  945. },
  946. /**
  947. * 选择优惠券
  948. */
  949. setTickDisc() {
  950. let that = this;
  951. if (that.data.tickDiscId00 != null && that.data.couponList00 != null && that.data.couponList00.length > 0) {
  952. for (var i = 0; i < that.data.couponList00.length; i++) {
  953. if (that.data.tickDiscId00 == that.data.couponList00[i].id) {
  954. that.setData({
  955. checkedCoupon00: that.data.couponList00[i],
  956. checkTickDiscId: that.data.tickDiscId00
  957. });
  958. break;
  959. }
  960. }
  961. }
  962. if (that.data.tickDiscId02 != null && that.data.couponList02 != null && that.data.couponList02.length > 0) {
  963. for (var i = 0; i < that.data.couponList02.length; i++) {
  964. if (that.data.tickDiscId02 == that.data.couponList02[i].id) {
  965. that.setData({
  966. checkedCoupon02: that.data.couponList02[i],
  967. checkTickDiscId: that.data.tickDiscId02
  968. });
  969. break;
  970. }
  971. }
  972. }
  973. if (that.data.tickDiscId10 != null && that.data.couponList10 != null && that.data.couponList10.length > 0) {
  974. for (var i = 0; i < that.data.couponList10.length; i++) {
  975. if (that.data.tickDiscId10 == that.data.couponList10[i].id) {
  976. that.setData({
  977. checkedCoupon10: that.data.couponList10[i],
  978. checkTickDiscId: that.data.tickDiscId10
  979. });
  980. break;
  981. }
  982. }
  983. }
  984. if (that.data.tickDiscId11 != null && that.data.couponList11 != null && that.data.couponList11.length > 0) {
  985. for (var i = 0; i < that.data.couponList11.length; i++) {
  986. if (that.data.tickDiscId11 == that.data.couponList11[i].id) {
  987. that.setData({
  988. checkedCoupon11: that.data.couponList11[i],
  989. checkTickDiscId: that.data.tickDiscId11
  990. });
  991. break;
  992. }
  993. }
  994. }
  995. }
  996. })