抖音c端
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

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