C端小程序
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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