C端小程序
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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