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

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