抖音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.

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