1
0

checkout.js 30 KB

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