抖音c端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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