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

1052 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 = {
  691. composeOrderId: res.data.outOrderNo
  692. }
  693. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  694. let options = {
  695. callbackData: tempCallbackData,
  696. goodsList: res.data.goodsList,
  697. payment: res.data.payment,
  698. success: res => {
  699. tt.hideLoading();
  700. that.setData({
  701. showbutton: false,
  702. })
  703. const { orderId, outOrderNo } = res;
  704. // that.setData({ orderId, outOrderNo });
  705. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  706. },
  707. fail: res => {
  708. const { orderId, outOrderNo, errNo, errMsg, errLogId } = res;
  709. if (errLogId) {
  710. tt.hideLoading();
  711. that.setData({
  712. showbutton: false,
  713. })
  714. console.log('预下单失败', errNo, errMsg, errLogId);
  715. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  716. tt.showToast({
  717. title: tempErrmsg[tempErrmsg.length - 1],
  718. icon: 'none',
  719. duration: 2000,
  720. mask: false
  721. });
  722. }
  723. if (orderId || outOrderNo) {
  724. tt.hideLoading();
  725. that.setData({
  726. showbutton: false,
  727. })
  728. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  729. console.log(that.payOrderUpdate, "payOrderUpdate");
  730. tt.showToast({
  731. title: "取消支付",
  732. icon: 'none',
  733. duration: 2000,
  734. mask: false
  735. });
  736. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  737. }
  738. },
  739. }
  740. console.log(options, "options");
  741. tt.createOrder(options)
  742. } else {
  743. tt.continueToPay({
  744. outOrderNo: res.data.outOrderNo, // 外部订单号 2个订单号必填一个
  745. success: res => {
  746. // const { orderId, outOrderNo } = res;
  747. // console.log('success res', res);
  748. // console.log('orderId', orderId, 'outOrderNo', outOrderNo);
  749. that.setData({
  750. showButton: false
  751. })
  752. tt.hideLoading();
  753. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that); // 支付成功
  754. },
  755. fail: res => {
  756. const { orderId, outOrderNo, errNo, errMsg, errLogId } = res;
  757. if (errLogId) {
  758. console.log('查询订单信息失败', errNo, errMsg, errLogId);
  759. that.setData({
  760. showButton: false
  761. })
  762. tt.showToast({
  763. title: errMsg,
  764. icon: 'none',
  765. duration: 2000,
  766. mask: false
  767. });
  768. tt.hideLoading();
  769. }
  770. if (orderId || outOrderNo) {
  771. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  772. tt.showToast({
  773. title: errMsg,
  774. icon: 'none',
  775. duration: 2000,
  776. mask: false
  777. });
  778. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail', that);
  779. that.setData({
  780. showButton: false
  781. })
  782. tt.hideLoading();
  783. }
  784. },
  785. });
  786. }
  787. }).catch(err => {
  788. tt.showToast({
  789. title: err.message ? err.message : err.data, // 内容
  790. icon: "none"
  791. });
  792. })
  793. } else {//不支持支付2.0 js-api
  794. tt.showToast({
  795. title: '请升级抖音', // 内容
  796. icon: "none"
  797. });
  798. return
  799. // 支付金额不为0
  800. Http.post({
  801. url: config.api.payOrderCreate,
  802. data: {
  803. orderId: orderId,
  804. composeOrderType: that.data.composeOrderType
  805. }
  806. }).then(res => {
  807. var payOrderId = "" + res.data.outOrderNo;
  808. tt.hideLoading();
  809. tt.pay({
  810. service: 5,
  811. orderInfo: {
  812. order_id: res.data.payOrderId,
  813. order_token: res.data.payOrderToken,
  814. },
  815. success: res => {
  816. tt.showLoading({
  817. title: '订单正在处理中...',
  818. })
  819. if (res.code == 0) {
  820. setTimeout(function () {
  821. tt.hideLoading()
  822. }, 5000)
  823. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that); // 支付成功
  824. if (res.errMsg == "requestPayment:ok") {
  825. if (that.data.order.type == 100) {
  826. tt.setStorage({
  827. key: 'couponNum2',
  828. data: "couponNum2"
  829. })
  830. } else if (that.data.order.type != 5) {
  831. tt.setStorage({
  832. key: 'couponNum',
  833. data: "couponNum"
  834. })
  835. }
  836. }
  837. } else if (res.code === 1) {
  838. that.setData({
  839. showButton: false
  840. })
  841. tt.hideLoading();
  842. tt.showToast({
  843. title: '支付超时', // 内容
  844. icon: "none"
  845. });
  846. } else if (res.code === 2) {
  847. that.setData({
  848. showButton: false
  849. })
  850. tt.hideLoading();
  851. tt.showToast({
  852. title: '支付失败', // 内容
  853. icon: "none"
  854. });
  855. } else if (res.code === 3) {
  856. that.setData({
  857. showButton: false
  858. })
  859. tt.hideLoading();
  860. tt.showToast({
  861. title: '支付关闭', // 内容
  862. icon: "none"
  863. });
  864. } else if (res.code === 4) {
  865. that.setData({
  866. showButton: false
  867. })
  868. tt.hideLoading();
  869. tt.showToast({
  870. title: '支付取消', // 内容
  871. icon: "none"
  872. });
  873. } else if (res.code === 9) {
  874. that.setData({
  875. showButton: false
  876. })
  877. tt.hideLoading();
  878. tt.showToast({
  879. title: '订单状态开发者自行获取', // 内容
  880. icon: "none"
  881. });
  882. }
  883. },
  884. fail: res => {
  885. that.setData({
  886. showButton: false
  887. })
  888. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  889. return;
  890. },
  891. });
  892. }).catch(err => {
  893. tt.hideLoading();
  894. that.setData({
  895. showButton: false
  896. })
  897. tt.showModal({
  898. title: "抱歉",
  899. content: err.message,
  900. showCancel: false
  901. })
  902. });
  903. }
  904. } else {
  905. // 免费券
  906. that.payOrderUpdate(orderId, "0", 1, '', 'free') // 支付成功
  907. if (that.data.order.type == 100) {
  908. tt.setStorage({
  909. key: 'couponNum2',
  910. data: "couponNum2"
  911. })
  912. } else if (that.data.order.type != "5") {
  913. tt.setStorage({
  914. key: 'couponNum',
  915. data: "couponNum"
  916. })
  917. }
  918. tt.showToast({
  919. title: "支付成功",
  920. duration: 2000,
  921. image: imgurl.success.url,
  922. });
  923. }
  924. // } else {//支持 支付2.0 js-api
  925. // }
  926. },
  927. /**
  928. * 支付订单更新
  929. */
  930. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  931. // 支付成功
  932. Http.post({
  933. url: config.api.payOrderUpdate,
  934. data: {
  935. payOrderId: payOrderId,
  936. composeOrderId: orderId,
  937. status: status,
  938. reason: reason
  939. }
  940. })
  941. .then(res => {
  942. tt.hideLoading();
  943. _this.setData({
  944. showButton: false
  945. })
  946. if (!type && type != 'free') {
  947. tt.showToast({
  948. title: "购买成功",
  949. duration: 2000,
  950. image: imgurl.success.url,
  951. mask: false,
  952. success: function () {
  953. tt.showLoading({
  954. title: "加载中..."
  955. });
  956. setTimeout(function () {
  957. tt.hideLoading();
  958. }, 1600);
  959. setTimeout(() => {
  960. let url = ""
  961. if (_this.data.orderFlag) {
  962. tt.redirectTo({
  963. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order`
  964. });
  965. } else {
  966. tt.redirectTo({
  967. url: `/pages/order/detail/index?orderId=${orderId}`
  968. });
  969. }
  970. }, 1600);
  971. }
  972. });
  973. } else if (type == 'free') {
  974. tt.redirectTo({
  975. url: `/pages/order/detail/index?orderId=${orderId}`
  976. });
  977. }
  978. })
  979. .catch(err => {
  980. console.log(err)
  981. if (!type) {
  982. setTimeout(function () {
  983. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  984. }, 1500)
  985. }
  986. });
  987. },
  988. onUnload: function () {
  989. let that = this;
  990. clearInterval(that.data.setInter);
  991. clearInterval(that.data.templTiem);
  992. },
  993. onHide: function () {
  994. let that = this;
  995. clearInterval(that.data.setInter);
  996. clearInterval(that.data.templTiem);
  997. },
  998. });