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

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