抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1428 regels
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. tt.setNavigationBarTitle({
  733. title: res.data.title,
  734. success() {
  735. console.log("setNavigationBarTitle 调用成功");
  736. },
  737. fail(res) {
  738. console.log(`setNavigationBarTitle 调用失败:`, res.errMsg);
  739. },
  740. });
  741. var EndTime = res.data.validStartDate;
  742. var NowTime = new Date().getTime();
  743. /**
  744. * activityStatus==0 活动未开始
  745. * activityStatus==1 活动已开始
  746. * flag == endclock 说明倒计时已经结束
  747. */
  748. if (res.data.endTime && res.data.beginTime) {
  749. that.setData({
  750. begin_time: res.data.beginTime,
  751. end_time: res.data.endTime,
  752. activityStatus: res.data.actStatus ? res.data.actStatus : ''
  753. })
  754. if (res.data.actStatus == 0 && flag != 'endclock') {
  755. that.countdown(res.data.beginTime);
  756. } else if (res.data.actStatus != 0 && flag != 'endclock') {
  757. that.countdown(res.data.endTime);
  758. } else {
  759. clearInterval(that.data.setInterval)
  760. }
  761. if (res.data.actStatus == 0) {
  762. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  763. if (util.timechuo(beginTime).indexOf('-') == 0) {
  764. that.setData({
  765. beginTime: "活动已结束",
  766. });
  767. } else {
  768. that.setData({
  769. beginTime: util.timechuo(beginTime)
  770. });
  771. }
  772. } else {
  773. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  774. if (util.timechuo(endTime).indexOf('-') == 0) {
  775. that.setData({
  776. endtime: "活动已结束",
  777. });
  778. } else {
  779. that.setData({
  780. endtime: util.timechuo(endTime)
  781. });
  782. }
  783. }
  784. }
  785. tt.hideLoading();
  786. that.setData({
  787. data: res.data,
  788. });
  789. if (res.data.type == 10) {
  790. that.setData({
  791. salePriceStr: res.data.salePriceStr,
  792. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  793. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  794. priceStr: res.data.priceStr,
  795. tailPriceStr: res.data.tailPriceStr,
  796. origPriceStr: res.data.origPriceStr
  797. })
  798. }
  799. if (res.data.validType == 1) {
  800. that.setData({
  801. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  802. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  803. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  804. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  805. });
  806. } else {
  807. if (res.data.validDays) {
  808. that.setData({
  809. validDays: res.data.validDays
  810. });
  811. }
  812. }
  813. if(res.data.itemGroup){
  814. let tempObj = this.data.data
  815. tempObj.itemGroup = JSON.parse(tempObj.itemGroup)
  816. this.setData({
  817. data:tempObj
  818. })
  819. console.log(this.data.data,"data");
  820. }
  821. }).catch(err => {
  822. tt.showToast({
  823. title: err.message,
  824. icon: 'none',
  825. duration: 2000,
  826. mask: false
  827. });
  828. })
  829. },
  830. /**
  831. * 邀请好友继续砍价
  832. */
  833. inviteFriend: function (e) {
  834. let that = this;
  835. let formId = e.detail.formId;
  836. that.setData({
  837. formId: formId,
  838. showbutton1: true
  839. })
  840. that.orderFunc("discount");
  841. },
  842. /**
  843. * 支付订单更新
  844. */
  845. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this, composeOrderType) => {
  846. let that = this;
  847. // 支付成功
  848. Http.post({
  849. url: config.api.payOrderUpdate,
  850. data: {
  851. payOrderId: payOrderId,
  852. composeOrderId: orderId,
  853. status: status,
  854. reason: reason
  855. }
  856. })
  857. .then(res => {
  858. tt.hideLoading()
  859. // 有价券
  860. if (!type && type != 'free') {
  861. tt.navigateTo({
  862. url: `/pages/order/detail/index?orderId=${orderId
  863. }`
  864. });
  865. } else if (type == 'free') {
  866. tt.navigateTo({
  867. url: `/pages/order/detail/index?orderId=${orderId
  868. }`
  869. });
  870. }
  871. })
  872. .catch(err => {
  873. console.log(err);
  874. if (!type) {
  875. setTimeout(function () {
  876. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  877. }, 2000)
  878. }
  879. })
  880. },
  881. checkPhoneStatus: function () {
  882. let that = this;
  883. Http.get({
  884. url: config.api.checkPhoneStatus,
  885. data: {}
  886. })
  887. .then(res => {
  888. console.log(666, '授权成功!')
  889. that.receiveCard()
  890. })
  891. .catch(err => {
  892. if (err.code == 11005) {
  893. /**
  894. * 手机号没有授权,将值传到用户手机号授权的页面
  895. *
  896. */
  897. tt.redirectTo({
  898. 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,
  899. });
  900. } else if (err.code == 11006) {
  901. // 用户手机已加密
  902. tt.redirectTo({
  903. 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,
  904. });
  905. } else {
  906. tt.showToast({
  907. title: err.message,
  908. icon: 'none',
  909. duration: 2000,
  910. mask: false
  911. });
  912. }
  913. })
  914. },
  915. // 券包支付
  916. /**
  917. * 发起支付
  918. */
  919. orderFunc(discount) {
  920. let that = this;
  921. Http.get({
  922. url: config.api.checkUserStatus,
  923. data: {
  924. token: app.globalData.token
  925. }
  926. }).then(res => {
  927. Http.get({
  928. url: config.api.checkPhoneStatus,
  929. data: {}
  930. }).then(res => {
  931. // 发起砍价
  932. if (discount == 'discount') {
  933. var data = {
  934. couponChannelId: "" + that.data.couponChannelId,
  935. couponId: "" + that.data.couponId,
  936. formId: "" + that.data.formId,
  937. press: true
  938. }
  939. } else if (discount == 'discount1') {
  940. var data = {
  941. couponChannelId: "" + that.data.couponChannelId,
  942. couponId: "" + that.data.couponId,
  943. formId: "" + that.data.formId,
  944. press: false
  945. }
  946. } else if (that.data.couponChannelId == null) {
  947. var data = {
  948. couponId: "" + that.data.couponId,
  949. formId: "" + that.data.formId,
  950. };
  951. } else {
  952. var data = {
  953. couponChannelId: "" + that.data.couponChannelId,
  954. couponId: "" + that.data.couponId,
  955. formId: "" + that.data.formId,
  956. }
  957. }
  958. console.log(data, "data")
  959. let url = ""
  960. let tempObj;
  961. let tempArr = []
  962. if (that.data.data.type == 12) {
  963. url = config.api.couponPackageSave
  964. tempObj = {
  965. signleOrder: {
  966. couponChannelId: "" + that.data.couponChannelId,
  967. couponId: "" + that.data.couponId,
  968. formId: "" + that.data.formId,
  969. },
  970. count: "1"
  971. }
  972. tempArr.push(tempObj)
  973. } else {
  974. url = config.api.orderSave
  975. }
  976. /**
  977. * orderSave 下单
  978. */
  979. return Http.post({
  980. url: url,
  981. data: that.data.data.type == 12 ? JSON.stringify(tempArr) : data
  982. });
  983. }).catch(err => {
  984. tt.hideLoading()
  985. that.setData({
  986. showbutton: false,
  987. showbutton1: false
  988. })
  989. if (err.code == 2011) {
  990. tt.showToast({
  991. title: "商户信息没找到",
  992. image: './../../../assets/images/fail.png',
  993. duration: 2000,
  994. mask: false
  995. });
  996. } else if (err.code == 2013) {
  997. tt.showToast({
  998. title: "商户信息禁用",
  999. image: './../../../assets/images/fail.png',
  1000. duration: 2000,
  1001. mask: false
  1002. });
  1003. } else if (err.code == 3000) {
  1004. tt.showToast({
  1005. title: "库存不足",
  1006. image: './../../../assets/images/fail.png',
  1007. duration: 2000,
  1008. mask: false
  1009. });
  1010. } else if (err.code == 3001) {
  1011. tt.showToast({
  1012. title: "您已超过限购",
  1013. image: './../../../assets/images/fail.png',
  1014. duration: 2000,
  1015. mask: false
  1016. });
  1017. } else if (err.code == 3002) {
  1018. tt.showToast({
  1019. title: "订单失败",
  1020. image: './../../../assets/images/fail.png',
  1021. duration: 2000,
  1022. mask: false
  1023. });
  1024. } else if (err.code == 3003) {
  1025. tt.showToast({
  1026. title: "订单不存在",
  1027. image: './../../../assets/images/fail.png',
  1028. duration: 2000,
  1029. mask: false
  1030. });
  1031. } else if (err.code == 3004) {
  1032. tt.showToast({
  1033. title: "订单不存在",
  1034. image: './../../../assets/images/fail.png',
  1035. duration: 2000,
  1036. mask: false
  1037. });
  1038. } else if (err.code == 4003) {
  1039. tt.showToast({
  1040. title: "卡券已作废",
  1041. image: './../../../assets/images/fail.png',
  1042. duration: 2000,
  1043. mask: false
  1044. });
  1045. } else if (err.code == 3012) {
  1046. that.getUnPaidOrder(that.data.couponId);
  1047. } else if (err.code == 11005) {
  1048. /**
  1049. * 将值传到用户手机号授权的页面
  1050. *
  1051. */
  1052. tt.redirectTo({
  1053. url: "/pages/getphoneInfo/index?couponChannelId=" +
  1054. that.data.couponChannelId
  1055. });
  1056. } else if (err.code == 11006) {
  1057. // 用户手机已加密
  1058. tt.redirectTo({
  1059. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  1060. that.data.couponChannelId
  1061. });
  1062. } else {
  1063. tt.showToast({
  1064. title: err.message,
  1065. icon: 'none',
  1066. duration: 2000,
  1067. mask: false
  1068. });
  1069. }
  1070. }).then(res => {
  1071. if (discount != 'discount') {
  1072. if (typeof (res) != "undefined") {
  1073. let orderId = "" + res.data.mainOrderId;
  1074. that.setData({
  1075. orderId: orderId,
  1076. composeOrderType: res.data.composeOrderType
  1077. });
  1078. if (res.data.payment > 0) {
  1079. // 支付金额不为0
  1080. /**
  1081. * 支付订单创建
  1082. */
  1083. Http.post({
  1084. url: config.api.payOrderCreate,
  1085. data: {
  1086. orderId: orderId,
  1087. composeOrderType: res.data.composeOrderType
  1088. }
  1089. }).then(res => {
  1090. var payOrderId = "" + res.data.outOrderNo;
  1091. tt.hideLoading();
  1092. tt.pay({
  1093. service: 5,
  1094. orderInfo: {
  1095. order_id: res.data.orderId,
  1096. order_token: res.data.token,
  1097. },
  1098. success: res => {
  1099. tt.showLoading({
  1100. title: '订单正在处理中...',
  1101. })
  1102. if (res.code === 0) {
  1103. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that, that.data.composeOrderType);
  1104. if (res.errMsg == "requestPayment:ok") {
  1105. /**
  1106. * 用户支付成功以后跳转到券包列表
  1107. */
  1108. if (that.data.cardType == 100) {
  1109. tt.setStorage({
  1110. key: 'couponNum2',
  1111. data: "couponNum2"
  1112. })
  1113. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  1114. tt.setStorage({
  1115. key: 'couponNum',
  1116. data: "couponNum"
  1117. })
  1118. }
  1119. }
  1120. }
  1121. else if (res.code === 1) {
  1122. that.setData({
  1123. showbutton: false
  1124. })
  1125. tt.hideLoading();
  1126. tt.showToast({
  1127. title: '支付超时', // 内容
  1128. icon: "none"
  1129. });
  1130. } else if (res.code === 2) {
  1131. that.setData({
  1132. showbutton: false
  1133. })
  1134. tt.hideLoading();
  1135. tt.showToast({
  1136. title: '支付失败', // 内容
  1137. icon: "none"
  1138. });
  1139. } else if (res.code === 3) {
  1140. that.setData({
  1141. showbutton: false
  1142. })
  1143. tt.hideLoading();
  1144. tt.showToast({
  1145. title: '支付关闭', // 内容
  1146. icon: "none"
  1147. });
  1148. } else if (res.code === 4) {
  1149. that.setData({
  1150. showbutton: false
  1151. })
  1152. tt.hideLoading();
  1153. tt.showToast({
  1154. title: '支付取消', // 内容
  1155. icon: "none"
  1156. });
  1157. } else if (res.code === 9) {
  1158. that.setData({
  1159. showbutton: false
  1160. })
  1161. tt.hideLoading();
  1162. tt.showToast({
  1163. title: '订单状态开发者自行获取', // 内容
  1164. icon: "none"
  1165. });
  1166. }
  1167. },
  1168. fail: res => {
  1169. tt.hideLoading();
  1170. /**
  1171. * 支付失败,需要更新订单的状态
  1172. */
  1173. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that, that.data.composeOrderType);
  1174. that.setData({
  1175. showbutton: false
  1176. })
  1177. return;
  1178. },
  1179. complete: res => { }
  1180. });
  1181. /// End payment --------
  1182. })
  1183. .catch(err => {
  1184. tt.hideLoading();
  1185. tt.showToast({
  1186. title: err.message,
  1187. icon: 'none',
  1188. duration: 2000,
  1189. mask: false
  1190. });
  1191. })
  1192. } else {
  1193. // 免费券
  1194. that.payOrderUpdate(orderId, "0", 1, '', 'free', that, that.data.composeOrderType);
  1195. if (that.data.cardType == 100) {
  1196. tt.setStorage({
  1197. key: 'couponNum2',
  1198. data: "couponNum2"
  1199. })
  1200. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  1201. tt.setStorage({
  1202. key: 'couponNum',
  1203. data: "couponNum"
  1204. })
  1205. }
  1206. }
  1207. }
  1208. } else {
  1209. if (res) {
  1210. tt.navigateTo({
  1211. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.mainOrderId}&composeOrderType=${res.data.composeOrderType}`,
  1212. })
  1213. }
  1214. }
  1215. })
  1216. }).catch(err => {
  1217. console.log(err)
  1218. if (err.code == 11004) {
  1219. tt.redirectTo({
  1220. url: `/pages/getuserinfo/index?fromflag=coupondetail&couponChannelIdflag=${that.data.couponChannelId}`,
  1221. })
  1222. } else {
  1223. tt.showToast({
  1224. title: err.message,
  1225. icon: "none",
  1226. duration: 2500
  1227. })
  1228. }
  1229. })
  1230. },
  1231. // 获得未支付的订单
  1232. getUnPaidOrder(couponId) {
  1233. let that = this;
  1234. Http.get({
  1235. url: config.api.getUnPaidOrder,
  1236. data: {
  1237. couponId: couponId
  1238. }
  1239. }).then(res => {
  1240. that.setData({
  1241. disOrderNumber: res.data.orderNumber,
  1242. composeOrderType: res.data.composeOrderType
  1243. })
  1244. if (res.data && res.data.pressEndDate) {
  1245. that.setData({
  1246. dispressEndDate: true
  1247. })
  1248. } else {
  1249. that.setData({
  1250. dispressEndDate: false
  1251. })
  1252. }
  1253. if (that.data.dispressEndDate) {
  1254. tt.showModal({
  1255. title: '提示',
  1256. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  1257. confirmText: "我的砍价",
  1258. success: function (res) {
  1259. if (res.confirm) {
  1260. tt.navigateTo({
  1261. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}&composeOrderType=${that.data.composeOrderType}`,
  1262. })
  1263. }
  1264. }
  1265. })
  1266. } else {
  1267. tt.showModal({
  1268. title: '提示',
  1269. content: '您有未支付订单,请先进行支付',
  1270. confirmText: "去支付",
  1271. success: function (res1) {
  1272. if (res1.confirm) {
  1273. if (that.data.composeOrderType > 0) {//券包
  1274. tt.navigateTo({
  1275. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}`,
  1276. })
  1277. } else {
  1278. tt.navigateTo({
  1279. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}`,
  1280. })
  1281. }
  1282. }
  1283. }
  1284. })
  1285. }
  1286. }).catch(error => {
  1287. tt.showToast({
  1288. title: error.message,
  1289. icon: "none",
  1290. duration: 3000
  1291. })
  1292. })
  1293. },
  1294. onShow() {
  1295. this.ifGetUser()//判断是否授权抖音
  1296. this.setData({
  1297. mouldType: app.globalData.mouldType,
  1298. showbutton: false,
  1299. showbutton1: false
  1300. })
  1301. if (this.data.end_time && this.data.activityStatus != 0) {
  1302. this.countdown(this.data.end_time)
  1303. } else if (this.data.begin_time && this.data.activityStatus == 0) {
  1304. this.countdown(this.data.begin_time)
  1305. }
  1306. },
  1307. onUnload: function () {
  1308. let that = this;
  1309. clearInterval(that.data.setInterval)
  1310. },
  1311. onHide: function () {
  1312. let that = this;
  1313. clearInterval(that.data.setInterval)
  1314. },
  1315. onShareAppMessage: function (options) {
  1316. app.globalData.previewFlag = true
  1317. var that = this;
  1318. console.log(options)
  1319. var shareObj = {
  1320. title: that.data.data.title,
  1321. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  1322. success: function (res) {
  1323. if (res.errMsg == 'shareAppMessage:ok') { }
  1324. },
  1325. fail: function (err) {
  1326. // if (err.errMsg == 'shareAppMessage:fail cancel') { } else if (err.errMsg == 'shareAppMessage:fail') { }
  1327. }
  1328. };
  1329. // 来自页面内的按钮的转发
  1330. if (options.from == 'button' && options.channel != 'video') {
  1331. var eData = options.target.dataset.id;
  1332. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  1333. } else
  1334. if (options.channel == 'video') {
  1335. // return {
  1336. // channel: 'video', // 必写 video
  1337. //     templateId: '',   // 分享的模版 id (如果未设置就是默认,下面会说如何设置)
  1338. // title: `${that.data.barTitle}`,     // 分享的标题
  1339. // desc: `${that.data.data.dyTitle}`,     // 分享的内容介绍目前没有用
  1340. //     path: `/pages/index/index`,  // 分享的路径
  1341. // extra: {
  1342. // videoTopics: [ that.data.data.dyTitle] // 只有抖音才会有的属性
  1343. // },
  1344. // }
  1345. shareObj.channel = 'video';
  1346. shareObj.title = `${that.data.data.title}`;
  1347. shareObj.extra = {
  1348. spu_id: that.data.spuIdObj.spuId
  1349. }
  1350. }
  1351. console.log(shareObj)
  1352. // 返回shareObj
  1353. return shareObj;
  1354. },
  1355. // onShareAppMessage: function(e) {
  1356. // console.log("onShareAppMessage", e);
  1357. // return {
  1358. // channel: 'video',
  1359. // title: "测试小程序分享",
  1360. // desc: "这是默认的分享文案,用户可以直接发送,也可以在发布器内修改",
  1361. // extra: {
  1362. // spu_id:"7091460633887279111" //开发者在抖音开放平台设置的商品id
  1363. // },
  1364. // success: function(e) {
  1365. // console.log("分享成功");
  1366. // },
  1367. // fail: function(e) {
  1368. // console.log(e,"分享成功失败")
  1369. // }
  1370. // };
  1371. // },
  1372. // 下拉刷新
  1373. onPullDownRefresh: function () {
  1374. this.getDetail(this.data.couponChannelId);
  1375. tt.stopPullDownRefresh()
  1376. },
  1377. onReachBottom: function () {
  1378. this.setData({
  1379. page: this.data.page + 1
  1380. })
  1381. if (this.data.idList.length > 0) {
  1382. this.getCouponList(this.data.idList)
  1383. }
  1384. }
  1385. });