抖音c端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

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