抖音c端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1192 rindas
32 KiB

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