抖音c端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

1392 Zeilen
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 startTime = that.data.order.validStartDATE
  179. const endTime = that.data.order.validEndDate
  180. const mallList = JSON.stringify(that.data.mallList)
  181. console.log(startTime, endTime, mallList);
  182. tt.navigateTo({
  183. url: `/package2/pages/appointment/appointment?id=${id}&orderId=${orderId}&startTime=${startTime}&endTime=${endTime}&mallList=${mallList}`,
  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. const Appointment = tt.getStorageSync('appointment');
  485. if (Appointment) {
  486. tt.showModal({
  487. title: "提示",
  488. content: "是否立即填写预约信息?",
  489. showCancel: true,
  490. confirmText: "现在预约",
  491. confirmColor: "#deb472",
  492. cancelText: "稍后预约",
  493. success(res) {
  494. if (res.confirm) {
  495. tt.setStorageSync('appointment', false);
  496. that.goAppointment(false, tempData.couponOrderId)
  497. }
  498. if (res.cancel) {
  499. }
  500. }
  501. });
  502. }
  503. }
  504. that.setData({
  505. outOrderNo: res.data.id,
  506. order: tempData,
  507. showPage: true,
  508. createDate: createDate,
  509. composeOrderType: tempData.composeOrderType,
  510. contentType: tempData.contentType ? tempData.contentType : 0,
  511. orderFlag: tempData.type == 11 ? true : false, //判断是不是线上配送
  512. })
  513. if (tempData.couponOrderId) { //0未付款 1已支付 2已取消 3退款中 4已退款
  514. that.setRq()
  515. // that.upStatus()
  516. let setInter = setInterval(() => {
  517. if (tempData.couponOrderStatus == 0) {
  518. Http.get({
  519. url: config.api.getStatus,
  520. data: {
  521. couponOrderId: tempData.couponOrderId,
  522. mallTenantId: this.data.mallTenantId || ''
  523. }
  524. }).then(res => {
  525. console.log(res);
  526. that.setData({
  527. couponOrderStatus: res.data.CouponOrderStatus
  528. });
  529. if (res.data.CouponOrderStatus == 1 || res.data.CouponOrderStatus == 3) {
  530. /**
  531. * 动态改变上一级页面的核销状态
  532. */
  533. // that.getStaticGame()
  534. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  535. clearInterval(that.data.setInter);
  536. clearInterval(that.data.templTiem);
  537. that.updetail()
  538. that.setData({
  539. mystatus: res.data.CouponOrderStatus
  540. });
  541. }
  542. })
  543. .catch(err => {
  544. tt.showToast({
  545. title: err.errMsg,
  546. icon: 'none',
  547. duration: 2000,
  548. mask: false
  549. });
  550. })
  551. } else {
  552. Http.get({
  553. url: config.api.getStatus,
  554. data: {
  555. couponOrderId: tempData.couponOrderId,
  556. mallTenantId: this.data.mallTenantId || ''
  557. }
  558. }).then(res => {
  559. console.log(res, 'getStatus');
  560. that.setData({
  561. couponOrderStatus: res.data.CouponOrderStatus
  562. });
  563. if (res.data.CouponOrderStatus == 1 || res.data.CouponOrderStatus == 3) {
  564. /**
  565. * 动态改变上一级页面的核销状态
  566. */
  567. // that.getStaticGame()
  568. //直接调用上一个页面的setData()方法,把数据存到上一个页面中去
  569. clearInterval(that.data.setInter);
  570. clearInterval(that.data.templTiem);
  571. that.updetail()
  572. that.setData({
  573. mystatus: res.data.CouponOrderStatus
  574. });
  575. }
  576. })
  577. .catch(err => {
  578. console.log(err);
  579. })
  580. }
  581. }, 2000);
  582. that.setData({
  583. setInter: setInter
  584. })
  585. }
  586. if (tempData.couponOrderStatus && tempData.couponOrderStatus == 1) { //核销后
  587. that.goIfEvaluate() //判断订单是否能评价
  588. }
  589. }).catch(error => {
  590. console.log(error, "error");
  591. tt.hideLoading();
  592. tt.showModal({
  593. title: '提示',
  594. content: error.errMsg,
  595. showCancel: false
  596. })
  597. })
  598. },
  599. //确认收货
  600. verify() {
  601. Http.post({
  602. url: config.api.verify,
  603. data: {
  604. couponOrderId: this.data.order.couponOrderId
  605. }
  606. }).then(res => {
  607. tt.showToast({
  608. title: '签收成功',
  609. icon: "none"
  610. })
  611. this.updetail()
  612. }).catch(err => {
  613. tt.showModal({
  614. title: '提示',
  615. content: err.message ? err.message : err.data,
  616. showCancel: false
  617. })
  618. })
  619. },
  620. phone: function (e) {
  621. let that = this;
  622. console.log(e);
  623. tt.makePhoneCall({
  624. phoneNumber: e.currentTarget.dataset.merchantlinkphone
  625. });
  626. },
  627. /**
  628. * 跳转到门店列表的详情页面
  629. */
  630. gotoDetail(e) {
  631. tt.navigateTo({
  632. url: `/pages/index/searchbar/detail/index?id=${e.currentTarget.dataset.id}`
  633. })
  634. },
  635. getUserInfo: function () {
  636. let that = this;
  637. // 获取用户信息
  638. Http.get({
  639. url: config.api.getScore,
  640. data: {}
  641. })
  642. .then(res => {
  643. console.log(res)
  644. that.setData({
  645. userName: res.data.nickName,
  646. avatarUrl: res.data.avatarUrl
  647. })
  648. })
  649. },
  650. onShareAppMessage: function (res) {
  651. app.globalData.previewFlag = true
  652. if (res.from === 'button') {
  653. console.log(res, 3333333333333333333333)
  654. // 来自页面内转发按钮
  655. let _this = this;
  656. return {
  657. title: _this.data.userName + '赠送您一张' + _this.data.order.title,
  658. 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,
  659. imageUrl: this.data.order.coverImg,
  660. success: function (res) {
  661. // 转发成功
  662. },
  663. fail: function (res) {
  664. // 转发失败
  665. }
  666. }
  667. } else {
  668. console.log(res, 444444444444444444)
  669. }
  670. },
  671. createQrCode: function (url, canvasId, cavW, cavH) {
  672. //调用插件中的draw方法,绘制二维码图片
  673. let that = this;
  674. QR.api.draw(url, canvasId, cavW, cavH, function (res) {
  675. that.setData({
  676. tempFilePath: res
  677. })
  678. });
  679. },
  680. setRq() {
  681. let _this = this
  682. _this.setData({
  683. showhieRq: false,
  684. })
  685. Http.get({ //获取动态二维码
  686. url: config.api.dynamicId,
  687. data: {
  688. couponOrderId: _this.data.order.couponOrderId,
  689. couponTenantId: _this.data.tenantId || ''
  690. }
  691. }).then(res => {
  692. console.log(res, "res")
  693. _this.setData({
  694. dynamicRq: res.data.dynamicId,
  695. expiredSeconds: res.data.expiredSeconds,
  696. couponTenantId: res.data.couponTenantId
  697. })
  698. let url = JSON.stringify({
  699. END: "C",
  700. TYPE: "couponorder",
  701. ID: _this.data.dynamicRq,
  702. couponTenantId: _this.data.couponTenantId
  703. })
  704. if (res.data.expiredSeconds == 0) {
  705. //倒计时为零直接显示券码
  706. } else {
  707. let inre = setInterval(() => {
  708. if (_this.data.expiredSeconds > 1) {
  709. _this.setData({
  710. expiredSeconds: _this.data.expiredSeconds - 1
  711. })
  712. // console.log("有效", _this.data.expiredSeconds)
  713. } else {
  714. // console.log("无效", _this.data.expiredSeconds)
  715. clearInterval(_this.data.templTiem)
  716. _this.setData({
  717. showhieRq: true
  718. })
  719. }
  720. _this.setData({
  721. templTiem: inre
  722. })
  723. }, 1000)
  724. }
  725. _this.createQrCode(url, "qrcode", 350, 350);
  726. }).catch(err => {
  727. tt.showToast({
  728. title: err.message,
  729. icon: 'none',
  730. duration: 2000,
  731. mask: false
  732. });
  733. })
  734. },
  735. goPaySnapshoot(e) {
  736. let id = e.currentTarget.dataset.id;
  737. tt.navigateTo({
  738. url: `/pages/paySnapshoot/paySnapshoot?id=${id}`,
  739. success: (res) => {
  740. },
  741. fail: (res) => {
  742. },
  743. });
  744. },
  745. powerDrawer: function (e) {
  746. let that = this;
  747. console.log(e)
  748. // couponOrderStatus
  749. // 0 未使用
  750. // 1 已使用
  751. // 2 已过期
  752. // 3 已经退款
  753. if (that.data.mystatus == "" || that.data.mystatus == undefined) {
  754. tt.navigateTo({
  755. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  756. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  757. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${e.currentTarget.dataset.couponorderstatus}&validstatus=${e.currentTarget.dataset.validstatus}
  758. &contentType=${that.data.contentType}`
  759. });
  760. } else {
  761. tt.navigateTo({
  762. url: `/pages/orderquanma/index?quancode=${e.currentTarget.dataset.quancode
  763. }&title=${e.currentTarget.dataset.title}&subtitle=${e.currentTarget.dataset.subtitle
  764. }&remark=${e.currentTarget.dataset.remark}&couponorderstatus=${that.data.mystatus}&validstatus=${e.currentTarget.dataset.validstatus}
  765. &contentType=${that.data.contentType}`
  766. });
  767. }
  768. },
  769. gotogame: function () {
  770. let that = this;
  771. tt.redirectTo({
  772. url: '/pages/game/index?url=' + that.data.staticGamedata.url + "&id=" + that.data.staticGamedata.id + "&gameId=" + that.data.staticGamedata.gameId,
  773. })
  774. },
  775. // 买完卡跳转到立即使用页面
  776. gotoUse: function () {
  777. tt.navigateTo({
  778. url: '/pages/cardorder/index/index'
  779. })
  780. },
  781. // 获取游戏
  782. getStaticGame(token) {
  783. let _this = this;
  784. Http.get({
  785. url: config.api.getGame,
  786. data: {
  787. triggleAction: 3 // 购买触发
  788. }
  789. }).then(res => {
  790. if (res.data.id) {
  791. _this.setData({
  792. showIf: true
  793. })
  794. }
  795. _this.setData({
  796. staticGamedata: res.data
  797. })
  798. })
  799. .catch(err => {
  800. console.log(err);
  801. })
  802. },
  803. goEvaluate() {
  804. let _this = this
  805. tt.rateAwemeOrder({
  806. orderId: _this.data.payOrderNo,
  807. success({
  808. result
  809. }) {
  810. console.log(result);
  811. if (result) {
  812. tt.navigateBack({
  813. delta: 1,
  814. success: (res) => {
  815. },
  816. fail: (res) => {
  817. },
  818. });
  819. // 用户已经评价的逻辑
  820. } else {
  821. // 用户没有评价的逻辑
  822. }
  823. },
  824. fail(err) {
  825. console.log(err);
  826. },
  827. });
  828. },
  829. goIfEvaluate() {
  830. let _this = this
  831. Http.get({
  832. url: config.api.getchanId,
  833. data: {
  834. id: _this.data.order.couponOrderId,
  835. mallTenantId: this.data.mallTenantId || ''
  836. }
  837. }).then(res => {
  838. tt.canRateAwemeOrders({
  839. orderIds: [res.data.payOrderNo],
  840. success({
  841. result
  842. }) {
  843. console.log("result", result);
  844. _this.setData({
  845. evaluateFlag: result[0],
  846. payOrderNo: res.data.payOrderNo
  847. })
  848. },
  849. fail(err) {
  850. console.log(err);
  851. },
  852. });
  853. }).catch(err => {
  854. tt.showToast({
  855. title: err.message ? err.message : err.data, // 内容
  856. icon: "none"
  857. });
  858. })
  859. },
  860. /**
  861. * 生命周期函数--监听页面加载
  862. */
  863. onLoad: function (option) {
  864. console.log(option, 'option');
  865. let options = null
  866. if (option.params) {
  867. options = JSON.parse(option.params)
  868. } else {
  869. options = option
  870. }
  871. // this.getSeUrl()
  872. if (options.mallTenantId) {
  873. this.setData({
  874. mallTenantId: options.mallTenantId,
  875. })
  876. }
  877. this.setData({
  878. mouldType: app.globalData.mouldType
  879. })
  880. let that = this;
  881. // if (options.dingdan && options.dingdan == "order") {
  882. // }
  883. that.setData({
  884. orderId: options.orderId,
  885. });
  886. tt.hideShareMenu()
  887. if (options.cardIf) { //转赠 展示不需
  888. that.setData({
  889. cardIf: true
  890. })
  891. }
  892. tt.showLoading({
  893. title: "加载中"
  894. });
  895. this.getCouponMerchant() //获取可用商户
  896. },
  897. onShow: function () {
  898. let that = this;
  899. that.setData({
  900. showButton: false
  901. })
  902. that.updetail()
  903. this.getCouponMerchant() //获取可用商户
  904. if (tt.canIUse("microapp-trade-plugin")) {
  905. that.setData({
  906. canIUseRefund: true
  907. })
  908. console.log(that.data.canIUseRefund, 'canIUseRefund');
  909. }
  910. },
  911. getSeUrl() { //获取客服链接
  912. const openId = tt.getStorageSync('openId');
  913. Http.post({
  914. url: config.api.getServiceUrl,
  915. data: {
  916. appid: app.globalData.appId,
  917. openid: openId
  918. }
  919. }).then(res => {
  920. this.setData({
  921. serviceUrl: res.data ? res.data : ''
  922. })
  923. if (res.data) {
  924. tt.setStorageSync('serviceData', res.data);
  925. }
  926. })
  927. },
  928. goWebView() {
  929. let _this = this
  930. tt.navigateTo({
  931. url: `/pages/serviceWebView/serviceWebView`,
  932. success: (res) => {
  933. },
  934. fail: (res) => {
  935. },
  936. });
  937. },
  938. /**
  939. * 去拼团
  940. */
  941. goToOrderGroup(orderId, orderGroupId, _this) {
  942. let that = this;
  943. // 支付成功
  944. Http.post({
  945. url: config.api.toOrderGroup,
  946. data: {
  947. id: orderGroupId,
  948. orderId,
  949. couponId: _this.data.order.productId
  950. }
  951. })
  952. .then(res => {
  953. tt.redirectTo({
  954. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.order.productId}&orderGroupId=${res.data.orderGroupId}&mallTenantId=${this.data.mallTenantId}`
  955. });
  956. })
  957. .catch(err => {
  958. console.log(err);
  959. })
  960. // return;
  961. },
  962. /**
  963. * 发起支付
  964. */
  965. orderFunc(e) {
  966. var that = this;
  967. const orderId = "" + that.data.orderId;
  968. that.setData({
  969. showButton: true
  970. })
  971. tt.showLoading({
  972. title: "加载中..."
  973. });
  974. // if (true) {//兼容不支持支付2.0 js-api !tt.canIUse('createOrder')
  975. if (that.data.order.payment > 0) {
  976. if (tt.canIUse('createOrder')) { //支付2.0 js-api
  977. const outOrderNo = that.data.outOrderNo
  978. console.log(outOrderNo, "outOrderNo");
  979. Http.post({
  980. url: config.api.payOrderCreate_2,
  981. data: {
  982. // composeOrderId: outOrderNo
  983. orderId: outOrderNo,
  984. composeOrderType: that.data.composeOrderType,
  985. mallTenantId: this.data.mallTenantId || ''
  986. }
  987. }).then(res => {
  988. if (res.data.createPay) {
  989. let tempCallbackData = res.data.callbackData
  990. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  991. let options = {
  992. callbackData: tempCallbackData,
  993. goodsList: res.data.goodsList,
  994. payment: res.data.payment,
  995. success: res => {
  996. tt.hideLoading();
  997. that.setData({
  998. showbutton: false,
  999. })
  1000. const {
  1001. orderId,
  1002. outOrderNo
  1003. } = res;
  1004. // that.setData({
  1005. // orderId,
  1006. // outOrderNo
  1007. // });
  1008. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  1009. },
  1010. fail: res => {
  1011. const {
  1012. orderId,
  1013. outOrderNo,
  1014. errNo,
  1015. errMsg,
  1016. errLogId
  1017. } = res;
  1018. if (errLogId) {
  1019. tt.hideLoading();
  1020. that.setData({
  1021. showbutton: false,
  1022. })
  1023. console.log('预下单失败', errNo, errMsg, errLogId);
  1024. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  1025. tt.showToast({
  1026. title: tempErrmsg[tempErrmsg.length - 1],
  1027. icon: 'none',
  1028. duration: 2000,
  1029. mask: false
  1030. });
  1031. }
  1032. if (orderId || outOrderNo) {
  1033. tt.hideLoading();
  1034. that.setData({
  1035. showbutton: false,
  1036. })
  1037. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1038. console.log(that.payOrderUpdate, "payOrderUpdate");
  1039. tt.showToast({
  1040. title: "取消支付",
  1041. icon: 'none',
  1042. duration: 2000,
  1043. mask: false
  1044. });
  1045. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  1046. }
  1047. },
  1048. }
  1049. console.log(options, "options");
  1050. tt.createOrder(options)
  1051. } else {
  1052. tt.continueToPay({
  1053. outOrderNo: res.data.outOrderNo, // 外部订单号 2个订单号必填一个
  1054. success: res => {
  1055. // const { orderId, outOrderNo } = res;
  1056. // console.log('success res', res);
  1057. // console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  1058. that.setData({
  1059. showButton: false
  1060. })
  1061. tt.hideLoading();
  1062. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that); // 支付成功
  1063. },
  1064. fail: res => {
  1065. const {
  1066. orderId,
  1067. outOrderNo,
  1068. errNo,
  1069. errMsg,
  1070. errLogId
  1071. } = res;
  1072. if (errLogId) {
  1073. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  1074. that.setData({
  1075. showButton: false
  1076. })
  1077. tt.showToast({
  1078. title: errMsg,
  1079. icon: 'none',
  1080. duration: 2000,
  1081. mask: false
  1082. });
  1083. tt.hideLoading();
  1084. }
  1085. if (orderId || outOrderNo) {
  1086. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1087. tt.showToast({
  1088. title: errMsg,
  1089. icon: 'none',
  1090. duration: 2000,
  1091. mask: false
  1092. });
  1093. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail', that);
  1094. that.setData({
  1095. showButton: false
  1096. })
  1097. tt.hideLoading();
  1098. }
  1099. },
  1100. });
  1101. }
  1102. }).catch(err => {
  1103. tt.showToast({
  1104. title: err.message ? err.message : err.data, // 内容
  1105. icon: "none"
  1106. });
  1107. })
  1108. } else { //不支持支付2.0 js-api
  1109. tt.showToast({
  1110. title: '请升级抖音', // 内容
  1111. icon: "none"
  1112. });
  1113. return
  1114. // 支付金额不为0
  1115. Http.post({
  1116. url: config.api.payOrderCreate,
  1117. data: {
  1118. orderId: orderId,
  1119. composeOrderType: that.data.composeOrderType
  1120. }
  1121. }).then(res => {
  1122. var payOrderId = "" + res.data.outOrderNo;
  1123. tt.hideLoading();
  1124. tt.pay({
  1125. service: 5,
  1126. orderInfo: {
  1127. order_id: res.data.payOrderId,
  1128. order_token: res.data.payOrderToken,
  1129. },
  1130. success: res => {
  1131. tt.showLoading({
  1132. title: '订单正在处理中...',
  1133. })
  1134. if (res.code == 0) {
  1135. setTimeout(function () {
  1136. tt.hideLoading()
  1137. }, 5000)
  1138. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  1139. if (res.errMsg == "requestPayment:ok") {
  1140. if (that.data.order.type == 100) {
  1141. tt.setStorage({
  1142. key: 'couponNum2',
  1143. data: "couponNum2"
  1144. })
  1145. } else if (that.data.order.type != 5) {
  1146. tt.setStorage({
  1147. key: 'couponNum',
  1148. data: "couponNum"
  1149. })
  1150. }
  1151. }
  1152. } else if (res.code === 1) {
  1153. that.setData({
  1154. showButton: false
  1155. })
  1156. tt.hideLoading();
  1157. tt.showToast({
  1158. title: '支付超时', // 内容
  1159. icon: "none"
  1160. });
  1161. } else if (res.code === 2) {
  1162. that.setData({
  1163. showButton: false
  1164. })
  1165. tt.hideLoading();
  1166. tt.showToast({
  1167. title: '支付失败', // 内容
  1168. icon: "none"
  1169. });
  1170. } else if (res.code === 3) {
  1171. that.setData({
  1172. showButton: false
  1173. })
  1174. tt.hideLoading();
  1175. tt.showToast({
  1176. title: '支付关闭', // 内容
  1177. icon: "none"
  1178. });
  1179. } else if (res.code === 4) {
  1180. that.setData({
  1181. showButton: false
  1182. })
  1183. tt.hideLoading();
  1184. tt.showToast({
  1185. title: '支付取消', // 内容
  1186. icon: "none"
  1187. });
  1188. } else if (res.code === 9) {
  1189. that.setData({
  1190. showButton: false
  1191. })
  1192. tt.hideLoading();
  1193. tt.showToast({
  1194. title: '订单状态开发者自行获取', // 内容
  1195. icon: "none"
  1196. });
  1197. }
  1198. },
  1199. fail: res => {
  1200. that.setData({
  1201. showButton: false
  1202. })
  1203. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  1204. return;
  1205. },
  1206. });
  1207. }).catch(err => {
  1208. tt.hideLoading();
  1209. that.setData({
  1210. showButton: false
  1211. })
  1212. tt.showModal({
  1213. title: "抱歉",
  1214. content: err.message,
  1215. showCancel: false
  1216. })
  1217. });
  1218. }
  1219. } else {
  1220. // 免费券
  1221. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  1222. if (that.data.order.type == 100) {
  1223. tt.setStorage({
  1224. key: 'couponNum2',
  1225. data: "couponNum2"
  1226. })
  1227. } else if (that.data.order.type != "5") {
  1228. tt.setStorage({
  1229. key: 'couponNum',
  1230. data: "couponNum"
  1231. })
  1232. }
  1233. tt.showToast({
  1234. title: "支付成功",
  1235. duration: 2000,
  1236. image: imgurl.success.url,
  1237. });
  1238. }
  1239. // } else {//支持 支付2.0 js-api
  1240. // }
  1241. },
  1242. /**
  1243. * 支付订单更新
  1244. */
  1245. payOrderUpdate(orderId, payOrderId, status, reason, type, _this) {
  1246. // 支付成功
  1247. Http.post({
  1248. url: config.api.payOrderUpdate,
  1249. data: {
  1250. payOrderId: payOrderId,
  1251. composeOrderId: orderId,
  1252. status: status,
  1253. reason: reason,
  1254. mallTenantId: this.data.mallTenantId || ''
  1255. }
  1256. })
  1257. .then(res => {
  1258. tt.hideLoading();
  1259. _this.setData({
  1260. showButton: false
  1261. })
  1262. if (!type && type != 'free') {
  1263. tt.showToast({
  1264. title: "购买成功",
  1265. duration: 2000,
  1266. image: imgurl.success.url,
  1267. mask: false,
  1268. success: function () {
  1269. tt.showLoading({
  1270. title: "加载中..."
  1271. });
  1272. setTimeout(function () {
  1273. tt.hideLoading();
  1274. }, 1600);
  1275. setTimeout(() => {
  1276. console.log('Here1');
  1277. tt.setStorageSync('appointment', true);
  1278. let url = ""
  1279. if (_this.data.orderFlag) {
  1280. tt.redirectTo({
  1281. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order}&mallTenantId=${that.data.mallTenantId}`
  1282. });
  1283. } else {
  1284. tt.redirectTo({
  1285. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  1286. });
  1287. }
  1288. }, 1600);
  1289. }
  1290. });
  1291. } else if (type == 'free') {
  1292. console.log('Here2');
  1293. tt.redirectTo({
  1294. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  1295. });
  1296. }
  1297. })
  1298. .catch(err => {
  1299. console.log(err)
  1300. if (!type) {
  1301. setTimeout(function () {
  1302. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  1303. }, 1500)
  1304. }
  1305. });
  1306. },
  1307. onUnload: function () {
  1308. let that = this;
  1309. clearInterval(that.data.setInter);
  1310. clearInterval(that.data.templTiem);
  1311. },
  1312. onHide: function () {
  1313. let that = this;
  1314. clearInterval(that.data.setInter);
  1315. clearInterval(that.data.templTiem);
  1316. },
  1317. });