C端小程序
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

814 wiersze
24 KiB

  1. var config = require("../../../config/config.js");
  2. var app = getApp();
  3. const Http = require("../../../utils/HttpBasics");
  4. const util = require("../../../utils/util");
  5. const imgurl = require("../../../utils/imgurl");
  6. Page({
  7. /**
  8. * 页面的初始数据
  9. */
  10. data: {
  11. cancelH: imgurl.cancelH.url,
  12. bannerUrl: imgurl.banner.url,
  13. wmhome: imgurl.wmhome.url,
  14. wmhelp: imgurl.wmhelp.url,
  15. wmsuccess01: imgurl.wmsuccess01.url,
  16. successHr: imgurl.successHr.url,
  17. fail: imgurl.fail.url,
  18. data: null,
  19. from: null,
  20. day: null,
  21. hour: null,
  22. min: null,
  23. sec: null,
  24. showPage: false,
  25. discountStatus: null,
  26. disabled: false,
  27. display: "block!important",
  28. showButton1: false
  29. },
  30. /**
  31. * 生命周期函数--监听页面加载
  32. */
  33. onLoad: function(options) {
  34. let that = this;
  35. if (options.orderId || options.orderId && options.from == 'discount') {
  36. if (options.from) {
  37. that.setData({
  38. orderId: options.orderId,
  39. from: "discount"
  40. })
  41. } else {
  42. that.setData({
  43. orderId: options.orderId
  44. })
  45. }
  46. app.globalData.wmorder = options.orderId
  47. that.pressOrderDetail(options.orderId);
  48. }
  49. this.getUserInfo()
  50. },
  51. getUserInfo: function() {
  52. let that = this;
  53. // 获取用户信息
  54. Http.get({
  55. url: config.api.getScore,
  56. data: {}
  57. })
  58. .then(res => {
  59. console.log(res)
  60. that.setData({
  61. nickName: res.data.nickName,
  62. avatarUrl: res.data.avatarUrl
  63. })
  64. })
  65. },
  66. onShow: function() {
  67. let that = this;
  68. var todayDate = new Date().getTime();
  69. that.setData({
  70. todayDate: todayDate,
  71. showButton1: false
  72. })
  73. if (that.data.pressEndDate) {
  74. that.countdown(that.data.pressEndDate)
  75. }
  76. },
  77. goback: function() {
  78. wx.switchTab({
  79. url: '/pages/main/index',
  80. })
  81. },
  82. /**
  83. * 更多砍价商品
  84. */
  85. gotomore: function() {
  86. wx.navigateTo({
  87. url: '/pages/bargain/bargain',
  88. })
  89. },
  90. /**
  91. * @param {砍价状态(1:我发起的砍价,2:未参与的砍价, 3:已参与的砍价)} orderId
  92. */
  93. getPressOrderStatus: function(orderId) {
  94. let that = this;
  95. Http.get({
  96. url: config.api.getPressOrderStatus,
  97. data: {
  98. orderId: orderId
  99. }
  100. })
  101. .then(res => {
  102. if (res.data.status == 1) {
  103. that.setData({
  104. discountStatus: 1
  105. })
  106. } else if (res.data.status == 2) {
  107. that.setData({
  108. discountStatus: 2
  109. })
  110. } else if (res.data.status == 3) {
  111. that.setData({
  112. discountStatus: 3
  113. })
  114. }
  115. wx.stopPullDownRefresh();
  116. })
  117. .catch(err => {
  118. console.log(err)
  119. wx.stopPullDownRefresh();
  120. wx.showToast({
  121. title: err.errMsg,
  122. icon: "none"
  123. })
  124. })
  125. },
  126. helpDiscount: function() {
  127. let that = this;
  128. that.pressOrderJoin(that.data.orderId);
  129. },
  130. //参与砍价
  131. pressOrderJoin: function(orderId) {
  132. let that = this;
  133. Http.post({
  134. url: config.api.pressOrderJoin,
  135. data: {
  136. orderId: orderId
  137. }
  138. })
  139. .then(res => {
  140. console.log(res);
  141. // id 是订单号
  142. that.pressOrderDetail(orderId);
  143. })
  144. .catch(err => {
  145. console.log(err)
  146. wx.showToast({
  147. title: err.message,
  148. icon: "none"
  149. })
  150. })
  151. },
  152. // 订单详情
  153. pressOrderDetail: function(orderId) {
  154. let that = this;
  155. Http.get({
  156. url: config.api.pressOrderDetail,
  157. data: {
  158. orderId: orderId
  159. }
  160. })
  161. .then(res => {
  162. console.log(res);
  163. res.data.orderPressList.map(file => {
  164. file.createDate = diffTime(file.createDate)
  165. })
  166. that.countdown(res.data.pressEndDate);
  167. that.setData({
  168. pressEndDate: res.data.pressEndDate
  169. })
  170. res.data.orderPressList.map(file => {
  171. compare(file.first);
  172. })
  173. console.log(res.data.orderPressList.sort(compare('first')))
  174. that.setData({
  175. data: res.data,
  176. already: (res.data.price / 100 - res.data.salePrice / 100 - res.data.pressCurrentValue / 100).toFixed(2),
  177. remain: (res.data.pressCurrentValue / 100).toFixed(2),
  178. showPage: true
  179. })
  180. that.getPressOrderStatus(orderId);
  181. })
  182. .catch(err => {
  183. wx.showToast({
  184. title: err.message,
  185. icon: "none"
  186. })
  187. wx.stopPullDownRefresh();
  188. })
  189. },
  190. setIntervalTime(end_time) {
  191. let that = this;
  192. var EndTime = end_time;
  193. var NowTime = new Date().getTime();
  194. var total_micro_second = EndTime - NowTime || [];
  195. // 渲染倒计时时钟
  196. let obj = that.dateformat(total_micro_second);
  197. if (total_micro_second > 0) {
  198. that.setData({
  199. clock: obj,
  200. day: obj.a1,
  201. hour: obj.b1,
  202. min: obj.c1,
  203. sec: obj.d1,
  204. })
  205. } else {
  206. that.setData({
  207. clock: "00",
  208. day: "00",
  209. hour: "00",
  210. min: "00",
  211. sec: "00",
  212. })
  213. //如果倒计时结束,需要重新查询一下券的状态
  214. // 给getDetail一个标识
  215. }
  216. total_micro_second -= 1000;
  217. },
  218. countdown: function(end_time) {
  219. let that = this;
  220. that.setIntervalTime(end_time);
  221. that.data.setInterval = setInterval(function() {
  222. that.setIntervalTime(end_time);
  223. }, 1000)
  224. },
  225. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  226. dateformat(micro_second) {
  227. // 总秒数
  228. var second = Math.floor(micro_second / 1000);
  229. // 天数
  230. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  231. // 小时
  232. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  233. // 分钟
  234. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  235. // 秒
  236. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  237. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  238. return {
  239. a1: day,
  240. b1: hr,
  241. c1: min,
  242. d1: sec
  243. }
  244. },
  245. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  246. let that = this;
  247. console.log(that)
  248. console.log(_this)
  249. // 支付成功
  250. Http.post({
  251. url: config.api.payOrderUpdate,
  252. data: {
  253. payOrderId: payOrderId,
  254. orderId: orderId,
  255. status: status,
  256. reason: reason
  257. }
  258. })
  259. .then(res => {
  260. wx.hideLoading();
  261. _this.setData({
  262. display: "none!important",
  263. })
  264. // 有价券
  265. if (!type && type != 'free') {
  266. wx.navigateTo({
  267. url: `/pages/order/detail/index?orderId=${
  268. orderId
  269. }`
  270. });
  271. } else if (type == 'free') {
  272. wx.navigateTo({
  273. url: `/pages/order/detail/index?orderId=${
  274. orderId
  275. }`
  276. });
  277. }
  278. })
  279. .catch(err => {
  280. console.log(err);
  281. if (!type) {
  282. setTimeout(function() {
  283. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  284. }, 2000)
  285. }
  286. })
  287. },
  288. /**
  289. * 按原价付款
  290. */
  291. // orderFunc1(e) {
  292. // var that = this;
  293. // let formId = e.detail.formId;
  294. // that.setData({
  295. // showButton: true
  296. // })
  297. // Http.get({
  298. // url: config.api.checkPhoneStatus,
  299. // data: {}
  300. // })
  301. // .then(res => {
  302. // that.setData({
  303. // showButton: false
  304. // })
  305. // /**
  306. // * orderSave 下单
  307. // */
  308. // var data = {
  309. // couponChannelId:e.currentTarget.dataset.couponchannelid,
  310. // couponId:e.currentTarget.dataset.couponid,
  311. // formId:formId
  312. // }
  313. // return Http.post({
  314. // url: config.api.orderSave,
  315. // data: data
  316. // });
  317. // })
  318. // .catch(err => {
  319. // that.setData({
  320. // showButton: true
  321. // })
  322. // if (err.code == 2011) {
  323. // wx.showToast({
  324. // title: "商户信息没找到",
  325. // image: './../../../assets/images/fail.png',
  326. // duration: 2000,
  327. // mask: false
  328. // });
  329. // } else if (err.code == 2013) {
  330. // wx.showToast({
  331. // title: "商户信息禁用",
  332. // image: './../../../assets/images/fail.png',
  333. // duration: 2000,
  334. // mask: false
  335. // });
  336. // } else if (err.code == 3000) {
  337. // wx.showToast({
  338. // title: "库存不足",
  339. // image: './../../../assets/images/fail.png',
  340. // duration: 2000,
  341. // mask: false
  342. // });
  343. // } else if (err.code == 3001) {
  344. // wx.showToast({
  345. // title: "您已超过限购",
  346. // image: './../../../assets/images/fail.png',
  347. // duration: 2000,
  348. // mask: false
  349. // });
  350. // } else if (err.code == 3002) {
  351. // wx.showToast({
  352. // title: "订单失败",
  353. // image: './../../../assets/images/fail.png',
  354. // duration: 2000,
  355. // mask: false
  356. // });
  357. // } else if (err.code == 3003) {
  358. // wx.showToast({
  359. // title: "订单不存在",
  360. // image: './../../../assets/images/fail.png',
  361. // duration: 2000,
  362. // mask: false
  363. // });
  364. // } else if (err.code == 3004) {
  365. // wx.showToast({
  366. // title: "订单不存在",
  367. // image: './../../../assets/images/fail.png',
  368. // duration: 2000,
  369. // mask: false
  370. // });
  371. // } else if (err.code == 4003) {
  372. // wx.showToast({
  373. // title: "卡券已作废",
  374. // image: './../../../assets/images/fail.png',
  375. // duration: 2000,
  376. // mask: false
  377. // });
  378. // } else if (err.code == 3012) {
  379. // wx.showModal({
  380. // title: '提示',
  381. // content: "您有未支付订单进行支付",
  382. // showCancel: false,
  383. // success: function (res) {
  384. // console.log(res.confirm)
  385. // if (res.confirm) {
  386. // }
  387. // }
  388. // })
  389. // }else if (err.code == 11005) {
  390. // /**
  391. // * 将值传到用户手机号授权的页面
  392. // *
  393. // */
  394. // wx.redirectTo({
  395. // url: "/pages/getphoneInfo/index?couponChannelId=" +
  396. // that.data.couponChannelId +
  397. // "&couponId=" +
  398. // that.data.couponId
  399. // });
  400. // } else if (err.code == 11006) {
  401. // // 用户手机已加密
  402. // wx.redirectTo({
  403. // url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  404. // that.data.couponChannelId +
  405. // "&couponId=" +
  406. // that.data.couponId
  407. // });
  408. // } else {
  409. // wx.showToast({
  410. // title: err.message,
  411. // icon: 'none',
  412. // duration: 2000,
  413. // mask: false
  414. // });
  415. // }
  416. // }).then(res => {
  417. // console.log(res);
  418. // if (typeof(res) != "undefined") {
  419. // let orderId = "" + res.data.id;
  420. // that.setData({
  421. // orderId: orderId
  422. // });
  423. // if (e.currentTarget.dataset.saleprice / 100 > 0 || e.currentTarget.dataset.price / 100 > 0) {
  424. // /**
  425. // * 支付订单创建
  426. // */
  427. // Http.post({
  428. // url: config.api.payOrderCreate,
  429. // data: {
  430. // orderId: orderId
  431. // }
  432. // })
  433. // .then(res => {
  434. // var payOrderId = "" + res.data.payOrderId;
  435. // wx.hideLoading();
  436. // wx.requestPayment({
  437. // timeStamp: res.data.timeStamp,
  438. // nonceStr: res.data.nonceStr,
  439. // package: res.data.package,
  440. // signType: (res.data.signType) ? res.data.signType : "MD5",
  441. // paySign: res.data.paySign,
  442. // success: res => {
  443. // wx.showLoading({
  444. // title: '订单正在处理中...',
  445. // })
  446. // setTimeout(function() {
  447. // wx.hideLoading()
  448. // }, 5000)
  449. // that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  450. // if (res.errMsg == "requestPayment:ok") {
  451. // setTimeout(function() {
  452. // wx.hideLoading();
  453. // }, 2000);
  454. // /**
  455. // * 用户支付成功以后跳转到券包列表
  456. // */
  457. // if (that.data.cardType == 100) {
  458. // wx.setStorage({
  459. // key: 'couponNum2',
  460. // data: "couponNum2"
  461. // })
  462. // } else {
  463. // wx.setStorage({
  464. // key: 'couponNum',
  465. // data: "couponNum"
  466. // })
  467. // }
  468. // }
  469. // },
  470. // fail: res => {
  471. // /**
  472. // * 支付失败,需要更新订单的状态
  473. // */
  474. // that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  475. // that.setData({
  476. // showbutton: false
  477. // })
  478. // return;
  479. // },
  480. // complete: res => {}
  481. // });
  482. // /// End payment --------
  483. // })
  484. // .catch(err => {
  485. // console.log(err);
  486. // wx.showToast({
  487. // title: err.message,
  488. // icon: 'none',
  489. // duration: 2000,
  490. // mask: false
  491. // });
  492. // })
  493. // } else {
  494. // // 免费券
  495. // that.payOrderUpdate(orderId, "0", 1, '', 'free', that);
  496. // if (that.data.cardType == 100) {
  497. // wx.setStorage({
  498. // key: 'couponNum2',
  499. // data: "couponNum2"
  500. // })
  501. // } else {
  502. // wx.setStorage({
  503. // key: 'couponNum',
  504. // data: "couponNum"
  505. // })
  506. // }
  507. // }
  508. // }
  509. // })
  510. // },
  511. /**
  512. * 发起支付
  513. */
  514. orderFunc(e) {
  515. var that = this;
  516. that.setData({
  517. showButton1: true
  518. })
  519. Http.get({
  520. url: config.api.checkPhoneStatus,
  521. data: {}
  522. })
  523. .then(res => {
  524. that.setData({
  525. showButton1: false
  526. })
  527. if (typeof(res) != "undefined") {
  528. let orderId = "" + e.currentTarget.dataset.orderid;
  529. that.setData({
  530. orderId: orderId
  531. });
  532. if (e.currentTarget.dataset.saleprice / 100 > 0 || e.currentTarget.dataset.price / 100 > 0) {
  533. /**
  534. * 支付订单创建
  535. */
  536. Http.post({
  537. url: config.api.payOrderCreate,
  538. data: {
  539. orderId: orderId
  540. }
  541. })
  542. .then(res => {
  543. var payOrderId = "" + res.data.payOrderId;
  544. wx.hideLoading();
  545. wx.requestPayment({
  546. timeStamp: res.data.timeStamp,
  547. nonceStr: res.data.nonceStr,
  548. package: res.data.package,
  549. signType: (res.data.signType) ? res.data.signType : "MD5",
  550. paySign: res.data.paySign,
  551. success: res => {
  552. wx.showLoading({
  553. title: '订单正在处理中...',
  554. })
  555. setTimeout(function() {
  556. wx.hideLoading()
  557. }, 5000)
  558. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  559. if (res.errMsg == "requestPayment:ok") {
  560. setTimeout(function() {
  561. wx.hideLoading();
  562. }, 2000);
  563. /**
  564. * 用户支付成功以后跳转到券包列表
  565. */
  566. if (that.data.cardType == 100) {
  567. wx.setStorage({
  568. key: 'couponNum2',
  569. data: "couponNum2"
  570. })
  571. } else {
  572. wx.setStorage({
  573. key: 'couponNum',
  574. data: "couponNum"
  575. })
  576. }
  577. }
  578. },
  579. fail: res => {
  580. /**
  581. * 支付失败,需要更新订单的状态
  582. */
  583. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  584. that.setData({
  585. showbutton1: false
  586. })
  587. return;
  588. },
  589. complete: res => {}
  590. });
  591. /// End payment --------
  592. })
  593. .catch(err => {
  594. console.log(err);
  595. wx.showToast({
  596. title: err.message,
  597. icon: 'none',
  598. duration: 2000,
  599. mask: false
  600. });
  601. })
  602. } else {
  603. // 免费券
  604. that.payOrderUpdate(orderId, "0", 1, '', 'free', that);
  605. if (that.data.cardType == 100) {
  606. wx.setStorage({
  607. key: 'couponNum2',
  608. data: "couponNum2"
  609. })
  610. } else {
  611. wx.setStorage({
  612. key: 'couponNum',
  613. data: "couponNum"
  614. })
  615. }
  616. }
  617. }
  618. })
  619. .catch(err => {
  620. that.setData({
  621. showButton1: true
  622. })
  623. if (err.code == 2011) {
  624. wx.showToast({
  625. title: "商户信息没找到",
  626. image: './../../../assets/images/fail.png',
  627. duration: 2000,
  628. mask: false
  629. });
  630. } else if (err.code == 2013) {
  631. wx.showToast({
  632. title: "商户信息禁用",
  633. image: './../../../assets/images/fail.png',
  634. duration: 2000,
  635. mask: false
  636. });
  637. } else if (err.code == 3000) {
  638. wx.showToast({
  639. title: "库存不足",
  640. image: './../../../assets/images/fail.png',
  641. duration: 2000,
  642. mask: false
  643. });
  644. } else if (err.code == 3001) {
  645. wx.showToast({
  646. title: "您已超过限购",
  647. image: './../../../assets/images/fail.png',
  648. duration: 2000,
  649. mask: false
  650. });
  651. } else if (err.code == 3002) {
  652. wx.showToast({
  653. title: "订单失败",
  654. image: './../../../assets/images/fail.png',
  655. duration: 2000,
  656. mask: false
  657. });
  658. } else if (err.code == 3003) {
  659. wx.showToast({
  660. title: "订单不存在",
  661. image: './../../../assets/images/fail.png',
  662. duration: 2000,
  663. mask: false
  664. });
  665. } else if (err.code == 3004) {
  666. wx.showToast({
  667. title: "订单不存在",
  668. image: './../../../assets/images/fail.png',
  669. duration: 2000,
  670. mask: false
  671. });
  672. } else if (err.code == 4003) {
  673. wx.showToast({
  674. title: "卡券已作废",
  675. image: './../../../assets/images/fail.png',
  676. duration: 2000,
  677. mask: false
  678. });
  679. } else if (err.code == 3012) {
  680. wx.showModal({
  681. title: '提示',
  682. content: '您有未支付订单,请先进行支付',
  683. confirmText: "去支付",
  684. success: function (res) {
  685. console.log(res.confirm)
  686. if (res.confirm) {
  687. wx.navigateTo({
  688. url: '/pages/order/index/index?id=all',
  689. })
  690. }
  691. }
  692. })
  693. }else if (err.code == 11005) {
  694. /**
  695. * 将值传到用户手机号授权的页面
  696. *
  697. */
  698. wx.redirectTo({
  699. url: "/pages/getphoneInfo/index?couponChannelId=" +
  700. that.data.couponChannelId +
  701. "&couponId=" +
  702. that.data.couponId
  703. });
  704. } else if (err.code == 11006) {
  705. // 用户手机已加密
  706. wx.redirectTo({
  707. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  708. that.data.couponChannelId +
  709. "&couponId=" +
  710. that.data.couponId
  711. });
  712. } else {
  713. wx.showToast({
  714. title: err.message,
  715. icon: 'none',
  716. duration: 2000,
  717. mask: false
  718. });
  719. }
  720. })
  721. },
  722. onUnload: function() {
  723. let that = this;
  724. clearInterval(that.data.setInterval)
  725. },
  726. onHide: function() {
  727. let that = this;
  728. clearInterval(that.data.setInterval)
  729. },
  730. /**
  731. *
  732. * @param {朋友邀请砍价} e
  733. */
  734. barginAgain: function(e) {
  735. let that = this;
  736. let couponChannelId = e.currentTarget.dataset.couponchannelid;
  737. let couponId = e.currentTarget.dataset.couponid;
  738. wx.navigateTo({
  739. url: `/pages/coupon/detail/index?couponChannelId=${couponChannelId}&couponId=${couponId}`,
  740. })
  741. },
  742. /**
  743. * 刷新
  744. */
  745. onPullDownRefresh: function(e) {
  746. let that = this;
  747. console.log(app.globalData.wmorder);
  748. if (app.globalData.wmorder) {
  749. that.pressOrderDetail(app.globalData.wmorder);
  750. }
  751. },
  752. onShareAppMessage: function(options) {
  753. var that = this;
  754. var shareObj = {
  755. title: that.data.nickName + '邀请您帮砍' + that.data.data.title,
  756. path: `/pages/index/index?orderId=${that.data.data.id}&from=${"discount"}`,
  757. success: function(res) {
  758. if (res.errMsg == 'shareAppMessage:ok') {}
  759. },
  760. fail: function(error) {
  761. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  762. }
  763. };
  764. // 来自页面内的按钮的转发
  765. if (options.from == 'button') {
  766. var orderId = options.target.dataset.orderid;
  767. shareObj.path = `/pages/index/index?orderId=${orderId}&from=${"discount"}`;
  768. }
  769. // 返回shareObj
  770. return shareObj;
  771. },
  772. })
  773. function diffTime(startDate) {
  774. var diff = new Date().getTime() - startDate;
  775. var days = Math.floor(diff / (24 * 3600 * 1000));
  776. var leave1 = diff % (24 * 3600 * 1000);
  777. var hours = Math.floor(leave1 / (3600 * 1000));
  778. var leave2 = leave1 % (3600 * 1000);
  779. var minutes = Math.floor(leave2 / (60 * 1000));
  780. var leave3 = leave2 % (60 * 1000);
  781. var seconds = Math.round(leave3 / 1000);
  782. var returnStr = seconds + "秒";
  783. if (minutes > 0) {
  784. returnStr = minutes + "分" + returnStr;
  785. }
  786. if (hours > 0) {
  787. returnStr = hours + "小时" + returnStr;
  788. }
  789. if (days > 0) {
  790. returnStr = days + "天" + returnStr;
  791. }
  792. if (returnStr.indexOf('-1') == -1) {
  793. return returnStr;
  794. } else {
  795. return '1秒'
  796. }
  797. }
  798. function compare(property) {
  799. return function(a, b) {
  800. var value1 = a[property];
  801. var value2 = b[property];
  802. return value2 - value1;
  803. }
  804. }