抖音c端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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