orderConfirm.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. import {
  2. get,
  3. post
  4. } from '../../utils/http'
  5. import {
  6. PROJECT_TYPE
  7. } from '../../utils/global'
  8. var WxParse = require('../../components/local/wxParse/wxParse.js')
  9. Page({
  10. /**
  11. * 页面的初始数据
  12. */
  13. data: {
  14. visible: false,
  15. visibleLandscape: false,
  16. detail: null,
  17. productDetail: null, // 项目耗材下单 - 产品信息
  18. projectOrderData: null, // 项目耗材下单 - 绑定的订单信息
  19. couponList: [],
  20. currentCoupon: -1,
  21. currentChangeCoupon: null,
  22. memberDiscountStatus: -1, // 是否可使用会员折扣 0 不是会员 1 是会员
  23. memberStatus: -1, // 是否为会员 0 不是会员 1 是会员
  24. recommendMemberCard: null, // 推荐开通的会员卡
  25. array: ['使用', '不使用'],
  26. memberCardCurrentDiscount: -1, // 是否可以使用会员抵扣,0使用,1不使用,-1不可选择
  27. source: 'project', // project, product, goods
  28. projectProducts: [], // 指定项目的耗材推荐产品(升级产品)
  29. selectProductId: 0, // 选择的项目耗材id
  30. selectProductIndex: -1, // 选择的项目耗材下标
  31. selectCardId: 0, // 选择的会员卡ID
  32. moneyData: {}, // 金额数据
  33. orderId: 0,
  34. wxParseMemberRules: false, // 是否已解析
  35. pay_methon: 1,
  36. payNow: false,
  37. switchPay: 'product',
  38. inFirstIn: false,
  39. card_sum: 0, //次卡分配总数量
  40. cardDetail: [], //固定次卡分配信息列表
  41. Ac_cardDetail: [], //非固定次卡分配信息列表
  42. card_type: null, //是否可以分配次数
  43. finshCardDetail: {}, //分配完成的产品列表
  44. all_cardDetail: [], //获取分配全部信息
  45. selectExchange: 0, //是否选中加购产品
  46. exchangePrice: '', //选中后的价格
  47. cardExchangeList: '', //加购产品列表
  48. cardExchangeId: '', //加购产品id
  49. toExchangePrice:'', //加购产品总价格
  50. level: '', //用户充值折扣等级 (0是未拥有等级)
  51. levelList: {
  52. 1: '0.98',
  53. 4: '0.95',
  54. 7: '0.90',
  55. }, //折扣列表
  56. levelPrice: '', //充值等级折扣优惠价格
  57. },
  58. knowSubmit: function () {
  59. this.setData({
  60. inFirstIn: false
  61. })
  62. },
  63. noneEnoughPeople() {
  64. },
  65. pay_methonw() {
  66. this.setData({
  67. pay_methon: 1
  68. })
  69. },
  70. // 获取用户充值折扣等级
  71. getLevel() {
  72. get('/v2/api/user/discount_level', {}, (res) => {
  73. if (res.code == 200) {
  74. if (res.data == 0) {
  75. this.setData({
  76. level: 0
  77. })
  78. return
  79. }
  80. let getValue = (item, val) => {
  81. return item[val]
  82. }
  83. this.setData({
  84. level: Number(getValue(this.data.levelList, res.data))
  85. })
  86. this.setData({
  87. tolevel: (this.data.level * 10).toFixed(1)
  88. })
  89. }
  90. })
  91. },
  92. pay_methonc() {
  93. this.setData({
  94. pay_methon: 2
  95. })
  96. },
  97. /**
  98. * 生命周期函数--监听页面加载
  99. */
  100. onLoad: function (options) {
  101. // 获取用户折扣等级
  102. this.getLevel()
  103. // console.log(options, 'options');
  104. this.getCardExchangeList(options.storeId, JSON.parse(options.data).id)
  105. let source = options.source || 'project'
  106. let productData = options.productData || null
  107. if (productData) {
  108. productData = JSON.parse(productData)
  109. }
  110. let userInfo = getApp().globalData.userInfo
  111. this.setData({
  112. exchangePrice: JSON.parse(options.data).price,
  113. detail: JSON.parse(options.data),
  114. productDetail: productData,
  115. timeData: JSON.parse(options.timeData),
  116. deviceData: JSON.parse(options.deviceData),
  117. selectProductId: productData && productData.id ? productData.id : 0, // 复用了项目下单的耗材推荐产品
  118. projectOrderData: options.projectOrderData ?
  119. JSON.parse(options.projectOrderData) : null,
  120. source: source,
  121. memberStatus: userInfo.is_vip || 0,
  122. storeId: options.storeId
  123. })
  124. // 产品类型 数据类型,1项目,2项目耗材,3美妆产品,4卡券产品分类, 默认1
  125. if (source == 'project') {
  126. // 项目
  127. this.getDiscount()
  128. } else if (source == 'product') {
  129. // 项目耗材
  130. this.getDiscount()
  131. } else if (['goods'].indexOf(source) > -1) {
  132. // 美妆产品
  133. this.getGoodsDiscount()
  134. } else if (source == 'cardgoods') {
  135. // 卡券产品
  136. this.getCardgoodsDiscount()
  137. } else if (source == 'product_with_project_order') {
  138. // 项目-升级产品(项目耗材)
  139. this.getProductWithProjectOrderDiscount()
  140. } else if (source == 'secondaryCard') {
  141. // 次卡
  142. // 发起请求获取次卡分配产品
  143. this.getCardProjectInfo()
  144. } else {
  145. // 默认为项目
  146. this.getDiscount()
  147. }
  148. },
  149. /**
  150. * 生命周期函数--监听页面初次渲染完成
  151. */
  152. onReady: function () {},
  153. /**
  154. * 生命周期函数--监听页面显示
  155. */
  156. onShow: function () {
  157. this.getAmount()
  158. let version4 = wx.getStorageSync('version4')
  159. if (!version4 || version4 != 1) {
  160. this.setData({
  161. inFirstIn: true
  162. })
  163. wx.setStorageSync('version4', 1)
  164. }
  165. },
  166. /**
  167. * 生命周期函数--监听页面隐藏
  168. */
  169. onHide: function () {},
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function () {},
  174. /**
  175. * 页面相关事件处理函数--监听用户下拉动作
  176. */
  177. onPullDownRefresh: function () {},
  178. /**
  179. * 页面上拉触底事件的处理函数
  180. */
  181. onReachBottom: function () {},
  182. /**
  183. * 用户点击右上角分享
  184. */
  185. onShareAppMessage: function () {},
  186. /**
  187. * 复制订单号
  188. */
  189. onCopyOrderNum(e) {
  190. wx.setClipboardData({
  191. data: e.currentTarget.dataset.num || '',
  192. success(res) {
  193. console.log(res)
  194. }
  195. })
  196. },
  197. /**
  198. * 打开优惠券
  199. */
  200. onCouponOpen() {
  201. if (
  202. this.data.couponList.length > 0 &&
  203. this.data.memberCardCurrentDiscount != 0
  204. ) {
  205. this.setData({
  206. visible: true
  207. })
  208. }
  209. },
  210. /**
  211. * 选择优惠券
  212. */
  213. onCouponChange(e) {
  214. let couponIndex = e.detail.checkStatus ? e.currentTarget.dataset.index : -1
  215. // 优惠券和会员卡互斥逻辑
  216. this.setData({
  217. currentCoupon: couponIndex,
  218. currentChangeCoupon: couponIndex == -1 ? null : this.data.couponList[couponIndex],
  219. memberCardCurrentDiscount: couponIndex != -1 ? -1 : this.data.memberCardCurrentDiscount // 会员卡与优惠券互斥逻辑
  220. },
  221. () => {
  222. this.calculateOrderPayMoney()
  223. }
  224. )
  225. },
  226. /**
  227. * 关闭弹框
  228. */
  229. onClose() {
  230. this.setData({
  231. visible: false
  232. })
  233. },
  234. onCancelCoupon() {
  235. this.setData({
  236. visible: false
  237. })
  238. },
  239. onConfirmCoupon() {
  240. let currentChangeCoupon = this.data.couponList[this.data.currentCoupon]
  241. this.setData({
  242. visible: false,
  243. currentChangeCoupon
  244. },
  245. () => {
  246. this.calculateOrderPayMoney()
  247. }
  248. )
  249. },
  250. /**
  251. * 订单支付
  252. */
  253. payOrder(orderId) {
  254. let that = this
  255. let uri = 'api/pay/project'
  256. if (that.data.source == 'goods') {
  257. uri = 'api/pay/goods'
  258. } else if (that.data.source == 'cardgoods') {
  259. uri = 'api/pay/cardgoods'
  260. } else if (that.data.source == 'secondaryCard') {
  261. uri = 'v2/api/order/card/pay'
  262. }
  263. post(
  264. uri, {
  265. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  266. order_id: orderId
  267. },
  268. (res) => {
  269. that.setData({
  270. payNow: false
  271. })
  272. if (that.data.pay_methon == 2) {
  273. that.goToOrder('支付成功')
  274. return
  275. }
  276. wx.requestPayment({
  277. timeStamp: res.data.pay_data.timeStamp,
  278. nonceStr: res.data.pay_data.nonceStr,
  279. package: res.data.pay_data.package,
  280. signType: res.data.pay_data.signType,
  281. paySign: res.data.pay_data.paySign,
  282. success(res) {
  283. if (res.errMsg == 'requestPayment:ok') {
  284. that.goToOrder('支付成功')
  285. }
  286. },
  287. fail(res) {
  288. that.goToOrder('支付失败')
  289. }
  290. })
  291. }
  292. )
  293. },
  294. /**
  295. * 订单支付 - 升级产品支付
  296. */
  297. payProductOrder(orderId) {
  298. let that = this
  299. post(
  300. 'api/pay/product', {
  301. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  302. order_id: orderId
  303. },
  304. (res) => {
  305. that.setData({
  306. payNow: false
  307. })
  308. if (that.data.pay_methon == 2) {
  309. that.goToOrder('支付成功')
  310. return
  311. }
  312. wx.requestPayment({
  313. timeStamp: res.data.pay_data.timeStamp,
  314. nonceStr: res.data.pay_data.nonceStr,
  315. package: res.data.pay_data.package,
  316. signType: res.data.pay_data.signType,
  317. paySign: res.data.pay_data.paySign,
  318. success(res) {
  319. if (res.errMsg == 'requestPayment:ok') {
  320. that.goToOrder('支付成功')
  321. }
  322. },
  323. fail(res) {
  324. that.goToOrder('支付失败')
  325. }
  326. })
  327. }
  328. )
  329. },
  330. onPay: function () {
  331. this.setData({
  332. payNow: true,
  333. switchPay: 'project',
  334. })
  335. },
  336. payNow() {
  337. switch (this.data.switchPay) {
  338. case 'project':
  339. this.payNowProduct()
  340. break;
  341. case 'product':
  342. this.onProductPayNow()
  343. break;
  344. case 'goods':
  345. this.onGoodsPayNow()
  346. break
  347. case 'cardgoods':
  348. this.onCardgoodsPayNow()
  349. break
  350. case 'secondaryCard':
  351. this.onSecondaryCardPayNow()
  352. break
  353. default:
  354. break;
  355. }
  356. },
  357. /**
  358. * 支付
  359. */
  360. payNowProduct() {
  361. let that = this
  362. this.checkFirst()
  363. .then((res) => {
  364. this.addOrder().then((res) => {
  365. console.log(res)
  366. that.setData({
  367. orderId: res.order_id
  368. }, () => {
  369. that.methonPayOrder(res.order_id)
  370. })
  371. })
  372. })
  373. .catch((rej) => {
  374. that.setData({
  375. payNow: false
  376. })
  377. wx.navigateTo({
  378. url: '/pages/disclaimer/disclaimer'
  379. })
  380. })
  381. },
  382. onClosePay() {
  383. this.setData({
  384. payNow: false
  385. })
  386. },
  387. /**
  388. * 订单支付
  389. */
  390. methonPayOrder(orderId) {
  391. let that = this
  392. let uri = 'api/pay/project'
  393. post(
  394. uri, {
  395. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  396. order_id: orderId
  397. },
  398. (res) => {
  399. that.setData({
  400. payNow: false
  401. })
  402. if (that.data.pay_methon == 2) {
  403. that.goToOrder('支付成功')
  404. return
  405. }
  406. wx.requestPayment({
  407. timeStamp: res.data.pay_data.timeStamp,
  408. nonceStr: res.data.pay_data.nonceStr,
  409. package: res.data.pay_data.package,
  410. signType: res.data.pay_data.signType,
  411. paySign: res.data.pay_data.paySign,
  412. success(res) {
  413. if (res.errMsg == 'requestPayment:ok') {
  414. that.goToOrder('支付成功')
  415. }
  416. },
  417. fail(res) {
  418. that.goToOrder('支付失败')
  419. }
  420. })
  421. }
  422. )
  423. },
  424. onGoodsPay() {
  425. this.setData({
  426. payNow: true,
  427. switchPay: 'goods'
  428. })
  429. },
  430. /**
  431. * 美妆产品-订单
  432. */
  433. onGoodsPayNow() {
  434. let {
  435. detail,
  436. currentChangeCoupon,
  437. memberCardCurrentDiscount,
  438. selectCardId
  439. } = this.data
  440. let discount_type
  441. let that = this
  442. if (memberCardCurrentDiscount == 0) {
  443. discount_type = 1
  444. } else if (currentChangeCoupon) {
  445. discount_type = 2
  446. } else {
  447. discount_type = 0
  448. }
  449. post(
  450. 'api/goods/buy', {
  451. goods_id: detail.id,
  452. coupon_id: currentChangeCoupon ? currentChangeCoupon.id : '',
  453. store_id: detail.store_id,
  454. card_id: selectCardId,
  455. discount_type
  456. },
  457. (res) => {
  458. let orderId = res.data.order_id
  459. let payStatus = res.data.pay_status //订单状态,1已支付,0未支付,需要调用支付接口
  460. this.setData({
  461. orderId: orderId
  462. }, () => {
  463. if (payStatus == 1) {
  464. that.goToOrder('支付成功')
  465. return
  466. }
  467. that.payOrder(orderId)
  468. })
  469. }
  470. )
  471. },
  472. onCardgoodsPay() {
  473. this.setData({
  474. payNow: true,
  475. switchPay: 'cardgoods'
  476. })
  477. },
  478. /**
  479. * 购买-卡券产品【下单】
  480. */
  481. onCardgoodsPayNow() {
  482. let {
  483. detail,
  484. currentChangeCoupon,
  485. memberCardCurrentDiscount,
  486. selectCardId
  487. } = this.data
  488. let discount_type
  489. let that = this
  490. if (memberCardCurrentDiscount == 0) {
  491. discount_type = 1
  492. } else if (currentChangeCoupon) {
  493. discount_type = 2
  494. } else {
  495. discount_type = 0
  496. }
  497. post(
  498. 'api/cardgoods/buy', {
  499. goods_id: detail.id,
  500. coupon_id: currentChangeCoupon ? currentChangeCoupon.id : '',
  501. store_id: detail.store_id,
  502. card_id: selectCardId,
  503. discount_type
  504. },
  505. (res) => {
  506. let orderId = res.data.order_id
  507. let payStatus = res.data.pay_status //订单状态,1已支付,0未支付,需要调用支付接口
  508. this.setData({
  509. orderId: orderId
  510. }, () => {
  511. if (payStatus == 1) {
  512. that.goToOrder('支付成功')
  513. return
  514. }
  515. that.payOrder(orderId)
  516. })
  517. }
  518. )
  519. },
  520. onSecondaryCardPay() {
  521. // 计算充值折扣
  522. this.setData({
  523. levelPrice: (this.data.detail.price * this.data.level+Number(this.data.toExchangePrice)).toFixed(2)
  524. })
  525. this.setData({
  526. toLevelPrice: (this.data.detail.price - this.data.levelPrice+Number(this.data.toExchangePrice)).toFixed(2)
  527. })
  528. // 判断是否有次卡分配
  529. if (this.data.card_type == 2) {
  530. // 判断分配次数是否分配完毕
  531. let num = 0
  532. this.data.Ac_cardDetail.map(item => {
  533. num += item.total_time
  534. })
  535. this.setData({
  536. card_sum: num
  537. })
  538. // 如果没有分配完毕就提示
  539. if (this.data.card_sum != 0) {
  540. wx.showToast({
  541. title: '您还有剩余次数',
  542. icon: 'error'
  543. })
  544. return
  545. }
  546. // 筛选分配后的数据
  547. let group = []
  548. this.data.Ac_cardDetail.map(item => {
  549. let vote = {}
  550. vote.id = item.id
  551. let project_list = []
  552. vote.project_list = project_list
  553. item.project_list.map(item1 => {
  554. let vote1 = {}
  555. if (item1.time != 0) {
  556. vote1.project_id = item1.project_id
  557. vote1.time = item1.time
  558. project_list.push(vote1)
  559. }
  560. })
  561. group.push(vote)
  562. })
  563. this.setData({
  564. finshCardDetail: group
  565. })
  566. }
  567. this.setData({
  568. payNow: true,
  569. switchPay: 'secondaryCard'
  570. })
  571. },
  572. /**
  573. * 次卡下单
  574. */
  575. onSecondaryCardPayNow() {
  576. console.log({
  577. group: '',
  578. id: this.data.all_cardDetail.id,
  579. store_id: this.data.all_cardDetail.store_id,
  580. group_type: this.data.card_type,
  581. plus_id: this.data.cardExchangeId
  582. });
  583. let {
  584. detail
  585. } = this.data
  586. let that = this
  587. post(
  588. // 判断是否有次卡分配
  589. 'v2/api/order/card/add',
  590. this.data.card_type == 2 ? {
  591. group: this.data.finshCardDetail,
  592. store_id: this.data.all_cardDetail.store_id,
  593. id: this.data.all_cardDetail.id,
  594. group_type: this.data.card_type,
  595. } : {
  596. group: '',
  597. id: this.data.all_cardDetail.id,
  598. store_id: this.data.all_cardDetail.store_id,
  599. group_type: this.data.card_type,
  600. plus_id: this.data.cardExchangeId
  601. },
  602. (res) => {
  603. console.log(res);
  604. let orderId = res.data.order_id
  605. let payStatus = res.data.pay_status //订单状态,1已支付,0未支付,需要调用支付接口
  606. // 因为要订阅消息,不能在回调函数里调用该方法所以修改
  607. this.setData({
  608. orderId: orderId
  609. })
  610. if (payStatus == 1) {
  611. that.goToOrder('支付成功')
  612. return
  613. }
  614. that.payOrder(orderId)
  615. // this.setData({
  616. // orderId: orderId
  617. // }, () => {
  618. // if (payStatus == 1) {
  619. // that.goToOrder('支付成功')
  620. // return
  621. // }
  622. // that.payOrder(orderId)
  623. // })
  624. }
  625. )
  626. },
  627. /**
  628. * 确认订单
  629. */
  630. getOrderInfo(order_id) {
  631. get(
  632. 'api/order/info', {
  633. order_id
  634. },
  635. (res) => {
  636. this.setData({
  637. detail: res.data
  638. })
  639. console.log(res)
  640. }
  641. )
  642. },
  643. /**
  644. * 获取预约订单折扣
  645. * api/order/get_discount
  646. */
  647. getDiscount() {
  648. let {
  649. memberCardCurrentDiscount,
  650. source
  651. } = this.data
  652. get(
  653. 'api/order/get_discount', {
  654. project_id: this.data.detail.id,
  655. order_day: this.data.timeData.order_day,
  656. order_time_id: this.data.timeData.time_id
  657. },
  658. (res) => {
  659. // 是否可以使用会员抵扣,member_status:1 可以抵扣,0不能抵扣
  660. if (res.data.member_status == 1) {
  661. memberCardCurrentDiscount = 0 // 是否可以使用会员抵扣,0使用,1不使用,-1不可选择
  662. }
  663. this.setData({
  664. couponList: res.data.coupon_list, // type: 类型,1抵扣券,2满减券,3全额券
  665. memberDiscountStatus: res.data.member_status, // 是否可以使用会员抵扣,1可以抵扣,0不能抵扣
  666. recommendMemberCard: res.data.member_card, // 推荐开通的会员卡
  667. memberCardCurrentDiscount,
  668. currentPayMoney: this.data.detail.price
  669. },
  670. () => {
  671. this.calculateOrderPayMoney()
  672. }
  673. )
  674. }
  675. )
  676. // 项目确认订单 - 获取指定项目的升级产品
  677. if (source == 'project') {
  678. this.getProjectProducts()
  679. }
  680. },
  681. /**
  682. * 选择会员抵扣
  683. */
  684. bindPickerChange(e) {
  685. let {
  686. memberCardCurrentDiscount,
  687. currentCoupon,
  688. currentChangeCoupon
  689. } =
  690. this.data
  691. this.setData({
  692. memberCardCurrentDiscount: e.detail.value,
  693. currentCoupon: memberCardCurrentDiscount == 0 ? -1 : currentCoupon,
  694. currentChangeCoupon: memberCardCurrentDiscount == 0 ? null : currentChangeCoupon
  695. },
  696. () => {
  697. this.calculateOrderPayMoney()
  698. }
  699. )
  700. },
  701. onSubmitCh(ids, source) {
  702. let that = this
  703. wx.showModal({
  704. title: '提示',
  705. content: '支付成功! 是否进行消息提醒',
  706. success: function (res) {
  707. if (res.confirm) {
  708. that.onSubmitTrue(ids, source)
  709. } else if (res.cancel) {
  710. that.messageAgree(ids)
  711. setTimeout(() => {
  712. wx.reLaunch({
  713. // url: '/pages/order/order?current=1'
  714. url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
  715. })
  716. }, 1000)
  717. }
  718. }
  719. });
  720. },
  721. onSubmitTrue(ids, source) {
  722. console.log("source")
  723. console.log(source)
  724. let that = this
  725. wx.requestSubscribeMessage({
  726. tmplIds: ids,
  727. success(res) {
  728. console.log(res)
  729. that.messageAgree(ids)
  730. wx.reLaunch({
  731. // url: '/pages/order/order?current=1'
  732. url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
  733. })
  734. },
  735. fail(rej) {
  736. console.log(rej)
  737. that.messageAgree(ids)
  738. wx.showToast({
  739. title: JSON.stringify(rej),
  740. icon: 'error'
  741. })
  742. setTimeout(() => {
  743. wx.reLaunch({
  744. // url: '/pages/order/order?current=1'
  745. url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
  746. })
  747. }, 1000)
  748. }
  749. })
  750. },
  751. /**
  752. * 获取我的储值
  753. * api/user
  754. */
  755. getAmount() {
  756. get('api/user/amount', {}, (res) => {
  757. if (res.data) {
  758. this.setData({
  759. inserllAmount: res.data.amount
  760. })
  761. }
  762. })
  763. },
  764. /**
  765. * 跳转订单列表
  766. */
  767. goToOrder(text) {
  768. let that = this
  769. let {
  770. source
  771. } = this.data
  772. // 此处按照接口定义,当选择项目耗材,且无项目时,下单用的是project
  773. if (source == 'product') {
  774. source = 'project'
  775. }
  776. wx.showToast({
  777. title: text,
  778. icon: text == '支付成功' ? 'success' : 'error'
  779. })
  780. if (text == '支付成功') {
  781. // 只有项目购买,需要订阅消息
  782. if (source != 'project') {
  783. wx.reLaunch({
  784. url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
  785. })
  786. // 获取下发权限
  787. wx.requestSubscribeMessage({
  788. tmplIds: ['RNife3ZhTYYpUuT26ylGQj8W0v07IPo2TGe941iR3y8'],
  789. success(res) {
  790. console.log(res);
  791. let status = ''
  792. if (res['RNife3ZhTYYpUuT26ylGQj8W0v07IPo2TGe941iR3y8'] == 'reject') {
  793. status = 2
  794. } else {
  795. status = 1
  796. }
  797. get('/v2/api/activity/push', {
  798. type: 2,
  799. status,
  800. }, res => {})
  801. },
  802. })
  803. return
  804. }
  805. get('api/message/ids', {}, (res) => {
  806. let ids = res.data.ids
  807. if (that.data.pay_methon == 2) {
  808. that.onSubmitCh(ids, source)
  809. return
  810. }
  811. wx.requestSubscribeMessage({
  812. tmplIds: ids,
  813. success(res) {
  814. console.log(res)
  815. that.messageAgree(ids)
  816. wx.reLaunch({
  817. // url: '/pages/order/order?current=1'
  818. url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
  819. })
  820. },
  821. fail(rej) {
  822. console.log(rej)
  823. that.messageAgree(ids)
  824. wx.showToast({
  825. title: JSON.stringify(rej),
  826. icon: 'error'
  827. })
  828. setTimeout(() => {
  829. wx.reLaunch({
  830. // url: '/pages/order/order?current=1'
  831. url: `/pages/paySuccess/paySuccess?current=1&source=${source}&order_id=${that.data.orderId}`
  832. })
  833. }, 1000)
  834. }
  835. })
  836. })
  837. } else {
  838. let failUrl = `/pages/order/order?current=0`
  839. if (['goods', 'cardgoods'].indexOf(source) > -1) {
  840. failUrl = `/pages/goods/orderList/orderList?current=0`
  841. }
  842. setTimeout(() => {
  843. wx.reLaunch({
  844. url: failUrl
  845. // url: `/pages/paySuccess/paySuccess?current=0&source=${source}&order_id=${that.data.orderId}`
  846. })
  847. }, 1000)
  848. }
  849. },
  850. /**
  851. * 是否首次购买
  852. */
  853. checkFirst() {
  854. return new Promise((resolve, reject) => {
  855. if (wx.getStorageSync('agree')) {
  856. resolve()
  857. } else {
  858. get('api/order/check_first', {}, (res) => {
  859. if (res.data.order_status == 1) {
  860. resolve()
  861. } else {
  862. reject()
  863. }
  864. })
  865. }
  866. })
  867. },
  868. /**
  869. * 提交订单
  870. * /api/order/add
  871. */
  872. addOrder() {
  873. let {
  874. deviceData,
  875. timeData,
  876. currentChangeCoupon,
  877. detail,
  878. memberCardCurrentDiscount,
  879. selectCardId,
  880. selectProductId
  881. } = this.data
  882. let discount_type
  883. let that = this
  884. return new Promise((resolve, reject) => {
  885. if (memberCardCurrentDiscount == 0) {
  886. discount_type = 1
  887. } else if (currentChangeCoupon) {
  888. discount_type = 2
  889. } else {
  890. discount_type = 0
  891. }
  892. post(
  893. 'api/order/add', {
  894. project_id: detail.id,
  895. store_id: detail.store_id,
  896. device_id: deviceData ? deviceData.id : '',
  897. order_day: timeData ? timeData.order_day : '',
  898. order_time_id: timeData ? timeData.time_id : '',
  899. coupon_id: currentChangeCoupon ? currentChangeCoupon.id : '',
  900. discount_type,
  901. card_id: selectCardId,
  902. product_id: selectProductId,
  903. product_coupon_id: currentChangeCoupon ? currentChangeCoupon.id : ''
  904. },
  905. (res) => {
  906. console.log(res)
  907. that.setData({
  908. orderId: res.data.order_id
  909. })
  910. if (res.data.pay_status == 1) {
  911. that.goToOrder('支付成功')
  912. } else {
  913. resolve(res.data)
  914. }
  915. }
  916. )
  917. })
  918. },
  919. // 统一集合的地方
  920. onProductPay() {
  921. this.setData({
  922. payNow: true,
  923. switchPay: 'product',
  924. })
  925. },
  926. /**
  927. * 单独购买升级产品【下单】
  928. * /api/product/buy
  929. *
  930. */
  931. onProductPayNow() {
  932. let {
  933. selectProductId,
  934. projectOrderData,
  935. memberCardCurrentDiscount,
  936. currentChangeCoupon
  937. } = this.data
  938. let discount_type
  939. let that = this
  940. if (memberCardCurrentDiscount == 0) {
  941. discount_type = 1
  942. } else if (currentChangeCoupon) {
  943. discount_type = 2
  944. } else {
  945. discount_type = 0
  946. }
  947. this.checkFirst()
  948. .then(() => {
  949. new Promise((resolve, reject) => {
  950. post(
  951. 'api/product/buy', {
  952. product_id: selectProductId,
  953. order_id: projectOrderData.order_id,
  954. coupon_id: currentChangeCoupon ? currentChangeCoupon.id : '',
  955. discount_type
  956. },
  957. (res) => {
  958. console.log(res)
  959. that.setData({
  960. orderId: res.data.order_id
  961. })
  962. if (res.data.pay_status == 1) {
  963. that.goToOrder('支付成功')
  964. } else {
  965. that.payProductOrder(res.data.order_id)
  966. }
  967. }
  968. )
  969. })
  970. })
  971. .catch((rej) => {
  972. wx.navigateTo({
  973. url: '/pages/disclaimer/disclaimer'
  974. })
  975. })
  976. },
  977. /**
  978. * 用户允许消息通知
  979. * /api/message/agree
  980. */
  981. messageAgree(ids) {
  982. post(
  983. 'api/message/agree', {
  984. order_id: this.data.orderId,
  985. ids
  986. },
  987. () => {}
  988. )
  989. },
  990. /**
  991. * 点击打开会员卡弹框
  992. */
  993. onOpenLandscape() {
  994. let that = this
  995. if (that.data.wxParseMemberRules) {
  996. that.setData({
  997. visibleLandscape: true
  998. })
  999. return
  1000. }
  1001. this.getmemberRules()
  1002. .then((memberRules) => {
  1003. WxParse.wxParse('article', 'html', memberRules, that, 5)
  1004. that.setData({
  1005. visibleLandscape: true,
  1006. wxParseMemberRules: true
  1007. })
  1008. })
  1009. .catch(() => {})
  1010. },
  1011. /**
  1012. * 点击关闭会员卡弹框
  1013. */
  1014. onCloseLandscape() {
  1015. this.setData({
  1016. visibleLandscape: false
  1017. })
  1018. },
  1019. /**
  1020. * 勾选会员卡
  1021. */
  1022. selectMemberCard(e) {
  1023. let that = this
  1024. this.setData({
  1025. selectCardId: that.data.selectCardId ? 0 : e.currentTarget.dataset.id,
  1026. memberCardCurrentDiscount: that.data.selectCardId ? -1 : 0,
  1027. memberStatus: that.data.selectCardId ? -1 : 1,
  1028. currentCoupon: that.data.selectCardId ? -1 : that.data.currentCoupon,
  1029. currentChangeCoupon: that.data.selectCardId ?
  1030. null : that.data.currentChangeCoupon
  1031. },
  1032. () => {
  1033. that.calculateOrderPayMoney()
  1034. }
  1035. )
  1036. },
  1037. /**
  1038. * 勾选升级产品
  1039. */
  1040. selectProjectProduct(e) {
  1041. let {
  1042. selectProductIndex
  1043. } = this.data
  1044. let productId = e.currentTarget.dataset.id
  1045. let index = e.currentTarget.dataset.index
  1046. this.setData({
  1047. selectProductId: selectProductIndex == index ? 0 : productId,
  1048. selectProductIndex: selectProductIndex == index ? -1 : index
  1049. },
  1050. () => {
  1051. this.calculateOrderPayMoney()
  1052. }
  1053. )
  1054. },
  1055. /**
  1056. * 获取指定项目的升级产品
  1057. */
  1058. getProjectProducts() {
  1059. get('api/project/products', {
  1060. project_id: this.data.detail.id
  1061. }, (res) => {
  1062. this.setData({
  1063. projectProducts: res.data.list && res.data.list.length > 0 ? res.data.list : []
  1064. })
  1065. })
  1066. },
  1067. /**
  1068. * 获取-美妆产品折扣
  1069. */
  1070. getGoodsDiscount() {
  1071. let memberCardCurrentDiscount = this.data.memberCardCurrentDiscount
  1072. get(
  1073. 'api/goods/get_discount', {
  1074. goods_id: this.data.detail.id
  1075. },
  1076. (res) => {
  1077. this.setData({
  1078. couponList: res.data.coupon_list, // type: 类型,1抵扣券,2满减券,3全额券
  1079. memberCardCurrentDiscount,
  1080. currentPayMoney: this.data.detail.price
  1081. },
  1082. () => {
  1083. this.calculateOrderPayMoney()
  1084. }
  1085. )
  1086. }
  1087. )
  1088. },
  1089. /**
  1090. * 获取-卡券产品折扣
  1091. */
  1092. getCardgoodsDiscount() {
  1093. let memberCardCurrentDiscount = this.data.memberCardCurrentDiscount
  1094. get(
  1095. 'api/cardgoods/get_discount', {
  1096. goods_id: this.data.detail.id
  1097. },
  1098. (res) => {
  1099. this.setData({
  1100. couponList: res.data.coupon_list, // type: 类型,1抵扣券,2满减券,3全额券,4卡券(效果和“全额券”一样)
  1101. memberCardCurrentDiscount,
  1102. currentPayMoney: this.data.detail.price
  1103. },
  1104. () => {
  1105. this.calculateOrderPayMoney()
  1106. }
  1107. )
  1108. }
  1109. )
  1110. },
  1111. /**
  1112. * 获取-项目升级产品的折扣信息
  1113. */
  1114. getProductWithProjectOrderDiscount() {
  1115. let {
  1116. selectProductId
  1117. } = this.data
  1118. get(
  1119. 'api/product/get_discount', {
  1120. product_id: selectProductId
  1121. },
  1122. (res) => {
  1123. this.setData({
  1124. couponList: res.data.coupon_list // type: 类型,1抵扣券,2满减券,3全额券,4卡券(效果和“全额券”一样)
  1125. },
  1126. () => {
  1127. this.calculateOrderPayMoney()
  1128. }
  1129. )
  1130. }
  1131. )
  1132. },
  1133. /**
  1134. * 获取会员守则
  1135. */
  1136. getmemberRules() {
  1137. let memberRules = getApp().globalData.memberRules
  1138. return new Promise((resolve, reject) => {
  1139. if (memberRules) {
  1140. resolve(memberRules)
  1141. } else {
  1142. get(
  1143. 'api/agreement', {},
  1144. (res) => {
  1145. memberRules = res.data.member_rules
  1146. memberRules = this.removeCss(memberRules)
  1147. getApp().globalData.memberRules = memberRules
  1148. resolve(memberRules)
  1149. },
  1150. () => {
  1151. reject()
  1152. }
  1153. )
  1154. }
  1155. })
  1156. },
  1157. /**
  1158. * 去除富文本图片默认样式
  1159. */
  1160. removeCss(content) {
  1161. let reg = /(style|class)="[^"]+"/gi
  1162. let img = /<img[^>]+>/gi
  1163. let res
  1164. if (img.test(content)) {
  1165. res = content.match(img)
  1166. for (let i = 0; i < res.length; i++) {
  1167. content = content.replace(res[i], res[i].replace(reg, ''))
  1168. }
  1169. }
  1170. // (/\<img/gi, '<img style="max-width:100%;height:auto;display:block;"')
  1171. return content.replace(/\<img/gi, '<img class="richImg" ')
  1172. },
  1173. /**
  1174. * 计算汇总价格
  1175. * memberCardCurrentDiscount 为1时会员卡可抵扣全额抵扣(项目)
  1176. * 会员
  1177. * 项目可以全额抵扣
  1178. * 美妆产品、项目耗材 会员价
  1179. *
  1180. * @param detail 项目(美妆产品共用)
  1181. * @param recommendMemberCard 推荐开通的会员卡
  1182. * @param memberCardCurrentDiscount 是否可以使用会员抵扣,0使用,1不使用,-1不可选择
  1183. * @param selectCardId 选中需要购买的会员卡ID
  1184. * @param currentChangeCoupon 优惠券对象
  1185. * @param productDetail 项目耗材下单时的耗材详情
  1186. * @param projectProducts 项目下单推荐的项目耗材
  1187. * @returns
  1188. */
  1189. calculateOrderPayMoney() {
  1190. let {
  1191. detail,
  1192. selectCardId,
  1193. source,
  1194. memberStatus,
  1195. recommendMemberCard,
  1196. productDetail,
  1197. memberCardCurrentDiscount,
  1198. currentCoupon,
  1199. currentChangeCoupon,
  1200. projectProducts,
  1201. selectProductIndex
  1202. } = this.data
  1203. let projectWithGoodsPrice = 0 // 项目价格 / 美妆产品价格 (项目是会员抵扣,美妆产品是会员价)
  1204. let payMoney = 0 // 需要支付的价格
  1205. let productPrice = 0 // 项目耗材价格
  1206. let memberCardPrice = 0 // 会员卡卡费
  1207. let couponMoney = 0 // 优惠券金额
  1208. let memberDiscountMoney = 0 // 会员折扣金额(项目)
  1209. let projectProductMoney = 0 // 项目下单推荐的项目耗材
  1210. // 处理优惠券、会员卡折扣互斥逻辑(优先会员卡)
  1211. if (memberCardCurrentDiscount == 0) {
  1212. // 使用了会员卡折扣
  1213. currentChangeCoupon = null
  1214. currentCoupon = -1
  1215. this.setData({
  1216. currentCoupon,
  1217. currentChangeCoupon
  1218. })
  1219. }
  1220. if (currentCoupon != -1) {
  1221. // 使用了优惠券
  1222. memberCardCurrentDiscount = -1
  1223. this.setData({
  1224. memberCardCurrentDiscount
  1225. })
  1226. }
  1227. // 项目耗材下单
  1228. if (productDetail) {
  1229. productPrice = parseFloat(productDetail.price ? productDetail.price : 0.0)
  1230. if (productDetail.is_member) {
  1231. productPrice = parseFloat(
  1232. productDetail.member_price ? productDetail.member_price : 0.0
  1233. )
  1234. }
  1235. }
  1236. // 项目价格(美妆产品价格)
  1237. projectWithGoodsPrice = detail.price ? parseFloat(detail.price) : 0
  1238. // 已是会员 项目是会员抵扣,美妆产品是会员价
  1239. if (memberStatus == 1 || detail.is_member == 1) {
  1240. // 美妆产品,享受会员价
  1241. projectWithGoodsPrice = detail.member_price ?
  1242. parseFloat(detail.member_price) :
  1243. 0 // 项目价格(美妆产品价格)
  1244. // 项目下单(project) + 耗材下单且购买一个项目(product) 显示原价,是否能用会员抵扣,交给用户选择
  1245. if (source == 'project' || source == 'product') {
  1246. projectWithGoodsPrice = detail.price ? parseFloat(detail.price) : 0
  1247. }
  1248. }
  1249. // 如果是单独购买项目耗材,不要计算项目的金额
  1250. if (source == 'product_with_project_order') {
  1251. projectWithGoodsPrice = 0
  1252. }
  1253. // 项目下单时勾选了推荐的耗材
  1254. if (selectProductIndex != -1) {
  1255. let selectProductItem = projectProducts[selectProductIndex]
  1256. projectProductMoney = selectProductItem ?
  1257. memberStatus ?
  1258. parseFloat(selectProductItem.member_price) :
  1259. parseFloat(selectProductItem.price) :
  1260. 0
  1261. }
  1262. // 勾选了购买会员卡,计算会员卡费
  1263. if (selectCardId) {
  1264. memberCardPrice = recommendMemberCard.price ?
  1265. parseFloat(recommendMemberCard.price) :
  1266. 0
  1267. }
  1268. // 是否可以使用会员抵扣,0使用,1不使用,-1不可选择
  1269. if (memberCardCurrentDiscount == 0) {
  1270. memberDiscountMoney = projectWithGoodsPrice
  1271. }
  1272. // 选择了优惠券
  1273. if (currentChangeCoupon) {
  1274. // 类型,1抵扣券,2满减券,3全额券,4卡券(效果和“全额券”一样)
  1275. let couponType = currentChangeCoupon.type
  1276. couponMoney = projectWithGoodsPrice // 全额抵扣券 、 卡券
  1277. if (couponType == 1) {
  1278. couponMoney = currentChangeCoupon.price ?
  1279. parseFloat(currentChangeCoupon.price) :
  1280. 0
  1281. } else if (couponType == 2) {
  1282. couponMoney =
  1283. currentChangeCoupon.full_price &&
  1284. projectWithGoodsPrice >= parseFloat(currentChangeCoupon.full_price) ?
  1285. parseFloat(currentChangeCoupon.price) :
  1286. 0
  1287. }
  1288. }
  1289. // 要支付的金额 = 项目(美妆产品)价格 - 优惠券金额 - 会员卡优惠金额
  1290. payMoney = projectWithGoodsPrice - couponMoney - memberDiscountMoney
  1291. payMoney = payMoney > 0 ? payMoney : 0
  1292. // 项目耗材价格(项目耗材单独下单)
  1293. payMoney = payMoney + productPrice
  1294. payMoney = payMoney > 0 ? payMoney : 0
  1295. // 项目耗材价格(项目下单时勾选了推荐的耗材产品)
  1296. payMoney = payMoney + projectProductMoney
  1297. // 会员卡卡费 (卡费不参与折扣)
  1298. payMoney = payMoney + memberCardPrice
  1299. payMoney = payMoney > 0 ? payMoney : 0
  1300. this.setData({
  1301. moneyData: {
  1302. payMoney: String(payMoney.toFixed(2)), // 需要支付的价格
  1303. projectWithGoodsPrice: String(projectWithGoodsPrice.toFixed(2)), // 项目价格 / 美妆产品价格
  1304. productPrice: String(productPrice.toFixed(2)), // 项目耗材价格
  1305. memberCardPrice: String(memberCardPrice.toFixed(2)), // 会员卡卡费
  1306. couponMoney: String(couponMoney.toFixed(2)), // 优惠券抵扣金额
  1307. memberDiscountMoney: String(memberDiscountMoney.toFixed(2)), // 会员折扣金额(项目)
  1308. projectProductMoney: String(projectProductMoney.toFixed(2)) // 项目下单推荐的项目耗材
  1309. }
  1310. })
  1311. return payMoney
  1312. },
  1313. // 次卡详情点击减少
  1314. onReduce(e) {
  1315. let index = e.currentTarget.dataset.index
  1316. // 根据id获取数组下标
  1317. let indexId = e.currentTarget.dataset.id
  1318. let num = this.data.Ac_cardDetail[indexId].project_list[index].time
  1319. num = num - 1
  1320. if (num < 0) {
  1321. num = 0
  1322. return
  1323. }
  1324. let dataNum = `Ac_cardDetail[${indexId}].project_list[${index}].time`
  1325. let total = this.data.Ac_cardDetail[indexId].total_time
  1326. total = total + 1
  1327. let total_time = `Ac_cardDetail[${indexId}].total_time`
  1328. this.setData({
  1329. [dataNum]: num,
  1330. [total_time]: total
  1331. })
  1332. },
  1333. // 次卡详情点击添加
  1334. onLationAdd(e) {
  1335. let index = e.currentTarget.dataset.index
  1336. // 根据id获取数组下标
  1337. let indexId = e.currentTarget.dataset.id
  1338. if (this.data.Ac_cardDetail[indexId].total_time == 0) {
  1339. return
  1340. }
  1341. let num = this.data.Ac_cardDetail[indexId].project_list[index].time
  1342. num = num + 1
  1343. let dataNum = `Ac_cardDetail[${indexId}].project_list[${index}].time`
  1344. let total = this.data.Ac_cardDetail[indexId].total_time
  1345. total = total - 1
  1346. let total_time = `Ac_cardDetail[${indexId}].total_time`
  1347. this.setData({
  1348. [dataNum]: num
  1349. })
  1350. this.setData({
  1351. [total_time]: total
  1352. })
  1353. },
  1354. //次卡分配产品详情获取
  1355. getCardProjectInfo() {
  1356. get('v2/api/card/project_list', {
  1357. id: this.data.detail.id,
  1358. store_id: this.data.storeId
  1359. },
  1360. (res) => {
  1361. console.log(res, 'product');
  1362. // 计算总分配次数(用来判断是否判断完毕)
  1363. let a = 0
  1364. // 给每一个可分配数组添加一个标识(便于产品数量加减)
  1365. res.data.group.map(item => {
  1366. item.Idindex = a++
  1367. })
  1368. this.setData({
  1369. cardDetail: res.data.projects,
  1370. card_type: res.data.type,
  1371. Ac_cardDetail: res.data.group,
  1372. all_cardDetail: res.data
  1373. })
  1374. }
  1375. )
  1376. },
  1377. // 选中加购产品
  1378. selectExchange(e) {
  1379. let index = e.currentTarget.dataset.index
  1380. let sum = Number(this.data.cardExchangeList[index].price) + Number(this.data.detail.price)
  1381. let id = this.data.cardExchangeList[index].id
  1382. this.setData({
  1383. selectExchange: this.data.selectExchange == 0 ? 1 : 0
  1384. })
  1385. if(this.data.selectExchange==1){
  1386. this.setData({
  1387. toExchangePrice:this.data.cardExchangeList[index].price
  1388. })
  1389. }else{
  1390. this.setData({
  1391. toExchangePrice:0
  1392. })
  1393. }
  1394. this.setData({
  1395. exchangePrice: String(sum.toFixed(2)),
  1396. cardExchangeId: id
  1397. })
  1398. },
  1399. // 获取次卡可换购列表
  1400. getCardExchangeList(storeId, id) {
  1401. get('/v2/api/card/plus', {
  1402. store_id: storeId,
  1403. card_id: id
  1404. }, (res) => {
  1405. if (res.code == 200) {
  1406. this.setData({
  1407. cardExchangeList: res.data.list
  1408. })
  1409. }
  1410. })
  1411. }
  1412. })