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

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