抖音c端
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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