confirmProjectOrder.js 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001
  1. // pages/confirmProjectOrder/confirmProjectOrder.js
  2. import {
  3. get,
  4. post
  5. } from '../../utils/http'
  6. const app = getApp()
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. currentCoupon: -1,
  13. visible: false,
  14. CouPonIndex: [],
  15. needSelect: false,
  16. coupSelectType: '',
  17. productDiscount: '',
  18. isSelectCoup: [], // 选择的优惠券
  19. // 下面是支付的数据
  20. pay_methon: 1,
  21. payNow: false,
  22. switchPay: 'product',
  23. showMoney: 0, // 价值总额
  24. showRuleText: 10086,
  25. dotSelectCard: false,
  26. marks: {
  27. // 优惠券类型,1直接抵扣券,2满减券,3全额减免券,4卡券
  28. 1: '抵扣券',
  29. 2: '满减券',
  30. 3: '全额减免券',
  31. 4: '项目卡券'
  32. },
  33. orderDiscount: 0,
  34. priceSet: 0,
  35. cardList: [], // 我的次卡对应项目列表
  36. selectCodeList: [], //选择的次卡的列表
  37. visibleCard: false,
  38. card_data: [], //选择次卡的项目id
  39. selectCardProjectList: [], //选择次卡的项目列表
  40. selectCoupPrice: 0, //选择优惠券之后的价格
  41. discountList: [], //折扣列表
  42. level: '', //用户充值折扣等级 (0是未拥有等级)
  43. levelPrice: '', //充值等级折扣优惠价格
  44. },
  45. // 获取用户充值折扣等级
  46. getLevel() {
  47. get('/v2/api/user/discount_level', {}, (res) => {
  48. if (res.code == 200) {
  49. res.data = Number(res.data)
  50. if (res.data == 0) {
  51. this.setData({
  52. level: 0
  53. })
  54. return
  55. }
  56. this.setData({
  57. level: Number(res.data * 0.1)
  58. })
  59. this.setData({
  60. tolevel: (this.data.level * 10).toFixed(1)
  61. })
  62. }
  63. })
  64. },
  65. clickRuleText(e) {
  66. let that = this
  67. let index = e.currentTarget.dataset.index
  68. if (this.data.showRuleText == index) {
  69. that.setData({
  70. showRuleText: 10086
  71. })
  72. } else {
  73. that.setData({
  74. showRuleText: index
  75. })
  76. }
  77. },
  78. /**
  79. * 点击使用按钮、勾选按钮
  80. */
  81. checkSelect: function (e) {
  82. // let index = e.currentTarget.dataset.index
  83. let CouPonIndex = this.data.productDiscount
  84. let selectIndex = e.currentTarget.dataset.index
  85. let project_list = this.data.orderDetails.project_list //这里是项目列表
  86. let project_ids = this.data.productDiscount[selectIndex].project_ids
  87. let _ids = 'productDiscount[' + selectIndex + '].project_ids'
  88. let isReturn = false
  89. //去掉已选择次卡的项目id
  90. this.data.card_data.forEach(res => {
  91. if (project_ids.indexOf(res.id) > -1) {
  92. project_ids.forEach((e, i) => {
  93. if (res.id == e) {
  94. project_ids.splice(i, 1)
  95. }
  96. })
  97. }
  98. })
  99. this.setData({
  100. _ids: project_ids
  101. })
  102. if (this.data.productDiscount[selectIndex].type != 4 && this.data.card_data.length != 0) {
  103. wx.showToast({
  104. title: '该项目已选择次卡',
  105. icon: 'none'
  106. })
  107. return
  108. }
  109. this.data.selectCardProjectList.forEach(res => {
  110. if (this.data.productDiscount[selectIndex].project_ids.indexOf(res.id) > -1) {
  111. wx.showToast({
  112. title: '该项目已选择次卡',
  113. icon: 'none'
  114. })
  115. isReturn = true
  116. }
  117. })
  118. if (isReturn) {
  119. return
  120. }
  121. let curreValue = !CouPonIndex[selectIndex].isSelect
  122. // 判断是否是不相同的项目券
  123. if (this.data.productDiscount[selectIndex].type != 4) {
  124. this.setData({
  125. priceSet: 0,
  126. showMoney: this.data.orderDetails.price
  127. })
  128. for (let i = 0; i < CouPonIndex.length; i++) {
  129. CouPonIndex[i].isSelect = false
  130. }
  131. for (let i = 0; i < project_list.length; i++) {
  132. project_list[i].cardId = ''
  133. }
  134. } else if (this.data.coupSelectType != 4) {
  135. for (let i = 0; i < CouPonIndex.length; i++) {
  136. CouPonIndex[i].isSelect = false
  137. }
  138. for (let i = 0; i < project_list.length; i++) {
  139. project_list[i].cardId = ''
  140. }
  141. } else {
  142. let numberSelect = 0
  143. for (let i = 0; i < CouPonIndex.length; i++) {
  144. if (CouPonIndex[i].isSelect) {
  145. numberSelect = numberSelect + 1
  146. }
  147. }
  148. console.log('numberSelect')
  149. console.log(numberSelect)
  150. if (numberSelect == this.data.orderDetails.project_list.length && curreValue) {
  151. wx.showToast({
  152. title: '最多选择' + this.data.orderDetails.project_list.length + '项目券!',
  153. icon: 'none'
  154. })
  155. return
  156. }
  157. }
  158. CouPonIndex[selectIndex].isSelect = curreValue
  159. if (!curreValue) {
  160. for (let j = 0; j < project_list.length; j++) {
  161. if (project_list[j].cardId && project_list[j].cardId == this.data.productDiscount[selectIndex].id) { // 如果是取消选择,那么也要取消绑定项目的id
  162. project_list[j].cardId = ''
  163. }
  164. }
  165. CouPonIndex[selectIndex].projectids = ''
  166. }
  167. let orderDetails1 = this.data.orderDetails
  168. orderDetails1.project_list = project_list
  169. this.setData({
  170. orderDetails: orderDetails1,
  171. productDiscount: CouPonIndex,
  172. coupSelectType: this.data.productDiscount[selectIndex].type
  173. })
  174. console.log(this.data.CouPonIndex)
  175. this.selectCoup()
  176. },
  177. // 计算总额
  178. calculateMoney() {
  179. let that = this
  180. let initPrice = 0
  181. if (this.data.selectCardProjectList.length > 0) {
  182. this.data.selectCardProjectList.forEach(res => {
  183. initPrice = Number(initPrice) + Number(res.price)
  184. })
  185. }
  186. console.log(initPrice, 'initPrice');
  187. let money = this.data.selectCardProjectList.length > 0 ? Number(this.data.orderDetails.price - initPrice) : this.data.orderDetails.price
  188. console.log(money, 'moneymoney');
  189. let isSelectCoup = this.data.isSelectCoup
  190. let project_list = this.data.orderDetails.project_list //这里是项目列表
  191. // if (isSelectCoup.length == 0) {
  192. // that.setData({
  193. // showMoney: money.toFixed(2)
  194. // })
  195. // return
  196. // }
  197. // 如果是项目
  198. if (isSelectCoup.length > 0) {
  199. if (isSelectCoup[0].type == 4) {
  200. let numberHaveCardId = 0
  201. for (let i = 0; i < project_list.length; i++) {
  202. if (project_list[i].cardId) {
  203. money = money - project_list[i].price
  204. numberHaveCardId = numberHaveCardId + 1
  205. }
  206. }
  207. } else if (isSelectCoup[0].type == 3) {
  208. for (let i = 0; i < project_list.length; i++) {
  209. money = money - project_list[i].price
  210. }
  211. } else {
  212. money = money - isSelectCoup[0].price
  213. }
  214. }
  215. /**
  216. * type:1项目,2设备分类,3耗材
  217. * discount_type:折扣条件,1数量/类型,2金额
  218. */
  219. let notSelectId = []
  220. this.data.isSelectCoup.forEach(item => {
  221. notSelectId.push(item.projectids)
  222. })
  223. //去除选择优惠券或者次卡的项目
  224. let _project_list = project_list.filter(res => {
  225. return notSelectId.toString().indexOf(res.id) && res.isCard == false
  226. })
  227. let _money = money
  228. console.log(money, 'money===', _money);
  229. let devicePrice = 0 //满足折扣设备的项目总金额
  230. let productPrice = 0 //耗材总金额
  231. //满足折扣设备的项目
  232. let deviceList = _project_list.filter(item => {
  233. return item.device_type_id == item.device_id
  234. })
  235. if (deviceList.length > 0) {
  236. deviceList.forEach(item => {
  237. devicePrice = devicePrice + Number(item.price)
  238. })
  239. }
  240. //拥有耗材的项目
  241. let productList = _project_list.filter(item => {
  242. return item.product_name != ""
  243. })
  244. console.log(productList, 'productList');
  245. if (productList.length > 0) {
  246. productList.forEach(item => {
  247. productPrice = productPrice + Number(item.product_price)
  248. })
  249. }
  250. let _priceSet = this.data.priceSet
  251. if (this.data.discountList.length > 0) {
  252. let discountList = this.data.discountList
  253. //计算所有的折扣金额
  254. discountList.forEach(item => {
  255. let priceSet = 0,
  256. initmoney = money,
  257. _initmoney = money
  258. if (item.type == 1 && item.discount_type == 1 && _project_list.length >= item.num) {
  259. initmoney = initmoney * item.discount_rate / 10
  260. priceSet = _initmoney - initmoney
  261. item["priceSet"] = priceSet
  262. } else if (item.type == 1 && item.discount_type == 2 && money > Number(item.amount)) {
  263. initmoney = initmoney * item.discount_rate / 10
  264. priceSet = _initmoney - initmoney
  265. item["priceSet"] = priceSet
  266. } else if (item.type == 2 && item.discount_type == 2 && devicePrice > Number(item.amount)) {
  267. //满足条件的项目折扣
  268. initmoney = (initmoney - devicePrice) + devicePrice * item.discount_rate / 10
  269. priceSet = _initmoney - initmoney
  270. item["priceSet"] = priceSet
  271. } else if (item.type == 3 && item.discount_type == 1 && productList.length >= item.num) {
  272. //满足条件的项目折扣
  273. initmoney = (initmoney - productPrice) + productPrice * item.discount_rate / 10
  274. priceSet = _initmoney - initmoney
  275. item["priceSet"] = priceSet
  276. } else if (item.type == 3 && item.discount_type == 2 && productPrice >= item.amount) {
  277. //满足条件的项目折扣
  278. initmoney = (initmoney - productPrice) + productPrice * item.discount_rate / 10
  279. priceSet = _initmoney - initmoney
  280. item["priceSet"] = priceSet
  281. }
  282. })
  283. console.log(discountList, 'discountList');
  284. //排序,最优折扣放第一位
  285. discountList = discountList.sort(this.compare("priceSet"))
  286. let discountInfo = discountList[0]
  287. if (discountInfo.type == 1 && discountInfo.discount_type == 1 && _project_list.length >= discountInfo.num) {
  288. money = money * discountInfo.discount_rate / 10
  289. _priceSet = _money - money
  290. } else if (discountInfo.type == 1 && discountInfo.discount_type == 2 && money > Number(discountInfo.amount)) {
  291. money = money * discountInfo.discount_rate / 10
  292. _priceSet = _money - money
  293. } else if (discountInfo.type == 2 && discountInfo.discount_type == 2 && devicePrice > Number(discountInfo.amount)) {
  294. //满足条件的项目折扣
  295. money = (money - devicePrice) + devicePrice * discountInfo.discount_rate / 10
  296. _priceSet = _money - money
  297. } else if (discountInfo.type == 3 && discountInfo.discount_type == 1 && productList.length >= discountInfo.num) {
  298. //满足条件的项目折扣
  299. money = (money - productPrice) + productPrice * discountInfo.discount_rate / 10
  300. _priceSet = _money - money
  301. } else if (discountInfo.type == 3 && discountInfo.discount_type == 2 && productPrice >= discountInfo.amount) {
  302. //满足条件的项目折扣
  303. money = (money - productPrice) + productPrice * discountInfo.discount_rate / 10
  304. _priceSet = _money - money
  305. }
  306. }
  307. console.log(_priceSet, '_priceSet');
  308. that.setData({
  309. showMoney: Number(money).toFixed(2) < 0 ? 0.00 : Number(money).toFixed(2),
  310. priceSet: Number(_priceSet).toFixed(2),
  311. orderDiscount: this.data.discountList.length!=0?this.data.discountList.sort(this.compare("priceSet"))[0].id:0
  312. })
  313. },
  314. //排序
  315. compare(property) {
  316. return function (obj1, obj2) {
  317. var value1 = obj1[property];
  318. var value2 = obj2[property];
  319. return value2 - value1; // 降序
  320. }
  321. },
  322. // 支付的操作
  323. onClosePay() {
  324. this.setData({
  325. payNow: false
  326. })
  327. },
  328. /**
  329. * 关闭弹框
  330. */
  331. onClose() {
  332. this.setData({
  333. visible: false
  334. })
  335. },
  336. // 关闭次卡弹窗
  337. onCloseCard() {
  338. this.setData({
  339. visibleCard: false
  340. })
  341. },
  342. // 点击x关闭次卡弹窗
  343. onCancelCard() {
  344. this.setData({
  345. visibleCard: false
  346. })
  347. },
  348. showCoup() {
  349. if (this.data.dotSelectCard) {
  350. wx.showToast({
  351. title: '本订单已使用优惠券!',
  352. icon: 'none'
  353. })
  354. return
  355. }
  356. this.setData({
  357. visible: true
  358. })
  359. },
  360. // 打开次卡窗口
  361. showCard() {
  362. this.setData({
  363. visibleCard: true,
  364. selectCoupPrice: this.data.showMoney
  365. })
  366. },
  367. // 选中次卡触发
  368. cardSel(e) {
  369. console.log(this.data.selectCardProjectList, e.currentTarget.dataset, 'e.currentTarget.dataset')
  370. let index = e.currentTarget.dataset.index
  371. let item = e.currentTarget.dataset.item
  372. let selList = this.data.cardList
  373. let isselectCard = false
  374. let isRepeat = false
  375. this.data.cardList.forEach(res => {
  376. if (JSON.stringify(item.project_ids) == JSON.stringify(res.project_ids) && res.isSelectCard && res.id != item.id) {
  377. isRepeat = true
  378. }
  379. })
  380. if (isRepeat) {
  381. wx.showToast({
  382. title: '不可重复选择相同次卡',
  383. icon: 'none'
  384. })
  385. return
  386. }
  387. this.data.orderDetails.project_list.forEach((res, i) => {
  388. if (res.cardId && this.data.cardList[index].project_ids.indexOf(res.id) > -1) {
  389. isselectCard = true
  390. }
  391. })
  392. if (isselectCard) {
  393. wx.showToast({
  394. title: '该项目已选择优惠券',
  395. icon: 'none'
  396. })
  397. return
  398. }
  399. let isProjectList = []
  400. //判断是否重复选择次卡
  401. let isTrueCode = false
  402. this.data.cardList.forEach(res => {
  403. if (res.isSelectCard) {
  404. isProjectList = isProjectList.concat(res.project_ids)
  405. }
  406. })
  407. if (e.currentTarget.dataset.item.isSelectCard) {
  408. e.currentTarget.dataset.item.project_ids.forEach((_item, index) => {
  409. isProjectList.forEach((item, i) => {
  410. if (_item == item) {
  411. isProjectList.splice(i, 1)
  412. }
  413. })
  414. })
  415. }
  416. if (this.includes(isProjectList, e.currentTarget.dataset.item.project_ids)) {
  417. isTrueCode = true
  418. }
  419. if (isTrueCode) {
  420. wx.showToast({
  421. title: '请勿重复选择次卡',
  422. icon: 'none'
  423. })
  424. return
  425. }
  426. console.log(isProjectList, 'isProjectList');
  427. let selValue = !selList[index].isSelectCard
  428. selList[index].isSelectCard = selValue
  429. this.setData({
  430. cardList: selList
  431. })
  432. },
  433. includes(arr1, arr2) {
  434. return arr2.every(val => arr1.includes(val));
  435. },
  436. onConfirmCard() {
  437. let price = this.data.orderDetails.price //订单价格
  438. let card_data = []
  439. let card_data_info = {}
  440. let selectCodeList = []
  441. let selectCardProjectList = []
  442. //选择次卡&价格计算
  443. let projectId = []
  444. this.data.orderDetails.project_list.forEach((res, i) => {
  445. if (res.cardId) {
  446. price = price - res.price
  447. }
  448. this.data.cardList.forEach(item => {
  449. //如果已选择优惠券
  450. console.log(res.cardId, 'cardId.length', item.isSelectCard);
  451. if (item.project_ids.indexOf(res.id) > -1 && projectId.indexOf(res.id) == -1 && item.isSelectCard) {
  452. projectId.push(res.id)
  453. price = price - res.price
  454. price = price < 0 ? 0 : price
  455. selectCardProjectList.push(res)
  456. selectCardProjectList = Array.from(new Set(selectCardProjectList))
  457. selectCodeList.push(item)
  458. card_data_info = {
  459. id: res.id,
  460. card_id: item.id
  461. }
  462. card_data.push(card_data_info)
  463. let _item = 'orderDetails.project_list[' + i + '].isCard'
  464. this.setData({
  465. [_item]: true
  466. })
  467. }
  468. })
  469. })
  470. let priceSet = 0
  471. if (selectCodeList.length == 0 && this.data.discountList.length > 0) {
  472. priceSet = this.data.discountList[0].priceSet.toFixed(2)
  473. price = this.data.orderDetails.price - priceSet
  474. }
  475. this.setData({
  476. card_data: card_data,
  477. showMoney: price,
  478. visibleCard: false,
  479. selectCodeList: selectCodeList,
  480. selectCardProjectList: selectCardProjectList,
  481. priceSet: priceSet
  482. })
  483. this.calculateMoney() //计算总额
  484. },
  485. onCancelCoupon() {
  486. this.setData({
  487. visible: false
  488. })
  489. },
  490. onConfirmCoupon() {
  491. // let currentChangeCoupon = this.data.couponList[this.data.currentCoupon]
  492. this.setData({
  493. visible: false,
  494. // currentChangeCoupon
  495. },
  496. () => {
  497. // this.calculateOrderPayMoney()
  498. }
  499. )
  500. },
  501. selectCoup() {
  502. let that = this
  503. let isSelectCoups = []
  504. for (let i = 0; i < this.data.productDiscount.length; i++) {
  505. if (this.data.productDiscount[i].isSelect) {
  506. let selectCoup = that.data.productDiscount[i]
  507. isSelectCoups.push(selectCoup)
  508. }
  509. }
  510. this.setData({
  511. isSelectCoup: isSelectCoups
  512. })
  513. console.log(isSelectCoups)
  514. that.theMoneyBest()
  515. },
  516. /**
  517. * 获取订单详情
  518. */
  519. getOrderData() {
  520. let that = this
  521. get('v2/api/order/info', {
  522. id: this.data.orderDetailsId
  523. }, (res) => {
  524. res.data.project_list.forEach(item => {
  525. item.isCard = false
  526. })
  527. if (res.data.discount != 0) {
  528. let newsPrice = res.data.price
  529. res.data.price = newsPrice * 1 + res.data.discount_price * 1
  530. this.setData({
  531. dotSelectCard: true,
  532. orderDetails: res.data,
  533. showMoney: newsPrice,
  534. priceSet: res.data.discount_price
  535. })
  536. return
  537. }
  538. if (res.data.coupon_list.length > 0) {
  539. res.data.coupon_list[0].type = 0
  540. }
  541. this.setData({
  542. orderDetails: res.data,
  543. showMoney: res.data.price,
  544. isSelectCoup: res.data.coupon_list,
  545. dotSelectCard: res.data.coupon_list.length !== 0 ? true : false,
  546. }, )
  547. that.productDiscount()
  548. if (res.data.type == "one") {
  549. return
  550. }
  551. that.orderDiscount()
  552. })
  553. },
  554. // 这里是立即支付的接口
  555. // v2/api/order/pay
  556. payNow: function () {
  557. // 计算折扣
  558. this.setData({
  559. levelPrice: (this.data.showMoney * this.data.level).toFixed(2)
  560. })
  561. this.setData({
  562. toLevelPrice: (this.data.showMoney - this.data.levelPrice).toFixed(2)
  563. })
  564. this.setData({
  565. payNow: true,
  566. })
  567. },
  568. // 活动折扣类型,非必填,0无折扣(默认),50新人五折活动,100仪器免费使用权益
  569. paybtm() {
  570. let isSelectCoup = this.data.isSelectCoup
  571. let coupType = isSelectCoup.length > 0 ? isSelectCoup[0].type : 5
  572. let coupData = []
  573. // 卡券,项目券数据包,id:订单项目ID,coupon_id:优惠券ID,如:[{"id":1220,coupon_id:199}]
  574. // 支付方式,amount余额支付,weixin微信支付
  575. if (coupType == 4) {
  576. for (let i = 0; i < isSelectCoup.length; i++) {
  577. let notData = {
  578. id: isSelectCoup[i].projectids,
  579. coupon_id: isSelectCoup[i].id,
  580. }
  581. coupData.push(notData)
  582. }
  583. }
  584. let dataTo = {
  585. id: this.data.orderDetails.id,
  586. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  587. }
  588. if (coupType == 4) {
  589. dataTo.coupon_data = JSON.stringify(coupData)
  590. } else if (coupType != 5) {
  591. dataTo.coupon_id = isSelectCoup[0].id
  592. }
  593. if (this.data.card_data.length != 0) {
  594. dataTo.card_data = JSON.stringify(this.data.card_data)
  595. }
  596. if (this.data.priceSet != 0 && !this.data.dotSelectCard && this.data.card_data.length == 0) {
  597. dataTo.discount = this.data.orderDiscount
  598. }
  599. let that = this
  600. console.log(dataTo)
  601. post('v2/api/order/pay', dataTo, (res) => {
  602. that.setData({
  603. payNow: false
  604. })
  605. if (res.data.pay_status == 1) {
  606. // wx.showToast({
  607. // title: '支付成功!',
  608. // icon: "none"
  609. // })
  610. that.payOkey()
  611. return
  612. }
  613. if (that.data.pay_methon == 2) {
  614. // wx.showToast({
  615. // title: '支付成功!',
  616. // icon: "none"
  617. // })
  618. that.payOkey()
  619. return
  620. }
  621. wx.requestPayment({
  622. timeStamp: res.data.pay_data.timeStamp,
  623. nonceStr: res.data.pay_data.nonceStr,
  624. package: res.data.pay_data.package,
  625. signType: res.data.pay_data.signType,
  626. paySign: res.data.pay_data.paySign,
  627. success(res) {
  628. if (res.errMsg == 'requestPayment:ok') {
  629. // wx.showToast({
  630. // title: '支付成功!',
  631. // icon: "none"
  632. // })
  633. that.payOkey()
  634. }
  635. },
  636. fail(res) {
  637. that.orderDiscount()
  638. that.getOrderData()
  639. wx.showToast({
  640. title: '支付失败!',
  641. icon: "none"
  642. })
  643. }
  644. })
  645. })
  646. },
  647. payOkey() {
  648. wx.showToast({
  649. title: '支付成功!',
  650. icon: "none"
  651. })
  652. let that = this
  653. setTimeout(function () {
  654. that.toDetails()
  655. }, 1000); //延迟时间 这里是1秒
  656. },
  657. toDetails() {
  658. wx.redirectTo({
  659. url: '/pages/orderDetailsProject/orderDetailsProject?id=' + this.data.orderDetails.id,
  660. })
  661. },
  662. pay_methonw() {
  663. this.setData({
  664. pay_methon: 1
  665. })
  666. },
  667. pay_methonc() {
  668. this.setData({
  669. pay_methon: 2
  670. })
  671. },
  672. //
  673. // 卡券,项目券数据包,id:订单项目ID,coupon_id:优惠券ID,如:[{"id":1220,coupon_id:199}]
  674. theMoneyBest() {
  675. let that = this
  676. let project_list = this.data.orderDetails.project_list //这里是项目列表
  677. let isSelectCoup = this.data.isSelectCoup //这里选择了的卡券列表
  678. let selectProjectList = [] // 适合的卡券列表
  679. // let CouPonIndex = this.data.CouPonIndex // 卡券选择的Id
  680. let productDiscount = this.data.productDiscount // 卡券列表
  681. console.log(productDiscount)
  682. if (isSelectCoup.length == 0) {
  683. this.setData({
  684. priceSet: 0,
  685. showMoney: this.data.orderDetails.price
  686. })
  687. that.onShowPrice()
  688. return
  689. }
  690. // debugger
  691. if (isSelectCoup[0].type == 4) {
  692. for (let i = 0; i < isSelectCoup.length; i++) { // 首先遍历卡券
  693. if (!isSelectCoup[i].projectids) { // 如果卡券没绑定项目
  694. console.log('没绑定过!')
  695. let selectIndexMoney = 0 // 初始值
  696. let selectIndex = 111 // 初始金额
  697. for (let j = 0; j < project_list.length; j++) { // 遍历项目
  698. if (isSelectCoup[i].project_ids.indexOf(project_list[j].id) != -1 && !project_list[j].cardId) { // 如果卡券能够使用这个项目并且这个项目没有被绑定过
  699. console.log('project_list[j].price')
  700. console.log(project_list[j].price)
  701. console.log(selectIndexMoney)
  702. console.log(project_list[j].price > selectIndexMoney)
  703. if (project_list[j].price * 1 > selectIndexMoney * 1) {
  704. selectIndex = j
  705. selectIndexMoney = project_list[j].price
  706. console.log('--' + selectIndexMoney)
  707. }
  708. // selectProjectList.push(project_list[i])
  709. }
  710. }
  711. if (selectIndex != 111) {
  712. isSelectCoup[i].projectids = project_list[selectIndex].id
  713. isSelectCoup[i].projectName = project_list[selectIndex].name
  714. project_list[selectIndex].cardId = isSelectCoup[i].id
  715. } else {
  716. for (let k = 0; k < productDiscount.length; k++) {
  717. if (productDiscount[k].id == isSelectCoup[i].id) {
  718. // isSelectCoup.
  719. productDiscount[k].isSelect = false
  720. // isSelectCoup.splice(isSelectCoup.length-1,1);
  721. wx.showToast({
  722. title: '没有适合的项目!',
  723. icon: "none"
  724. })
  725. }
  726. }
  727. }
  728. if (selectIndex == 111) {
  729. isSelectCoup.splice(isSelectCoup.length - 1, 1);
  730. }
  731. }
  732. }
  733. let orderDetails1 = this.data.orderDetails
  734. orderDetails1.project_list = project_list
  735. this.setData({
  736. // CouPonIndex: CouPonIndex,
  737. productDiscount: productDiscount,
  738. isSelectCoup: isSelectCoup,
  739. orderDetails: orderDetails1,
  740. })
  741. }
  742. this.calculateMoney() //计算总额
  743. },
  744. /**
  745. * 获取订单详情
  746. */
  747. productDiscount() {
  748. let that = this
  749. let ids = ''
  750. // for (let i = 0; i < this.data.orderDetails.project_list.length; i++) {
  751. // ids = ids + ',' + this.data.orderDetails.project_list[i].id
  752. // }
  753. let storeData = getApp().globalData.storeData
  754. let storeId = storeData.id || wx.getStorageSync('store_id')
  755. get('v2/api/order/coupon', {
  756. id: this.data.orderDetails.id,
  757. store_id: storeId,
  758. page: 1,
  759. limit: 200,
  760. }, (res) => {
  761. let showLine = res.data.list
  762. let CouPonIndex = []
  763. for (let i = 0; i < showLine.length; i++) {
  764. if (showLine[i].full_price * 1 < that.data.orderDetails.price * 1 || showLine[i].full_price * 1 == that.data.orderDetails.price * 1) {
  765. showLine[i].isSelect = false
  766. CouPonIndex.push(showLine[i])
  767. }
  768. }
  769. this.setData({
  770. productDiscount: CouPonIndex,
  771. // CouPonIndex: CouPonIndex
  772. }, )
  773. })
  774. },
  775. /**
  776. * 获取当前用户折扣
  777. */
  778. orderDiscount() {
  779. get('/v3/api/order/discount', {
  780. id: this.data.orderDetailsId
  781. }, (res) => {
  782. this.setData({
  783. discountList: res.data.list
  784. }, )
  785. this.onShowPrice()
  786. // 判断是否有别的折扣
  787. if(res.data.total==0){
  788. // 获取用户折扣等级
  789. this.getLevel()
  790. }
  791. })
  792. },
  793. // 计算折扣价格
  794. onShowPrice() {
  795. if (this.data.discountList.length == 0) {
  796. return
  797. }
  798. this.calculateMoney()
  799. // let money = Number(this.data.orderDetails.price) * Number(this.data.discountList[0].discount_rate) / 10
  800. // this.setData({
  801. // priceSet: (Number(this.data.orderDetails.price) - money).toFixed(2),
  802. // showMoney: money.toFixed(2)
  803. // })
  804. // orderDiscount
  805. },
  806. /**
  807. * 生命周期函数--监听页面加载
  808. */
  809. onLoad: function (options) {
  810. if (options.q) {
  811. let conUrlAll = decodeURIComponent(options.q)
  812. this.setData({
  813. orderDetailsId: conUrlAll.replace('https://test-img.ijolijoli.com/wxmini/pay?id=', '')
  814. })
  815. } else {
  816. this.setData({
  817. orderDetailsId: options.id
  818. })
  819. }
  820. this.getOrderData()
  821. // 获取项目可用的次卡列表
  822. this.getAvaCardList()
  823. let lat1 = app.address.latitude
  824. let lng1 = app.address.longitude
  825. this.setData({
  826. lat1: lat1,
  827. lng1: lng1,
  828. })
  829. },
  830. onCopy: function (e) {
  831. let content = e.currentTarget.dataset.no
  832. var that = this;
  833. wx.setClipboardData({
  834. data: content,
  835. success: function (res) {
  836. wx.showToast({
  837. title: '复制成功!',
  838. icon: "none"
  839. })
  840. }
  841. });
  842. },
  843. /**
  844. * 生命周期函数--监听页面初次渲染完成
  845. */
  846. onReady: function () {
  847. },
  848. /**
  849. * 生命周期函数--监听页面显示
  850. */
  851. onShow: function () {
  852. this.getAmount()
  853. },
  854. /**
  855. * 获取我的储值
  856. * api/user
  857. */
  858. getAmount() {
  859. get('api/user/amount', {}, (res) => {
  860. if (res.data) {
  861. this.setData({
  862. inserllAmount: res.data.amount
  863. })
  864. }
  865. })
  866. },
  867. // 获取项目可用的次卡列表
  868. getAvaCardList() {
  869. console.log(this, 'shit')
  870. get('v2/api/order/card', {
  871. page: 1,
  872. limit: 200,
  873. id: this.data.orderDetailsId
  874. }, (res) => {
  875. console.log(res, 'getAvaCardList')
  876. res.data.list.forEach((item) => {
  877. item.isSelectCard = false
  878. })
  879. this.setData({
  880. cardList: res.data.list,
  881. })
  882. }, (error) => {
  883. console.log("请求失败", error)
  884. })
  885. },
  886. /**
  887. * 生命周期函数--监听页面隐藏
  888. */
  889. onHide: function () {
  890. },
  891. /**
  892. * 生命周期函数--监听页面卸载
  893. */
  894. onUnload: function () {
  895. },
  896. /**
  897. * 页面相关事件处理函数--监听用户下拉动作
  898. */
  899. onPullDownRefresh: function () {
  900. },
  901. /**
  902. * 页面上拉触底事件的处理函数
  903. */
  904. onReachBottom: function () {
  905. },
  906. /**
  907. * 用户点击右上角分享
  908. */
  909. onShareAppMessage: function () {
  910. }
  911. })