goodsOrderConfirm.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. // pages/goodsOrderConfirm/goodsOrderConfirm.js
  2. import {
  3. get,
  4. post
  5. } from '../../utils/http'
  6. const app = getApp()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. selectMakeupList: [], //商品列表
  13. couponList: [], //优惠券列表
  14. selectCouponList: [], //选中的优惠券
  15. showMoneyGood: 0, //原价
  16. selectCouponPrice: 0, //券后价格
  17. couponPrice: 0, //总优惠券金额
  18. inserllAmount: 0,
  19. pay_methon: 1,
  20. store_name: "",
  21. storeId: wx.getStorageSync('store_id'),
  22. page: 1,
  23. limit: 20,
  24. visible: false,
  25. payNow: false,
  26. currentCoupon: -1,
  27. coupon_id: '',
  28. orderId: '',
  29. projectData: null, // 跳转商品数据
  30. productId: null, // 产品id
  31. isShow: null, // 产品详情订单标识
  32. source: '', // 产品类型
  33. isDirectOrder: false, //直接下单
  34. listNum: 0, //订单产品总数
  35. discountList: [], //折扣列表
  36. discountSet: 0, //折扣扣除金额
  37. discount_total: 0, //折扣后总金额
  38. discount_id: '', //折扣id
  39. goods_ids: [], //商品id
  40. type: '', //直接购买还是购物车跳转
  41. CardDiscount: '', //次卡购买获取美妆折扣
  42. exchangeList: [], //加购产品列表
  43. exchangePrice: '', //选中加购产品后的价格
  44. exchangeSelect: false, //是否选中加购产品
  45. exchangeInfo: '', //需要加购多少商品的价格信息
  46. toExchangePrice: 0, //选中加购产品的总价格
  47. exchangeCondition: '', //加购规则
  48. exchangeSum: 0, //加购总次数
  49. level: '', //用户充值折扣等级 (0是未拥有等级)
  50. levelPrice: '', //充值等级折扣优惠价格
  51. toLevelPrice: '', //充值折扣扣除金额
  52. notSalePrice: 0, //不是秒杀产品的总价
  53. salePrice: 0, //秒杀产品总价
  54. meet_discount: 0, //满足什么折扣 0无折扣 1品牌 2充值余额折扣
  55. exchangePop: true, //加购弹窗
  56. exchangeCountDown: 5, //加购弹窗倒计时
  57. timer: null, //倒计时器
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad(options) {
  63. console.log(options.goods_ids);
  64. let isDirectOrder = false
  65. if (options.isDirectOrder) {
  66. isDirectOrder = true
  67. }
  68. // 获取跳转过来商品的id
  69. this.setData({
  70. goods_ids: options.goods_ids,
  71. type: options.type,
  72. productId: options.productId,
  73. isShow: options.isShow,
  74. source: options.source,
  75. isDirectOrder: isDirectOrder,
  76. })
  77. if (this.data.isShow) {
  78. this.getProductInfo()
  79. } else {
  80. return
  81. }
  82. // 弹窗倒计时
  83. this.countDown()
  84. },
  85. /**
  86. * 生命周期函数--监听页面初次渲染完成
  87. */
  88. onReady() {
  89. if (this.data.isDirectOrder) {
  90. this.onConfirm()
  91. } else {
  92. this.needAddGood()
  93. }
  94. },
  95. /**
  96. * 生命周期函数--监听页面显示
  97. */
  98. onShow() {
  99. this.setData({
  100. storeId: wx.getStorageSync('store_id'),
  101. })
  102. },
  103. // 加购弹窗倒计时
  104. countDown: function () {
  105. let that = this;
  106. let exchangeCountDown = that.data.exchangeCountDown; //获取倒计时初始值
  107. that.setData({
  108. timer: setInterval(function () {
  109. exchangeCountDown--;
  110. that.setData({
  111. exchangeCountDown: exchangeCountDown
  112. })
  113. if (exchangeCountDown == 0) {
  114. clearInterval(that.data.timer);
  115. that.setData({
  116. exchangePop: false
  117. })
  118. }
  119. }, 1000)
  120. })
  121. },
  122. // 计算品牌折扣 和 充值折扣中的最优折扣
  123. calculateDiscount() {
  124. // 如果充值等级为0折扣金额也为0
  125. if (this.data.level == 0) {
  126. this.setData({
  127. toLevelPrice: 0
  128. })
  129. }
  130. console.log(this.data.discountSet, this.data.toLevelPrice, 33333);
  131. if (this.data.discountSet == 0 && this.data.toLevelPrice == 0) {
  132. this.setData({
  133. meet_discount: 0
  134. })
  135. return
  136. }
  137. // 如果品牌折扣优惠大就用品牌
  138. if (Number(this.data.discountSet) > Number(this.data.toLevelPrice) || Number(this.data.discountSet) == Number(this.data.toLevelPrice)) {
  139. this.setData({
  140. level: 0,
  141. meet_discount: 1
  142. })
  143. } else {
  144. this.setData({
  145. ['discountList.discount_money']: 0,
  146. meet_discount: 2
  147. })
  148. }
  149. },
  150. // 获取用户充值折扣等级
  151. getLevel(sale) {
  152. console.log(sale);
  153. get('/v2/api/user/discount_level', {}, (res) => {
  154. if (res.code == 200) {
  155. res.data = Number(res.data)
  156. if (res.data == 0 || sale == 1) {
  157. this.setData({
  158. level: 0
  159. })
  160. return
  161. }
  162. this.setData({
  163. // 优惠的等级
  164. level: Number(res.data * 0.1)
  165. })
  166. this.setData({
  167. // 优惠的折扣 (等级*10)
  168. tolevel: (this.data.level * 10).toFixed(1)
  169. })
  170. }
  171. // 计算充值折扣
  172. this.rechargeDiscount()
  173. })
  174. },
  175. // 计算充值折扣
  176. rechargeDiscount() {
  177. // 计算折扣
  178. this.setData({
  179. // 优惠完的价格
  180. levelPrice: (this.data.notSalePrice * this.data.level + Number(this.data.salePrice) + Number(this.data.toExchangePrice) || Number(0)).toFixed(2),
  181. })
  182. this.setData({
  183. // 优惠了多少
  184. toLevelPrice: (this.data.selectCouponPrice - this.data.levelPrice + Number(this.data.toExchangePrice) || Number(0)).toFixed(2)
  185. })
  186. },
  187. // 获取产品最低折扣
  188. getDiscount(goods_ids, type) {
  189. post('v2/api/car/discount', {
  190. store_id: this.data.storeId,
  191. goods_ids: goods_ids,
  192. type: type
  193. }, (res) => {
  194. this.setData({
  195. discountList: res.data,
  196. discount_id: res.data.id,
  197. discountSet: res.data.discount_money,
  198. })
  199. // 计算总金额
  200. this.countDiscount()
  201. // 计算品牌折扣和充值折扣最低折扣
  202. this.calculateDiscount()
  203. // 获取加购列表
  204. this.getNewPlus()
  205. })
  206. },
  207. // 计算折扣价格
  208. countDiscount() {
  209. let discountList = this.data.discountList
  210. let discount_total = this.data.discount_total
  211. discount_total = Number(this.data.showMoneyGood) - Number(discountList.discount_money) + Number(this.data.toExchangePrice) - Number(this.data.couponPrice)
  212. this.setData({
  213. discount_total: discount_total.toFixed(2)
  214. })
  215. },
  216. // 判断订单里的秒杀产品统计
  217. salePrice(list) {
  218. let notSalePrice = '' //非秒杀产品总价格
  219. let salePrice = '' // 秒杀产品总价格
  220. let sale = 1
  221. list.forEach(item => {
  222. if (item.sale == 0) {
  223. sale = 0
  224. return
  225. }
  226. })
  227. list.forEach(item => {
  228. if (item.sale == 0) {
  229. notSalePrice = Number(notSalePrice) + Number(item.price) * Number(item.num)
  230. } else {
  231. salePrice = Number(salePrice) + Number(item.price) * Number(item.num)
  232. }
  233. })
  234. this.setData({
  235. notSalePrice: notSalePrice,
  236. salePrice: salePrice
  237. })
  238. // 获取用户折扣等级
  239. this.getLevel(sale)
  240. },
  241. needAddGood() {
  242. let params = {
  243. store_id: this.data.storeId,
  244. page: this.data.page,
  245. limit: this.data.limit
  246. }
  247. get('v2/api/car/list', params, (res) => {
  248. if (res.code == 200) {
  249. let selectProductCarData = []
  250. selectProductCarData = selectProductCarData.concat(res.data.list)
  251. this.setData({
  252. selectMakeupList: selectProductCarData,
  253. showMoneyGood: res.data.total_money,
  254. selectCouponPrice: this.data.isShow ? this.data.projectData.is_member == 1 ? this.data.projectData.member_price : this.data.projectData.price : res.data.total_money,
  255. store_name: res.data.store_name,
  256. exchangePrice: res.data.total_money,
  257. })
  258. // 获取优惠券列表
  259. this.getCoupon()
  260. // 判断订单里的秒杀产品统计
  261. this.salePrice(res.data.list)
  262. // 获取最低折扣
  263. this.getDiscount(this.data.goods_ids, this.data.type)
  264. // 计算产品总数量
  265. let num = 0
  266. selectProductCarData.map(item => {
  267. num += item.num
  268. })
  269. this.setData({
  270. listNum: num
  271. })
  272. if (this.data.selectMakeupList < res.data.count) {
  273. this.setData({
  274. page: this.data.page + 1
  275. })
  276. this.needAddGood()
  277. }
  278. }
  279. })
  280. },
  281. onConfirm() {
  282. let params = {
  283. goods_ids: this.data.productId,
  284. store_id: this.data.storeId,
  285. type: 2
  286. }
  287. post('v2/api/goods_order/confirm', params, (res) => {
  288. if (res.code == 200) {
  289. let selectProductCarData = []
  290. selectProductCarData = selectProductCarData.concat(res.data.list)
  291. this.setData({
  292. selectMakeupList: selectProductCarData,
  293. showMoneyGood: res.data.total_price,
  294. selectCouponPrice: this.data.isShow ? this.data.projectData.is_member == 1 ? this.data.projectData.member_price : this.data.projectData.price : res.data.total_money,
  295. store_name: res.data.store_name,
  296. exchangePrice: res.data.total_price
  297. })
  298. // 获取最低折扣
  299. this.getDiscount(this.data.goods_ids, this.data.type)
  300. // 获取优惠券列表
  301. this.getCoupon()
  302. }
  303. })
  304. },
  305. onClosePay() {
  306. this.setData({
  307. payNow: false
  308. })
  309. },
  310. pay_methonw() {
  311. this.setData({
  312. pay_methon: 1
  313. })
  314. },
  315. pay_methonc() {
  316. this.setData({
  317. pay_methon: 2
  318. })
  319. },
  320. /**
  321. * 获取我的储值
  322. * api/user
  323. */
  324. getAmount() {
  325. get('api/user/amount', {}, (res) => {
  326. if (res.data) {
  327. this.setData({
  328. inserllAmount: res.data.amount
  329. })
  330. }
  331. })
  332. },
  333. getCoupon() {
  334. post('v2/api/car/coupon', {
  335. page: 1,
  336. limit: 50,
  337. store_id: this.storeId
  338. }, res => {
  339. if (res.code == 200) {
  340. res.data.list.forEach(item => {
  341. item["checkStatus"] = false
  342. item['showMoneyGood'] = this.data.showMoneyGood
  343. item['couponSource'] = 'goods'
  344. })
  345. this.setData({
  346. couponList: res.data.list
  347. })
  348. }
  349. })
  350. },
  351. // 提交订单
  352. onCardgoodsPay() {
  353. // 判断加购产品是否选择完成
  354. if (this.data.exchangeSelect) {
  355. if (this.data.exchangeSum < this.data.exchangeCondition.time) {
  356. wx.showToast({
  357. title: '您还有剩余次数未选',
  358. icon: 'none'
  359. })
  360. return
  361. }
  362. }
  363. // 计算充值折扣
  364. this.rechargeDiscount()
  365. let goods_ids = [],
  366. coupon_id = []
  367. this.data.selectMakeupList.forEach(res => {
  368. if (this.data.isDirectOrder) {
  369. goods_ids.push(res.id)
  370. } else {
  371. goods_ids.push(res.goods_id)
  372. }
  373. })
  374. this.data.selectCouponList.forEach(res => {
  375. coupon_id.push(res.id)
  376. })
  377. // 筛选添加换购产品
  378. let plus = []
  379. this.data.exchangeList.list.forEach(item => {
  380. let list = {}
  381. if (item.num != 0) {
  382. list.id = item.id
  383. list.time = item.num
  384. plus.push(list)
  385. }
  386. })
  387. let discount_money = 0
  388. if (this.data.discountList.balance_discount > this.data.discountList.discount_money) {
  389. discount_money = this.data.discountList.balance_discount
  390. } else {
  391. discount_money = this.data.discountList.discount_money
  392. }
  393. // 判断是否使用优惠券
  394. let discount_id = this.data.discount_id
  395. let meet_discount = this.data.meet_discount
  396. if (coupon_id!='') {
  397. discount_id= '',
  398. meet_discount= 0,
  399. discount_money = 0
  400. }
  401. let params = {
  402. goods_ids: this.data.isshow ? this.data.projectData : goods_ids.toString(),
  403. store_id: this.data.storeId,
  404. coupon_id: coupon_id.toString(),
  405. type: this.data.isShow ? 2 : 1,
  406. discount_id: discount_id || '',
  407. discount_money: discount_money,
  408. plus,
  409. meet_discount: meet_discount,
  410. source: app.globalData.isH5 ? 'h5' : '', //来源:值为 h5 (触屏商城)
  411. share_user_id: app.globalData.shareUserId || '', //分享人ID
  412. }
  413. post('v2/api/car/closing', params, res => {
  414. if (res.code == 200) {
  415. if (res.data.pay_status == 1) {
  416. wx.showToast({
  417. title: '支付成功',
  418. icon: 'success'
  419. })
  420. // 只有项目购买,需要订阅消息
  421. wx.reLaunch({
  422. url: `/pages/paySuccess/paySuccess?current=1&source=goods&order_id=${res.data.order_id}`
  423. })
  424. } else {
  425. this.setData({
  426. payNow: true,
  427. orderId: res.data.order_id
  428. })
  429. this.getAmount()
  430. }
  431. }
  432. })
  433. },
  434. onCouponOpen() {
  435. this.setData({
  436. visible: true
  437. })
  438. },
  439. onCancelCoupon() {
  440. this.setData({
  441. visible: false
  442. })
  443. },
  444. onCouponChange(e) {
  445. this.setData({
  446. currentCoupon: e.currentTarget.dataset.index,
  447. })
  448. this.data.couponList.forEach((res, index) => {
  449. let currentCouponItem = `couponList[${index}].checkStatus`
  450. if (e.currentTarget.dataset.index == index && e.detail.checkStatus) {
  451. this.setData({
  452. [currentCouponItem]: e.detail.checkStatus
  453. })
  454. } else {
  455. this.setData({
  456. [currentCouponItem]: false
  457. })
  458. }
  459. })
  460. },
  461. // 确认选择优惠券
  462. onConfirmCoupon() {
  463. let coupon_id = '',
  464. selectCouponList = [],
  465. selectCouponPrice = Number(this.data.showMoneyGood),
  466. couponPrice = 0
  467. let flag = false
  468. this.data.couponList.forEach(res => {
  469. if (res.checkStatus) {
  470. flag = true
  471. selectCouponList.push(res)
  472. selectCouponPrice = selectCouponPrice - Number(res.price)
  473. selectCouponPrice = selectCouponPrice<0?0:selectCouponPrice + Number(this.data.toExchangePrice)
  474. couponPrice = couponPrice + Number(res.price)
  475. }
  476. })
  477. if (flag) {
  478. this.setData({
  479. discountSet: '0.00'
  480. })
  481. } else {
  482. this.setData({
  483. discountSet: this.data.discountList.discount_money
  484. })
  485. }
  486. if (this.data.currentCoupon != '' && this.data.couponList[this.data.currentCoupon].checkStatus) {
  487. coupon_id = this.data.couponList[this.data.currentCoupon].id
  488. }
  489. // 判断使用优惠券后的价格是否满足加购条件
  490. if (this.data.exchangeList.length!=0) {
  491. let couponExchangPrice = Number(this.data.showMoneyGood) - Number(couponPrice)
  492. if (couponExchangPrice < this.data.exchangeCondition.price) {
  493. wx.showToast({
  494. title: '选择优惠券后,不满足加购金额',
  495. icon: 'none'
  496. })
  497. // 重新计算满足哪种加购条件
  498. let flagA = true
  499. this.data.exchangeList.time.forEach(item => {
  500. if (Number(this.data.showMoneyGood) - Number(couponPrice) >= item.price && flagA) {
  501. flagA = false
  502. this.setData({
  503. exchangeCondition: item
  504. })
  505. }
  506. if(flagA){
  507. this.setData({
  508. exchangeCondition: ''
  509. })
  510. }
  511. })
  512. // 重置加购数量
  513. let list = this.data.exchangeList.list.map(item => {
  514. item.num = 0
  515. return item
  516. })
  517. let exchangeList = `exchangeList.list`
  518. selectCouponPrice = Number(selectCouponPrice)-Number(this.data.toExchangePrice)
  519. this.setData({
  520. [exchangeList]: list,
  521. exchangeSum: 0,
  522. exchangeSelect: false,
  523. })
  524. } else {
  525. // 重新计算满足哪种加购条件
  526. let flag = true
  527. this.data.exchangeList.time.forEach(item => {
  528. if (Number(this.data.showMoneyGood) - Number(couponPrice) >= item.price && flag) {
  529. console.log(1111);
  530. flag = false
  531. this.setData({
  532. exchangeCondition: item
  533. })
  534. }
  535. })
  536. }
  537. }
  538. this.setData({
  539. coupon_id: coupon_id,
  540. visible: false,
  541. selectCouponList: selectCouponList,
  542. selectCouponPrice: selectCouponPrice.toFixed(2),
  543. couponPrice: couponPrice.toFixed(2),
  544. })
  545. },
  546. /**
  547. * 订单支付
  548. */
  549. payOrder() {
  550. let that = this
  551. let uri = 'v2/api/order/goods/pay'
  552. post(
  553. uri, {
  554. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  555. order_id: this.data.orderId
  556. },
  557. (res) => {
  558. that.setData({
  559. payNow: false
  560. })
  561. if (that.data.pay_methon == 2) {
  562. that.goToOrder('支付成功')
  563. return
  564. }
  565. wx.requestPayment({
  566. timeStamp: res.data.pay_data.timeStamp,
  567. nonceStr: res.data.pay_data.nonceStr,
  568. package: res.data.pay_data.package,
  569. signType: res.data.pay_data.signType,
  570. paySign: res.data.pay_data.paySign,
  571. success(res) {
  572. if (res.errMsg == 'requestPayment:ok') {
  573. that.goToOrder('支付成功')
  574. }
  575. },
  576. fail(res) {
  577. that.goToOrder('支付失败')
  578. }
  579. })
  580. }
  581. )
  582. },
  583. /**
  584. * 跳转订单列表
  585. */
  586. goToOrder(text) {
  587. let that = this
  588. wx.showToast({
  589. title: text,
  590. icon: text == '支付成功' ? 'success' : 'error'
  591. })
  592. if (text == '支付成功') {
  593. // 只有项目购买,需要订阅消息
  594. wx.reLaunch({
  595. url: `/pages/paySuccess/paySuccess?current=1&source=${this.data.source}&order_id=${that.data.orderId}`
  596. })
  597. // 获取下发权限
  598. wx.requestSubscribeMessage({
  599. tmplIds: ['RNife3ZhTYYpUuT26ylGQj8W0v07IPo2TGe941iR3y8'],
  600. success(res) {
  601. console.log(res);
  602. let status = ''
  603. if (res['RNife3ZhTYYpUuT26ylGQj8W0v07IPo2TGe941iR3y8'] == 'reject') {
  604. status = 2
  605. } else {
  606. status = 1
  607. }
  608. get('/v2/api/activity/push', {
  609. type: 2,
  610. status,
  611. }, res => {})
  612. },
  613. })
  614. return
  615. } else {
  616. let failUrl = `/pages/goods/orderList/orderList?current=0`
  617. setTimeout(() => {
  618. wx.reLaunch({
  619. url: failUrl
  620. })
  621. }, 1000)
  622. }
  623. },
  624. // 获取产品详情
  625. getProductInfo() {
  626. get(
  627. '/api/product/info', {
  628. store_id: wx.getStorageSync('store_id'),
  629. product_id: this.data.productId,
  630. type: 3
  631. },
  632. (res) => {
  633. this.setData({
  634. projectData: res.data,
  635. sale: res.data.sale,
  636. notSalePrice: res.data.price,
  637. selectCouponPrice: res.data.price
  638. })
  639. // 获取用户折扣等级
  640. this.getLevel(res.data.sale)
  641. },
  642. )
  643. },
  644. // 获取购买次卡享受的折扣
  645. getCardDiscount() {
  646. get('', {}, (res) => {
  647. this.setData({
  648. CardDiscount: ''
  649. })
  650. })
  651. },
  652. //获取新加购列表
  653. getNewPlus() {
  654. post('v2/api/car/plus', {}, (res => {
  655. if (res.code == 200) {
  656. let flag = true
  657. res.data.time = res.data.time.reverse()
  658. let price = 0 //折扣
  659. if (this.data.discountList.discount_money > this.data.discountList.balance_discount) {
  660. price = this.data.discountList.discount_money
  661. }
  662. res.data.time.forEach(item => {
  663. if (Number(this.data.showMoneyGood) - Number(price) >= item.price && flag) {
  664. flag = false
  665. this.setData({
  666. exchangeCondition: item
  667. })
  668. }
  669. })
  670. res.data.list.forEach(item => {
  671. item.num = 0
  672. })
  673. this.setData({
  674. exchangeList: res.data,
  675. })
  676. }
  677. }))
  678. },
  679. // 加购加产品
  680. add(e) {
  681. let index = e.currentTarget.dataset.index
  682. // 如果加购产品数量大于总次数就返回
  683. if (this.data.exchangeSum + 1 > this.data.exchangeCondition.time) {
  684. return
  685. }
  686. let exchangeList = `exchangeList.list[${index}].num`
  687. this.setData({
  688. [exchangeList]: this.data.exchangeList.list[index].num + 1
  689. })
  690. // 遍历计算出总共加购多少次
  691. let sum = 0
  692. this.data.exchangeList.list.forEach(item => {
  693. sum = item.num + sum
  694. })
  695. this.setData({
  696. exchangeSum: sum
  697. })
  698. // 判断是否选中加购产品
  699. if (sum >= 1) {
  700. this.setData({
  701. exchangeSelect: true,
  702. toExchangePrice: 99,
  703. exchangePrice: (Number(this.data.showMoneyGood) + 99).toFixed(2),
  704. selectCouponPrice: (Number(this.data.showMoneyGood)-Number(this.data.couponPrice) + 99).toFixed(2)
  705. })
  706. }
  707. // 计算价格
  708. this.countDiscount()
  709. },
  710. // 加购减产品
  711. reduce(e) {
  712. let index = e.currentTarget.dataset.index
  713. if (this.data.exchangeList.list[index].num == 0) {
  714. return
  715. }
  716. let exchangeList = `exchangeList.list[${index}].num`
  717. this.setData({
  718. [exchangeList]: this.data.exchangeList.list[index].num - 1
  719. })
  720. // 遍历计算出总共加购多少次
  721. let sum = 0
  722. this.data.exchangeList.list.forEach(item => {
  723. sum = item.num + sum
  724. })
  725. this.setData({
  726. exchangeSum: sum
  727. })
  728. // 判断是否选中加购产品
  729. if (sum < 1) {
  730. this.setData({
  731. exchangeSelect: false,
  732. toExchangePrice: 0,
  733. selectCouponPrice: (Number(this.data.selectCouponPrice) - 99).toFixed(2)
  734. })
  735. }
  736. // 计算价格
  737. this.countDiscount()
  738. },
  739. // 关闭弹窗
  740. onCloseLandscape() {
  741. clearInterval(this.data.timer);
  742. this.setData({
  743. exchangePop: false
  744. })
  745. }
  746. })