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

1216 lines
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. console.log(curHtml, 'curHtml')
  593. var temp = ttParse.wxParse('article', 'html', curHtml, that, 5);
  594. app.globalData.curHtml = this.data.curHtml;
  595. }
  596. })
  597. },
  598. getSupId(id) {
  599. Http.get({
  600. url: config.api.getSpuid,
  601. data: {
  602. id: id,
  603. mallTenantId: this.data.mallTenantId || ''
  604. }
  605. }).then(res => {
  606. if (res.data) {
  607. this.setData({
  608. spuIdObj: res.data,
  609. goodId: res.data.spuId
  610. })
  611. }
  612. }).catch(err => {
  613. // tt.showToast({
  614. // title: err.message,
  615. // icon: 'none',
  616. // duration: 2000,
  617. // mask: false
  618. // });
  619. })
  620. },
  621. getCouponPriceAndStock(couponChannelId) { //获取券价格与库存
  622. Http.get({
  623. url: config.api.couponPriceAndStock,
  624. data: {
  625. couponChannelId,
  626. mallTenantId: this.data.mallTenantId || ''
  627. }
  628. }).then(res => {
  629. let tempBoj = JSON.parse(res.data)
  630. console.log(tempBoj, "$");
  631. this.setData({
  632. priceAndStockObj: tempBoj
  633. })
  634. })
  635. },
  636. getCouponMerchant(couponChannelId) { //获取适用门店
  637. Http.get({
  638. url: config.api.couponMerchant,
  639. data: {
  640. couponChannelId: couponChannelId,
  641. mallTenantId: this.data.mallTenantId || ''
  642. }
  643. }).then(res => {
  644. const keys = Object.keys(res.data)
  645. const mallList = []
  646. let i = 0
  647. keys.forEach(item => {
  648. const arr = item.split('|')
  649. const obj = {
  650. tenantId: arr[0],
  651. mallName: arr[1],
  652. merchantVoList: res.data[item],
  653. expand: false
  654. }
  655. if (i == 0) {
  656. obj.expand = true
  657. }
  658. mallList.push(obj)
  659. i++
  660. })
  661. this.setData({
  662. mallList: mallList
  663. })
  664. })
  665. },
  666. getDetail: function (couponChannelId, flag) {
  667. let that = this;
  668. let data = {};
  669. that.getCouponMerchant(couponChannelId); //获取适用门店
  670. that.getCouponPriceAndStock(couponChannelId); //获取券价格和库存
  671. if (that.data.couponIds) {
  672. data.couponId = couponChannelId
  673. } else {
  674. data.couponChannelId = couponChannelId
  675. }
  676. if (that.data.mallTenantId) {
  677. data.mallTenantId = that.data.mallTenantId
  678. }
  679. var parmer = {
  680. url: config.api.newCouponDetail,
  681. data: data
  682. };
  683. Http.get(parmer)
  684. .then(res => {
  685. //aaa
  686. if (res.data.contentType != undefined && res.data.contentType == 1) {
  687. //获取图文展示详情html
  688. this.setData({
  689. contentType: res.data.contentType
  690. })
  691. this.getHtml(couponChannelId);
  692. }
  693. that.setData({
  694. couponId: res.data.couponId
  695. })
  696. that.setData({
  697. showPage: true
  698. })
  699. if (res && res.data && res.data.detailPicture) {
  700. that.setData({
  701. detailPicture: JSON.parse(res.data.detailPicture)
  702. })
  703. }
  704. if (res && res.data && res.data.coverPicture) {
  705. that.setData({
  706. coverPicture: JSON.parse(res.data.coverPicture)
  707. })
  708. }
  709. if (res && res.data && res.data.conditions) {
  710. that.setData({
  711. limitCondition: JSON.parse(res.data.conditions).type
  712. })
  713. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  714. that.setData({
  715. minLimit: JSON.parse(res.data.conditions).min
  716. })
  717. }
  718. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  719. that.setData({
  720. maxLimit: JSON.parse(res.data.conditions).max
  721. })
  722. }
  723. }
  724. /**
  725. * 将优惠券优惠卡的详情的BarTitle
  726. * 设置成券的名称
  727. */
  728. // tt.setNavigationBarTitle({
  729. // title: res.data.title
  730. // })
  731. that.setData({
  732. barTitle: res.data.title
  733. })
  734. tt.setNavigationBarTitle({
  735. title: res.data.title,
  736. success() {
  737. console.log("setNavigationBarTitle 调用成功");
  738. },
  739. fail(res) {
  740. console.log(`setNavigationBarTitle 调用失败:`, res.errMsg);
  741. },
  742. });
  743. var EndTime = res.data.validStartDate;
  744. var NowTime = new Date().getTime();
  745. /**
  746. * activityStatus==0 活动未开始
  747. * activityStatus==1 活动已开始
  748. * flag == endclock 说明倒计时已经结束
  749. */
  750. if (res.data.endTime && res.data.beginTime) {
  751. that.setData({
  752. begin_time: res.data.beginTime,
  753. end_time: res.data.endTime,
  754. activityStatus: res.data.actStatus ? res.data.actStatus : ''
  755. })
  756. if (res.data.actStatus == 0 && flag != 'endclock') {
  757. that.countdown(res.data.beginTime);
  758. } else if (res.data.actStatus != 0 && flag != 'endclock') {
  759. that.countdown(res.data.endTime);
  760. } else {
  761. clearInterval(that.data.setInterval)
  762. }
  763. if (res.data.actStatus == 0) {
  764. var beginTime = util.timestampToTime(res.data.beginTime, "YYYY-MM-DD hh:mm:ss");
  765. if (util.timechuo(beginTime).indexOf('-') == 0) {
  766. that.setData({
  767. beginTime: "活动已结束",
  768. });
  769. } else {
  770. that.setData({
  771. beginTime: util.timechuo(beginTime)
  772. });
  773. }
  774. } else {
  775. var endTime = util.timestampToTime(res.data.endTime, "YYYY-MM-DD hh:mm:ss");
  776. if (util.timechuo(endTime).indexOf('-') == 0) {
  777. that.setData({
  778. endtime: "活动已结束",
  779. });
  780. } else {
  781. that.setData({
  782. endtime: util.timechuo(endTime)
  783. });
  784. }
  785. }
  786. }
  787. tt.hideLoading();
  788. that.setData({
  789. data: res.data,
  790. });
  791. if (res.data.type == 10) {
  792. that.setData({
  793. salePriceStr: res.data.salePriceStr,
  794. pickEndDate: util.timestampToTime(res.data.pickEndDate, "YYYY-MM-DD"),
  795. pickStartDate: util.timestampToTime(res.data.pickStartDate, "YYYY-MM-DD"),
  796. priceStr: res.data.priceStr,
  797. tailPriceStr: res.data.tailPriceStr,
  798. origPriceStr: res.data.origPriceStr
  799. })
  800. }
  801. if (res.data.validType == 1) {
  802. that.setData({
  803. soldStartTime: util.timestampToTime(res.data.soldStartTime, "YYYY-MM-DD") || null,
  804. soldEndTime: util.timestampToTime(res.data.soldEndTime, "YYYY-MM-DD") || null,
  805. validStartDate: util.timestampToTime(res.data.validStartDate, "YYYY-MM-DD"),
  806. validEndDate: util.timestampToTime(res.data.validEndDate, "YYYY-MM-DD"),
  807. pickStartDate: util.timestampToTime(res.data.pickStartDate, "YYYY-MM-DD"),
  808. pickEndDate: util.timestampToTime(res.data.pickEndDate, "YYYY-MM-DD"),
  809. });
  810. } else {
  811. if (res.data.validDays) {
  812. that.setData({
  813. validDays: res.data.validDays
  814. });
  815. }
  816. }
  817. if (res.data.itemGroup) {
  818. let tempObj = this.data.data
  819. tempObj.itemGroup = JSON.parse(tempObj.itemGroup)
  820. this.setData({
  821. data: tempObj
  822. })
  823. console.log(this.data.data, "data");
  824. }
  825. if (res.data.productAttrs && res.data.skuAttrs) {
  826. let tempObj = this.data.data
  827. tempObj.productAttrs = JSON.parse(tempObj.productAttrs)
  828. tempObj.skuAttrs = JSON.parse(tempObj.skuAttrs)
  829. tempObj.productAttrs.map(item => {
  830. if (item.key == "appointment") {
  831. let tempAppoinObj = JSON.parse(item.data)
  832. if (tempAppoinObj.need_appointment) {
  833. let subscribeSing = "";
  834. if (tempAppoinObj.ahead_time_type == 1) {
  835. subscribeSing = `需提前${tempAppoinObj.ahead_day_num}天预约`
  836. } else if (tempAppoinObj.ahead_time_type == 2) {
  837. subscribeSing = `需提前${tempAppoinObj.ahead_hour_num}小时预约`
  838. } else if (tempAppoinObj.ahead_time_type == 3) {
  839. subscribeSing = `需提前${tempAppoinObj.ahead_minute_num}分钟预约`
  840. }
  841. tempObj.subscribeSing = subscribeSing
  842. }
  843. }
  844. if (item.key == "limit_use_rule") {
  845. console.log(item, 'item');
  846. if (item.data != '') {
  847. let tempAppoinObj = JSON.parse(item.data)
  848. that.setData({
  849. use_num_per_consume: tempAppoinObj.use_num_per_consume || ""
  850. })
  851. }
  852. }
  853. if (item.key == "Notification") {
  854. if (item.data != '') {
  855. tempObj.curLsit = JSON.parse(item.data)
  856. }
  857. }
  858. if (item.key == "bring_out_meal") {
  859. tempObj.besides = item.data
  860. }
  861. if (item.key == "free_pack") {
  862. tempObj.pack = item.data
  863. }
  864. if (item.key == "superimposed_discounts") {
  865. tempObj.superimposed_discounts = item.data
  866. }
  867. if (item.key == "private_room") {
  868. tempObj.private_room = item.data
  869. }
  870. if (item.key == "rec_person_num_max") {
  871. tempObj.rec_person_num_max = item.data
  872. }
  873. if (item.key == 'Description' && item.isRequired) {
  874. tempObj.Description = JSON.parse(item.data)
  875. }
  876. if (item.key == "can_no_use_date") {
  877. tempObj.can_no_use_date = JSON.parse(item.data)
  878. }
  879. })
  880. tempObj.skuAttrs.map(item => {
  881. if (item.key == "commodity" && item.data) {
  882. tempObj.itemGroup = JSON.parse(item.data)
  883. }
  884. })
  885. this.setData({
  886. data: tempObj
  887. })
  888. console.log(this.data.data, "data");
  889. const mallTenantId = this.data.data.tenantId
  890. tt.setStorageSync('mallTenantId', mallTenantId)
  891. }
  892. }).catch(err => {
  893. console.log(err, 'err');
  894. tt.showToast({
  895. title: err.message,
  896. icon: 'none',
  897. duration: 2000,
  898. mask: false
  899. });
  900. })
  901. },
  902. /**
  903. * 邀请好友继续砍价
  904. */
  905. inviteFriend: function (e) {
  906. let that = this;
  907. let formId = e.detail.formId;
  908. that.setData({
  909. formId: formId,
  910. showbutton1: true
  911. })
  912. that.orderFunc("discount");
  913. },
  914. /**
  915. * 支付订单更新
  916. */
  917. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this, composeOrderType) => {
  918. let that = this;
  919. // 支付成功
  920. Http.post({
  921. url: config.api.payOrderUpdate,
  922. data: {
  923. payOrderId: payOrderId,
  924. composeOrderId: orderId,
  925. status: status,
  926. reason: reason,
  927. mallTenantId: this.data.mallTenantId || ''
  928. }
  929. })
  930. .then(res => {
  931. tt.hideLoading()
  932. // 有价券
  933. if (!type && type != 'free') {
  934. tt.navigateTo({
  935. url: `/pages/order/detail/index?orderId=${orderId
  936. }`
  937. });
  938. } else if (type == 'free') {
  939. tt.navigateTo({
  940. url: `/pages/order/detail/index?orderId=${orderId
  941. }`
  942. });
  943. }
  944. })
  945. .catch(err => {
  946. console.log(err);
  947. if (!type) {
  948. setTimeout(function () {
  949. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  950. }, 2000)
  951. }
  952. })
  953. },
  954. checkPhoneStatus: function () {
  955. let that = this;
  956. Http.get({
  957. url: config.api.checkPhoneStatus,
  958. data: {}
  959. })
  960. .then(res => {
  961. console.log(666, '授权成功!')
  962. that.receiveCard()
  963. })
  964. .catch(err => {
  965. if (err.code == 11005) {
  966. /**
  967. * 手机号没有授权,将值传到用户手机号授权的页面
  968. *
  969. */
  970. tt.redirectTo({
  971. 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
  972. });
  973. } else if (err.code == 11006) {
  974. // 用户手机已加密
  975. tt.redirectTo({
  976. 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,
  977. });
  978. } else {
  979. tt.showToast({
  980. title: err.message,
  981. icon: 'none',
  982. duration: 2000,
  983. mask: false
  984. });
  985. }
  986. })
  987. },
  988. // 券包支付
  989. /**
  990. * 发起支付
  991. */
  992. orderFunc(discount) {
  993. const merOrderId = this.data.couponChannelId
  994. tt.navigateTo({
  995. url: `/pages/coupon/confirmation/confirmation?couponChannelId=${this.data.couponChannelId}&mallTenantId=${this.data.mallTenantId}&merOrderId=${merOrderId}`,
  996. })
  997. // return
  998. },
  999. // 获得未支付的订单
  1000. getUnPaidOrder(couponId) {
  1001. let that = this;
  1002. Http.get({
  1003. url: config.api.getUnPaidOrder,
  1004. data: {
  1005. couponId: couponId
  1006. }
  1007. }).then(res => {
  1008. that.setData({
  1009. disOrderNumber: res.data.orderNumber,
  1010. composeOrderType: res.data.composeOrderType
  1011. })
  1012. if (res.data && res.data.pressEndDate) {
  1013. that.setData({
  1014. dispressEndDate: true
  1015. })
  1016. } else {
  1017. that.setData({
  1018. dispressEndDate: false
  1019. })
  1020. }
  1021. if (that.data.dispressEndDate) {
  1022. tt.showModal({
  1023. title: '提示',
  1024. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  1025. confirmText: "我的砍价",
  1026. success: function (res) {
  1027. if (res.confirm) {
  1028. tt.navigateTo({
  1029. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}&composeOrderType=${that.data.composeOrderType}`,
  1030. })
  1031. }
  1032. }
  1033. })
  1034. } else {
  1035. tt.showModal({
  1036. title: '提示',
  1037. content: '您有未支付订单,请先进行支付',
  1038. confirmText: "去支付",
  1039. success: function (res1) {
  1040. if (res1.confirm) {
  1041. if (that.data.composeOrderType > 0) { //券包
  1042. tt.navigateTo({
  1043. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}`,
  1044. })
  1045. } else {
  1046. tt.navigateTo({
  1047. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}`,
  1048. })
  1049. }
  1050. }
  1051. }
  1052. })
  1053. }
  1054. }).catch(error => {
  1055. tt.showToast({
  1056. title: error.message,
  1057. icon: "none",
  1058. duration: 3000
  1059. })
  1060. })
  1061. },
  1062. onShow() {
  1063. this.ifGetUser() //判断是否授权抖音
  1064. this.getIm()
  1065. this.setData({
  1066. mouldType: app.globalData.mouldType,
  1067. showbutton: false,
  1068. showbutton1: false
  1069. })
  1070. if (this.data.end_time && this.data.activityStatus != 0) {
  1071. this.countdown(this.data.end_time)
  1072. } else if (this.data.begin_time && this.data.activityStatus == 0) {
  1073. this.countdown(this.data.begin_time)
  1074. }
  1075. },
  1076. onUnload: function () {
  1077. let that = this;
  1078. clearInterval(that.data.setInterval)
  1079. },
  1080. onHide: function () {
  1081. let that = this;
  1082. clearInterval(that.data.setInterval)
  1083. },
  1084. onShareAppMessage: function (options) {
  1085. app.globalData.previewFlag = true
  1086. var that = this;
  1087. console.log(options)
  1088. var shareObj = {
  1089. title: that.data.data.title,
  1090. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  1091. success: function (res) {
  1092. if (res.errMsg == 'shareAppMessage:ok') {}
  1093. },
  1094. fail: function (err) {
  1095. // if (err.errMsg == 'shareAppMessage:fail cancel') { } else if (err.errMsg == 'shareAppMessage:fail') { }
  1096. }
  1097. };
  1098. // 来自页面内的按钮的转发
  1099. if (options.from == 'button' && options.channel != 'video') {
  1100. var eData = options.target.dataset.id;
  1101. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  1102. } else
  1103. if (options.channel == 'video') {
  1104. // return {
  1105. // channel: 'video', // 必写 video
  1106. //     templateId: '',   // 分享的模版 id (如果未设置就是默认,下面会说如何设置)
  1107. // title: `${that.data.barTitle}`,     // 分享的标题
  1108. // desc: `${that.data.data.dyTitle}`,     // 分享的内容介绍目前没有用
  1109. //     path: `/pages/index/index`,  // 分享的路径
  1110. // extra: {
  1111. // videoTopics: [ that.data.data.dyTitle] // 只有抖音才会有的属性
  1112. // },
  1113. // }
  1114. shareObj.channel = 'video';
  1115. shareObj.title = `${that.data.data.title}`;
  1116. shareObj.extra = {
  1117. spu_id: that.data.spuIdObj.spuId
  1118. }
  1119. }
  1120. console.log(shareObj)
  1121. // 返回shareObj
  1122. return shareObj;
  1123. },
  1124. // onShareAppMessage: function(e) {
  1125. // console.log("onShareAppMessage", e);
  1126. // return {
  1127. // channel: 'video',
  1128. // title: "测试小程序分享",
  1129. // desc: "这是默认的分享文案,用户可以直接发送,也可以在发布器内修改",
  1130. // extra: {
  1131. // spu_id:"7091460633887279111" //开发者在抖音开放平台设置的商品id
  1132. // },
  1133. // success: function(e) {
  1134. // console.log("分享成功");
  1135. // },
  1136. // fail: function(e) {
  1137. // console.log(e,"分享成功失败")
  1138. // }
  1139. // };
  1140. // },
  1141. // 下拉刷新
  1142. onPullDownRefresh: function () {
  1143. this.getDetail(this.data.couponChannelId);
  1144. tt.stopPullDownRefresh()
  1145. },
  1146. onReachBottom: function () {
  1147. this.setData({
  1148. page: this.data.page + 1
  1149. })
  1150. if (this.data.idList.length > 0) {
  1151. this.getCouponList(this.data.idList)
  1152. }
  1153. }
  1154. });