抖音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.

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