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

978 regels
31 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  2. var config = require("../../../config/config.js");
  3. var app = getApp();
  4. const Http = require("../../../utils/HttpBasics");
  5. const util = require("../../../utils/util");
  6. const imgurl = require("../../../utils/imgurl");
  7. Page({
  8. data: {
  9. couponIds: "",
  10. showPhoem: false,
  11. couponChannelId: "",
  12. showPage: false,
  13. data: {},
  14. spuIdObj: {},
  15. priceAndStockObj: {},
  16. mallTenantId: '',
  17. imId: "",
  18. goodId: "",
  19. IMorderId: ""
  20. },
  21. onLoad: function (options) {
  22. console.log(options, 'options!!!!!!!');
  23. if (options.mallTenantId) {
  24. this.setData({
  25. mallTenantId: options.mallTenantId,
  26. })
  27. } else {
  28. this.setData({
  29. mallTenantId: tt.getStorageSync('mallTenantId'),
  30. })
  31. }
  32. console.log(this.data.mallTenantId, 'mallTenantId');
  33. tt.showLoading({
  34. title: "加载中..."
  35. });
  36. let that = this
  37. if (app.globalData.token) {
  38. if (options && options.couponChannelId) {
  39. that.setData({
  40. couponChannelId: options.couponChannelId
  41. })
  42. that.getDetail(options.couponChannelId, 'notendclock');
  43. }
  44. } else {
  45. app.tokenCallback = token => {
  46. that.setData({
  47. couponChannelId: options.couponChannelId
  48. })
  49. if (options && options.couponChannelId) {
  50. that.getDetail(options.couponChannelId, 'notendclock');
  51. }
  52. }
  53. }
  54. },
  55. imCallback(e) {
  56. console.log("跳转IM客服成功", e);
  57. },
  58. onimError(e) {
  59. console.log("拉起IM客服失败", e.detail);
  60. },
  61. goInstructions() {
  62. tt.navigateTo({
  63. url: '/pages/coupon/instructions/instructions?couponChannelId=' + this.data.couponChannelId,
  64. success: (res) => {
  65. },
  66. fail: (res) => {
  67. },
  68. });
  69. },
  70. getIm() { //获取im客服id
  71. const that = this
  72. Http.get({
  73. url: config.api.getIm,
  74. data: {
  75. mallTenantId: this.data.mallTenantId || ''
  76. }
  77. }).then(res => {
  78. console.log(res, 'getIm');
  79. const imId = res.data.imId || ''
  80. that.setData({
  81. imId: imId
  82. })
  83. }).catch(err => {
  84. console.log(err, 'res');
  85. })
  86. },
  87. getSupId(id) {
  88. Http.get({
  89. url: config.api.getSpuid,
  90. data: {
  91. id: id
  92. }
  93. }).then(res => {
  94. if (res.data) {
  95. this.setData({
  96. spuIdObj: res.data,
  97. goodId: res.data.spuId
  98. })
  99. }
  100. }).catch(err => {
  101. // tt.showToast({
  102. // title: err.message,
  103. // icon: 'none',
  104. // duration: 2000,
  105. // mask: false
  106. // });
  107. })
  108. },
  109. setPhone(paramData) {
  110. //子组件调用这个方法说明手机号已经授权成功
  111. this.setData({
  112. showPhoem: paramData.detail,
  113. })
  114. tt.showToast({
  115. title: '授权成功', // 内容
  116. icon: 'none', // 图标
  117. success: (res) => {
  118. },
  119. fail: (res) => {
  120. },
  121. });
  122. },
  123. setBox(paramData) {
  124. this.setData({
  125. showPhoem: paramData.detail
  126. })
  127. tt.showToast({
  128. title: '取消授权', // 内容
  129. icon: 'none', // 图标
  130. success: (res) => {
  131. tt.reLaunch({
  132. url: "/index/index",
  133. success(res) {
  134. console.log(`${res}`);
  135. app.globalData.selected = 0
  136. },
  137. fail(err) {
  138. console.log(`navigateTo调用失败`, err);
  139. },
  140. });
  141. },
  142. fail: (res) => {
  143. },
  144. });
  145. },
  146. getCouponPriceAndStock(couponChannelId) { //获取券价格与库存
  147. Http.get({
  148. url: config.api.couponPriceAndStock,
  149. data: {
  150. couponChannelId,
  151. mallTenantId: this.data.mallTenantId || ''
  152. }
  153. }).then(res => {
  154. let tempBoj = JSON.parse(res.data)
  155. console.log(tempBoj, "$");
  156. this.setData({
  157. priceAndStockObj: tempBoj
  158. })
  159. })
  160. },
  161. getDetail: function (couponChannelId, flag) {
  162. let that = this;
  163. let data = {};
  164. that.getCouponPriceAndStock(couponChannelId); //获取券价格和库存
  165. if (that.data.couponIds) {
  166. data.couponId = couponChannelId
  167. } else {
  168. data.couponChannelId = couponChannelId
  169. }
  170. var parmer = {
  171. url: config.api.newCouponDetail,
  172. data: data
  173. };
  174. Http.get(parmer).then(res => {
  175. that.setData({
  176. couponId: res.data.couponId
  177. })
  178. /**
  179. * activityStatus==0 活动未开始
  180. * activityStatus==1 活动已开始
  181. * flag == endclock 说明倒计时已经结束
  182. */
  183. if (res.data.endTime && res.data.beginTime) {
  184. that.setData({
  185. begin_time: res.data.beginTime,
  186. end_time: res.data.endTime,
  187. activityStatus: res.data.actStatus ? res.data.actStatus : ''
  188. })
  189. if (res.data.actStatus == 0 && flag != 'endclock') {
  190. that.countdown(res.data.beginTime);
  191. } else if (res.data.actStatus != 0 && flag != 'endclock') {
  192. that.countdown(res.data.endTime);
  193. } else {
  194. clearInterval(that.data.setInterval)
  195. }
  196. if (res.data.actStatus == 0) {
  197. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  198. if (util.timechuo(beginTime).indexOf('-') == 0) {
  199. that.setData({
  200. beginTime: "活动已结束",
  201. });
  202. } else {
  203. that.setData({
  204. beginTime: util.timechuo(beginTime)
  205. });
  206. }
  207. } else {
  208. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  209. if (util.timechuo(endTime).indexOf('-') == 0) {
  210. that.setData({
  211. endtime: "活动已结束",
  212. });
  213. } else {
  214. that.setData({
  215. endtime: util.timechuo(endTime)
  216. });
  217. }
  218. }
  219. }
  220. tt.hideLoading();
  221. that.setData({
  222. data: res.data,
  223. });
  224. if (res.data.type == 10) {
  225. that.setData({
  226. salePriceStr: res.data.salePriceStr,
  227. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  228. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  229. priceStr: res.data.priceStr,
  230. tailPriceStr: res.data.tailPriceStr,
  231. origPriceStr: res.data.origPriceStr
  232. })
  233. }
  234. if (res.data.validType == 1) {
  235. that.setData({
  236. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  237. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  238. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  239. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  240. });
  241. } else {
  242. if (res.data.validDays) {
  243. that.setData({
  244. validDays: res.data.validDays
  245. });
  246. }
  247. }
  248. if (res.data.itemGroup) {
  249. let tempObj = this.data.data
  250. tempObj.itemGroup = JSON.parse(tempObj.itemGroup)
  251. this.setData({
  252. data: tempObj
  253. })
  254. console.log(this.data.data, "data");
  255. }
  256. if (res.data.productAttrs && res.data.skuAttrs) {
  257. let tempObj = this.data.data
  258. tempObj.productAttrs = JSON.parse(tempObj.productAttrs)
  259. tempObj.skuAttrs = JSON.parse(tempObj.skuAttrs)
  260. tempObj.productAttrs.map(item => {
  261. if (item.key == "Notification") {
  262. if (item.data != '') {
  263. tempObj.curLsit = JSON.parse(item.data)
  264. }
  265. }
  266. if (item.key == "bring_out_meal") {
  267. tempObj.besides = item.data
  268. }
  269. if (item.key == "free_pack") {
  270. tempObj.pack = item.data
  271. }
  272. if (item.key == "superimposed_discounts") {
  273. tempObj.superimposed_discounts = item.data
  274. }
  275. if (item.key == "private_room") {
  276. tempObj.private_room = item.data
  277. }
  278. if (item.key == "rec_person_num_max") {
  279. tempObj.rec_person_num_max = item.data
  280. }
  281. if (item.key == 'Description') {
  282. tempObj.Description = JSON.parse(item.data)
  283. }
  284. if (item.key == "can_no_use_date") {
  285. tempObj.can_no_use_date = JSON.parse(item.data)
  286. }
  287. })
  288. tempObj.skuAttrs.map(item => {
  289. if (item.key == "commodity") {
  290. if (item.data != '') {
  291. tempObj.itemGroup = JSON.parse(item.data)
  292. }
  293. }
  294. })
  295. this.setData({
  296. data: tempObj
  297. })
  298. console.log(this.data.data, "data");
  299. }
  300. }).catch(err => {
  301. tt.showToast({
  302. title: err.message,
  303. icon: 'none',
  304. duration: 2000,
  305. mask: false
  306. });
  307. })
  308. },
  309. /**
  310. * 支付订单更新
  311. */
  312. payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType) {
  313. let that = this;
  314. console.log(orderId, 'orderId');
  315. // 支付成功
  316. Http.post({
  317. url: config.api.payOrderUpdate,
  318. data: {
  319. payOrderId: payOrderId,
  320. composeOrderId: orderId,
  321. status: status,
  322. reason: reason,
  323. mallTenantId: that.data.mallTenantId
  324. }
  325. })
  326. .then(res => {
  327. tt.hideLoading()
  328. // 有价券
  329. if (!type && type != 'free') {
  330. console.log('Over Here! type');
  331. setTimeout(() => {
  332. console.log(_this.data.orderFlag, orderId, that.data.mallTenantId, 'notice!!!');
  333. let url = ""
  334. if (_this.data.orderFlag) {
  335. tt.redirectTo({
  336. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order&mallTenantId=${that.data.mallTenantId}`
  337. });
  338. } else {
  339. tt.redirectTo({
  340. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  341. });
  342. }
  343. }, 1600);
  344. } else if (type == 'free') {
  345. console.log('Over Here! type2');
  346. tt.navigateTo({
  347. url: `/pages/order/detail/index?orderId=${orderId
  348. }&mallTenantId=${that.data.mallTenantId}`
  349. });
  350. }
  351. })
  352. .catch(err => {
  353. console.log(err);
  354. console.log('Over Here! type3');
  355. if (!type) {
  356. setTimeout(function () {
  357. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  358. }, 2000)
  359. }
  360. })
  361. },
  362. // 获得未支付的订单
  363. getUnPaidOrder(couponId) {
  364. let that = this;
  365. Http.get({
  366. url: config.api.getUnPaidOrder,
  367. data: {
  368. couponId: couponId,
  369. mallTenantId: this.data.mallTenantId || ''
  370. }
  371. }).then(res => {
  372. that.setData({
  373. disOrderNumber: res.data.orderNumber,
  374. composeOrderType: res.data.composeOrderType
  375. })
  376. if (res.data && res.data.pressEndDate) {
  377. that.setData({
  378. dispressEndDate: true
  379. })
  380. } else {
  381. that.setData({
  382. dispressEndDate: false
  383. })
  384. }
  385. if (that.data.dispressEndDate) {
  386. tt.showModal({
  387. title: '提示',
  388. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  389. confirmText: "我的砍价",
  390. success: function (res) {
  391. if (res.confirm) {
  392. tt.navigateTo({
  393. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}&composeOrderType=${that.data.composeOrderType}`,
  394. })
  395. }
  396. }
  397. })
  398. } else {
  399. tt.showModal({
  400. title: '提示',
  401. content: '您有未支付订单,请先进行支付',
  402. confirmText: "去支付",
  403. success: function (res1) {
  404. if (res1.confirm) {
  405. if (that.data.composeOrderType > 0) { //券包
  406. tt.navigateTo({
  407. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&mallTenantId=${that.data.mallTenantId}`,
  408. })
  409. } else {
  410. tt.navigateTo({
  411. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&mallTenantId=${that.data.mallTenantId}`,
  412. })
  413. }
  414. }
  415. }
  416. })
  417. }
  418. }).catch(error => {
  419. tt.showToast({
  420. title: error.message,
  421. icon: "none",
  422. duration: 3000
  423. })
  424. })
  425. },
  426. /**
  427. * 发起支付
  428. */
  429. orderFunc(discount) {
  430. if (this.data.showbutton) return;
  431. let that = this;
  432. tt.showLoading({
  433. title: "加载中..."
  434. });
  435. that.setData({
  436. showbutton: true,
  437. })
  438. Http.get({
  439. url: config.api.checkUserStatus,
  440. data: {
  441. token: app.globalData.token,
  442. }
  443. }).then(res => {
  444. Http.get({
  445. url: config.api.checkPhoneStatus,
  446. data: {}
  447. }).then(res => {
  448. //
  449. // if (!tt.canIUse('createOrder') || that.data.data.type == 50 || that.data.priceAndStockObj.salePrice == 0) {
  450. //积分券和免费券
  451. // 发起砍价
  452. if (discount == 'discount') {
  453. var data = {
  454. couponChannelId: "" + that.data.couponChannelId,
  455. couponId: "" + that.data.couponId,
  456. formId: "" + that.data.formId,
  457. press: true
  458. }
  459. } else if (discount == 'discount1') {
  460. var data = {
  461. couponChannelId: "" + that.data.couponChannelId,
  462. couponId: "" + that.data.couponId,
  463. formId: "" + that.data.formId,
  464. press: false
  465. }
  466. } else if (that.data.couponChannelId == null) {
  467. var data = {
  468. couponId: "" + that.data.couponId,
  469. formId: "" + that.data.formId,
  470. };
  471. } else {
  472. var data = {
  473. couponChannelId: "" + that.data.couponChannelId,
  474. couponId: "" + that.data.couponId,
  475. formId: "" + that.data.formId,
  476. }
  477. }
  478. console.log(data, "data")
  479. let url = ""
  480. let tempObj;
  481. let tempArr = []
  482. if (that.data.data.type == 12) {
  483. url = config.api.couponPackageSave
  484. tempObj = {
  485. signleOrder: {
  486. couponChannelId: "" + that.data.couponChannelId,
  487. couponId: "" + that.data.couponId,
  488. formId: "" + that.data.formId,
  489. },
  490. count: "1"
  491. }
  492. tempArr.push(tempObj)
  493. } else {
  494. url = config.api.orderSave
  495. data.mallTenantId = that.data.mallTenantId || ''
  496. }
  497. /**
  498. * orderSave 下单
  499. */
  500. Http.post({
  501. url: url,
  502. data: that.data.data.type == 12 ? JSON.stringify(tempArr) : data
  503. }).then(res => {
  504. if (discount != 'discount') {
  505. if (typeof (res) != "undefined") {
  506. let orderId = "" + res.data.mainOrderId;
  507. that.setData({
  508. orderId: orderId,
  509. composeOrderType: res.data.composeOrderType
  510. });
  511. if (res.data.payment > 0) {
  512. // 支付金额不为0
  513. if (tt.canIUse('createOrder')) {
  514. Http.post({
  515. url: config.api.payOrderCreate_2,
  516. data: {
  517. orderId: orderId,
  518. composeOrderType: res.data.composeOrderType,
  519. mallTenantId: that.data.mallTenantId
  520. }
  521. }).then(res => {
  522. console.log(res, "789789");
  523. let tempCallbackData = res.data.callbackData
  524. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  525. let options = {
  526. callbackData: tempCallbackData,
  527. goodsList: res.data.goodsList,
  528. payment: res.data.payment,
  529. success: res => {
  530. console.log('save,success!');
  531. tt.hideLoading();
  532. that.setData({
  533. showbutton: false,
  534. })
  535. const {
  536. orderId,
  537. outOrderNo
  538. } = res;
  539. that.setData({
  540. orderId,
  541. outOrderNo
  542. });
  543. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  544. },
  545. fail: res => {
  546. console.log('save,fail!');
  547. const {
  548. orderId,
  549. outOrderNo,
  550. errNo,
  551. errMsg,
  552. errLogId
  553. } = res;
  554. if (errLogId) {
  555. tt.hideLoading();
  556. that.setData({
  557. showbutton: false,
  558. })
  559. console.log('预下单失败', errNo, errMsg, errLogId);
  560. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  561. tt.showToast({
  562. title: tempErrmsg[tempErrmsg.length - 1],
  563. icon: 'none',
  564. duration: 2000,
  565. mask: false
  566. });
  567. }
  568. if (orderId || outOrderNo) {
  569. tt.hideLoading();
  570. that.setData({
  571. showbutton: false,
  572. })
  573. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  574. console.log(that.payOrderUpdate, "payOrderUpdate");
  575. tt.showToast({
  576. title: "取消支付",
  577. icon: 'none',
  578. duration: 2000,
  579. mask: false
  580. });
  581. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  582. }
  583. },
  584. }
  585. console.log(options, "options");
  586. tt.createOrder(options)
  587. })
  588. } else { //不支持2.0支付
  589. /**
  590. * 支付订单创建
  591. */
  592. tt.showToast({
  593. title: '请升级抖音', // 内容
  594. icon: "none"
  595. });
  596. return
  597. Http.post({
  598. url: config.api.payOrderCreate,
  599. data: {
  600. orderId: orderId,
  601. composeOrderType: res.data.composeOrderType
  602. }
  603. }).then(res => {
  604. var payOrderId = "" + res.data.outOrderNo;
  605. tt.hideLoading();
  606. tt.pay({
  607. service: 5,
  608. orderInfo: {
  609. order_id: res.data.payOrderId,
  610. order_token: res.data.payOrderToken,
  611. },
  612. success: res => {
  613. tt.showLoading({
  614. title: '订单正在处理中...',
  615. })
  616. if (res.code === 0) {
  617. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that, that.data.composeOrderType);
  618. if (res.errMsg == "requestPayment:ok") {
  619. /**
  620. * 用户支付成功以后跳转到券包列表
  621. */
  622. if (that.data.cardType == 100) {
  623. tt.setStorage({
  624. key: 'couponNum2',
  625. data: "couponNum2"
  626. })
  627. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  628. tt.setStorage({
  629. key: 'couponNum',
  630. data: "couponNum"
  631. })
  632. }
  633. }
  634. } else if (res.code === 1) {
  635. that.setData({
  636. showbutton: false
  637. })
  638. tt.hideLoading();
  639. tt.showToast({
  640. title: '支付超时', // 内容
  641. icon: "none"
  642. });
  643. } else if (res.code === 2) {
  644. that.setData({
  645. showbutton: false
  646. })
  647. tt.hideLoading();
  648. tt.showToast({
  649. title: '支付失败', // 内容
  650. icon: "none"
  651. });
  652. } else if (res.code === 3) {
  653. that.setData({
  654. showbutton: false
  655. })
  656. tt.hideLoading();
  657. tt.showToast({
  658. title: '支付关闭', // 内容
  659. icon: "none"
  660. });
  661. } else if (res.code === 4) {
  662. that.setData({
  663. showbutton: false
  664. })
  665. tt.hideLoading();
  666. tt.showToast({
  667. title: '支付取消', // 内容
  668. icon: "none"
  669. });
  670. } else if (res.code === 9) {
  671. that.setData({
  672. showbutton: false
  673. })
  674. tt.hideLoading();
  675. tt.showToast({
  676. title: '订单状态开发者自行获取', // 内容
  677. icon: "none"
  678. });
  679. }
  680. },
  681. fail: res => {
  682. tt.hideLoading();
  683. /**
  684. * 支付失败,需要更新订单的状态
  685. */
  686. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that, that.data.composeOrderType);
  687. that.setData({
  688. showbutton: false
  689. })
  690. return;
  691. },
  692. complete: res => {}
  693. });
  694. /// End payment --------
  695. })
  696. .catch(err => {
  697. tt.hideLoading();
  698. tt.showToast({
  699. title: err.message,
  700. icon: 'none',
  701. duration: 2000,
  702. mask: false
  703. });
  704. })
  705. }
  706. } else {
  707. // 免费券
  708. that.payOrderUpdate(orderId, "0", 1, '', 'free', that, that.data.composeOrderType);
  709. if (that.data.cardType == 100) {
  710. tt.setStorage({
  711. key: 'couponNum2',
  712. data: "couponNum2"
  713. })
  714. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  715. tt.setStorage({
  716. key: 'couponNum',
  717. data: "couponNum"
  718. })
  719. }
  720. }
  721. }
  722. } else {
  723. if (res) {
  724. tt.navigateTo({
  725. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.mainOrderId}&composeOrderType=${res.data.composeOrderType}`,
  726. })
  727. }
  728. }
  729. }).catch(err => {
  730. tt.hideLoading();
  731. that.setData({
  732. showbutton: false,
  733. })
  734. if (err.code == 3012) {
  735. that.getUnPaidOrder(that.data.couponId);
  736. } else {
  737. tt.showToast({
  738. title: err.message ? err.message : err.data,
  739. icon: 'none',
  740. duration: 2000,
  741. success(res) {
  742. console.log(res);
  743. },
  744. fail(res) {
  745. console.log("showToast 调用失败", res);
  746. },
  747. });
  748. }
  749. })
  750. // } else {
  751. // //有价券
  752. // console.log(tt.canIUse('createOrder'), "是否支持2.0js-api");
  753. // if (tt.canIUse('createOrder')) {
  754. // //支持 支付2.0 js-api
  755. // let tempCallbackData = {}
  756. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  757. // let options = {
  758. // callbackData: tempCallbackData,
  759. // goodsList: [
  760. // {
  761. // quantity: 1, // 购买数量 必填
  762. // price: that.data.priceAndStockObj.salePrice, // 商品价格 必填
  763. // goodsName: that.data.data.title, // 商品名称 必填
  764. // goodsPhoto: that.data.data.coverImg, // 商品图片链接 必填
  765. // goodsId: that.data.data.couponChannel.ttSpuId, // 商品ID 必填
  766. // goodsType: 1, // 商品类型 必填
  767. // goodsLabels: ['过期退', '随时退', '免预约'], // 商品标签 非必填
  768. // dateRule: '', // 使用规则 非必填
  769. // },
  770. // ],
  771. // payment: {
  772. // totalAmount: that.data.priceAndStockObj.salePrice, // 订单总价 必填
  773. // },
  774. // success: res => {
  775. // tt.hideLoading();
  776. // that.setData({
  777. // showbutton: false,
  778. // })
  779. // const { orderId, outOrderNo } = res;
  780. // that.setData({ orderId, outOrderNo });
  781. // that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  782. // },
  783. // fail: res => {
  784. // const { orderId, outOrderNo, errNo, errMsg, errLogId } = res;
  785. // if (errLogId) {
  786. // tt.hideLoading();
  787. // that.setData({
  788. // showbutton: false,
  789. // })
  790. // console.log('预下单失败', errNo, errMsg, errLogId);
  791. // let tempErrmsg = errMsg.split('开发者拒绝交易:');
  792. // tt.showToast({
  793. // title: tempErrmsg[tempErrmsg.length - 1],
  794. // icon: 'none',
  795. // duration: 2000,
  796. // mask: false
  797. // });
  798. // }
  799. // if (orderId || outOrderNo) {
  800. // tt.hideLoading();
  801. // that.setData({
  802. // showbutton: false,
  803. // })
  804. // console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  805. // console.log(that.payOrderUpdate, "payOrderUpdate");
  806. // tt.showToast({
  807. // title: "取消支付",
  808. // icon: 'none',
  809. // duration: 2000,
  810. // mask: false
  811. // });
  812. // that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  813. // }
  814. // },
  815. // }
  816. // console.log(options, "options");
  817. // tt.createOrder(options)
  818. // } else {
  819. // //不支持 支付2.0 js -api
  820. // }
  821. // }
  822. }).catch(err => {
  823. tt.hideLoading()
  824. that.setData({
  825. showbutton: false,
  826. })
  827. if (err.code == 2011) {
  828. tt.showToast({
  829. title: "商户信息没找到",
  830. image: './../../../assets/images/fail.png',
  831. duration: 2000,
  832. mask: false
  833. });
  834. } else if (err.code == 2013) {
  835. tt.showToast({
  836. title: "商户信息禁用",
  837. image: './../../../assets/images/fail.png',
  838. duration: 2000,
  839. mask: false
  840. });
  841. } else if (err.code == 3000) {
  842. tt.showToast({
  843. title: "库存不足",
  844. image: './../../../assets/images/fail.png',
  845. duration: 2000,
  846. mask: false
  847. });
  848. } else if (err.code == 3001) {
  849. tt.showToast({
  850. title: "您已超过限购",
  851. image: './../../../assets/images/fail.png',
  852. duration: 2000,
  853. mask: false
  854. });
  855. } else if (err.code == 3002) {
  856. tt.showToast({
  857. title: "订单失败",
  858. image: './../../../assets/images/fail.png',
  859. duration: 2000,
  860. mask: false
  861. });
  862. } else if (err.code == 3003) {
  863. tt.showToast({
  864. title: "订单不存在",
  865. image: './../../../assets/images/fail.png',
  866. duration: 2000,
  867. mask: false
  868. });
  869. } else if (err.code == 3004) {
  870. tt.showToast({
  871. title: "订单不存在",
  872. image: './../../../assets/images/fail.png',
  873. duration: 2000,
  874. mask: false
  875. });
  876. } else if (err.code == 4003) {
  877. tt.showToast({
  878. title: "卡券已作废",
  879. image: './../../../assets/images/fail.png',
  880. duration: 2000,
  881. mask: false
  882. });
  883. } else if (err.code == 3012) {
  884. that.getUnPaidOrder(that.data.couponId);
  885. } else if (err.code == 11005) {
  886. /**
  887. * 将值传到用户手机号授权的页面
  888. *
  889. */
  890. if (app.globalData.ifCongPh == 1) {
  891. tt.navigateTo({
  892. url: `/pages/getPhone/getPhone?couponChannelId=${that.data.couponChannelId}&mallTenantId=${that.data.mallTenantId}&path=qr`,
  893. });
  894. } else {
  895. this.setData({
  896. showPhoem: true
  897. })
  898. }
  899. } else if (err.code == 11006) {
  900. // 用户手机已加密
  901. tt.navigateTo({
  902. url: `/pages/getPhone/getPhone?couponChannelId=${that.data.couponChannelId}&mallTenantId=${that.data.mallTenantId}&path=qr`
  903. });
  904. } else {
  905. tt.showToast({
  906. title: err.message,
  907. icon: 'none',
  908. duration: 2000,
  909. mask: false
  910. });
  911. }
  912. })
  913. }).catch(err => {
  914. tt.hideLoading()
  915. that.setData({
  916. showbutton: false,
  917. })
  918. console.log(err)
  919. if (err.code == 11004) {
  920. tt.navigateTo({
  921. url: `/pages/getuserinfo/getuserinfo?fromflag=confirmation&confirmationFlag=${that.data.couponChannelId}&mallTenantId=${that.data.mallTenantId}`,
  922. })
  923. } else {
  924. tt.showToast({
  925. title: err.message,
  926. icon: "none",
  927. duration: 2500
  928. })
  929. }
  930. })
  931. },
  932. onShow() {
  933. this.getIm()
  934. }
  935. })