抖音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: `/package2/pages/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:ss')
  199. const appointEnd = util.timestampToTime(res.data.endDate, 'hh:mm:ss')
  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. console.log(app.globalData.curHtml)
  775. }
  776. })
  777. },
  778. goPaySnapshoot(e) {
  779. let id = e.currentTarget.dataset.id;
  780. tt.navigateTo({
  781. url: `/pages/paySnapshoot/paySnapshoot?id=${id}`,
  782. success: (res) => {
  783. },
  784. fail: (res) => {
  785. },
  786. });
  787. },
  788. powerDrawer: function (e) {
  789. let that = this;
  790. console.log(e)
  791. // couponOrderStatus
  792. // 0 未使用
  793. // 1 已使用
  794. // 2 已过期
  795. // 3 已经退款
  796. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  797. tt.navigateTo({
  798. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  799. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  800. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  801. &contentType=${that.data.contentType}`
  802. });
  803. } else {
  804. tt.navigateTo({
  805. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  806. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  807. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  808. &contentType=${that.data.contentType}`
  809. });
  810. }
  811. },
  812. gotogame: function () {
  813. let that = this;
  814. tt.redirectTo({
  815. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  816. })
  817. },
  818. // 买完卡跳转到立即使用页面
  819. gotoUse: function () {
  820. tt.navigateTo({
  821. url: '/pages/cardorder/index/index'
  822. })
  823. },
  824. // 获取游戏
  825. getStaticGame(token) {
  826. let _this = this;
  827. Http.get({
  828. url: config.api.getGame,
  829. data: {
  830. triggleAction: 3 // 购买触发
  831. }
  832. }).then(res => {
  833. if (res.data.id) {
  834. _this.setData({
  835. showIf: true
  836. })
  837. }
  838. _this.setData({
  839. staticGamedata: res.data
  840. })
  841. })
  842. .catch(err => {
  843. console.log(err);
  844. })
  845. },
  846. goEvaluate() {
  847. let _this = this
  848. tt.rateAwemeOrder({
  849. orderId: _this.data.payOrderNo,
  850. success({
  851. result
  852. }) {
  853. console.log(result);
  854. if (result) {
  855. tt.navigateBack({
  856. delta: 1,
  857. success: (res) => {
  858. },
  859. fail: (res) => {
  860. },
  861. });
  862. // 用户已经评价的逻辑
  863. } else {
  864. // 用户没有评价的逻辑
  865. }
  866. },
  867. fail(err) {
  868. console.log(err);
  869. },
  870. });
  871. },
  872. goIfEvaluate() {
  873. let _this = this
  874. Http.get({
  875. url: config.api.getchanId,
  876. data: {
  877. id: _this.data.order.couponOrderId,
  878. mallTenantId: this.data.mallTenantId || ''
  879. }
  880. }).then(res => {
  881. tt.canRateAwemeOrders({
  882. orderIds: [res.data.payOrderNo],
  883. success({
  884. result
  885. }) {
  886. console.log("result", result);
  887. _this.setData({
  888. evaluateFlag: result[0],
  889. payOrderNo: res.data.payOrderNo
  890. })
  891. },
  892. fail(err) {
  893. console.log(err);
  894. },
  895. });
  896. }).catch(err => {
  897. tt.showToast({
  898. title: err.message ? err.message : err.data, // 内容
  899. icon: "none"
  900. });
  901. })
  902. },
  903. /**
  904. * 生命周期函数--监听页面加载
  905. */
  906. onLoad: function (option) {
  907. console.log(option, 'option');
  908. let options = null
  909. if (option.params) {
  910. options = JSON.parse(option.params)
  911. } else {
  912. options = option
  913. }
  914. // this.getSeUrl()
  915. if (options.mallTenantId) {
  916. this.setData({
  917. mallTenantId: options.mallTenantId,
  918. })
  919. }
  920. this.setData({
  921. mouldType: app.globalData.mouldType
  922. })
  923. let that = this;
  924. // if (options.dingdan && options.dingdan == "order") {
  925. // }
  926. that.setData({
  927. orderId: options.orderId,
  928. });
  929. tt.hideShareMenu()
  930. if (options.cardIf) { //转赠 展示不需
  931. that.setData({
  932. cardIf: true
  933. })
  934. }
  935. tt.showLoading({
  936. title: "加载中"
  937. });
  938. this.getCouponMerchant() //获取可用商户
  939. },
  940. onShow: function () {
  941. let that = this;
  942. that.setData({
  943. showButton: false
  944. })
  945. that.updetail()
  946. this.getCouponMerchant() //获取可用商户
  947. if (tt.canIUse("microapp-trade-plugin")) {
  948. that.setData({
  949. canIUseRefund: true
  950. })
  951. console.log(that.data.canIUseRefund, 'canIUseRefund');
  952. }
  953. },
  954. getSeUrl() { //获取客服链接
  955. const openId = tt.getStorageSync('openId');
  956. Http.post({
  957. url: config.api.getServiceUrl,
  958. data: {
  959. appid: app.globalData.appId,
  960. openid: openId
  961. }
  962. }).then(res => {
  963. this.setData({
  964. serviceUrl: res.data ? res.data : ''
  965. })
  966. if (res.data) {
  967. tt.setStorageSync('serviceData', res.data);
  968. }
  969. })
  970. },
  971. goWebView() {
  972. let _this = this
  973. tt.navigateTo({
  974. url: `/pages/serviceWebView/serviceWebView`,
  975. success: (res) => {
  976. },
  977. fail: (res) => {
  978. },
  979. });
  980. },
  981. /**
  982. * 去拼团
  983. */
  984. goToOrderGroup(orderId, orderGroupId, _this) {
  985. let that = this;
  986. // 支付成功
  987. Http.post({
  988. url: config.api.toOrderGroup,
  989. data: {
  990. id: orderGroupId,
  991. orderId,
  992. couponId: _this.data.order.productId
  993. }
  994. })
  995. .then(res => {
  996. tt.redirectTo({
  997. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}&mallTenantId=${this.data.mallTenantId}`
  998. });
  999. })
  1000. .catch(err => {
  1001. console.log(err);
  1002. })
  1003. // return;
  1004. },
  1005. /**
  1006. * 发起支付
  1007. */
  1008. orderFunc(e) {
  1009. var that = this;
  1010. const orderId = "" + that.data.orderId;
  1011. that.setData({
  1012. showButton: true
  1013. })
  1014. tt.showLoading({
  1015. title: "加载中..."
  1016. });
  1017. // if (true) {//兼容不支持支付2.0 js-api !tt.canIUse('createOrder')
  1018. if (that.data.order.payment > 0) {
  1019. if (tt.canIUse('createOrder')) { //支付2.0 js-api
  1020. const outOrderNo = that.data.outOrderNo
  1021. console.log(outOrderNo, "outOrderNo");
  1022. Http.post({
  1023. url: config.api.payOrderCreate_2,
  1024. data: {
  1025. // composeOrderId: outOrderNo
  1026. orderId: outOrderNo,
  1027. composeOrderType: that.data.composeOrderType,
  1028. mallTenantId: this.data.mallTenantId || ''
  1029. }
  1030. }).then(res => {
  1031. if (res.data.createPay) {
  1032. let tempCallbackData = res.data.callbackData
  1033. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  1034. let options = {
  1035. callbackData: tempCallbackData,
  1036. goodsList: res.data.goodsList,
  1037. payment: res.data.payment,
  1038. success: res => {
  1039. tt.hideLoading();
  1040. that.setData({
  1041. showbutton: false,
  1042. })
  1043. const {
  1044. orderId,
  1045. outOrderNo
  1046. } = res;
  1047. // that.setData({
  1048. // orderId,
  1049. // outOrderNo
  1050. // });
  1051. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  1052. },
  1053. fail: res => {
  1054. const {
  1055. orderId,
  1056. outOrderNo,
  1057. errNo,
  1058. errMsg,
  1059. errLogId
  1060. } = res;
  1061. if (errLogId) {
  1062. tt.hideLoading();
  1063. that.setData({
  1064. showbutton: false,
  1065. })
  1066. console.log('预下单失败', errNo, errMsg, errLogId);
  1067. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  1068. tt.showToast({
  1069. title: tempErrmsg[tempErrmsg.length - 1],
  1070. icon: 'none',
  1071. duration: 2000,
  1072. mask: false
  1073. });
  1074. }
  1075. if (orderId || outOrderNo) {
  1076. tt.hideLoading();
  1077. that.setData({
  1078. showbutton: false,
  1079. })
  1080. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1081. console.log(that.payOrderUpdate, "payOrderUpdate");
  1082. tt.showToast({
  1083. title: "取消支付",
  1084. icon: 'none',
  1085. duration: 2000,
  1086. mask: false
  1087. });
  1088. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  1089. }
  1090. },
  1091. }
  1092. console.log(options, "options");
  1093. tt.createOrder(options)
  1094. } else {
  1095. tt.continueToPay({
  1096. outOrderNo: res.data.outOrderNo, // 外部订单号 2个订单号必填一个
  1097. success: res => {
  1098. // const { orderId, outOrderNo } = res;
  1099. // console.log('success res', res);
  1100. // console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  1101. that.setData({
  1102. showButton: false
  1103. })
  1104. tt.hideLoading();
  1105. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that); // 支付成功
  1106. },
  1107. fail: res => {
  1108. const {
  1109. orderId,
  1110. outOrderNo,
  1111. errNo,
  1112. errMsg,
  1113. errLogId
  1114. } = res;
  1115. if (errLogId) {
  1116. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  1117. that.setData({
  1118. showButton: false
  1119. })
  1120. tt.showToast({
  1121. title: errMsg,
  1122. icon: 'none',
  1123. duration: 2000,
  1124. mask: false
  1125. });
  1126. tt.hideLoading();
  1127. }
  1128. if (orderId || outOrderNo) {
  1129. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1130. tt.showToast({
  1131. title: errMsg,
  1132. icon: 'none',
  1133. duration: 2000,
  1134. mask: false
  1135. });
  1136. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail', that);
  1137. that.setData({
  1138. showButton: false
  1139. })
  1140. tt.hideLoading();
  1141. }
  1142. },
  1143. });
  1144. }
  1145. }).catch(err => {
  1146. tt.showToast({
  1147. title: err.message ? err.message : err.data, // 内容
  1148. icon: "none"
  1149. });
  1150. })
  1151. } else { //不支持支付2.0 js-api
  1152. tt.showToast({
  1153. title: '请升级抖音', // 内容
  1154. icon: "none"
  1155. });
  1156. return
  1157. // 支付金额不为0
  1158. Http.post({
  1159. url: config.api.payOrderCreate,
  1160. data: {
  1161. orderId: orderId,
  1162. composeOrderType: that.data.composeOrderType
  1163. }
  1164. }).then(res => {
  1165. var payOrderId = "" + res.data.outOrderNo;
  1166. tt.hideLoading();
  1167. tt.pay({
  1168. service: 5,
  1169. orderInfo: {
  1170. order_id: res.data.payOrderId,
  1171. order_token: res.data.payOrderToken,
  1172. },
  1173. success: res => {
  1174. tt.showLoading({
  1175. title: '订单正在处理中...',
  1176. })
  1177. if (res.code == 0) {
  1178. setTimeout(function () {
  1179. tt.hideLoading()
  1180. }, 5000)
  1181. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  1182. if (res.errMsg == "requestPayment:ok") {
  1183. if (that.data.order.type == 100) {
  1184. tt.setStorage({
  1185. key: 'couponNum2',
  1186. data: "couponNum2"
  1187. })
  1188. } else if (that.data.order.type != 5) {
  1189. tt.setStorage({
  1190. key: 'couponNum',
  1191. data: "couponNum"
  1192. })
  1193. }
  1194. }
  1195. } else if (res.code === 1) {
  1196. that.setData({
  1197. showButton: false
  1198. })
  1199. tt.hideLoading();
  1200. tt.showToast({
  1201. title: '支付超时', // 内容
  1202. icon: "none"
  1203. });
  1204. } else if (res.code === 2) {
  1205. that.setData({
  1206. showButton: false
  1207. })
  1208. tt.hideLoading();
  1209. tt.showToast({
  1210. title: '支付失败', // 内容
  1211. icon: "none"
  1212. });
  1213. } else if (res.code === 3) {
  1214. that.setData({
  1215. showButton: false
  1216. })
  1217. tt.hideLoading();
  1218. tt.showToast({
  1219. title: '支付关闭', // 内容
  1220. icon: "none"
  1221. });
  1222. } else if (res.code === 4) {
  1223. that.setData({
  1224. showButton: false
  1225. })
  1226. tt.hideLoading();
  1227. tt.showToast({
  1228. title: '支付取消', // 内容
  1229. icon: "none"
  1230. });
  1231. } else if (res.code === 9) {
  1232. that.setData({
  1233. showButton: false
  1234. })
  1235. tt.hideLoading();
  1236. tt.showToast({
  1237. title: '订单状态开发者自行获取', // 内容
  1238. icon: "none"
  1239. });
  1240. }
  1241. },
  1242. fail: res => {
  1243. that.setData({
  1244. showButton: false
  1245. })
  1246. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  1247. return;
  1248. },
  1249. });
  1250. }).catch(err => {
  1251. tt.hideLoading();
  1252. that.setData({
  1253. showButton: false
  1254. })
  1255. tt.showModal({
  1256. title: "抱歉",
  1257. content: err.message,
  1258. showCancel: false
  1259. })
  1260. });
  1261. }
  1262. } else {
  1263. // 免费券
  1264. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  1265. if (that.data.order.type == 100) {
  1266. tt.setStorage({
  1267. key: 'couponNum2',
  1268. data: "couponNum2"
  1269. })
  1270. } else if (that.data.order.type != "5") {
  1271. tt.setStorage({
  1272. key: 'couponNum',
  1273. data: "couponNum"
  1274. })
  1275. }
  1276. tt.showToast({
  1277. title: "支付成功",
  1278. duration: 2000,
  1279. image: imgurl.success.url,
  1280. });
  1281. }
  1282. // } else {//支持 支付2.0 js-api
  1283. // }
  1284. },
  1285. /**
  1286. * 支付订单更新
  1287. */
  1288. payOrderUpdate(orderId, payOrderId, status, reason, type, _this) {
  1289. // 支付成功
  1290. Http.post({
  1291. url: config.api.payOrderUpdate,
  1292. data: {
  1293. payOrderId: payOrderId,
  1294. composeOrderId: orderId,
  1295. status: status,
  1296. reason: reason,
  1297. mallTenantId: this.data.mallTenantId || ''
  1298. }
  1299. })
  1300. .then(res => {
  1301. tt.hideLoading();
  1302. _this.setData({
  1303. showButton: false
  1304. })
  1305. if (!type && type != 'free') {
  1306. tt.showToast({
  1307. title: "购买成功",
  1308. duration: 2000,
  1309. image: imgurl.success.url,
  1310. mask: false,
  1311. success: function () {
  1312. tt.showLoading({
  1313. title: "加载中..."
  1314. });
  1315. setTimeout(function () {
  1316. tt.hideLoading();
  1317. }, 1600);
  1318. setTimeout(() => {
  1319. console.log('Here1');
  1320. tt.setStorageSync('appointment', true);
  1321. let url = ""
  1322. if (_this.data.orderFlag) {
  1323. tt.redirectTo({
  1324. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order}&mallTenantId=${that.data.mallTenantId}`
  1325. });
  1326. } else {
  1327. tt.redirectTo({
  1328. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  1329. });
  1330. }
  1331. }, 1600);
  1332. }
  1333. });
  1334. } else if (type == 'free') {
  1335. console.log('Here2');
  1336. tt.redirectTo({
  1337. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  1338. });
  1339. }
  1340. })
  1341. .catch(err => {
  1342. console.log(err)
  1343. if (!type) {
  1344. setTimeout(function () {
  1345. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  1346. }, 1500)
  1347. }
  1348. });
  1349. },
  1350. onUnload: function () {
  1351. let that = this;
  1352. clearInterval(that.data.setInter);
  1353. clearInterval(that.data.templTiem);
  1354. },
  1355. onHide: function () {
  1356. let that = this;
  1357. clearInterval(that.data.setInter);
  1358. clearInterval(that.data.templTiem);
  1359. },
  1360. });