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.

1150 line
32 KiB

  1. const navigationBarHeight = (getApp().statusBarHeight + 44) + '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. navigationBarHeight,
  10. homeSelectedO: imgurl.homeSelectedO.url,
  11. isshowposter: false, //是否显示分享弹框
  12. fenxiang: imgurl.fenxiang1.url,
  13. fenxiangUrl: imgurl.fenxiang.url,
  14. clockUrl: imgurl.clock.url,
  15. yushouUrl: imgurl.yushou.url,
  16. teljpgUrl: imgurl.teljpg.url,
  17. closedUrl: imgurl.closed.url,
  18. quesGouUrl: imgurl.ques_gou.url,
  19. headbgUrl: imgurl.headbg.url,
  20. quesBgUrl: imgurl.ques_bg.url,
  21. close02: imgurl.close02.url,
  22. share01: imgurl.share01.url,
  23. fail: imgurl.fail.url,
  24. wmhome: imgurl.wmhome.url,
  25. swiperCurrent: 0,
  26. detailPicture: [],
  27. coverPicture: [],
  28. couponList:[],
  29. data: {
  30. title: null
  31. },
  32. showPage: false,
  33. questions1: null,
  34. questions2: null,
  35. carList: [],
  36. couponChannelId: null,
  37. orderId: "",
  38. hour: null,
  39. day: null,
  40. month: null,
  41. year: null,
  42. minute: "",
  43. tempFilePaths: null,
  44. userInfo: {},
  45. hasUserInfo: false,
  46. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  47. id: null,
  48. result: [],
  49. end_time: null,
  50. checked: false,
  51. questionnaire: {},
  52. questionId: null,
  53. widthScreen: null,
  54. moveData: null,
  55. rotateData: null,
  56. alphaData: null,
  57. scaleData: null,
  58. skewData: null,
  59. matrixData: null,
  60. opacity: 0,
  61. queueData: null,
  62. zIndex: 11,
  63. display: "none",
  64. showbutton: false,
  65. cardData: null,
  66. showCardOffer: false,
  67. isSamePeople: true,
  68. statusText: '',
  69. isReceived: false,
  70. receivedDisabled: false,
  71. clock: "结束",
  72. day: "00",
  73. hour: "00",
  74. min: "00",
  75. sec: "00",
  76. clock02: "00",
  77. day02: "00",
  78. hour02: "00",
  79. min02: "00",
  80. sec02: "00",
  81. countdown: "",
  82. showbutton1: false,
  83. limitCondition: "",
  84. minLimit: 0,
  85. maxLimit: 0,
  86. dispressEndDate: false,
  87. barTitle: "",
  88. activityStatus: "",
  89. //图文混排
  90. curHtml: '',
  91. contentType: 0,
  92. page:1,//查询商户优惠券page
  93. idList:[],
  94. },
  95. /**
  96. * 显示分享弹框
  97. */
  98. showshare: function() {
  99. this.setData({
  100. isshowposter: true,
  101. })
  102. },
  103. getCouponList: function(id) {
  104. let that = this;
  105. let data;
  106. data = {
  107. status: 0,
  108. merchantIds: id,
  109. pageNum: that.data.page,
  110. pageSize: 4,
  111. }
  112. Http.post({
  113. url: config.api.listByMerchant,
  114. data: data
  115. }).then(res => {
  116. if (res.data.page.list<=0){
  117. return
  118. }
  119. let dataLsit = []
  120. dataLsit = that.data.couponList
  121. dataLsit.push(...res.data.page.list)
  122. dataLsit.map((item,index)=>{
  123. if (item.id == that.data.couponChannelId){
  124. dataLsit.splice(index,1)
  125. }
  126. })
  127. if (that.data.page>1){
  128. let tmpeLsit = dataLsit
  129. tmpeLsit.push(...res.data.page.list)
  130. that.setData({
  131. couponList: tmpeLsit,
  132. })
  133. }else{
  134. that.setData({
  135. couponList: dataLsit,
  136. })
  137. }
  138. // if (res.data && res.data.qrCode){
  139. // that.setData({
  140. // qrCode: res.data.qrCode,
  141. // })
  142. // }
  143. })
  144. .catch(err => {
  145. wx.showToast({
  146. title: err.errMsg,
  147. icon: 'none',
  148. duration: 2000,
  149. mask: false
  150. });
  151. })
  152. },
  153. /**
  154. * 隐藏分享弹框
  155. */
  156. hidemodal: function() {
  157. this.setData({
  158. isshowposter: false,
  159. })
  160. },
  161. /**
  162. * 显示分享海报
  163. */
  164. /* showPoster: function() {
  165. //跳转到海报生成页
  166. console.log(this.data.canIUse)
  167. // return;
  168. wx.navigateTo({
  169. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  170. })
  171. }, */
  172. showPoster: function() {
  173. //跳转到海报生成页
  174. let that = this;
  175. Http.get({
  176. url: config.api.checkUserStatus,
  177. data: {
  178. token: app.globalData.token
  179. }
  180. }).then(res => {
  181. wx.navigateTo({
  182. url: `/pages/canvas/index?couponChannelId=${that.data.data.id}`
  183. })
  184. }).catch(err => {
  185. console.log(err)
  186. if (err.code == 11004) {
  187. // 用户昵称未授权
  188. wx.redirectTo({
  189. url: `/pages/getuserinfo/index?couponChannelId=${that.data.data.id}&fromflag=poster`
  190. })
  191. }
  192. })
  193. },
  194. swiperChange: function(e) {
  195. this.setData({
  196. swiperCurrent: e.detail.current
  197. });
  198. },
  199. //获取当前登录用户信息
  200. getUserInfo: function() {
  201. let that = this;
  202. // 获取用户信息
  203. Http.get({
  204. url: config.api.getScore,
  205. data: {}
  206. })
  207. .then(res => {
  208. console.log(res)
  209. that.getQueryCardStatus()
  210. if (that.data.cardData.cuserId != res.data.id) {
  211. console.log(2222, 6666)
  212. that.setData({
  213. isSamePeople: false
  214. })
  215. }
  216. })
  217. },
  218. //获取卡转赠状态
  219. getQueryCardStatus() {
  220. let that = this;
  221. let param = {
  222. id: this.data.cardData.couponOrderId,
  223. cUserId: this.data.cardData.cuserId,
  224. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  225. }
  226. Http.get({
  227. url: config.api.queryCardStatus,
  228. data: param
  229. })
  230. .then(res => {
  231. console.log(res, 333333333333)
  232. })
  233. .catch(err => {
  234. that.setData({
  235. isReceived: true,
  236. statusText: err.message
  237. })
  238. })
  239. },
  240. receiveCard() {
  241. let that = this;
  242. let param = {
  243. id: this.data.cardData.couponOrderId,
  244. cUserId: this.data.cardData.cuserId,
  245. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  246. }
  247. this.setData({
  248. receivedDisabled: true
  249. })
  250. Http.post({
  251. url: config.api.cardAccept,
  252. data: param
  253. })
  254. .then(res => {
  255. wx.showToast({
  256. title: '领取成功!',
  257. icon: 'none',
  258. duration: 2000,
  259. mask: false
  260. });
  261. wx.reLaunch({
  262. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  263. })
  264. })
  265. .catch(err => {
  266. wx.showToast({
  267. title: err.message,
  268. icon: 'none',
  269. duration: 2000,
  270. mask: false
  271. });
  272. that.setData({
  273. receivedDisabled: false
  274. })
  275. })
  276. },
  277. closeAlert() {
  278. this.setData({
  279. showCardOffer: false
  280. })
  281. },
  282. goback: function() {
  283. wx.switchTab({
  284. url: '/index/index',
  285. })
  286. },
  287. /**
  288. * 点击提交问题单选
  289. */
  290. formSubmit: function(e) {
  291. console.log(e);
  292. let that = this;
  293. /**
  294. * 多选
  295. */
  296. if (e.currentTarget.dataset.flags == 'multi') {
  297. if (that.data.anwserId.length == 0) {
  298. var answserIs = null
  299. } else {
  300. var answserIs = that.data.anwserId.join(",");
  301. }
  302. } else if (e.currentTarget.dataset.flags == 'single') {
  303. var answserIs = e.detail.value;
  304. }
  305. console.log(answserIs)
  306. console.log(e.currentTarget.dataset.questionid)
  307. Http.post({
  308. url: config.api.answerQuestion,
  309. data: {
  310. answer: answserIs,
  311. questionId: e.currentTarget.dataset.questionid
  312. }
  313. })
  314. .then(res => {
  315. that.closeQuestion();
  316. })
  317. .catch(err => {
  318. wx.showToast({
  319. title: err.message,
  320. icon: 'none',
  321. duration: 2000,
  322. mask: false
  323. });
  324. })
  325. },
  326. /**
  327. * 多选
  328. */
  329. checkboxChange: function(e) {
  330. console.log(e)
  331. this.setData({
  332. anwserId: e.detail.value
  333. })
  334. },
  335. closeQuestion: function() {
  336. let that = this;
  337. that.setData({
  338. display: "none",
  339. zIndex: 11,
  340. opacity: 0
  341. })
  342. setTimeout(function() {
  343. that.orderFunc();
  344. }, 500)
  345. },
  346. gotopay: function(e) {
  347. app.globalData.previewFlag = true
  348. /* 判断是否授权*/
  349. Http.get({
  350. url: config.api.checkUserStatus,
  351. data: {
  352. token: app.globalData.token
  353. }
  354. }).then(res => {
  355. Http.get({
  356. url: config.api.checkPhoneStatus,
  357. data: {}
  358. }).then(res => {
  359. let that = this;
  360. console.log(e);
  361. wx.showLoading();
  362. if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50) {
  363. wx.navigateTo({
  364. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId,
  365. })
  366. } else {
  367. let formId = e.detail.formId;
  368. var discount = e.detail.target.dataset.discount;
  369. that.setData({
  370. queueData: null,
  371. showbutton: true,
  372. formId: formId
  373. })
  374. Http.get({
  375. url: config.api.getQuestion,
  376. data: {
  377. couponType: JSON.stringify(that.data.data.type)
  378. }
  379. })
  380. .then(res => {
  381. wx.hideLoading();
  382. if (res.data == undefined) {
  383. // 立即购买
  384. that.orderFunc(discount);
  385. that.setData({
  386. flag: false
  387. })
  388. } else if (res.data) {
  389. var animation = wx.createAnimation({});
  390. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  391. duration: 500
  392. })
  393. that.setData({
  394. queueData: animation.export(),
  395. zIndex: 9,
  396. opacity: 1,
  397. display: "block",
  398. questionnaire: JSON.parse(res.data.content),
  399. questionId: res.data.id
  400. });
  401. }
  402. })
  403. .catch(err => {
  404. wx.hideLoading();
  405. wx.showToast({
  406. title: err.message,
  407. icon: 'none',
  408. duration: 2000,
  409. mask: false
  410. });
  411. })
  412. }
  413. }).catch(err => {
  414. wx.redirectTo({
  415. url: `/pages/getphoneInfo/index?skipUrl=1`
  416. });
  417. })
  418. }).catch(err => {
  419. wx.navigateTo({
  420. url: `/pages/getuserinfo/index?fromflag=coupondetail&couponChannelIdflag=${this.data.couponChannelId}`,
  421. })
  422. })
  423. },
  424. setIntervalTime(end_time) {
  425. let that = this;
  426. var EndTime = end_time;
  427. var NowTime = new Date().getTime();
  428. var total_micro_second = EndTime - NowTime || [];
  429. // 渲染倒计时时钟
  430. let obj = that.dateformat(total_micro_second);
  431. if (total_micro_second > 0) {
  432. that.setData({
  433. clock: obj,
  434. day: obj.a1,
  435. hour: obj.b1,
  436. min: obj.c1,
  437. sec: obj.d1,
  438. })
  439. } else {
  440. that.setData({
  441. clock: "00",
  442. day: "00",
  443. hour: "00",
  444. min: "00",
  445. sec: "00",
  446. })
  447. //如果倒计时结束,需要重新查询一下券的状态
  448. // 给getDetail一个标识
  449. that.getDetail(that.data.couponChannelId, 'endclock');
  450. }
  451. total_micro_second -= 1000;
  452. },
  453. countdown: function(end_time) {
  454. let that = this;
  455. that.setIntervalTime(end_time);
  456. that.data.setInterval = setInterval(function() {
  457. that.setIntervalTime(end_time);
  458. }, 1000)
  459. },
  460. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  461. dateformat(micro_second) {
  462. // 总秒数
  463. var second = Math.floor(micro_second / 1000);
  464. // 天数
  465. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  466. // 小时
  467. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  468. // 分钟
  469. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  470. // 秒
  471. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  472. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  473. return {
  474. a1: day,
  475. b1: hr,
  476. c1: min,
  477. d1: sec
  478. }
  479. },
  480. /**
  481. * 获取用户信息
  482. */
  483. onLoad(options) {
  484. let that = this;
  485. if (options.g) {
  486. app.globalData.havePlayEd1 = true;
  487. }
  488. wx.showLoading({
  489. title: "加载中..."
  490. });
  491. that.setData({
  492. onshow: false
  493. })
  494. if (options && options.couponChannelId) {
  495. that.getDetail(options.couponChannelId, 'notendclock');
  496. }
  497. /**
  498. * 转赠判断
  499. */
  500. if (options.cuserId) {
  501. this.setData({
  502. showCardOffer: true,
  503. cardData: options
  504. })
  505. this.getUserInfo()
  506. }
  507. that.setData({
  508. couponChannelId: options.couponChannelId,
  509. title: that.data.data.title ? that.data.data.title : '',
  510. });
  511. if (options.cardType) {
  512. that.setData({
  513. cardType: options.cardType
  514. })
  515. }
  516. },
  517. getHtml(couponChannelId) {
  518. Http.get({
  519. url: config.api.couponHtmlDetail,
  520. data: {
  521. couponChannelId: couponChannelId
  522. }
  523. }).then(res => {
  524. console.log(res)
  525. if (res.code == 200 && res.data.html) {
  526. this.setData({
  527. curHtml: decodeURI(res.data.html)
  528. })
  529. app.globalData.curHtml = this.data.curHtml;
  530. console.log(app.globalData.curHtml)
  531. }
  532. })
  533. },
  534. getDetail: function(couponChannelId, flag) {
  535. let that = this;
  536. var parmer = {
  537. url: config.api.couponDetail,
  538. data: {
  539. couponChannelId: couponChannelId
  540. }
  541. };
  542. Http.get(parmer)
  543. .then(res => {
  544. if (res.data.merchantVoList && res.data.merchantVoList.length){
  545. let merchantVoList = res.data.merchantVoList
  546. let idList = []
  547. merchantVoList.map(item=>{
  548. idList.push(item.id)
  549. })
  550. that.setData({
  551. idList: idList
  552. })
  553. that.getCouponList(idList)
  554. }
  555. //aaa
  556. if (res.data.contentType != undefined && res.data.contentType == 1) {
  557. //获取图文展示详情html
  558. this.setData({
  559. contentType: res.data.contentType
  560. })
  561. this.getHtml(couponChannelId);
  562. }
  563. that.setData({
  564. couponId: res.data.couponId
  565. })
  566. that.setData({
  567. showPage: true
  568. })
  569. if (res && res.data && res.data.detailPicture) {
  570. that.setData({
  571. detailPicture: JSON.parse(res.data.detailPicture)
  572. })
  573. }
  574. if (res && res.data && res.data.coverPicture) {
  575. that.setData({
  576. coverPicture: JSON.parse(res.data.coverPicture)
  577. })
  578. }
  579. if (res && res.data && res.data.conditions) {
  580. that.setData({
  581. limitCondition: JSON.parse(res.data.conditions).type
  582. })
  583. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  584. that.setData({
  585. minLimit: JSON.parse(res.data.conditions).min
  586. })
  587. }
  588. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  589. that.setData({
  590. maxLimit: JSON.parse(res.data.conditions).max
  591. })
  592. }
  593. }
  594. /**
  595. * 将优惠券优惠卡的详情的BarTitle
  596. * 设置成券的名称
  597. */
  598. // wx.setNavigationBarTitle({
  599. // title: res.data.title
  600. // })
  601. that.setData({
  602. barTitle: res.data.title
  603. })
  604. var EndTime = res.data.validStartDate;
  605. var NowTime = new Date().getTime();
  606. /**
  607. * activityStatus==0 活动未开始
  608. * activityStatus==1 活动已开始
  609. * flag == endclock 说明倒计时已经结束
  610. */
  611. if (res.data.endTime && res.data.beginTime) {
  612. that.setData({
  613. begin_time: res.data.beginTime,
  614. end_time: res.data.endTime,
  615. activityStatus: res.data.activityStatus ? res.data.activityStatus : ''
  616. })
  617. if (res.data.activityStatus == 0 && flag != 'endclock') {
  618. that.countdown(res.data.beginTime);
  619. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  620. that.countdown(res.data.endTime);
  621. } else {
  622. clearInterval(that.data.setInterval)
  623. }
  624. if (res.data.activityStatus == 0) {
  625. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  626. if (util.timechuo(beginTime).indexOf('-') == 0) {
  627. that.setData({
  628. beginTime: "活动已结束",
  629. });
  630. } else {
  631. that.setData({
  632. beginTime: util.timechuo(beginTime)
  633. });
  634. }
  635. } else {
  636. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  637. if (util.timechuo(endTime).indexOf('-') == 0) {
  638. that.setData({
  639. endtime: "活动已结束",
  640. });
  641. } else {
  642. that.setData({
  643. endtime: util.timechuo(endTime)
  644. });
  645. }
  646. }
  647. }
  648. wx.hideLoading();
  649. that.setData({
  650. data: res.data,
  651. merchantVoList: res.data.merchantVoList
  652. });
  653. if(res.data.type == 10){
  654. that.setData({
  655. salePriceStr: res.data.salePriceStr,
  656. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  657. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  658. priceStr: res.data.priceStr,
  659. tailPriceStr: res.data.tailPriceStr,
  660. origPriceStr: res.data.origPriceStr
  661. })
  662. }
  663. if (res.data.validType == 1) {
  664. that.setData({
  665. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  666. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  667. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  668. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  669. });
  670. } else {
  671. if (res.data.validDays) {
  672. that.setData({
  673. validDays: res.data.validDays
  674. });
  675. }
  676. }
  677. }).catch(err => {
  678. wx.showToast({
  679. title: err.message,
  680. icon: 'none',
  681. duration: 2000,
  682. mask: false
  683. });
  684. })
  685. },
  686. /**
  687. * 邀请好友继续砍价
  688. */
  689. inviteFriend: function(e) {
  690. let that = this;
  691. let formId = e.detail.formId;
  692. that.setData({
  693. formId: formId,
  694. showbutton1: true
  695. })
  696. that.orderFunc("discount");
  697. },
  698. /**
  699. * 支付订单更新
  700. */
  701. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this) => {
  702. console.log("*-----------------")
  703. let that = this;
  704. // 支付成功
  705. Http.post({
  706. url: config.api.payOrderUpdate,
  707. data: {
  708. payOrderId: payOrderId,
  709. orderId: orderId,
  710. status: status,
  711. reason: reason
  712. }
  713. })
  714. .then(res => {
  715. wx.hideLoading()
  716. // 有价券
  717. if (!type && type != 'free') {
  718. wx.navigateTo({
  719. url: `/pages/order/detail/index?orderId=${
  720. orderId
  721. }&cardIf=true&contentType=${_this.data.contentType}`
  722. });
  723. } else if (type == 'free') {
  724. wx.navigateTo({
  725. url: `/pages/order/detail/index?orderId=${
  726. orderId
  727. }&contentType=${_this.data.contentType}`
  728. });
  729. }
  730. })
  731. .catch(err => {
  732. console.log(err);
  733. if (!type) {
  734. setTimeout(function() {
  735. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this);
  736. }, 2000)
  737. }
  738. })
  739. },
  740. checkPhoneStatus: function() {
  741. let that = this;
  742. Http.get({
  743. url: config.api.checkPhoneStatus,
  744. data: {}
  745. })
  746. .then(res => {
  747. console.log(666, '授权成功!')
  748. that.receiveCard()
  749. })
  750. .catch(err => {
  751. if (err.code == 11005) {
  752. /**
  753. * 手机号没有授权,将值传到用户手机号授权的页面
  754. *
  755. */
  756. wx.redirectTo({
  757. url: "/pages/getphoneInfo/index?path=index&cuserId=" + that.data.cardData.cuserId + "&couponChannelId=" + that.data.cardData.couponChannelId + "&userName=" + that.data.cardData.userName + "&coverImg=" + that.data.cardData.coverImg + "&avatarUrl=" + that.data.cardData.avatarUrl + "&couponOrderId=" + that.data.cardData.couponOrderId + "&updateDate=" + that.data.cardData.updateDate,
  758. });
  759. } else if (err.code == 11006) {
  760. // 用户手机已加密
  761. wx.redirectTo({
  762. url: "/pages/phoneinput/phoneinput?path=index&cuserId=" + that.data.cardData.cuserId + "&couponChannelId=" + that.data.cardData.couponChannelId + "&userName=" + that.data.cardData.userName + "&coverImg=" + that.data.cardData.coverImg + "&avatarUrl=" + that.data.cardData.avatarUrl + "&couponOrderId=" + that.data.cardData.couponOrderId + "&updateDate=" + that.data.cardData.updateDate,
  763. });
  764. } else {
  765. wx.showToast({
  766. title: err.message,
  767. icon: 'none',
  768. duration: 2000,
  769. mask: false
  770. });
  771. }
  772. })
  773. },
  774. /**
  775. * 发起支付
  776. */
  777. orderFunc(discount) {
  778. let that = this;
  779. Http.get({
  780. url: config.api.checkUserStatus,
  781. data: {
  782. token: app.globalData.token
  783. }
  784. }).then(res => {
  785. Http.get({
  786. url: config.api.checkPhoneStatus,
  787. data: {}
  788. })
  789. .then(res => {
  790. // 发起砍价
  791. if (discount == 'discount') {
  792. var data = {
  793. couponChannelId: "" + that.data.couponChannelId,
  794. couponId: "" + that.data.couponId,
  795. formId: "" + that.data.formId,
  796. press: true
  797. }
  798. } else if (discount == 'discount1') {
  799. var data = {
  800. couponChannelId: "" + that.data.couponChannelId,
  801. couponId: "" + that.data.couponId,
  802. formId: "" + that.data.formId,
  803. press: false
  804. }
  805. } else if (that.data.couponChannelId == null) {
  806. var data = {
  807. couponId: "" + that.data.couponId,
  808. formId: "" + that.data.formId,
  809. };
  810. } else {
  811. var data = {
  812. couponChannelId: "" + that.data.couponChannelId,
  813. couponId: "" + that.data.couponId,
  814. formId: "" + that.data.formId,
  815. }
  816. }
  817. /**
  818. * orderSave 下单
  819. */
  820. return Http.post({
  821. url: config.api.orderSave,
  822. data: data
  823. });
  824. })
  825. .catch(err => {
  826. wx.hideLoading()
  827. that.setData({
  828. showbutton: false,
  829. showbutton1: false
  830. })
  831. if (err.code == 2011) {
  832. wx.showToast({
  833. title: "商户信息没找到",
  834. image: './../../../assets/images/fail.png',
  835. duration: 2000,
  836. mask: false
  837. });
  838. } else if (err.code == 2013) {
  839. wx.showToast({
  840. title: "商户信息禁用",
  841. image: './../../../assets/images/fail.png',
  842. duration: 2000,
  843. mask: false
  844. });
  845. } else if (err.code == 3000) {
  846. wx.showToast({
  847. title: "库存不足",
  848. image: './../../../assets/images/fail.png',
  849. duration: 2000,
  850. mask: false
  851. });
  852. } else if (err.code == 3001) {
  853. wx.showToast({
  854. title: "您已超过限购",
  855. image: './../../../assets/images/fail.png',
  856. duration: 2000,
  857. mask: false
  858. });
  859. } else if (err.code == 3002) {
  860. wx.showToast({
  861. title: "订单失败",
  862. image: './../../../assets/images/fail.png',
  863. duration: 2000,
  864. mask: false
  865. });
  866. } else if (err.code == 3003) {
  867. wx.showToast({
  868. title: "订单不存在",
  869. image: './../../../assets/images/fail.png',
  870. duration: 2000,
  871. mask: false
  872. });
  873. } else if (err.code == 3004) {
  874. wx.showToast({
  875. title: "订单不存在",
  876. image: './../../../assets/images/fail.png',
  877. duration: 2000,
  878. mask: false
  879. });
  880. } else if (err.code == 4003) {
  881. wx.showToast({
  882. title: "卡券已作废",
  883. image: './../../../assets/images/fail.png',
  884. duration: 2000,
  885. mask: false
  886. });
  887. } else if (err.code == 3012) {
  888. that.getUnPaidOrder(that.data.couponId);
  889. } else if (err.code == 11005) {
  890. /**
  891. * 将值传到用户手机号授权的页面
  892. *
  893. */
  894. wx.redirectTo({
  895. url: "/pages/getphoneInfo/index?couponChannelId=" +
  896. that.data.couponChannelId
  897. });
  898. } else if (err.code == 11006) {
  899. // 用户手机已加密
  900. wx.redirectTo({
  901. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  902. that.data.couponChannelId
  903. });
  904. } else {
  905. wx.showToast({
  906. title: err.message,
  907. icon: 'none',
  908. duration: 2000,
  909. mask: false
  910. });
  911. }
  912. })
  913. .then(res => {
  914. if (discount != 'discount') {
  915. if (typeof(res) != "undefined") {
  916. let orderId = "" + res.data.id;
  917. that.setData({
  918. orderId: orderId
  919. });
  920. if (res.data.payment > 0) {
  921. // 支付金额不为0
  922. /**
  923. * 支付订单创建
  924. */
  925. Http.post({
  926. url: config.api.payOrderCreate,
  927. data: {
  928. orderId: orderId
  929. }
  930. })
  931. .then(res => {
  932. var payOrderId = "" + res.data.payOrderId;
  933. wx.hideLoading();
  934. wx.requestPayment({
  935. timeStamp: res.data.timeStamp,
  936. nonceStr: res.data.nonceStr,
  937. package: res.data.package,
  938. signType: (res.data.signType) ? res.data.signType : "MD5",
  939. paySign: res.data.paySign,
  940. success: res => {
  941. wx.showLoading({
  942. title: '订单正在处理中...',
  943. })
  944. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that);
  945. if (res.errMsg == "requestPayment:ok") {
  946. /**
  947. * 用户支付成功以后跳转到券包列表
  948. */
  949. if (that.data.cardType == 100) {
  950. wx.setStorage({
  951. key: 'couponNum2',
  952. data: "couponNum2"
  953. })
  954. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  955. wx.setStorage({
  956. key: 'couponNum',
  957. data: "couponNum"
  958. })
  959. }
  960. }
  961. },
  962. fail: res => {
  963. wx.hideLoading();
  964. /**
  965. * 支付失败,需要更新订单的状态
  966. */
  967. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that);
  968. that.setData({
  969. showbutton: false
  970. })
  971. return;
  972. },
  973. complete: res => {}
  974. });
  975. /// End payment --------
  976. })
  977. .catch(err => {
  978. wx.hideLoading();
  979. wx.showToast({
  980. title: err.message,
  981. icon: 'none',
  982. duration: 2000,
  983. mask: false
  984. });
  985. })
  986. } else {
  987. // 免费券
  988. that.payOrderUpdate(orderId, "0", 1, '', 'free', that);
  989. if (that.data.cardType == 100) {
  990. wx.setStorage({
  991. key: 'couponNum2',
  992. data: "couponNum2"
  993. })
  994. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  995. wx.setStorage({
  996. key: 'couponNum',
  997. data: "couponNum"
  998. })
  999. }
  1000. }
  1001. }
  1002. } else {
  1003. if (res) {
  1004. wx.navigateTo({
  1005. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.id}`,
  1006. })
  1007. }
  1008. }
  1009. })
  1010. }).catch(err => {
  1011. console.log(err)
  1012. if (err.code == 11004) {
  1013. wx.redirectTo({
  1014. url: `/pages/getuserinfo/index?fromflag=coupondetail&couponChannelIdflag=${that.data.couponChannelId}`,
  1015. })
  1016. } else {
  1017. wx.showToast({
  1018. title: err.message,
  1019. icon: "none",
  1020. duration: 2500
  1021. })
  1022. }
  1023. })
  1024. },
  1025. // 获得未支付的订单
  1026. getUnPaidOrder(couponId) {
  1027. let that = this;
  1028. Http.get({
  1029. url: config.api.getUnPaidOrder,
  1030. data: {
  1031. couponId: couponId
  1032. }
  1033. }).then(res => {
  1034. that.setData({
  1035. disOrderNumber: res.data.orderNumber,
  1036. })
  1037. if (res.data && res.data.pressEndDate) {
  1038. that.setData({
  1039. dispressEndDate: true
  1040. })
  1041. } else {
  1042. that.setData({
  1043. dispressEndDate: false
  1044. })
  1045. }
  1046. if (that.data.dispressEndDate) {
  1047. wx.showModal({
  1048. title: '提示',
  1049. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  1050. confirmText: "我的砍价",
  1051. success: function(res) {
  1052. if (res.confirm) {
  1053. wx.navigateTo({
  1054. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}`,
  1055. })
  1056. }
  1057. }
  1058. })
  1059. } else {
  1060. wx.showModal({
  1061. title: '提示',
  1062. content: '您有未支付订单,请先进行支付',
  1063. confirmText: "去支付",
  1064. success: function(res) {
  1065. if (res.confirm) {
  1066. wx.navigateTo({
  1067. url: `/pages/order/detail/index?orderId=${that.data.disOrderNumber}&contentType=${that.data.contentType}`,
  1068. })
  1069. }
  1070. }
  1071. })
  1072. }
  1073. }).catch(error => {
  1074. wx.showToast({
  1075. title: error.message,
  1076. icon: "none",
  1077. duration: 3000
  1078. })
  1079. })
  1080. },
  1081. onShow() {
  1082. this.setData({
  1083. showbutton: false,
  1084. showbutton1: false
  1085. })
  1086. if (this.data.end_time && this.data.activityStatus != 0) {
  1087. this.countdown(this.data.end_time)
  1088. } else if (this.data.begin_time && this.data.activityStatus == 0) {
  1089. this.countdown(this.data.begin_time)
  1090. }
  1091. },
  1092. onUnload: function() {
  1093. let that = this;
  1094. clearInterval(that.data.setInterval)
  1095. },
  1096. onHide: function() {
  1097. let that = this;
  1098. clearInterval(that.data.setInterval)
  1099. },
  1100. onShareAppMessage: function(options) {
  1101. app.globalData.previewFlag = true
  1102. var that = this;
  1103. console.log(options)
  1104. var shareObj = {
  1105. title: that.data.data.title,
  1106. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  1107. success: function(res) {
  1108. if (res.errMsg == 'shareAppMessage:ok') {}
  1109. },
  1110. fail: function(error) {
  1111. if (res.errMsg == 'shareAppMessage:fail cancel') {} else if (res.errMsg == 'shareAppMessage:fail') {}
  1112. }
  1113. };
  1114. // 来自页面内的按钮的转发
  1115. if (options.from == 'button') {
  1116. var eData = options.target.dataset.id;
  1117. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  1118. }
  1119. // 返回shareObj
  1120. return shareObj;
  1121. },
  1122. // 下拉刷新
  1123. onPullDownRefresh: function() {
  1124. this.getDetail(this.data.couponChannelId);
  1125. wx.stopPullDownRefresh()
  1126. },
  1127. onReachBottom:function(){
  1128. this.setData({
  1129. page:this.data.page+1
  1130. })
  1131. if (this.data.idList.length>0){
  1132. this.getCouponList(this.data.idList)
  1133. }
  1134. }
  1135. });