抖音c端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1411 行
39 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  2. let config = require("../../../config/config.js");
  3. let util = require("../../../utils/util");
  4. let Http = require("../../../utils/HttpBasics");
  5. let app = getApp();
  6. const imgurl = require("../../../utils/imgurl");
  7. const QR = require("../../../utils/memberqrcode.js");
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. curHtml: '',
  14. showIdFalg: false,
  15. outOrderNo: '', //支付2.0继续支付id
  16. payOrderNo: "", //评价订单id
  17. evaluateFlag: false, //控制评价显隐藏
  18. serviceUrl: '', //客服外部链接
  19. dynamicRq: "",
  20. expiredSeconds: 0,
  21. couponTenantId: '',
  22. showhieRq: false,
  23. mouldType: 0,
  24. showFlag: false,
  25. navigationBarHeight,
  26. upDataRqUrlF: imgurl.upDataRqF.url,
  27. succUrl: imgurl.succ.url,
  28. spcodeUrl: imgurl.spcode.url,
  29. chevronUrl: imgurl.chevron.url,
  30. teljpgUrl: imgurl.teljpg.url,
  31. newUrl: imgurl.new1.url,
  32. weixinTitle: imgurl.weixinTitle.url,
  33. lineUrl: imgurl.line.url,
  34. wm01Url: imgurl.wm01.url,
  35. wm02Url: imgurl.wm02.url,
  36. wm03Url: imgurl.wm03.url,
  37. wm04Url: imgurl.wm04.url,
  38. wm05Url: imgurl.wm05.url,
  39. showModalStatus: false,
  40. flag: 0,
  41. order: null,
  42. orderId: null,
  43. //存储计时器
  44. setInter: "",
  45. mystatus: '',
  46. staticGamedata: {},
  47. showIf: false,
  48. showPage: false,
  49. showButton: false,
  50. cardDetail: null,
  51. supportTransfer: '',
  52. cardIf: false,
  53. contentType: 0,
  54. orderFlag: false, //判断是不是线上配送
  55. tenantId: '',
  56. mallList: [],
  57. imId: "",
  58. orderStatus: 1,
  59. tenantId: "",
  60. IMorderId: "",
  61. outOrderId: "",
  62. outRefundOrderId: "",
  63. canIUseRefund: false,
  64. isAppointment: false,
  65. appointStart: "",
  66. appointEnd: "",
  67. appointmentId: "",
  68. appointmentStatus: "",
  69. use_num_per_consume: "",
  70. },
  71. imCallback(e) {
  72. console.log("跳转IM客服成功", e);
  73. },
  74. onimError(e) {
  75. console.log("拉起IM客服失败", e.detail);
  76. },
  77. handleRefund(event) {
  78. const {
  79. status,
  80. result
  81. } = event.detail;
  82. if (status === 'success') {
  83. const {
  84. refundId,
  85. outRefundNo
  86. } = result;
  87. console.log(refundId, outRefundNo, 'handleRefund');
  88. } else {
  89. const {
  90. errMsg
  91. } = result;
  92. console.log(errMsg);
  93. }
  94. },
  95. applyRefund(event) {
  96. console.log('applyRefund');
  97. const {
  98. orderId
  99. } = event.detail;
  100. const extra = {
  101. tenantId: this.data.tenantId
  102. }; // 开发者需要透传的参数,可自定义内容
  103. return new Promise(resolve => {
  104. console.log(extra, 'extra');
  105. console.log(this.data.outOrderId, 'outOrderId');
  106. resolve(extra);
  107. });
  108. },
  109. handleError(event) {
  110. const {
  111. errMsg,
  112. errNo
  113. } = event.detail;
  114. console.log(event, 'err');
  115. },
  116. showId() {
  117. let this_ = this;
  118. if (!this_.data.showIdFalg) {
  119. tt.showModal({
  120. // title: "查看券码",
  121. content: "是否查看完整券码",
  122. success(res) {
  123. if (res.confirm) {
  124. console.log("confirm, continued");
  125. this_.setData({
  126. showIdFalg: true
  127. })
  128. } else if (res.cancel) {
  129. //取消
  130. console.log("cancel, cold");
  131. } else {
  132. // what happend?
  133. }
  134. },
  135. fail(err) {
  136. console.log(`showModal 调用失败`, err);
  137. },
  138. });
  139. } else {
  140. this.setData({
  141. showIdFalg: false
  142. })
  143. }
  144. },
  145. copeCode(e) {
  146. let code = e.currentTarget.dataset.text
  147. tt.setClipboardData({
  148. data: code,
  149. success: function () {
  150. tt.showToast({
  151. title: '复制成功',
  152. icon: "none"
  153. })
  154. }
  155. })
  156. },
  157. gokuaidi(e) {
  158. let nu = e.currentTarget.dataset.nu
  159. tt.navigateToMiniProgram({
  160. appId: 'wx6885acbedba59c14',
  161. path: `pages/result/result?nu=${nu}&com=&querysource=third_xcx`
  162. })
  163. },
  164. setShow() {
  165. this.setData({
  166. showFlag: true
  167. })
  168. },
  169. hieShow() {
  170. this.setData({
  171. showFlag: false
  172. })
  173. },
  174. goAppointment(e, orderIdin) {
  175. const that = this
  176. const orderId = e ? e.currentTarget.dataset.id : orderIdin
  177. const id = this.data.appointmentId
  178. const merOrderId = this.data.orderId
  179. const startTime = that.data.order.validStartDATE
  180. const endTime = that.data.order.validEndDate
  181. console.log(startTime, endTime);
  182. tt.navigateTo({
  183. url: `/package2/pages/appointment/appointment?id=${id}&orderId=${orderId}&merOrderId=${merOrderId}&startTime=${startTime}&endTime=${endTime}`,
  184. });
  185. },
  186. getUserReservation(couponOrderId) {
  187. const that = this
  188. Http.get({
  189. url: config.api.getUserReservation,
  190. data: {
  191. couponOrderId,
  192. mallTenantId: this.data.mallTenantId || ''
  193. }
  194. }).then(res => {
  195. console.log(res, 'getUserReservation');
  196. if (res.data) {
  197. const appointStart = util.timestampToTime(res.data.startDate, 'YYYY-MM-DD hh:mm:ss')
  198. const appointEnd = util.timestampToTime(res.data.endDate, 'hh:mm:ss')
  199. console.log(appointStart, appointEnd);
  200. const appointmentId = res.data.id
  201. const appointmentStatus = res.data.status
  202. that.setData({
  203. appointStart,
  204. appointEnd,
  205. appointmentId,
  206. appointmentStatus,
  207. isAppointment: true
  208. })
  209. }
  210. }).catch(err => {
  211. console.log(err, 'getUserReservation');
  212. })
  213. },
  214. getOrderStatus(orderId) {
  215. const that = this
  216. Http.get({
  217. url: config.api.getRefundStatus,
  218. data: {
  219. orderId,
  220. mallTenantId: this.data.mallTenantId || ''
  221. }
  222. }).then(res => {
  223. console.log(res, 'res');
  224. const orderStatus = res.data.orderStatus
  225. const outOrderId = res.data.outOrderId
  226. const refundOrderStatus = res.data.refundOrderStatus
  227. const outRefundOrderId = res.data.outRefundOrderId
  228. let status = ''
  229. if (orderStatus == 1) { // 申请退款
  230. status = 1
  231. } else if (orderStatus == 3 || orderStatus == 4 || orderStatus == 5) {
  232. if (refundOrderStatus == 1 || refundOrderStatus == 11) { // 退款中
  233. status = 2
  234. } else if (refundOrderStatus == 3) { //退款成功
  235. status = 3
  236. } else if (refundOrderStatus == 4) { //退款失败
  237. status = 4
  238. } else { // 退款处理中
  239. status = 0
  240. }
  241. that.setData({
  242. outRefundOrderId: outRefundOrderId
  243. })
  244. } else if (orderStatus == 2) {
  245. status = 'orderCancel'
  246. } else {
  247. status = 'noRefund'
  248. }
  249. that.setData({
  250. orderStatus: status,
  251. outOrderId: outOrderId
  252. })
  253. }).catch(err => {
  254. console.log(err, 'err');
  255. })
  256. },
  257. getIm() { //获取im客服id
  258. const that = this
  259. Http.get({
  260. url: config.api.getIm,
  261. data: {
  262. mallTenantId: this.data.mallTenantId || ''
  263. }
  264. }).then(res => {
  265. console.log(res, 'getIm');
  266. const imId = res.data.imId || ''
  267. that.setData({
  268. imId: imId
  269. })
  270. }).catch(err => {
  271. console.log(err, 'err');
  272. })
  273. },
  274. getCouponMerchant() { //获取适用门店
  275. const that = this
  276. Http.get({
  277. url: config.api.orderDetail,
  278. data: {
  279. orderId: this.data.orderId,
  280. mallTenantId: this.data.mallTenantId || ''
  281. }
  282. }).then(res => {
  283. const couponChannelId = res.data.orders[0].couponChannelId
  284. const orderID = res.data.orders[0].id
  285. const cOrderID = res.data.orders[0].couponOrderId
  286. that.getOrderStatus(orderID)
  287. that.getUserReservation(cOrderID)
  288. that.getIm()
  289. const extParam = res.data.extParam || null
  290. if (extParam) {
  291. const obj = JSON.parse(extParam)
  292. that.setData({
  293. IMorderId: obj.order_id,
  294. tenantId: res.data.tenantId,
  295. })
  296. }
  297. Http.get({
  298. url: config.api.couponMerchant,
  299. data: {
  300. couponChannelId: couponChannelId,
  301. mallTenantId: this.data.mallTenantId || ''
  302. }
  303. }).then(res => {
  304. const keys = Object.keys(res.data)
  305. const mallList = []
  306. let i = 0
  307. keys.forEach(item => {
  308. const arr = item.split('|')
  309. const obj = {
  310. tenantId: arr[0],
  311. mallName: arr[1],
  312. merchantVoList: res.data[item],
  313. expand: false
  314. }
  315. if (i == 0) {
  316. obj.expand = true
  317. }
  318. mallList.push(obj)
  319. i++
  320. })
  321. this.setData({
  322. mallList: mallList
  323. })
  324. })
  325. }).catch(err => {
  326. })
  327. },
  328. goDetail(e) {
  329. if (e.target.id == "payBtn") return
  330. tt.navigateTo({
  331. url: `/pages/coupon/detail/index?couponChannelId=${this.data.order.couponChannelId}&mallTenantId=${this.data.mallTenantId}`,
  332. success: (res) => {
  333. },
  334. fail: (res) => {
  335. },
  336. });
  337. },
  338. refund() { //退款
  339. Http.post({
  340. url: config.api.refund,
  341. data: {
  342. orderId: this.data.order.id,
  343. mallTenantId: this.data.mallTenantId || ''
  344. }
  345. }).then(res => {
  346. tt.navigateTo({
  347. url: `/pages/refund/refund?id=${this.data.order.id}&mallTenantId=${this.data.mallTenantId}`,
  348. success: (res) => {
  349. },
  350. fail: (res) => {
  351. },
  352. });
  353. }).catch(err => {
  354. tt.showToast({
  355. title: err.message ? err.message : err.data, // 内容
  356. icon: "none"
  357. });
  358. })
  359. },
  360. goRefund(e) {
  361. let this_ = this
  362. if (this_.data.order.couponOrderStatus == 0) {
  363. tt.showModal({
  364. title: "申请退款",
  365. content: "提交申请退款",
  366. confirmText: "确定",
  367. success(res) {
  368. if (res.confirm) {
  369. this_.refund()
  370. console.log("confirm, continued");
  371. } else if (res.cancel) {
  372. console.log("cancel, cold");
  373. } else {
  374. // what happend?
  375. }
  376. },
  377. fail(res) {
  378. console.log(`showModal调用失败`);
  379. },
  380. });
  381. } else if (this_.data.order.couponOrderStatus == 3) { //退款中
  382. tt.navigateTo({
  383. url: `/pages/refund/refund?id=${this.data.order.id}&mallTenantId=${this.data.mallTenantId}`,
  384. success: (res) => {
  385. },
  386. fail: (res) => {
  387. },
  388. });
  389. }
  390. },
  391. //刷新订单
  392. updetail() {
  393. let that = this
  394. let url = config.api.orderDetail
  395. Http.get({
  396. url: url,
  397. data: {
  398. orderId: this.data.orderId,
  399. mallTenantId: this.data.mallTenantId || ''
  400. }
  401. }).then(res => {
  402. tt.hideLoading();
  403. if (res.data.tenantId) {
  404. that.setData({
  405. tenantId: res.data.tenantId
  406. })
  407. }
  408. var createDate = util.timestampToTime(res.data.orders[0].createDate, "YYYY-MM-DD");
  409. let tempData = res.data.orders[0]
  410. tempData.deliveryInfo = tempData.deliveryInfo ? JSON.parse(tempData.deliveryInfo) : ""
  411. tempData.itemGroup = tempData.itemGroup ? JSON.parse(tempData.itemGroup) : ""
  412. tempData.soldStartTime = util.timestampToTime(tempData.soldStartTime, "YYYY-MM-DD") || null,
  413. tempData.soldEndTime = util.timestampToTime(tempData.soldEndTime, "YYYY-MM-DD") || null,
  414. tempData.validStartDATE = tempData.validStartDate
  415. tempData.validEndDATE = tempData.validEndDate
  416. tempData.validStartDate = util.timestampToTime(tempData.validStartDate, "YYYY-MM-DD")
  417. tempData.validEndDate = util.timestampToTime(tempData.validEndDate, "YYYY-MM-DD")
  418. tempData.couponOrderIdS = tempData.couponOrderId ? tempData.couponOrderId.slice(0, 4) + `******` + tempData.couponOrderId.slice(14) : ''
  419. if (tempData.productAttrs && tempData.skuAttrs) {
  420. tempData.productAttrs = JSON.parse(tempData.productAttrs)
  421. tempData.skuAttrs = JSON.parse(tempData.skuAttrs)
  422. console.log(tempData.productAttrs);
  423. console.log(tempData.skuAttrs);
  424. console.log('****');
  425. tempData.productAttrs.map(item => {
  426. if (item.key == "appointment") {
  427. let tempAppoinObj = JSON.parse(item.data)
  428. if (tempAppoinObj.need_appointment) {
  429. let subscribeSing = "";
  430. if (tempAppoinObj.ahead_time_type == 1) {
  431. subscribeSing = `需提前${tempAppoinObj.ahead_day_num}天预约`
  432. } else if (tempAppoinObj.ahead_time_type == 2) {
  433. subscribeSing = `需提前${tempAppoinObj.ahead_hour_num}小时预约`
  434. } else if (tempAppoinObj.ahead_time_type == 3) {
  435. subscribeSing = `需提前${tempAppoinObj.ahead_minute_num}分钟预约`
  436. }
  437. tempData.subscribeSing = subscribeSing
  438. }
  439. }
  440. if (item.key == "limit_use_rule") {
  441. if (item.data != '') {
  442. let tempAppoinObj = JSON.parse(item.data)
  443. that.setData({
  444. use_num_per_consume: tempAppoinObj.use_num_per_consume || ""
  445. })
  446. }
  447. }
  448. if (item.key == "Notification") {
  449. if (item.data != '') {
  450. tempData.curLsit = JSON.parse(item.data)
  451. }
  452. }
  453. if (item.key == "bring_out_meal") {
  454. tempData.besides = item.data
  455. }
  456. if (item.key == "free_pack") {
  457. tempData.pack = item.data
  458. }
  459. if (item.key == "superimposed_discounts") {
  460. tempData.superimposed_discounts = item.data
  461. }
  462. if (item.key == "private_room") {
  463. tempData.private_room = item.data
  464. }
  465. if (item.key == "rec_person_num_max") {
  466. tempData.rec_person_num_max = item.data
  467. }
  468. if (item.key == 'Description' && item.isRequired) {
  469. tempData.Description = JSON.parse(item.data)
  470. }
  471. if (item.key == "can_no_use_date") {
  472. tempData.can_no_use_date = JSON.parse(item.data)
  473. }
  474. })
  475. tempData.skuAttrs.map(item => {
  476. if (item.key == "commodity") {
  477. if (item.data != '') {
  478. tempData.itemGroup = JSON.parse(item.data)
  479. }
  480. }
  481. })
  482. }
  483. if (tempData.type == 69 && tempData.couponOrderStatus == 0) {
  484. // Http.get({
  485. // url: config.api.orderDetail,
  486. // data: {
  487. // orderId: that.data.orderId,
  488. // mallTenantId: that.data.mallTenantId || ''
  489. // }
  490. // }).then(res => {
  491. // const cOrderID = res.data.orders[0].couponOrderId
  492. // that.getUserReservation(cOrderID)
  493. // }).catch(err => {
  494. // })
  495. setTimeout(() => {
  496. const isAppointment = that.data.isAppointment
  497. const Appointment = tt.getStorageSync('appointment');
  498. if (Appointment && !isAppointment) {
  499. tt.showModal({
  500. title: "提示",
  501. content: "是否立即填写预约信息?",
  502. showCancel: true,
  503. confirmText: "现在预约",
  504. confirmColor: "#deb472",
  505. cancelText: "稍后预约",
  506. success(res) {
  507. if (res.confirm) {
  508. tt.setStorageSync('appointment', false);
  509. that.goAppointment(false, tempData.couponOrderId)
  510. }
  511. if (res.cancel) {
  512. }
  513. }
  514. });
  515. }
  516. }, 2000);
  517. }
  518. that.setData({
  519. outOrderNo: res.data.id,
  520. order: tempData,
  521. showPage: true,
  522. createDate: createDate,
  523. composeOrderType: tempData.composeOrderType,
  524. contentType: tempData.contentType ? tempData.contentType : 0,
  525. orderFlag: tempData.type == 11 ? true : false, //判断是不是线上配送
  526. })
  527. if (tempData.couponOrderId) { //0未付款 1已支付 2已取消 3退款中 4已退款
  528. that.setRq()
  529. // that.upStatus()
  530. let setInter = setInterval(() => {
  531. if (tempData.couponOrderStatus == 0) {
  532. Http.get({
  533. url: config.api.getStatus,
  534. data: {
  535. couponOrderId: tempData.couponOrderId,
  536. mallTenantId: this.data.mallTenantId || ''
  537. }
  538. }).then(res => {
  539. console.log(res);
  540. that.setData({
  541. couponOrderStatus: res.data.CouponOrderStatus
  542. });
  543. if (res.data.CouponOrderStatus == 1 || res.data.CouponOrderStatus == 3) {
  544. /**
  545. * 动态改变上一级页面的核销状态
  546. */
  547. // that.getStaticGame()
  548. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  549. clearInterval(that.data.setInter);
  550. clearInterval(that.data.templTiem);
  551. that.updetail()
  552. that.setData({
  553. mystatus: res.data.CouponOrderStatus
  554. });
  555. }
  556. })
  557. .catch(err => {
  558. tt.showToast({
  559. title: err.errMsg,
  560. icon: 'none',
  561. duration: 2000,
  562. mask: false
  563. });
  564. })
  565. } else {
  566. Http.get({
  567. url: config.api.getStatus,
  568. data: {
  569. couponOrderId: tempData.couponOrderId,
  570. mallTenantId: this.data.mallTenantId || ''
  571. }
  572. }).then(res => {
  573. console.log(res, 'getStatus');
  574. that.setData({
  575. couponOrderStatus: res.data.CouponOrderStatus
  576. });
  577. if (res.data.CouponOrderStatus == 1 || res.data.CouponOrderStatus == 3) {
  578. /**
  579. * 动态改变上一级页面的核销状态
  580. */
  581. // that.getStaticGame()
  582. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  583. clearInterval(that.data.setInter);
  584. clearInterval(that.data.templTiem);
  585. that.updetail()
  586. that.setData({
  587. mystatus: res.data.CouponOrderStatus
  588. });
  589. }
  590. })
  591. .catch(err => {
  592. console.log(err);
  593. })
  594. }
  595. }, 2000);
  596. that.setData({
  597. setInter: setInter
  598. })
  599. }
  600. if (tempData.couponOrderStatus && tempData.couponOrderStatus == 1) { //核销后
  601. that.goIfEvaluate() //判断订单是否能评价
  602. }
  603. }).catch(error => {
  604. console.log(error, "error");
  605. tt.hideLoading();
  606. tt.showModal({
  607. title: '提示',
  608. content: error.errMsg,
  609. showCancel: false
  610. })
  611. })
  612. },
  613. //确认收货
  614. verify() {
  615. Http.post({
  616. url: config.api.verify,
  617. data: {
  618. couponOrderId: this.data.order.couponOrderId
  619. }
  620. }).then(res => {
  621. tt.showToast({
  622. title: '签收成功',
  623. icon: "none"
  624. })
  625. this.updetail()
  626. }).catch(err => {
  627. tt.showModal({
  628. title: '提示',
  629. content: err.message ? err.message : err.data,
  630. showCancel: false
  631. })
  632. })
  633. },
  634. phone: function (e) {
  635. let that = this;
  636. console.log(e);
  637. tt.makePhoneCall({
  638. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  639. });
  640. },
  641. /**
  642. * 跳转到门店列表的详情页面
  643. */
  644. gotoDetail(e) {
  645. tt.navigateTo({
  646. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  647. })
  648. },
  649. getUserInfo: function () {
  650. let that = this;
  651. // 获取用户信息
  652. Http.get({
  653. url: config.api.getScore,
  654. data: {}
  655. })
  656. .then(res => {
  657. console.log(res)
  658. that.setData({
  659. userName: res.data.nickName,
  660. avatarUrl: res.data.avatarUrl
  661. })
  662. })
  663. },
  664. onShareAppMessage: function (res) {
  665. app.globalData.previewFlag = true
  666. if (res.from === 'button') {
  667. console.log(res, 3333333333333333333333)
  668. // 来自页面内转发按钮
  669. let _this = this;
  670. return {
  671. title: _this.data.userName + '赠送您一张' + _this.data.order.title,
  672. path: '/pages/index/index?couponChannelId=' + this.data.order.couponChannelId + '&cuserId=' + this.data.order.cuserId + '&couponId=' + this.data.order.productId + '&coverImg=' + this.data.order.coverImg + '&userName=' + this.data.userName + '&avatarUrl=' + this.data.avatarUrl + '&couponOrderId=' + this.data.order.couponOrderId + '&updateDate=' + this.data.order.updateDate,
  673. imageUrl: this.data.order.coverImg,
  674. success: function (res) {
  675. // 转发成功
  676. },
  677. fail: function (res) {
  678. // 转发失败
  679. }
  680. }
  681. } else {
  682. console.log(res, 444444444444444444)
  683. }
  684. },
  685. createQrCode: function (url, canvasId, cavW, cavH) {
  686. //调用插件中的draw方法,绘制二维码图片
  687. let that = this;
  688. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  689. that.setData({
  690. tempFilePath: res
  691. })
  692. });
  693. },
  694. setRq() {
  695. let _this = this
  696. _this.setData({
  697. showhieRq: false,
  698. })
  699. Http.get({ //获取动态二维码
  700. url: config.api.dynamicId,
  701. data: {
  702. couponOrderId: _this.data.order.couponOrderId,
  703. couponTenantId: _this.data.tenantId || ''
  704. }
  705. }).then(res => {
  706. console.log(res, "res")
  707. _this.setData({
  708. dynamicRq: res.data.dynamicId,
  709. expiredSeconds: res.data.expiredSeconds,
  710. couponTenantId: res.data.couponTenantId
  711. })
  712. let url = JSON.stringify({
  713. END: "C",
  714. TYPE: "couponorder",
  715. ID: _this.data.dynamicRq,
  716. couponTenantId: _this.data.couponTenantId
  717. })
  718. if (res.data.expiredSeconds == 0) {
  719. //倒计时为零直接显示券码
  720. } else {
  721. let inre = setInterval(() => {
  722. if (_this.data.expiredSeconds > 1) {
  723. _this.setData({
  724. expiredSeconds: _this.data.expiredSeconds - 1
  725. })
  726. // console.log("有效", _this.data.expiredSeconds)
  727. } else {
  728. // console.log("无效", _this.data.expiredSeconds)
  729. clearInterval(_this.data.templTiem)
  730. _this.setData({
  731. showhieRq: true
  732. })
  733. }
  734. _this.setData({
  735. templTiem: inre
  736. })
  737. }, 1000)
  738. }
  739. _this.createQrCode(url, "qrcode", 350, 350);
  740. }).catch(err => {
  741. tt.showToast({
  742. title: err.message,
  743. icon: 'none',
  744. duration: 2000,
  745. mask: false
  746. });
  747. })
  748. },
  749. goPaySnapshoot(e) {
  750. let id = e.currentTarget.dataset.id;
  751. tt.navigateTo({
  752. url: `/pages/paySnapshoot/paySnapshoot?id=${id}`,
  753. success: (res) => {
  754. },
  755. fail: (res) => {
  756. },
  757. });
  758. },
  759. powerDrawer: function (e) {
  760. let that = this;
  761. console.log(e)
  762. // couponOrderStatus
  763. // 0 未使用
  764. // 1 已使用
  765. // 2 已过期
  766. // 3 已经退款
  767. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  768. tt.navigateTo({
  769. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  770. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  771. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  772. &contentType=${that.data.contentType}`
  773. });
  774. } else {
  775. tt.navigateTo({
  776. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  777. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  778. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  779. &contentType=${that.data.contentType}`
  780. });
  781. }
  782. },
  783. gotogame: function () {
  784. let that = this;
  785. tt.redirectTo({
  786. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  787. })
  788. },
  789. // 买完卡跳转到立即使用页面
  790. gotoUse: function () {
  791. tt.navigateTo({
  792. url: '/pages/cardorder/index/index'
  793. })
  794. },
  795. // 获取游戏
  796. getStaticGame(token) {
  797. let _this = this;
  798. Http.get({
  799. url: config.api.getGame,
  800. data: {
  801. triggleAction: 3 // 购买触发
  802. }
  803. }).then(res => {
  804. if (res.data.id) {
  805. _this.setData({
  806. showIf: true
  807. })
  808. }
  809. _this.setData({
  810. staticGamedata: res.data
  811. })
  812. })
  813. .catch(err => {
  814. console.log(err);
  815. })
  816. },
  817. goEvaluate() {
  818. let _this = this
  819. tt.rateAwemeOrder({
  820. orderId: _this.data.payOrderNo,
  821. success({
  822. result
  823. }) {
  824. console.log(result);
  825. if (result) {
  826. tt.navigateBack({
  827. delta: 1,
  828. success: (res) => {
  829. },
  830. fail: (res) => {
  831. },
  832. });
  833. // 用户已经评价的逻辑
  834. } else {
  835. // 用户没有评价的逻辑
  836. }
  837. },
  838. fail(err) {
  839. console.log(err);
  840. },
  841. });
  842. },
  843. goIfEvaluate() {
  844. let _this = this
  845. Http.get({
  846. url: config.api.getchanId,
  847. data: {
  848. id: _this.data.order.couponOrderId,
  849. mallTenantId: this.data.mallTenantId || ''
  850. }
  851. }).then(res => {
  852. tt.canRateAwemeOrders({
  853. orderIds: [res.data.payOrderNo],
  854. success({
  855. result
  856. }) {
  857. console.log("result", result);
  858. _this.setData({
  859. evaluateFlag: result[0],
  860. payOrderNo: res.data.payOrderNo
  861. })
  862. },
  863. fail(err) {
  864. console.log(err);
  865. },
  866. });
  867. }).catch(err => {
  868. tt.showToast({
  869. title: err.message ? err.message : err.data, // 内容
  870. icon: "none"
  871. });
  872. })
  873. },
  874. /**
  875. * 生命周期函数--监听页面加载
  876. */
  877. onLoad: function (option) {
  878. console.log(option, 'option');
  879. let options = null
  880. if (option.params) {
  881. options = JSON.parse(option.params)
  882. } else {
  883. options = option
  884. }
  885. // this.getSeUrl()
  886. if (options.mallTenantId) {
  887. this.setData({
  888. mallTenantId: options.mallTenantId,
  889. })
  890. }
  891. this.setData({
  892. mouldType: app.globalData.mouldType
  893. })
  894. let that = this;
  895. // if (options.dingdan && options.dingdan == "order") {
  896. // }
  897. that.setData({
  898. orderId: options.orderId,
  899. });
  900. tt.hideShareMenu()
  901. if (options.cardIf) { //转赠 展示不需
  902. that.setData({
  903. cardIf: true
  904. })
  905. }
  906. tt.showLoading({
  907. title: "加载中"
  908. });
  909. this.getCouponMerchant() //获取可用商户
  910. },
  911. onShow: function () {
  912. let that = this;
  913. that.setData({
  914. showButton: false
  915. })
  916. that.updetail()
  917. this.getCouponMerchant() //获取可用商户
  918. if (tt.canIUse("microapp-trade-plugin")) {
  919. that.setData({
  920. canIUseRefund: true
  921. })
  922. console.log(that.data.canIUseRefund, 'canIUseRefund');
  923. }
  924. },
  925. getSeUrl() { //获取客服链接
  926. const openId = tt.getStorageSync('openId');
  927. Http.post({
  928. url: config.api.getServiceUrl,
  929. data: {
  930. appid: app.globalData.appId,
  931. openid: openId
  932. }
  933. }).then(res => {
  934. this.setData({
  935. serviceUrl: res.data ? res.data : ''
  936. })
  937. if (res.data) {
  938. tt.setStorageSync('serviceData', res.data);
  939. }
  940. })
  941. },
  942. goWebView() {
  943. let _this = this
  944. tt.navigateTo({
  945. url: `/pages/serviceWebView/serviceWebView`,
  946. success: (res) => {
  947. },
  948. fail: (res) => {
  949. },
  950. });
  951. },
  952. /**
  953. * 去拼团
  954. */
  955. goToOrderGroup(orderId, orderGroupId, _this) {
  956. let that = this;
  957. // 支付成功
  958. Http.post({
  959. url: config.api.toOrderGroup,
  960. data: {
  961. id: orderGroupId,
  962. orderId,
  963. couponId: _this.data.order.productId
  964. }
  965. })
  966. .then(res => {
  967. tt.redirectTo({
  968. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}&mallTenantId=${this.data.mallTenantId}`
  969. });
  970. })
  971. .catch(err => {
  972. console.log(err);
  973. })
  974. // return;
  975. },
  976. /**
  977. * 发起支付
  978. */
  979. orderFunc(e) {
  980. var that = this;
  981. const orderId = "" + that.data.orderId;
  982. that.setData({
  983. showButton: true
  984. })
  985. tt.showLoading({
  986. title: "加载中..."
  987. });
  988. // if (true) {//兼容不支持支付2.0 js-api !tt.canIUse('createOrder')
  989. if (that.data.order.payment > 0) {
  990. if (tt.canIUse('createOrder')) { //支付2.0 js-api
  991. const outOrderNo = that.data.outOrderNo
  992. console.log(outOrderNo, "outOrderNo");
  993. Http.post({
  994. url: config.api.payOrderCreate_2,
  995. data: {
  996. // composeOrderId: outOrderNo
  997. orderId: outOrderNo,
  998. composeOrderType: that.data.composeOrderType,
  999. mallTenantId: this.data.mallTenantId || ''
  1000. }
  1001. }).then(res => {
  1002. if (res.data.createPay) {
  1003. let tempCallbackData = res.data.callbackData
  1004. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  1005. let options = {
  1006. callbackData: tempCallbackData,
  1007. goodsList: res.data.goodsList,
  1008. payment: res.data.payment,
  1009. success: res => {
  1010. tt.hideLoading();
  1011. that.setData({
  1012. showbutton: false,
  1013. })
  1014. const {
  1015. orderId,
  1016. outOrderNo
  1017. } = res;
  1018. // that.setData({
  1019. // orderId,
  1020. // outOrderNo
  1021. // });
  1022. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  1023. },
  1024. fail: res => {
  1025. const {
  1026. orderId,
  1027. outOrderNo,
  1028. errNo,
  1029. errMsg,
  1030. errLogId
  1031. } = res;
  1032. if (errLogId) {
  1033. tt.hideLoading();
  1034. that.setData({
  1035. showbutton: false,
  1036. })
  1037. console.log('预下单失败', errNo, errMsg, errLogId);
  1038. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  1039. tt.showToast({
  1040. title: tempErrmsg[tempErrmsg.length - 1],
  1041. icon: 'none',
  1042. duration: 2000,
  1043. mask: false
  1044. });
  1045. }
  1046. if (orderId || outOrderNo) {
  1047. tt.hideLoading();
  1048. that.setData({
  1049. showbutton: false,
  1050. })
  1051. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1052. console.log(that.payOrderUpdate, "payOrderUpdate");
  1053. tt.showToast({
  1054. title: "取消支付",
  1055. icon: 'none',
  1056. duration: 2000,
  1057. mask: false
  1058. });
  1059. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  1060. }
  1061. },
  1062. }
  1063. console.log(options, "options");
  1064. tt.createOrder(options)
  1065. } else {
  1066. tt.continueToPay({
  1067. outOrderNo: res.data.outOrderNo, // 外部订单号 2个订单号必填一个
  1068. success: res => {
  1069. // const { orderId, outOrderNo } = res;
  1070. // console.log('success res', res);
  1071. // console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  1072. that.setData({
  1073. showButton: false
  1074. })
  1075. tt.hideLoading();
  1076. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that); // 支付成功
  1077. },
  1078. fail: res => {
  1079. const {
  1080. orderId,
  1081. outOrderNo,
  1082. errNo,
  1083. errMsg,
  1084. errLogId
  1085. } = res;
  1086. if (errLogId) {
  1087. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  1088. that.setData({
  1089. showButton: false
  1090. })
  1091. tt.showToast({
  1092. title: errMsg,
  1093. icon: 'none',
  1094. duration: 2000,
  1095. mask: false
  1096. });
  1097. tt.hideLoading();
  1098. }
  1099. if (orderId || outOrderNo) {
  1100. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1101. tt.showToast({
  1102. title: errMsg,
  1103. icon: 'none',
  1104. duration: 2000,
  1105. mask: false
  1106. });
  1107. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail', that);
  1108. that.setData({
  1109. showButton: false
  1110. })
  1111. tt.hideLoading();
  1112. }
  1113. },
  1114. });
  1115. }
  1116. }).catch(err => {
  1117. tt.showToast({
  1118. title: err.message ? err.message : err.data, // 内容
  1119. icon: "none"
  1120. });
  1121. })
  1122. } else { //不支持支付2.0 js-api
  1123. tt.showToast({
  1124. title: '请升级抖音', // 内容
  1125. icon: "none"
  1126. });
  1127. return
  1128. // 支付金额不为0
  1129. Http.post({
  1130. url: config.api.payOrderCreate,
  1131. data: {
  1132. orderId: orderId,
  1133. composeOrderType: that.data.composeOrderType
  1134. }
  1135. }).then(res => {
  1136. var payOrderId = "" + res.data.outOrderNo;
  1137. tt.hideLoading();
  1138. tt.pay({
  1139. service: 5,
  1140. orderInfo: {
  1141. order_id: res.data.payOrderId,
  1142. order_token: res.data.payOrderToken,
  1143. },
  1144. success: res => {
  1145. tt.showLoading({
  1146. title: '订单正在处理中...',
  1147. })
  1148. if (res.code == 0) {
  1149. setTimeout(function () {
  1150. tt.hideLoading()
  1151. }, 5000)
  1152. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  1153. if (res.errMsg == "requestPayment:ok") {
  1154. if (that.data.order.type == 100) {
  1155. tt.setStorage({
  1156. key: 'couponNum2',
  1157. data: "couponNum2"
  1158. })
  1159. } else if (that.data.order.type != 5) {
  1160. tt.setStorage({
  1161. key: 'couponNum',
  1162. data: "couponNum"
  1163. })
  1164. }
  1165. }
  1166. } else if (res.code === 1) {
  1167. that.setData({
  1168. showButton: false
  1169. })
  1170. tt.hideLoading();
  1171. tt.showToast({
  1172. title: '支付超时', // 内容
  1173. icon: "none"
  1174. });
  1175. } else if (res.code === 2) {
  1176. that.setData({
  1177. showButton: false
  1178. })
  1179. tt.hideLoading();
  1180. tt.showToast({
  1181. title: '支付失败', // 内容
  1182. icon: "none"
  1183. });
  1184. } else if (res.code === 3) {
  1185. that.setData({
  1186. showButton: false
  1187. })
  1188. tt.hideLoading();
  1189. tt.showToast({
  1190. title: '支付关闭', // 内容
  1191. icon: "none"
  1192. });
  1193. } else if (res.code === 4) {
  1194. that.setData({
  1195. showButton: false
  1196. })
  1197. tt.hideLoading();
  1198. tt.showToast({
  1199. title: '支付取消', // 内容
  1200. icon: "none"
  1201. });
  1202. } else if (res.code === 9) {
  1203. that.setData({
  1204. showButton: false
  1205. })
  1206. tt.hideLoading();
  1207. tt.showToast({
  1208. title: '订单状态开发者自行获取', // 内容
  1209. icon: "none"
  1210. });
  1211. }
  1212. },
  1213. fail: res => {
  1214. that.setData({
  1215. showButton: false
  1216. })
  1217. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  1218. return;
  1219. },
  1220. });
  1221. }).catch(err => {
  1222. tt.hideLoading();
  1223. that.setData({
  1224. showButton: false
  1225. })
  1226. tt.showModal({
  1227. title: "抱歉",
  1228. content: err.message,
  1229. showCancel: false
  1230. })
  1231. });
  1232. }
  1233. } else {
  1234. // 免费券
  1235. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  1236. if (that.data.order.type == 100) {
  1237. tt.setStorage({
  1238. key: 'couponNum2',
  1239. data: "couponNum2"
  1240. })
  1241. } else if (that.data.order.type != "5") {
  1242. tt.setStorage({
  1243. key: 'couponNum',
  1244. data: "couponNum"
  1245. })
  1246. }
  1247. tt.showToast({
  1248. title: "支付成功",
  1249. duration: 2000,
  1250. image: imgurl.success.url,
  1251. });
  1252. }
  1253. // } else {//支持 支付2.0 js-api
  1254. // }
  1255. },
  1256. /**
  1257. * 支付订单更新
  1258. */
  1259. payOrderUpdate(orderId, payOrderId, status, reason, type, _this) {
  1260. // 支付成功
  1261. Http.post({
  1262. url: config.api.payOrderUpdate,
  1263. data: {
  1264. payOrderId: payOrderId,
  1265. composeOrderId: orderId,
  1266. status: status,
  1267. reason: reason,
  1268. mallTenantId: this.data.mallTenantId || ''
  1269. }
  1270. })
  1271. .then(res => {
  1272. tt.hideLoading();
  1273. _this.setData({
  1274. showButton: false
  1275. })
  1276. if (!type && type != 'free') {
  1277. tt.showToast({
  1278. title: "购买成功",
  1279. duration: 2000,
  1280. image: imgurl.success.url,
  1281. mask: false,
  1282. success: function () {
  1283. tt.showLoading({
  1284. title: "加载中..."
  1285. });
  1286. setTimeout(function () {
  1287. tt.hideLoading();
  1288. }, 1600);
  1289. setTimeout(() => {
  1290. console.log('Here1');
  1291. tt.setStorageSync('appointment', true);
  1292. let url = ""
  1293. if (_this.data.orderFlag) {
  1294. tt.redirectTo({
  1295. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order}&mallTenantId=${that.data.mallTenantId}`
  1296. });
  1297. } else {
  1298. tt.redirectTo({
  1299. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  1300. });
  1301. }
  1302. }, 1600);
  1303. }
  1304. });
  1305. } else if (type == 'free') {
  1306. console.log('Here2');
  1307. tt.redirectTo({
  1308. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  1309. });
  1310. }
  1311. })
  1312. .catch(err => {
  1313. console.log(err)
  1314. if (!type) {
  1315. setTimeout(function () {
  1316. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  1317. }, 1500)
  1318. }
  1319. });
  1320. },
  1321. onUnload: function () {
  1322. let that = this;
  1323. clearInterval(that.data.setInter);
  1324. clearInterval(that.data.templTiem);
  1325. },
  1326. onHide: function () {
  1327. let that = this;
  1328. clearInterval(that.data.setInter);
  1329. clearInterval(that.data.templTiem);
  1330. },
  1331. });