抖音c端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

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