抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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