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

979 line
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' && item.isRequired) {
  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. console.log(err, 'err');
  302. tt.showToast({
  303. title: err.message,
  304. icon: 'none',
  305. duration: 2000,
  306. mask: false
  307. });
  308. })
  309. },
  310. /**
  311. * 支付订单更新
  312. */
  313. payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType) {
  314. let that = this;
  315. console.log(orderId, 'orderId');
  316. // 支付成功
  317. Http.post({
  318. url: config.api.payOrderUpdate,
  319. data: {
  320. payOrderId: payOrderId,
  321. composeOrderId: orderId,
  322. status: status,
  323. reason: reason,
  324. mallTenantId: that.data.mallTenantId
  325. }
  326. })
  327. .then(res => {
  328. tt.hideLoading()
  329. // 有价券
  330. tt.setStorageSync('appointment', true);
  331. if (!type && type != 'free') {
  332. console.log('Over Here! type');
  333. setTimeout(() => {
  334. console.log(_this.data.orderFlag, orderId, that.data.mallTenantId, 'notice!!!');
  335. let url = ""
  336. if (_this.data.orderFlag) {
  337. tt.redirectTo({
  338. url: `/pages/order/detail/index?orderId=${orderId}&dingdan=order&mallTenantId=${that.data.mallTenantId}`
  339. });
  340. } else {
  341. tt.redirectTo({
  342. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  343. });
  344. }
  345. }, 1600);
  346. } else if (type == 'free') {
  347. console.log('Over Here! type2');
  348. tt.navigateTo({
  349. url: `/pages/order/detail/index?orderId=${orderId}&mallTenantId=${that.data.mallTenantId}`
  350. });
  351. }
  352. })
  353. .catch(err => {
  354. console.log(err);
  355. console.log('Over Here! type3');
  356. if (!type) {
  357. setTimeout(function () {
  358. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  359. }, 2000)
  360. }
  361. })
  362. },
  363. // 获得未支付的订单
  364. getUnPaidOrder(couponId) {
  365. let that = this;
  366. Http.get({
  367. url: config.api.getUnPaidOrder,
  368. data: {
  369. couponId: couponId,
  370. mallTenantId: this.data.mallTenantId || ''
  371. }
  372. }).then(res => {
  373. that.setData({
  374. disOrderNumber: res.data.orderNumber,
  375. composeOrderType: res.data.composeOrderType
  376. })
  377. if (res.data && res.data.pressEndDate) {
  378. that.setData({
  379. dispressEndDate: true
  380. })
  381. } else {
  382. that.setData({
  383. dispressEndDate: false
  384. })
  385. }
  386. if (that.data.dispressEndDate) {
  387. tt.showModal({
  388. title: '提示',
  389. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  390. confirmText: "我的砍价",
  391. success: function (res) {
  392. if (res.confirm) {
  393. tt.navigateTo({
  394. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}&composeOrderType=${that.data.composeOrderType}`,
  395. })
  396. }
  397. }
  398. })
  399. } else {
  400. tt.showModal({
  401. title: '提示',
  402. content: '您有未支付订单,请先进行支付',
  403. confirmText: "去支付",
  404. success: function (res1) {
  405. if (res1.confirm) {
  406. if (that.data.composeOrderType > 0) { //券包
  407. tt.navigateTo({
  408. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&mallTenantId=${that.data.mallTenantId}`,
  409. })
  410. } else {
  411. tt.navigateTo({
  412. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}&mallTenantId=${that.data.mallTenantId}`,
  413. })
  414. }
  415. }
  416. }
  417. })
  418. }
  419. }).catch(error => {
  420. tt.showToast({
  421. title: error.message,
  422. icon: "none",
  423. duration: 3000
  424. })
  425. })
  426. },
  427. /**
  428. * 发起支付
  429. */
  430. orderFunc(discount) {
  431. if (this.data.showbutton) return;
  432. let that = this;
  433. tt.showLoading({
  434. title: "加载中..."
  435. });
  436. that.setData({
  437. showbutton: true,
  438. })
  439. Http.get({
  440. url: config.api.checkUserStatus,
  441. data: {
  442. token: app.globalData.token,
  443. }
  444. }).then(res => {
  445. Http.get({
  446. url: config.api.checkPhoneStatus,
  447. data: {}
  448. }).then(res => {
  449. //
  450. // if (!tt.canIUse('createOrder') || that.data.data.type == 50 || that.data.priceAndStockObj.salePrice == 0) {
  451. //积分券和免费券
  452. // 发起砍价
  453. if (discount == 'discount') {
  454. var data = {
  455. couponChannelId: "" + that.data.couponChannelId,
  456. couponId: "" + that.data.couponId,
  457. formId: "" + that.data.formId,
  458. press: true
  459. }
  460. } else if (discount == 'discount1') {
  461. var data = {
  462. couponChannelId: "" + that.data.couponChannelId,
  463. couponId: "" + that.data.couponId,
  464. formId: "" + that.data.formId,
  465. press: false
  466. }
  467. } else if (that.data.couponChannelId == null) {
  468. var data = {
  469. couponId: "" + that.data.couponId,
  470. formId: "" + that.data.formId,
  471. };
  472. } else {
  473. var data = {
  474. couponChannelId: "" + that.data.couponChannelId,
  475. couponId: "" + that.data.couponId,
  476. formId: "" + that.data.formId,
  477. }
  478. }
  479. console.log(data, "data")
  480. let url = ""
  481. let tempObj;
  482. let tempArr = []
  483. if (that.data.data.type == 12) {
  484. url = config.api.couponPackageSave
  485. tempObj = {
  486. signleOrder: {
  487. couponChannelId: "" + that.data.couponChannelId,
  488. couponId: "" + that.data.couponId,
  489. formId: "" + that.data.formId,
  490. },
  491. count: "1"
  492. }
  493. tempArr.push(tempObj)
  494. } else {
  495. url = config.api.orderSave
  496. data.mallTenantId = that.data.mallTenantId || ''
  497. }
  498. /**
  499. * orderSave 下单
  500. */
  501. Http.post({
  502. url: url,
  503. data: that.data.data.type == 12 ? JSON.stringify(tempArr) : data
  504. }).then(res => {
  505. if (discount != 'discount') {
  506. if (typeof (res) != "undefined") {
  507. let orderId = "" + res.data.mainOrderId;
  508. that.setData({
  509. orderId: orderId,
  510. composeOrderType: res.data.composeOrderType
  511. });
  512. if (res.data.payment > 0) {
  513. // 支付金额不为0
  514. if (tt.canIUse('createOrder')) {
  515. Http.post({
  516. url: config.api.payOrderCreate_2,
  517. data: {
  518. orderId: orderId,
  519. composeOrderType: res.data.composeOrderType,
  520. mallTenantId: that.data.mallTenantId
  521. }
  522. }).then(res => {
  523. console.log(res, "789789");
  524. let tempCallbackData = res.data.callbackData
  525. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  526. let options = {
  527. callbackData: tempCallbackData,
  528. goodsList: res.data.goodsList,
  529. payment: res.data.payment,
  530. success: res => {
  531. console.log('save,success!');
  532. tt.hideLoading();
  533. that.setData({
  534. showbutton: false,
  535. })
  536. const {
  537. orderId,
  538. outOrderNo
  539. } = res;
  540. that.setData({
  541. orderId,
  542. outOrderNo
  543. });
  544. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  545. },
  546. fail: res => {
  547. console.log('save,fail!');
  548. const {
  549. orderId,
  550. outOrderNo,
  551. errNo,
  552. errMsg,
  553. errLogId
  554. } = res;
  555. if (errLogId) {
  556. tt.hideLoading();
  557. that.setData({
  558. showbutton: false,
  559. })
  560. console.log('预下单失败', errNo, errMsg, errLogId);
  561. let tempErrmsg = errMsg.split('开发者拒绝交易:');
  562. tt.showToast({
  563. title: tempErrmsg[tempErrmsg.length - 1],
  564. icon: 'none',
  565. duration: 2000,
  566. mask: false
  567. });
  568. }
  569. if (orderId || outOrderNo) {
  570. tt.hideLoading();
  571. that.setData({
  572. showbutton: false,
  573. })
  574. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  575. console.log(that.payOrderUpdate, "payOrderUpdate");
  576. tt.showToast({
  577. title: "取消支付",
  578. icon: 'none',
  579. duration: 2000,
  580. mask: false
  581. });
  582. that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  583. }
  584. },
  585. }
  586. console.log(options, "options");
  587. tt.createOrder(options)
  588. })
  589. } else { //不支持2.0支付
  590. /**
  591. * 支付订单创建
  592. */
  593. tt.showToast({
  594. title: '请升级抖音', // 内容
  595. icon: "none"
  596. });
  597. return
  598. Http.post({
  599. url: config.api.payOrderCreate,
  600. data: {
  601. orderId: orderId,
  602. composeOrderType: res.data.composeOrderType
  603. }
  604. }).then(res => {
  605. var payOrderId = "" + res.data.outOrderNo;
  606. tt.hideLoading();
  607. tt.pay({
  608. service: 5,
  609. orderInfo: {
  610. order_id: res.data.payOrderId,
  611. order_token: res.data.payOrderToken,
  612. },
  613. success: res => {
  614. tt.showLoading({
  615. title: '订单正在处理中...',
  616. })
  617. if (res.code === 0) {
  618. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that, that.data.composeOrderType);
  619. if (res.errMsg == "requestPayment:ok") {
  620. /**
  621. * 用户支付成功以后跳转到券包列表
  622. */
  623. if (that.data.cardType == 100) {
  624. tt.setStorage({
  625. key: 'couponNum2',
  626. data: "couponNum2"
  627. })
  628. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  629. tt.setStorage({
  630. key: 'couponNum',
  631. data: "couponNum"
  632. })
  633. }
  634. }
  635. } else if (res.code === 1) {
  636. that.setData({
  637. showbutton: false
  638. })
  639. tt.hideLoading();
  640. tt.showToast({
  641. title: '支付超时', // 内容
  642. icon: "none"
  643. });
  644. } else if (res.code === 2) {
  645. that.setData({
  646. showbutton: false
  647. })
  648. tt.hideLoading();
  649. tt.showToast({
  650. title: '支付失败', // 内容
  651. icon: "none"
  652. });
  653. } else if (res.code === 3) {
  654. that.setData({
  655. showbutton: false
  656. })
  657. tt.hideLoading();
  658. tt.showToast({
  659. title: '支付关闭', // 内容
  660. icon: "none"
  661. });
  662. } else if (res.code === 4) {
  663. that.setData({
  664. showbutton: false
  665. })
  666. tt.hideLoading();
  667. tt.showToast({
  668. title: '支付取消', // 内容
  669. icon: "none"
  670. });
  671. } else if (res.code === 9) {
  672. that.setData({
  673. showbutton: false
  674. })
  675. tt.hideLoading();
  676. tt.showToast({
  677. title: '订单状态开发者自行获取', // 内容
  678. icon: "none"
  679. });
  680. }
  681. },
  682. fail: res => {
  683. tt.hideLoading();
  684. /**
  685. * 支付失败,需要更新订单的状态
  686. */
  687. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that, that.data.composeOrderType);
  688. that.setData({
  689. showbutton: false
  690. })
  691. return;
  692. },
  693. complete: res => {}
  694. });
  695. /// End payment --------
  696. })
  697. .catch(err => {
  698. tt.hideLoading();
  699. tt.showToast({
  700. title: err.message,
  701. icon: 'none',
  702. duration: 2000,
  703. mask: false
  704. });
  705. })
  706. }
  707. } else {
  708. // 免费券
  709. that.payOrderUpdate(orderId, "0", 1, '', 'free', that, that.data.composeOrderType);
  710. if (that.data.cardType == 100) {
  711. tt.setStorage({
  712. key: 'couponNum2',
  713. data: "couponNum2"
  714. })
  715. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  716. tt.setStorage({
  717. key: 'couponNum',
  718. data: "couponNum"
  719. })
  720. }
  721. }
  722. }
  723. } else {
  724. if (res) {
  725. tt.navigateTo({
  726. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.mainOrderId}&composeOrderType=${res.data.composeOrderType}`,
  727. })
  728. }
  729. }
  730. }).catch(err => {
  731. tt.hideLoading();
  732. that.setData({
  733. showbutton: false,
  734. })
  735. if (err.code == 3012) {
  736. that.getUnPaidOrder(that.data.couponId);
  737. } else {
  738. tt.showToast({
  739. title: err.message ? err.message : err.data,
  740. icon: 'none',
  741. duration: 2000,
  742. success(res) {
  743. console.log(res);
  744. },
  745. fail(res) {
  746. console.log("showToast 调用失败", res);
  747. },
  748. });
  749. }
  750. })
  751. // } else {
  752. // //有价券
  753. // console.log(tt.canIUse('createOrder'), "是否支持2.0js-api");
  754. // if (tt.canIUse('createOrder')) {
  755. // //支持 支付2.0 js-api
  756. // let tempCallbackData = {}
  757. // tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  758. // let options = {
  759. // callbackData: tempCallbackData,
  760. // goodsList: [
  761. // {
  762. // quantity: 1, // 购买数量 必填
  763. // price: that.data.priceAndStockObj.salePrice, // 商品价格 必填
  764. // goodsName: that.data.data.title, // 商品名称 必填
  765. // goodsPhoto: that.data.data.coverImg, // 商品图片链接 必填
  766. // goodsId: that.data.data.couponChannel.ttSpuId, // 商品ID 必填
  767. // goodsType: 1, // 商品类型 必填
  768. // goodsLabels: ['过期退', '随时退', '免预约'], // 商品标签 非必填
  769. // dateRule: '', // 使用规则 非必填
  770. // },
  771. // ],
  772. // payment: {
  773. // totalAmount: that.data.priceAndStockObj.salePrice, // 订单总价 必填
  774. // },
  775. // success: res => {
  776. // tt.hideLoading();
  777. // that.setData({
  778. // showbutton: false,
  779. // })
  780. // const { orderId, outOrderNo } = res;
  781. // that.setData({ orderId, outOrderNo });
  782. // that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  783. // },
  784. // fail: res => {
  785. // const { orderId, outOrderNo, errNo, errMsg, errLogId } = res;
  786. // if (errLogId) {
  787. // tt.hideLoading();
  788. // that.setData({
  789. // showbutton: false,
  790. // })
  791. // console.log('预下单失败', errNo, errMsg, errLogId);
  792. // let tempErrmsg = errMsg.split('开发者拒绝交易:');
  793. // tt.showToast({
  794. // title: tempErrmsg[tempErrmsg.length - 1],
  795. // icon: 'none',
  796. // duration: 2000,
  797. // mask: false
  798. // });
  799. // }
  800. // if (orderId || outOrderNo) {
  801. // tt.hideLoading();
  802. // that.setData({
  803. // showbutton: false,
  804. // })
  805. // console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  806. // console.log(that.payOrderUpdate, "payOrderUpdate");
  807. // tt.showToast({
  808. // title: "取消支付",
  809. // icon: 'none',
  810. // duration: 2000,
  811. // mask: false
  812. // });
  813. // that.payOrderUpdate(outOrderNo, outOrderNo, 2, '', 'fail')
  814. // }
  815. // },
  816. // }
  817. // console.log(options, "options");
  818. // tt.createOrder(options)
  819. // } else {
  820. // //不支持 支付2.0 js -api
  821. // }
  822. // }
  823. }).catch(err => {
  824. tt.hideLoading()
  825. that.setData({
  826. showbutton: false,
  827. })
  828. if (err.code == 2011) {
  829. tt.showToast({
  830. title: "商户信息没找到",
  831. image: './../../../assets/images/fail.png',
  832. duration: 2000,
  833. mask: false
  834. });
  835. } else if (err.code == 2013) {
  836. tt.showToast({
  837. title: "商户信息禁用",
  838. image: './../../../assets/images/fail.png',
  839. duration: 2000,
  840. mask: false
  841. });
  842. } else if (err.code == 3000) {
  843. tt.showToast({
  844. title: "库存不足",
  845. image: './../../../assets/images/fail.png',
  846. duration: 2000,
  847. mask: false
  848. });
  849. } else if (err.code == 3001) {
  850. tt.showToast({
  851. title: "您已超过限购",
  852. image: './../../../assets/images/fail.png',
  853. duration: 2000,
  854. mask: false
  855. });
  856. } else if (err.code == 3002) {
  857. tt.showToast({
  858. title: "订单失败",
  859. image: './../../../assets/images/fail.png',
  860. duration: 2000,
  861. mask: false
  862. });
  863. } else if (err.code == 3003) {
  864. tt.showToast({
  865. title: "订单不存在",
  866. image: './../../../assets/images/fail.png',
  867. duration: 2000,
  868. mask: false
  869. });
  870. } else if (err.code == 3004) {
  871. tt.showToast({
  872. title: "订单不存在",
  873. image: './../../../assets/images/fail.png',
  874. duration: 2000,
  875. mask: false
  876. });
  877. } else if (err.code == 4003) {
  878. tt.showToast({
  879. title: "卡券已作废",
  880. image: './../../../assets/images/fail.png',
  881. duration: 2000,
  882. mask: false
  883. });
  884. } else if (err.code == 3012) {
  885. that.getUnPaidOrder(that.data.couponId);
  886. } else if (err.code == 11005) {
  887. /**
  888. * 将值传到用户手机号授权的页面
  889. *
  890. */
  891. if (app.globalData.ifCongPh == 1) {
  892. tt.navigateTo({
  893. url: `/pages/getPhone/getPhone?couponChannelId=${that.data.couponChannelId}&mallTenantId=${that.data.mallTenantId}&path=qr`,
  894. });
  895. } else {
  896. this.setData({
  897. showPhoem: true
  898. })
  899. }
  900. } else if (err.code == 11006) {
  901. // 用户手机已加密
  902. tt.navigateTo({
  903. url: `/pages/getPhone/getPhone?couponChannelId=${that.data.couponChannelId}&mallTenantId=${that.data.mallTenantId}&path=qr`
  904. });
  905. } else {
  906. tt.showToast({
  907. title: err.message,
  908. icon: 'none',
  909. duration: 2000,
  910. mask: false
  911. });
  912. }
  913. })
  914. }).catch(err => {
  915. tt.hideLoading()
  916. that.setData({
  917. showbutton: false,
  918. })
  919. console.log(err)
  920. if (err.code == 11004) {
  921. tt.navigateTo({
  922. url: `/pages/getuserinfo/getuserinfo?fromflag=confirmation&confirmationFlag=${that.data.couponChannelId}&mallTenantId=${that.data.mallTenantId}`,
  923. })
  924. } else {
  925. tt.showToast({
  926. title: err.message,
  927. icon: "none",
  928. duration: 2500
  929. })
  930. }
  931. })
  932. },
  933. onShow() {
  934. this.getIm()
  935. }
  936. })