orderDetail.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465
  1. import { get, post } from '../../utils/http'
  2. import { $wuxCountDown } from '../../components/dist/index'
  3. import { toQrcode } from '../../utils/util'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. time: '',
  10. sum: 0, // 防止进入死循环
  11. detail: {},
  12. showTips: false, // 是否展示页面顶部提示
  13. tips: {
  14. status_0: ['待支付', '逾期未付款,订单将自动取消!'],
  15. status_1: ['预约成功', '您的预约单已生效,请准时到店体验!'],
  16. status_2: ['预约成功', '您的预约单已生效,请准时到店体验!']
  17. },
  18. status: {
  19. 0: '待付款',
  20. 1: '已预约',
  21. 2: '进行中',
  22. 3: '已结算',
  23. 4: '已取消'
  24. },
  25. pay_methon: 1,
  26. payNow: false,
  27. },
  28. pay_methonw() {
  29. this.setData({
  30. pay_methon: 1
  31. })
  32. },
  33. pay_methonc() {
  34. this.setData({
  35. pay_methon: 2
  36. })
  37. },
  38. /**
  39. * 生命周期函数--监听页面加载
  40. */
  41. onLoad: function (options) {
  42. console.log(options)
  43. this.getAmount()
  44. this.getOrderDetail(options.id)
  45. },
  46. /**
  47. * 生命周期函数--监听页面初次渲染完成
  48. */
  49. onReady: function () {},
  50. /**
  51. * 生命周期函数--监听页面显示
  52. */
  53. onShow: function () {},
  54. /**
  55. * 生命周期函数--监听页面隐藏
  56. */
  57. onHide: function () {},
  58. /**
  59. * 生命周期函数--监听页面卸载
  60. */
  61. onUnload: function () {
  62. if (this.c1) this.c1.stop()
  63. },
  64. /**
  65. * 页面相关事件处理函数--监听用户下拉动作
  66. */
  67. onPullDownRefresh: function () {},
  68. /**
  69. * 页面上拉触底事件的处理函数
  70. */
  71. onReachBottom: function () {},
  72. /**
  73. * 用户点击右上角分享
  74. */
  75. onShareAppMessage: function () {},
  76. /**
  77. * 复制订单号
  78. */
  79. onCopyOrderNum(e) {
  80. wx.setClipboardData({
  81. data: e.currentTarget.dataset.num || '',
  82. success(res) {
  83. console.log(res)
  84. }
  85. })
  86. },
  87. /**
  88. * 取消订单
  89. */
  90. onCancelOrder() {
  91. let that = this
  92. wx.showModal({
  93. title: '提示',
  94. content: '是否取消当前订单',
  95. success(res) {
  96. if (res.confirm) {
  97. console.log('用户点击确定')
  98. post(
  99. 'api/order/cancel',
  100. {
  101. order_id: that.data.detail.id
  102. },
  103. (res) => {
  104. wx.showToast({
  105. title: res.msg,
  106. icon: 'success',
  107. duration: 2000
  108. })
  109. that.getOrderDetail(that.data.detail.id)
  110. }
  111. )
  112. } else if (res.cancel) {
  113. console.log('用户点击取消')
  114. }
  115. }
  116. })
  117. },
  118. onPay: function (e) {
  119. this.setData({
  120. payNow: true
  121. })
  122. },
  123. /**
  124. * 支付
  125. */
  126. payNow() {
  127. let that = this
  128. that.methonPayOrder()
  129. },
  130. onClosePay() {
  131. this.setData({
  132. payNow: false
  133. })
  134. },
  135. /**
  136. * 去支付
  137. */
  138. methonPayOrder() {
  139. let that = this
  140. post(
  141. 'api/pay/project', {
  142. order_id: that.data.detail.id,
  143. pay_way: this.data.pay_methon == 1 ? 'weixin' : 'amount',
  144. },
  145. (res) => {
  146. that.setData({
  147. payNow: false
  148. })
  149. if (that.data.pay_methon == 2) {
  150. that.getOrderDetail(that.data.detail.id)
  151. get('api/message/ids', {}, (res) => {
  152. let ids = res.data.ids
  153. that.onSubmitCh(ids)
  154. })
  155. return
  156. }
  157. wx.requestPayment({
  158. timeStamp: res.data.pay_data.timeStamp,
  159. nonceStr: res.data.pay_data.nonceStr,
  160. package: res.data.pay_data.package,
  161. signType: res.data.pay_data.signType,
  162. paySign: res.data.pay_data.paySign,
  163. success(res) {
  164. if (res.errMsg == 'requestPayment:ok') {
  165. wx.showToast({
  166. title: '支付成功',
  167. icon: 'success'
  168. })
  169. that.getOrderDetail(that.data.detail.id)
  170. get('api/message/ids', {}, (res) => {
  171. let ids = res.data.ids
  172. wx.requestSubscribeMessage({
  173. tmplIds: ids,
  174. success(res) {
  175. console.log(res)
  176. that.messageAgree(ids, that.data.detail.id)
  177. },
  178. fail(rej) {
  179. console.log(rej)
  180. that.messageAgree(ids)
  181. wx.showToast({
  182. title: JSON.stringify(rej),
  183. icon: 'error'
  184. })
  185. }
  186. })
  187. })
  188. }
  189. },
  190. fail(res) {
  191. wx.showToast({
  192. title: '支付失败',
  193. icon: 'error'
  194. })
  195. }
  196. })
  197. }
  198. )
  199. },
  200. onSubmitCh(ids) {
  201. let that = this
  202. wx.showModal({
  203. title: '提示',
  204. content: '支付成功! 是否进行消息提醒',
  205. success: function (res) {
  206. if (res.confirm) {
  207. that.onSubmitTrue(ids)
  208. } else if (res.cancel) {
  209. that.messageAgree(ids, that.data.detail.id)
  210. }
  211. }
  212. });
  213. },
  214. /**
  215. * 获取我的储值
  216. * api/user
  217. */
  218. getAmount() {
  219. get('api/user/amount', {}, (res) => {
  220. if (res.data) {
  221. this.setData({
  222. inserllAmount: res.data.amount
  223. })
  224. }
  225. })
  226. },
  227. onSubmitTrue(ids) {
  228. let that = this
  229. wx.requestSubscribeMessage({
  230. tmplIds: ids,
  231. success(res) {
  232. console.log(res)
  233. that.messageAgree(ids, that.data.detail.id)
  234. },
  235. fail(rej) {
  236. console.log(rej)
  237. that.messageAgree(ids, that.data.detail.id)
  238. wx.showToast({
  239. title: JSON.stringify(rej),
  240. icon: 'error'
  241. })
  242. }
  243. })
  244. },
  245. /**
  246. * 去支付
  247. */
  248. // onPay(e) {
  249. // let that = this
  250. // post(
  251. // 'api/pay/project',
  252. // {
  253. // order_id: that.data.detail.id
  254. // },
  255. // (res) => {
  256. // wx.requestPayment({
  257. // timeStamp: res.data.pay_data.timeStamp,
  258. // nonceStr: res.data.pay_data.nonceStr,
  259. // package: res.data.pay_data.package,
  260. // signType: res.data.pay_data.signType,
  261. // paySign: res.data.pay_data.paySign,
  262. // success(res) {
  263. // if (res.errMsg == 'requestPayment:ok') {
  264. // wx.showToast({
  265. // title: '支付成功',
  266. // icon: 'success'
  267. // })
  268. // that.getOrderDetail(that.data.detail.id)
  269. // get('api/message/ids', {}, (res) => {
  270. // let ids = res.data.ids
  271. // wx.requestSubscribeMessage({
  272. // tmplIds: ids,
  273. // success(res) {
  274. // console.log(res)
  275. // that.messageAgree(ids, that.data.detail.id)
  276. // },
  277. // fail(rej) {
  278. // console.log(rej)
  279. // that.messageAgree(ids)
  280. // wx.showToast({
  281. // title: JSON.stringify(rej),
  282. // icon: 'error'
  283. // })
  284. // }
  285. // })
  286. // })
  287. // }
  288. // },
  289. // fail(res) {
  290. // wx.showToast({
  291. // title: '支付失败',
  292. // icon: 'error'
  293. // })
  294. // }
  295. // })
  296. // }
  297. // )
  298. // },
  299. /**
  300. * 申请退款
  301. */
  302. onRefundOrder() {
  303. let that = this
  304. let showData = {
  305. title: '提示',
  306. content: '是否申请退款',
  307. success(res) {
  308. if (res.confirm) {
  309. console.log('用户点击确定')
  310. post(
  311. 'api/order/refund',
  312. {
  313. order_id: that.data.detail.id
  314. },
  315. (res) => {
  316. wx.showToast({
  317. title: res.msg,
  318. icon: 'success',
  319. duration: 2000
  320. })
  321. that.getOrderDetail(that.data.detail.id)
  322. }
  323. )
  324. } else if (res.cancel) {
  325. console.log('用户点击取消')
  326. }
  327. }
  328. }
  329. let hasValidProduct = that.data.detail.products.length > 0
  330. if (hasValidProduct) {
  331. hasValidProduct = false
  332. that.data.detail.products.map((item) => {
  333. hasValidProduct = item.status == 1 ? true : hasValidProduct
  334. })
  335. }
  336. if (hasValidProduct) {
  337. showData = Object.assign(showData, {
  338. title: '订单取消确认',
  339. content: '检测到该订单有升级套餐产品,将一并取消。您确认要取消吗?',
  340. cancelText: '再想想',
  341. cancelColor: '#000000',
  342. confirmText: '确认取消',
  343. confirmColor: '#FA7D22'
  344. })
  345. }
  346. wx.showModal(showData)
  347. },
  348. /**
  349. * 申请退款 -- 项目升级产品
  350. */
  351. onRefundProjectProductOrder(e) {
  352. let product = e.currentTarget.dataset.item
  353. let that = this
  354. wx.showModal({
  355. title: '订单取消确认',
  356. content:
  357. '检测到该订单为项目升级产品,取消后您将只能享受基础产品。您确认要取消吗?',
  358. cancelText: '再想想',
  359. cancelColor: '#000000',
  360. confirmText: '确认取消',
  361. confirmColor: '#FA7D22',
  362. success(res) {
  363. if (res.confirm) {
  364. console.log('用户点击确定')
  365. post(
  366. 'api/product/refund',
  367. {
  368. product_id: product.id,
  369. order_id: that.data.detail.id
  370. },
  371. (res) => {
  372. wx.showToast({
  373. title: res.msg,
  374. icon: 'success',
  375. duration: 2000
  376. })
  377. that.getOrderDetail(that.data.detail.id)
  378. }
  379. )
  380. } else if (res.cancel) {
  381. console.log('用户点击取消')
  382. }
  383. }
  384. })
  385. },
  386. /**
  387. * 获取详情数据
  388. * /api/order/info
  389. */
  390. getOrderDetail(order_id) {
  391. let that = this
  392. get(
  393. 'api/order/info',
  394. {
  395. order_id
  396. },
  397. (res) => {
  398. console.log(res)
  399. this.setData({
  400. detail: res.data,
  401. showTips: [0, 1, 2].indexOf(res.data.status) > -1
  402. })
  403. if (res.data.status == 0 && this.data.sum <= 0) {
  404. this.data.sum++
  405. that.c1 = new $wuxCountDown({
  406. date: +new Date() + res.data.invalid_time * 1000,
  407. render(date) {
  408. const hours = this.leadingZeros(date.hours, 2)
  409. const min = this.leadingZeros(date.min, 2)
  410. const sec = this.leadingZeros(date.sec, 2)
  411. that.setData({ time: `${hours}:${min}:${sec}` })
  412. },
  413. onEnd() {
  414. that.c1.stop()
  415. that.getOrderDetail(that.data.detail.id)
  416. }
  417. })
  418. }
  419. }
  420. )
  421. },
  422. /**
  423. * 用户允许消息通知
  424. * /api/message/agree
  425. */
  426. messageAgree(ids, order_id) {
  427. post(
  428. 'api/message/agree',
  429. {
  430. order_id,
  431. ids
  432. },
  433. () => {}
  434. )
  435. }
  436. })