orderConfirm.js 40 KB

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