C端小程序
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

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