C端小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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