C端小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

766 Zeilen
20 KiB

  1. // pages/spellGroup/mySpellGroup/index.js
  2. const navigationBarHeight = (getApp().statusBarHeight + 50) + 'px'
  3. var config = require("../../../config/config.js");
  4. const Http = require("../../../utils/HttpBasics");
  5. const imgurl = require("../../../utils/imgurl");
  6. const utils = require("../../../utils/util.js")
  7. Page({
  8. /**
  9. * 页面的初始数据
  10. */
  11. data: {
  12. navigationBarHeight,
  13. fenxiang: imgurl.fenxiang1.url,
  14. homeSelectedO:imgurl.homeSelectedO.url,
  15. isshowposter:false,//是否显示分享弹框
  16. teljpgUrl: imgurl.teljpg.url,
  17. wmhome: imgurl.wmhome.url,
  18. share01: imgurl.share01.url,
  19. close02: imgurl.close02.url,
  20. closedUrl: imgurl.closed.url,
  21. quesGouUrl: imgurl.ques_gou.url,
  22. headbgUrl: imgurl.headbg.url,
  23. quesBgUrl: imgurl.ques_bg.url,
  24. couponChannelId: '',
  25. couponId: '',
  26. data: null,
  27. spellData: null,
  28. canSpell: true,
  29. canBuyIf: true,
  30. clock: "00",
  31. day: "00",
  32. hour: "00",
  33. min: "00",
  34. sec: "00",
  35. detailPicture: [],
  36. coverPicture: [],
  37. swiperCurrent: 0,
  38. showTime: true,
  39. limitCondition: "",
  40. minLimit: 0,
  41. maxLimit: 0,
  42. spellGroupOrder:false,
  43. opacity: 0,
  44. queueData: null,
  45. zIndex: 11,
  46. display: "none",
  47. orderGroupId:''
  48. },
  49. /**
  50. * 生命周期函数--监听页面加载
  51. */
  52. onLoad: function(options) {
  53. this.setData({
  54. couponChannelId: options.couponChannelId,
  55. couponId: options.couponId ? options.couponId:''
  56. })
  57. if (options && options.couponChannelId) {
  58. this.getDetail(options.couponChannelId);
  59. }
  60. if (options && options.couponId) {
  61. this.getOneSpell(options.couponId)
  62. }
  63. console.log(this.data.couponId)
  64. this.getUserInfo();
  65. },
  66. /**
  67. * 显示分享海报
  68. */
  69. showPoster: function() {
  70. //跳转到海报生成页
  71. wx.navigateTo({
  72. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  73. })
  74. },
  75. /**
  76. * 显示分享弹框
  77. */
  78. showshare: function() {
  79. this.setData({
  80. isshowposter: true,
  81. })
  82. },
  83. /**
  84. * 隐藏分享弹框
  85. */
  86. hidemodal: function() {
  87. this.setData({
  88. isshowposter: false,
  89. })
  90. },
  91. getUserInfo: function() {
  92. let that = this;
  93. // 获取用户信息
  94. Http.get({
  95. url: config.api.getScore,
  96. data: {}
  97. })
  98. .then(res => {
  99. console.log(res)
  100. that.setData({
  101. nickName: res.data.nickName,
  102. avatarUrl: res.data.avatarUrl
  103. })
  104. })
  105. },
  106. gotoIndex: function() {
  107. wx.switchTab({
  108. url: '/index/index',
  109. })
  110. },
  111. /**
  112. * 拨打电话
  113. */
  114. phone: function(e) {
  115. let that = this;
  116. wx.makePhoneCall({
  117. phoneNumber: e.target.dataset.merchantlinkphone
  118. });
  119. },
  120. /**
  121. * 直接购买
  122. */
  123. gotoBuy(e) {
  124. let that = this;
  125. this.setData({
  126. canBuyIf: false,
  127. formId: e.detail.formId,
  128. queueData: null,
  129. orderGroupId:''
  130. })
  131. that.getQuestions();
  132. },
  133. getQuestions(type){
  134. let that = this;
  135. Http.get({
  136. url: config.api.getQuestion,
  137. data: {
  138. couponType: JSON.stringify(that.data.data.type)
  139. }
  140. })
  141. .then(res => {
  142. wx.hideLoading();
  143. if (res.data == undefined) {
  144. // 立即购买
  145. that.orderFunc(type);
  146. } else if (res.data) {
  147. var animation = wx.createAnimation({});
  148. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  149. duration: 500
  150. })
  151. that.setData({
  152. queueData: animation.export(),
  153. zIndex: 9,
  154. opacity: 1,
  155. display: "block",
  156. questionnaire: JSON.parse(res.data.content),
  157. questionId: res.data.id
  158. });
  159. }
  160. })
  161. .catch(err => {
  162. wx.hideLoading();
  163. wx.showToast({
  164. title: err.message,
  165. icon: 'none',
  166. duration: 2000,
  167. mask: false
  168. });
  169. })
  170. },
  171. /**
  172. * 点击提交问题单选
  173. */
  174. formSubmit: function (e) {
  175. console.log(e);
  176. let that = this;
  177. /**
  178. * 多选
  179. */
  180. if (e.currentTarget.dataset.flags == 'multi') {
  181. if (that.data.anwserId.length == 0) {
  182. var answserIs = null
  183. } else {
  184. var answserIs = that.data.anwserId.join(",");
  185. }
  186. } else if (e.currentTarget.dataset.flags == 'single') {
  187. var answserIs = e.detail.value;
  188. }
  189. console.log(answserIs)
  190. console.log(e.currentTarget.dataset.questionid)
  191. Http.post({
  192. url: config.api.answerQuestion,
  193. data: {
  194. answer: answserIs,
  195. questionId: e.currentTarget.dataset.questionid
  196. }
  197. })
  198. .then(res => {
  199. that.closeQuestion();
  200. })
  201. .catch(err => {
  202. wx.showToast({
  203. title: err.message,
  204. icon: 'none',
  205. duration: 2000,
  206. mask: false
  207. });
  208. })
  209. },
  210. /**
  211. * 多选
  212. */
  213. checkboxChange: function (e) {
  214. console.log(e)
  215. this.setData({
  216. anwserId: e.detail.value
  217. })
  218. },
  219. closeQuestion: function () {
  220. let that = this;
  221. that.setData({
  222. display: "none",
  223. zIndex: 11,
  224. opacity: 0
  225. })
  226. setTimeout(function () {
  227. that.orderFunc();
  228. }, 500)
  229. },
  230. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  231. dateformat(micro_second) {
  232. // 总秒数
  233. var second = Math.floor(micro_second / 1000);
  234. // 天数
  235. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  236. // 小时
  237. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  238. // 分钟
  239. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  240. // 秒
  241. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  242. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  243. return {
  244. a1: day,
  245. b1: hr,
  246. c1: min,
  247. d1: sec
  248. }
  249. },
  250. countdown(time) {
  251. let that = this;
  252. var EndTime = time;
  253. if (that.data.spellData != null) {
  254. EndTime = that.data.spellData.expiredDate;
  255. }
  256. var NowTime = new Date().getTime();
  257. var total_micro_second = EndTime - NowTime || [];
  258. // 渲染倒计时时钟
  259. let obj = that.dateformat(total_micro_second);
  260. if (total_micro_second > 0) {
  261. that.setData({
  262. clock: obj,
  263. day: obj.a1,
  264. hour: obj.b1,
  265. min: obj.c1,
  266. sec: obj.d1,
  267. })
  268. } else {
  269. that.setData({
  270. clock: "00",
  271. day: "00",
  272. hour: "00",
  273. min: "00",
  274. sec: "00",
  275. })
  276. }
  277. if (that.data.showTime) {
  278. setTimeout(function() {
  279. total_micro_second -= 1000;
  280. that.countdown();
  281. }, 1000)
  282. }
  283. },
  284. // 获得未支付的订单
  285. getUnPaidOrder(couponId) {
  286. let that = this;
  287. Http.get({
  288. url: config.api.getUnPaidOrder,
  289. data: {
  290. couponId: couponId
  291. }
  292. }).then(res => {
  293. that.setData({
  294. disOrderNumber: res.data.orderNumber,
  295. couponChannelId: res.data.couponChannelId,
  296. orderGroupId: res.data.orderGroupId
  297. })
  298. // 拼团订单
  299. if (res.data.payment/100 != Number(that.data.data.price)) {
  300. that.setData({
  301. spellGroupOrder: true
  302. })
  303. } else {
  304. // 原价购买订单
  305. that.setData({
  306. spellGroupOrder: false
  307. })
  308. }
  309. if (that.data.spellGroupOrder) {
  310. wx.showModal({
  311. title: '提示',
  312. content: "您有未支付拼团订单,请先进行支付",
  313. confirmText: "去支付",
  314. success: function (res) {
  315. if (res.confirm) {
  316. wx.navigateTo({
  317. url: `/pages/spellGroup/paySpellGroup/index?orderId=${that.data.disOrderNumber}&couponChannelId=${that.data.couponChannelId}&couponId=${couponId}&orderGroupId={that.data.orderGroupId}`,
  318. })
  319. }
  320. }
  321. })
  322. } else {
  323. wx.showModal({
  324. title: '提示',
  325. content: '您有未支付订单,请先进行支付',
  326. confirmText: "去支付",
  327. success: function (res) {
  328. if (res.confirm) {
  329. wx.navigateTo({
  330. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}`,
  331. })
  332. }
  333. }
  334. })
  335. }
  336. }).catch(error => {
  337. console.log(error)
  338. wx.showToast({
  339. title: error.message,
  340. icon:"none",
  341. duration:3000
  342. })
  343. })
  344. },
  345. /**
  346. * 发起拼团
  347. */
  348. gotoSpell(e) {
  349. let that = this;
  350. that.setData({
  351. canSpell: false,
  352. formId: e.detail.formId,
  353. orderGroupId:0
  354. })
  355. that.getQuestions(0);
  356. },
  357. //参与别人的拼团
  358. gotoPartner() {
  359. wx.navigateTo({
  360. url: `/pages/joinFrDpell/index?orderId=${this.data.spellData.orderId}&couponId=${this.data.spellData.couponId}&orderGroupId=${this.data.spellData.orderGroupId}&couponChannelId=${this.data.couponChannelId}&avatarUrl=${this.data.spellData.avatarUrl}&nickName=${this.data.spellData.nickName}`
  361. });
  362. },
  363. /**
  364. * 获取一个拼团信息
  365. */
  366. getOneSpell(couponId) {
  367. let that = this;
  368. Http.get({
  369. url: config.api.queryRemainOne,
  370. data: {
  371. couponId: couponId
  372. }
  373. }).then(res => {
  374. wx.stopPullDownRefresh();
  375. if (res.data) {
  376. that.countdown(res.data.expiredDate);
  377. that.setData({
  378. spellData: res.data
  379. });
  380. }
  381. });
  382. },
  383. /**
  384. * 获取券详情信息
  385. */
  386. getDetail(couponChannelId) {
  387. let that = this;
  388. Http.get({
  389. url: config.api.couponDetail,
  390. data: {
  391. couponChannelId: couponChannelId
  392. }
  393. }).then(res => {
  394. wx.stopPullDownRefresh();
  395. let data = res.data;
  396. if (res && res.data && res.data.detailPicture) {
  397. that.setData({
  398. detailPicture: JSON.parse(res.data.detailPicture)
  399. })
  400. }
  401. if (res && res.data && res.data.coverPicture) {
  402. that.setData({
  403. coverPicture: JSON.parse(res.data.coverPicture)
  404. })
  405. }
  406. if (res && res.data && res.data.conditions) {
  407. that.setData({
  408. limitCondition: JSON.parse(res.data.conditions).type
  409. })
  410. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  411. that.setData({
  412. minLimit: JSON.parse(res.data.conditions).min
  413. })
  414. }
  415. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  416. that.setData({
  417. maxLimit: JSON.parse(res.data.conditions).max
  418. })
  419. }
  420. }
  421. data.price = (data.price / 100).toFixed(2)
  422. data.salePrice = (data.salePrice / 100).toFixed(2);
  423. data.validStartDate = utils.formatTime(data.validStartDate, 'yyyy-MM-dd')
  424. data.validEndDate = utils.formatTime(data.validEndDate, 'yyyy-MM-dd')
  425. that.setData({
  426. data,
  427. merchantVoList: data.merchantVoList
  428. });
  429. });
  430. },
  431. /**
  432. * 去拼团
  433. */
  434. goToOrderGroup(orderId, orderGroupId, _this) {
  435. let that = this;
  436. // 支付成功
  437. Http.post({
  438. url: config.api.toOrderGroup,
  439. data: {
  440. id: orderGroupId,
  441. orderId,
  442. couponId: _this.data.data.couponId
  443. }
  444. })
  445. .then(res => {
  446. wx.navigateTo({
  447. url: `/pages/spellDetail/index?orderId=${orderId}&couponId=${_this.data.data.couponId}&orderGroupId=${res.data.orderGroupId}&couponChannelId=${_this.data.couponChannelId}`
  448. });
  449. })
  450. .catch(err => {
  451. console.log(err);
  452. })
  453. },
  454. /**
  455. * 支付订单更新
  456. */
  457. payOrderUpdate: (orderId, payOrderId, status, reason, _this, orderGroupId) => {
  458. console.log(orderGroupId, 7777)
  459. let that = this;
  460. // 支付成功
  461. Http.post({
  462. url: config.api.payOrderUpdate,
  463. data: {
  464. payOrderId: payOrderId,
  465. orderId: orderId,
  466. status: status,
  467. reason: reason
  468. }
  469. })
  470. .then(res => {
  471. wx.hideLoading()
  472. if (orderGroupId == undefined) {
  473. wx.navigateTo({
  474. url: '/pages/order/detail/index?orderId=' + res.data.id,
  475. })
  476. } else {
  477. _this.goToOrderGroup(orderId, res.data.orderGroupId, _this)
  478. }
  479. })
  480. .catch(err => {
  481. if (err.code != 12002) {
  482. setTimeout(function() {
  483. _this.payOrderUpdate(orderId, payOrderId, status, reason, _this, orderGroupId);
  484. }, 2000)
  485. }
  486. })
  487. },
  488. /**
  489. * 发起支付
  490. */
  491. orderFunc() {
  492. let orderGroupId = this.data.orderGroupId;
  493. let data = {
  494. couponChannelId: this.data.data.id,
  495. couponId: this.data.data.couponId,
  496. formId: this.data.formId
  497. }
  498. /**
  499. * 拼团订单
  500. */
  501. let that = this;
  502. if (this.data.orderGroupId == 0) {
  503. data.orderGroupId = this.data.orderGroupId,
  504. that.setData({
  505. isFromSpell:true
  506. })
  507. }else{
  508. that.setData({
  509. isFromSpell: false
  510. })
  511. }
  512. Http.get({
  513. url: config.api.checkPhoneStatus,
  514. data: {}
  515. })
  516. .then(res => {
  517. /**
  518. * orderSave 下单
  519. */
  520. return Http.post({
  521. url: config.api.orderSave,
  522. data: data
  523. });
  524. })
  525. .catch(err => {
  526. console.log(err);
  527. that.setData({
  528. showbutton: false,
  529. showbutton1: false,
  530. canSpell: true,
  531. canBuyIf: true
  532. })
  533. if (err.code == 2011) {
  534. wx.showToast({
  535. title: "商户信息没找到",
  536. image: './../../../assets/images/fail.png',
  537. duration: 2000,
  538. mask: false
  539. });
  540. } else if (err.code == 2013) {
  541. wx.showToast({
  542. title: "商户信息禁用",
  543. image: './../../../assets/images/fail.png',
  544. duration: 2000,
  545. mask: false
  546. });
  547. } else if (err.code == 3000) {
  548. wx.showToast({
  549. title: "库存不足",
  550. image: './../../../assets/images/fail.png',
  551. duration: 2000,
  552. mask: false
  553. });
  554. } else if (err.code == 3001) {
  555. wx.showToast({
  556. title: "您已超过限购",
  557. image: './../../../assets/images/fail.png',
  558. duration: 2000,
  559. mask: false
  560. });
  561. } else if (err.code == 3002) {
  562. wx.showToast({
  563. title: "订单失败",
  564. image: './../../../assets/images/fail.png',
  565. duration: 2000,
  566. mask: false
  567. });
  568. } else if (err.code == 3003) {
  569. wx.showToast({
  570. title: "订单不存在",
  571. image: './../../../assets/images/fail.png',
  572. duration: 2000,
  573. mask: false
  574. });
  575. } else if (err.code == 3004) {
  576. wx.showToast({
  577. title: "订单不存在",
  578. image: './../../../assets/images/fail.png',
  579. duration: 2000,
  580. mask: false
  581. });
  582. } else if (err.code == 4003) {
  583. wx.showToast({
  584. title: "卡券已作废",
  585. image: './../../../assets/images/fail.png',
  586. duration: 2000,
  587. mask: false
  588. });
  589. } else if (err.code == 3012) {
  590. // wx.showToast({
  591. // title: err.message,
  592. // icon: "none"
  593. // })
  594. that.getUnPaidOrder(that.data.data.couponId);
  595. } else if (err.code == 11005) {
  596. /**
  597. * 将值传到用户手机号授权的页面
  598. *
  599. */
  600. wx.redirectTo({
  601. url: `/pages/getphoneInfo/index?path=spell&couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}`
  602. });
  603. } else if (err.code == 11006) {
  604. // 用户手机已加密
  605. wx.redirectTo({
  606. url: `/pages/phoneinput/phoneinput?path=spell&couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}`
  607. });
  608. } else {
  609. wx.showToast({
  610. title: err.message,
  611. icon: 'none',
  612. duration: 2000,
  613. mask: false
  614. });
  615. }
  616. })
  617. .then(res => {
  618. console.log(res)
  619. if (typeof(res) != "undefined") {
  620. let orderId = "" + res.data.id;
  621. that.setData({
  622. orderId: orderId,
  623. canSpell: false,
  624. canBuyIf: true
  625. });
  626. // 支付金额不为0
  627. /**
  628. * 支付订单创建
  629. */
  630. Http.post({
  631. url: config.api.payOrderCreate,
  632. data: {
  633. orderId: orderId
  634. }
  635. })
  636. .then(res => {
  637. var payOrderId = "" + res.data.payOrderId;
  638. wx.hideLoading();
  639. wx.requestPayment({
  640. timeStamp: res.data.timeStamp,
  641. nonceStr: res.data.nonceStr,
  642. package: res.data.package,
  643. signType: (res.data.signType) ? res.data.signType : "MD5",
  644. paySign: res.data.paySign,
  645. success: res => {
  646. that.setData({
  647. canSpell: false
  648. })
  649. wx.showLoading({
  650. title: '订单正在处理中...',
  651. })
  652. setTimeout(function() {
  653. wx.hideLoading()
  654. }, 5000)
  655. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', that, orderGroupId);
  656. if (res.errMsg == "requestPayment:ok") {
  657. setTimeout(function() {
  658. wx.hideLoading();
  659. }, 2000);
  660. }
  661. },
  662. fail: res => {
  663. /**
  664. * 支付失败,需要更新订单的状态
  665. */
  666. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', that, orderGroupId);
  667. that.setData({
  668. showbutton: false,
  669. canSpell: true,
  670. canBuyIf: true
  671. })
  672. return;
  673. },
  674. complete: res => {}
  675. });
  676. /// End payment --------
  677. })
  678. .catch(err => {
  679. that.setData({
  680. canSpell: true,
  681. canBuyIf: true
  682. })
  683. wx.showToast({
  684. title: err.message,
  685. icon: 'none',
  686. duration: 2000,
  687. mask: false
  688. });
  689. })
  690. }
  691. })
  692. },
  693. /**
  694. * 生命周期函数--监听页面显示
  695. */
  696. onShow: function() {
  697. this.setData({
  698. canSpell: true,
  699. canBuyIf: true,
  700. showTime: true
  701. })
  702. if (this.data.spellData != null) {
  703. this.countdown()
  704. }
  705. },
  706. /**
  707. * 生命周期函数--监听页面隐藏
  708. */
  709. onHide: function() {
  710. this.setData({
  711. showTime: false
  712. })
  713. },
  714. /**
  715. * 生命周期函数--监听页面卸载
  716. */
  717. onUnload: function() {
  718. this.setData({
  719. showTime: false
  720. })
  721. },
  722. /**
  723. * 页面相关事件处理函数--监听用户下拉动作
  724. */
  725. onPullDownRefresh: function(e) {
  726. let that = this;
  727. console.log(this.data.couponId,222)
  728. that.getDetail(that.data.couponChannelId);
  729. if (that.data.couponId) {
  730. that.getOneSpell(that.data.couponId)
  731. }
  732. },
  733. onShareAppMessage: function (options) {
  734. console.log(options)
  735. var that = this;
  736. var shareObj = {
  737. title: that.data.data.title,
  738. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}&couponId=${that.data.data.couponId}&spellGroup=spellGroup`,
  739. success: function (res) {
  740. if (res.errMsg == 'shareAppMessage:ok') { }
  741. },
  742. fail: function (error) {
  743. if (res.errMsg == 'shareAppMessage:fail cancel') { } else if (res.errMsg == 'shareAppMessage:fail') { }
  744. }
  745. };
  746. // 来自页面内的按钮的转发
  747. if (options.from == 'button') {
  748. var eData = options.target.dataset.id;
  749. shareObj.path = `/pages/index/index?couponChannelId=${eData}&couponId=${that.data.data.couponId}&spellGroup=spellGroup&frommd=JC`;
  750. }
  751. // 返回shareObj
  752. return shareObj;
  753. },
  754. })