抖音小程序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.

1419 rader
40 KiB

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