抖音c端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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