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

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