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.

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