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.

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