1
0

checkout.js 31 KB

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