抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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