抖音c端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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