1
0

checkout.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. },
  65. bindMultiPickerColumnChange: function(e) {
  66. let that = this;
  67. // console.log('修改的列为', e.detail.column, ',值为', e.detail.value);
  68. var data = {
  69. multiArray: this.data.multiArray,
  70. multiIndex: this.data.multiIndex
  71. };
  72. data.multiIndex[e.detail.column] = e.detail.value
  73. if (e.detail.column == 0) {
  74. data.multiIndex[1] = 0
  75. }
  76. let timeArray = that.data.timeArray;
  77. if (data.multiIndex[0] == 1) {
  78. timeArray = util.timeArray.slice(0);
  79. } else {
  80. timeArray = util.getNowTimeArray();
  81. }
  82. data.timeArray = timeArray;
  83. data.multiArray[1] = timeArray;
  84. this.setData(data)
  85. },
  86. bindMultiPickerChange: function(e) {
  87. let that = this;
  88. console.log('picker发送选择改变,携带值为', e.detail.value)
  89. this.setData({
  90. multiIndex: e.detail.value,
  91. delivery_date: dateArray[e.detail.value[0]],
  92. delivery_remark: e.detail.value[0] == 0 ? that.data.timeArray[e.detail.value[1]] : that.data.timeArray[e.detail.value[1]]
  93. })
  94. console.log('delivery_date', this.data.delivery_date, ',delivery_remark', this.data.delivery_remark)
  95. },
  96. initPicker() {
  97. let that = this;
  98. let date = new Date();
  99. let hours = date.getHours();
  100. let minutes = date.getMinutes();
  101. let index = 0;
  102. var today = util.getNowTime();
  103. var tomorrow = util.getDateStr(new Date(), 1);
  104. dateArray = [today, tomorrow];
  105. this.setData({
  106. 'multiArray[0]': dateArray,
  107. 'multiArray[1]': that.data.timeArray,
  108. })
  109. },
  110. formatidcard(idcard) {
  111. if (idcard.length == 15) {
  112. return idcard.replace(/(\d{6})\d{6}(\d{3})/, "$1******$2");
  113. } else {
  114. return idcard.replace(/(\d{5})\d{6}(\d{6})/, "$1******$2");
  115. }
  116. },
  117. getCheckoutInfo: function() {
  118. let that = this;
  119. util.request(api.CartCheckout, {
  120. tickDiscId00: that.data.tickDiscId00,
  121. tickDiscId02: that.data.tickDiscId02,
  122. tickDiscId10: that.data.tickDiscId10,
  123. tickDiscId11: that.data.tickDiscId11,
  124. merchSn: wx.getStorageSync('merchSn'),
  125. checkCart: that.data.checkCart
  126. }).then(function(res) {
  127. if (res.errno === 0) {
  128. console.log(res.data);
  129. that.setData({
  130. checkedGoodsList: res.data.checkedGoodsList,
  131. actualPrice: res.data.actualPrice,
  132. actualPrice00: res.data.actualPrice00,
  133. actualPrice02: res.data.actualPrice02,
  134. actualPrice10: res.data.actualPrice10,
  135. actualPrice11: res.data.actualPrice11,
  136. addressVo: res.data.addressVo,
  137. checkedCoupon00: res.data.checkedCoupon00,
  138. checkedCoupon02: res.data.checkedCoupon02,
  139. checkedCoupon10: res.data.checkedCoupon10,
  140. checkedCoupon11: res.data.checkedCoupon11,
  141. couponList00: res.data.couponList00,
  142. couponList02: res.data.couponList02,
  143. couponList10: res.data.couponList10,
  144. couponList11: res.data.couponList11,
  145. fullCutCouponId: res.data.fullCutCouponId,
  146. couponPrice: res.data.couponPrice,
  147. freightPrice00: res.data.freightPrice00,
  148. freightPrice02: res.data.freightPrice02,
  149. freightPrice10: res.data.freightPrice10,
  150. freightPrice11: res.data.freightPrice11,
  151. goodsTotalPrice: res.data.goodsTotalPrice,
  152. orderTotalPrice: res.data.orderTotalPrice,
  153. fullCutCouponDec: res.data.fullCutCouponDec,
  154. userName: res.data.userName,
  155. idNo: res.data.idNo
  156. });
  157. if (that.data.idNo) {
  158. that.setData({
  159. idNoM: that.formatidcard(that.data.idNo)
  160. });
  161. }
  162. if (that.data.idNo) {
  163. that.setData({
  164. idNoDisabled: true
  165. });
  166. }
  167. let num00 = 0;
  168. let num02 = 0;
  169. let num10 = 0;
  170. let num11 = 0;
  171. let goodsTotalPrice00 = 0;
  172. let goodsTotalPrice02 = 0;
  173. let goodsTotalPrice10 = 0;
  174. let goodsTotalPrice11 = 0;
  175. for (var i = 0; i < that.data.checkedGoodsList.length; i++) {
  176. if ('00' == that.data.checkedGoodsList[i].goodsBizType) {
  177. num00 = num00 + that.data.checkedGoodsList[i].number;
  178. goodsTotalPrice00 = goodsTotalPrice00 +
  179. (that.data.checkedGoodsList[i].retail_price * that.data.checkedGoodsList[i].number);
  180. }
  181. if ('02' == that.data.checkedGoodsList[i].goodsBizType) {
  182. num02 = num02 + that.data.checkedGoodsList[i].number;
  183. goodsTotalPrice02 = goodsTotalPrice02 +
  184. (that.data.checkedGoodsList[i].retail_price * that.data.checkedGoodsList[i].number);
  185. }
  186. if ('10' == that.data.checkedGoodsList[i].goodsBizType) {
  187. num10 = num10 + that.data.checkedGoodsList[i].number;
  188. goodsTotalPrice10 = goodsTotalPrice10 +
  189. (that.data.checkedGoodsList[i].retail_price * that.data.checkedGoodsList[i].number);
  190. }
  191. if ('11' == that.data.checkedGoodsList[i].goodsBizType) {
  192. num11 = num11 + that.data.checkedGoodsList[i].number;
  193. goodsTotalPrice11 = goodsTotalPrice11 +
  194. (that.data.checkedGoodsList[i].retail_price * that.data.checkedGoodsList[i].number);
  195. }
  196. }
  197. that.setData({
  198. goodsTotalByType00: num00,
  199. goodsTotalByType02: num02,
  200. goodsTotalByType10: num10,
  201. goodsTotalByType11: num11,
  202. goodsTotalPrice00: (goodsTotalPrice00 + that.data.freightPrice00).toFixed(2),
  203. goodsTotalPrice02: (goodsTotalPrice02 + that.data.freightPrice02).toFixed(2),
  204. goodsTotalPrice10: (goodsTotalPrice10 + that.data.freightPrice10).toFixed(2),
  205. goodsTotalPrice11: (goodsTotalPrice11 + that.data.freightPrice11).toFixed(2)
  206. });
  207. // console.log(that.data.goodsTotalByType00);
  208. // console.log(that.data.goodsTotalByType02);
  209. // console.log(that.data.goodsTotalByType10);
  210. // console.log(that.data.goodsTotalByType11);
  211. // 选择优惠券
  212. if (that.data.tickDiscId00 && that.data.couponList00.length > 0) {
  213. for (var i = 0; i < that.data.couponList00.length; i++) {
  214. if (that.data.tickDiscId00 == that.data.couponList00[i].id) {
  215. that.setData({
  216. checkedCoupon00: that.data.couponList00[i]
  217. });
  218. break;
  219. }
  220. }
  221. }
  222. if (that.data.tickDiscId02 && that.data.couponList02.length > 0) {
  223. for (var i = 0; i < that.data.couponList02.length; i++) {
  224. if (that.data.tickDiscId02 == that.data.couponList02[i].id) {
  225. that.setData({
  226. checkedCoupon02: that.data.couponList02[i]
  227. });
  228. break;
  229. }
  230. }
  231. }
  232. if (that.data.tickDiscId10 && that.data.couponList10.length > 0) {
  233. for (var i = 0; i < that.data.couponList10.length; i++) {
  234. if (that.data.tickDiscId10 == that.data.couponList10[i].id) {
  235. that.setData({
  236. checkedCoupon10: that.data.couponList10[i]
  237. });
  238. break;
  239. }
  240. }
  241. }
  242. if (that.data.tickDiscId11 && that.data.couponList11.length > 0) {
  243. for (var i = 0; i < that.data.couponList11.length; i++) {
  244. if (that.data.tickDiscId11 == that.data.couponList11[i].id) {
  245. that.setData({
  246. checkedCoupon11: that.data.couponList11[i]
  247. });
  248. break;
  249. }
  250. }
  251. }
  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. }, 'POST').then(function(res) {
  357. if (res.errno === 0) {
  358. let actualPrice = that.data.actualPrice;
  359. let orderIds = [];
  360. for (let i = 0; i < res.data.orderInfo.length; i++) {
  361. orderIds[i] = res.data.orderInfo[i].id;
  362. }
  363. wx.redirectTo({
  364. url: '/pages/pay/pay?orderIds=' + orderIds + '&actualPrice=' + actualPrice + '&isMergePay=1' //此处提交支付属于合并支付
  365. })
  366. } else {
  367. wx.showModal({
  368. title: '提示信息',
  369. content: res.errmsg,
  370. showCancel: false
  371. });
  372. }
  373. wx.hideLoading();
  374. });
  375. },
  376. // 校验门店
  377. checkStore: function() {
  378. let that = this;
  379. util.request(api.CheckStore, {
  380. checkedAddress: that.data.addressVo,
  381. storeId: wx.getStorageSync('storeId')
  382. }, 'POST').then(function(res) {
  383. if (res.errno === 0) {
  384. that.setData({
  385. storeVo: res.data,
  386. checkStore: true
  387. });
  388. } else {
  389. // console.log(res.errmsg);
  390. // util.showErrorToast(res.errmsg);
  391. that.setData({
  392. checkStore: false
  393. });
  394. }
  395. });
  396. },
  397. onLoad: function(options) {
  398. // 页面初始化 options为页面跳转所带来的参数
  399. // console.log(options.checkCart);
  400. this.setData({
  401. checkCart: options.checkCart
  402. });
  403. },
  404. onReady: function() {
  405. // 页面渲染完成
  406. },
  407. onShow: function() {
  408. let that = this;
  409. // 页面显示
  410. wx.showLoading({
  411. title: '加载中...',
  412. })
  413. if (wx.getStorageSync('userInfo') || wx.getStorageSync('token')) {
  414. if (wx.getStorageSync('storeId')) {
  415. util.request(api.ChooseStoreId, {
  416. storeId: wx.getStorageSync('storeId'),
  417. merchSn: wx.getStorageSync('merchSn')
  418. }, 'POST').then(function(res) {
  419. if (res.errno === 0) {
  420. wx.setStorageSync('storeId', wx.getStorageSync('storeId'));
  421. wx.setStorageSync('merchSn', wx.getStorageSync('merchSn'));
  422. that.reLoad();
  423. }
  424. });
  425. that.getCheckoutInfo();
  426. that.initPicker()
  427. }
  428. } else {
  429. wx.navigateTo({
  430. url: '/pages/auth/btnAuth/btnAuth',
  431. })
  432. }
  433. },
  434. onHide: function() {
  435. // 页面隐藏
  436. },
  437. onUnload: function() {
  438. // 页面关闭
  439. },
  440. reLoad: function() {
  441. let that = this;
  442. if (wx.getStorageSync('storeId')) {
  443. if (wx.getStorageSync('userId')) {
  444. wx.request({
  445. url: api.updateLoginUser,
  446. data: {
  447. userId: wx.getStorageSync('userId'),
  448. storeId: wx.getStorageSync('storeId'),
  449. merchSn: wx.getStorageSync('merchSn')
  450. },
  451. method: 'POST',
  452. header: {
  453. 'Content-Type': 'application/json'
  454. },
  455. success: function(wxRes) {
  456. if (wxRes.data.errno === 0) {
  457. // console.log("用户信息更新成功");
  458. }
  459. },
  460. fail: function(err) {
  461. console.log("failed");
  462. }
  463. });
  464. }
  465. }
  466. },
  467. // 校验身份证号
  468. //校验码校验
  469. checkCode: function(val) {
  470. 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]$/;
  471. var factor = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
  472. var parity = [1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2];
  473. var code = val.substring(17);
  474. if (p.test(val)) {
  475. var sum = 0;
  476. for (var i = 0; i < 17; i++) {
  477. sum += val[i] * factor[i];
  478. }
  479. if (parity[sum % 11] == code.toUpperCase()) {
  480. return true;
  481. }
  482. }
  483. return false;
  484. },
  485. //省份校验
  486. checkProv: function(val) {
  487. var pattern = /^[1-9][0-9]/;
  488. var provs = {
  489. 11: "北京",
  490. 12: "天津",
  491. 13: "河北",
  492. 14: "山西",
  493. 15: "内蒙古",
  494. 21: "辽宁",
  495. 22: "吉林",
  496. 23: "黑龙江 ",
  497. 31: "上海",
  498. 32: "江苏",
  499. 33: "浙江",
  500. 34: "安徽",
  501. 35: "福建",
  502. 36: "江西",
  503. 37: "山东",
  504. 41: "河南",
  505. 42: "湖北 ",
  506. 43: "湖南",
  507. 44: "广东",
  508. 45: "广西",
  509. 46: "海南",
  510. 50: "重庆",
  511. 51: "四川",
  512. 52: "贵州",
  513. 53: "云南",
  514. 54: "西藏 ",
  515. 61: "陕西",
  516. 62: "甘肃",
  517. 63: "青海",
  518. 64: "宁夏",
  519. 65: "新疆",
  520. 71: "台湾",
  521. 81: "香港",
  522. 82: "澳门"
  523. };
  524. if (pattern.test(val)) {
  525. if (provs[val]) {
  526. return true;
  527. }
  528. }
  529. return false;
  530. },
  531. //出生日期码校验
  532. checkDate: function(val) {
  533. var pattern = /^(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)$/;
  534. if (pattern.test(val)) {
  535. var year = val.substring(0, 4);
  536. var month = val.substring(4, 6);
  537. var date = val.substring(6, 8);
  538. var date2 = new Date(year + "-" + month + "-" + date);
  539. if (date2 && date2.getMonth() == (parseInt(month) - 1)) {
  540. return true;
  541. }
  542. }
  543. return false;
  544. },
  545. checkIdcard: function(val) {
  546. if (this.checkCode(val)) {
  547. var date = val.substring(6, 14);
  548. if (this.checkDate(date)) {
  549. if (this.checkProv(val.substring(0, 2))) {
  550. return true;
  551. }
  552. }
  553. }
  554. // this.isError("请输入正确身份证号");
  555. return false;
  556. },
  557. // 通过身份证号获取出生日期和性别
  558. getBirthAndSex: function(idCard) {
  559. var that = this;
  560. var info = {};
  561. var birth = (idCard.length === 18) ? idCard.slice(6, 14) : idCard.slice(6, 12);
  562. var order = (idCard.length === 18) ? idCard.slice(-2, -1) : idCard.slice(-1);
  563. 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('-');
  564. info.sex = (order % 2 === 0 ? 2 : 0);
  565. return info;
  566. },
  567. selectCoupon(e) {
  568. let goodsBizType = e.currentTarget.dataset.goodsType;
  569. let that = this;
  570. // wx.navigateTo({
  571. // url: '/pages/shopping/coupon/coupon',
  572. // })
  573. that.setData({
  574. openTicketAttr: !that.data.openTicketAttr
  575. })
  576. if (that.data.openTicketAttr) {
  577. that.getTicketDiscountList(goodsBizType);
  578. }
  579. },
  580. hideSwitchTicketPop: function() {
  581. this.setData({
  582. openTicketAttr: false
  583. })
  584. },
  585. /**
  586. * 查看当前用户已领取的且购订单商品所支持的优惠券列表
  587. */
  588. getTicketDiscountList: function(bizType) {
  589. wx.showLoading({
  590. title: '加载中...',
  591. });
  592. let that = this;
  593. util.request(api.DiscountByCheckCartList, {
  594. storeId: wx.getStorageSync('storeId'),
  595. checkCart: that.data.checkCart,
  596. bizType: bizType
  597. }).then(function(res) {
  598. if (res.errno === 0) {
  599. that.setData({
  600. ticketDiscountList: res.data
  601. });
  602. wx.hideLoading();
  603. }
  604. });
  605. },
  606. selectTicket(e) {
  607. let that = this;
  608. let id = e.currentTarget.dataset.ticketId;
  609. let goodsBizType = e.currentTarget.dataset.goodsType;
  610. // console.log(id);
  611. if (id) {
  612. if (goodsBizType == '00') {
  613. that.setData({
  614. tickDiscId00: id,
  615. checkTickDiscId: id
  616. });
  617. }
  618. if (goodsBizType == '02') {
  619. that.setData({
  620. tickDiscId02: id,
  621. checkTickDiscId: id
  622. });
  623. }
  624. if (goodsBizType == '10') {
  625. that.setData({
  626. tickDiscId10: id,
  627. checkTickDiscId: id
  628. });
  629. }
  630. if (goodsBizType == '11') {
  631. that.setData({
  632. tickDiscId11: id,
  633. checkTickDiscId: id
  634. });
  635. }
  636. }
  637. },
  638. submitTicket() {
  639. let that = this;
  640. that.setData({
  641. openTicketAttr: false
  642. });
  643. wx.showLoading({
  644. title: '加载中...',
  645. });
  646. util.request(api.CartCheckout, {
  647. tickDiscId00: that.data.tickDiscId00,
  648. tickDiscId02: that.data.tickDiscId02,
  649. tickDiscId10: that.data.tickDiscId10,
  650. tickDiscId11: that.data.tickDiscId11,
  651. merchSn: wx.getStorageSync('merchSn'),
  652. checkCart: that.data.checkCart
  653. }).then(function(res) {
  654. if (res.errno === 0) {
  655. that.setData({
  656. actualPrice: res.data.actualPrice,
  657. actualPrice00: res.data.actualPrice00,
  658. actualPrice02: res.data.actualPrice02,
  659. actualPrice10: res.data.actualPrice10,
  660. actualPrice11: res.data.actualPrice11,
  661. checkedCoupon00: res.data.checkedCoupon00,
  662. checkedCoupon02: res.data.checkedCoupon02,
  663. checkedCoupon10: res.data.checkedCoupon10,
  664. checkedCoupon11: res.data.checkedCoupon11,
  665. couponList00: res.data.couponList00,
  666. couponList02: res.data.couponList02,
  667. couponList10: res.data.couponList10,
  668. couponList11: res.data.couponList11,
  669. goodsTotalPrice: res.data.goodsTotalPrice,
  670. orderTotalPrice: res.data.orderTotalPrice,
  671. fullCutCouponDec: res.data.fullCutCouponDec,
  672. fullCutCouponId: res.data.fullCutCouponId,
  673. });
  674. // 选择优惠券
  675. if (that.data.tickDiscId00 && that.data.couponList00.length > 0) {
  676. for (var i = 0; i < that.data.couponList00.length; i++) {
  677. if (that.data.tickDiscId00 == that.data.couponList00[i].id) {
  678. that.setData({
  679. checkedCoupon00: that.data.couponList00[i]
  680. });
  681. break;
  682. }
  683. }
  684. }
  685. if (that.data.tickDiscId02 && that.data.couponList02.length > 0) {
  686. for (var i = 0; i < that.data.couponList02.length; i++) {
  687. if (that.data.tickDiscId02 == that.data.couponList02[i].id) {
  688. that.setData({
  689. checkedCoupon02: that.data.couponList02[i]
  690. });
  691. break;
  692. }
  693. }
  694. }
  695. if (that.data.tickDiscId10 && that.data.couponList10.length > 0) {
  696. for (var i = 0; i < that.data.couponList10.length; i++) {
  697. if (that.data.tickDiscId10 == that.data.couponList10[i].id) {
  698. that.setData({
  699. checkedCoupon10: that.data.couponList10[i]
  700. });
  701. break;
  702. }
  703. }
  704. }
  705. if (that.data.tickDiscId11 && that.data.couponList11.length > 0) {
  706. for (var i = 0; i < that.data.couponList11.length; i++) {
  707. if (that.data.tickDiscId11 == that.data.couponList11[i].id) {
  708. that.setData({
  709. checkedCoupon11: that.data.couponList11[i]
  710. });
  711. break;
  712. }
  713. }
  714. }
  715. }
  716. wx.hideLoading();
  717. });
  718. }
  719. })