C端小程序
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

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