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.

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