抖音c端
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

720 lignes
19 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. isGetUser: true,//判断是否授权抖音
  10. mouldType: 0,
  11. navigationBarHeight,
  12. homeSelectedO: imgurl.homeSelectedO.url,
  13. isshowposter: false, //是否显示分享弹框
  14. fenxiang: imgurl.fenxiang1.url,
  15. fenxiangUrl: imgurl.fenxiang.url,
  16. clockUrl: imgurl.clock.url,
  17. yushouUrl: imgurl.yushou.url,
  18. teljpgUrl: imgurl.teljpg.url,
  19. closedUrl: imgurl.closed.url,
  20. quesGouUrl: imgurl.ques_gou.url,
  21. headbgUrl: imgurl.headbg.url,
  22. quesBgUrl: imgurl.ques_bg.url,
  23. close02: imgurl.close02.url,
  24. share01: imgurl.share01.url,
  25. fail: imgurl.fail.url,
  26. wmhome: imgurl.wmhome.url,
  27. swiperCurrent: 0,
  28. detailPicture: [],
  29. coverPicture: [],
  30. couponList: [],
  31. data: {
  32. title: null
  33. },
  34. showPage: false,
  35. questions1: null,
  36. questions2: null,
  37. carList: [],
  38. couponChannelId: null,
  39. orderId: "",
  40. hour: null,
  41. day: null,
  42. month: null,
  43. year: null,
  44. minute: "",
  45. tempFilePaths: null,
  46. userInfo: {},
  47. hasUserInfo: false,
  48. id: null,
  49. result: [],
  50. end_time: null,
  51. checked: false,
  52. questionnaire: {},
  53. questionId: null,
  54. widthScreen: null,
  55. moveData: null,
  56. rotateData: null,
  57. alphaData: null,
  58. scaleData: null,
  59. skewData: null,
  60. matrixData: null,
  61. opacity: 0,
  62. queueData: null,
  63. zIndex: 11,
  64. display: "none",
  65. showbutton: false,
  66. cardData: null,
  67. showCardOffer: false,
  68. isSamePeople: true,
  69. statusText: '',
  70. isReceived: false,
  71. receivedDisabled: false,
  72. clock: "结束",
  73. day: "00",
  74. hour: "00",
  75. min: "00",
  76. sec: "00",
  77. clock02: "00",
  78. day02: "00",
  79. hour02: "00",
  80. min02: "00",
  81. sec02: "00",
  82. countdown: "",
  83. showbutton1: false,
  84. limitCondition: "",
  85. minLimit: 0,
  86. maxLimit: 0,
  87. dispressEndDate: false,
  88. barTitle: "",
  89. activityStatus: "",
  90. //图文混排
  91. curHtml: '',
  92. contentType: 0,
  93. page: 1,//查询商户优惠券page
  94. idList: [],
  95. showBox: false,//手机号授权框
  96. },
  97. /**
  98. * 显示分享弹框
  99. */
  100. showshare: function () {
  101. this.setData({
  102. isshowposter: true,
  103. })
  104. },
  105. setPhone(paramData) {//子组件调用这个方法说明手机号已经授权成功
  106. this.setData({
  107. showBox: paramData.detail,
  108. })
  109. tt.showToast({
  110. title: '授权成功', // 内容
  111. icon: 'none', // 图标
  112. success: (res) => {
  113. },
  114. fail: (res) => {
  115. },
  116. });
  117. },
  118. setBox(paramData) {
  119. this.setData({
  120. showBox: paramData.detail
  121. })
  122. tt.showToast({
  123. title: '取消授权', // 内容
  124. icon: 'none', // 图标
  125. success: (res) => {
  126. },
  127. fail: (res) => {
  128. },
  129. });
  130. },
  131. /**
  132. * 隐藏分享弹框
  133. */
  134. hidemodal: function () {
  135. this.setData({
  136. isshowposter: false,
  137. })
  138. },
  139. /**
  140. * 显示分享海报
  141. */
  142. /* showPoster: function() {
  143. //跳转到海报生成页
  144. console.log(this.data.canIUse)
  145. // return;
  146. tt.navigateTo({
  147. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  148. })
  149. }, */
  150. showPoster: function () {
  151. //跳转到海报生成页
  152. let that = this;
  153. Http.get({
  154. url: config.api.checkUserStatus,
  155. data: {
  156. token: app.globalData.token
  157. }
  158. }).then(res => {
  159. tt.navigateTo({
  160. url: `/pages/canvas/index?couponChannelId=${that.data.data.id}`
  161. })
  162. }).catch(err => {
  163. console.log(err)
  164. if (err.code == 11004) {
  165. // 用户昵称未授权
  166. tt.redirectTo({
  167. url: `/pages/getuserinfo/index?couponChannelId=${that.data.data.id}&fromflag=poster`
  168. })
  169. }
  170. })
  171. },
  172. swiperChange: function (e) {
  173. this.setData({
  174. swiperCurrent: e.detail.current
  175. });
  176. },
  177. gohome(e) {
  178. console.log(e.currentTarget.dataset.id, "123")
  179. tt.navigateTo({
  180. url: `/pages/fillIndent/fillIndent?couponChannelId=${e.currentTarget.dataset.couponchannelid}&couponId=${e.currentTarget.dataset.couponid}&shippingtype=${e.currentTarget.dataset.shippingtype}`,
  181. })
  182. },
  183. gochild(e) {
  184. let id = e.currentTarget.dataset.id
  185. tt.navigateTo({
  186. url: `/pages/coupon/childDetail/childDetail?couponIds=${id}`,
  187. })
  188. },
  189. //获取当前登录用户信息
  190. getUserInfo: function () {
  191. let that = this;
  192. // 获取用户信息
  193. Http.get({
  194. url: config.api.getScore,
  195. data: {}
  196. })
  197. .then(res => {
  198. console.log(res)
  199. that.getQueryCardStatus()
  200. if (that.data.cardData.cuserId != res.data.id) {
  201. console.log(2222, 6666)
  202. that.setData({
  203. isSamePeople: false
  204. })
  205. }
  206. })
  207. },
  208. //获取卡转赠状态
  209. getQueryCardStatus() {
  210. let that = this;
  211. let param = {
  212. id: this.data.cardData.couponOrderId,
  213. cUserId: this.data.cardData.cuserId,
  214. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  215. }
  216. Http.get({
  217. url: config.api.queryCardStatus,
  218. data: param
  219. })
  220. .then(res => {
  221. console.log(res, 333333333333)
  222. })
  223. .catch(err => {
  224. that.setData({
  225. isReceived: true,
  226. statusText: err.message
  227. })
  228. })
  229. },
  230. receiveCard() {
  231. let that = this;
  232. let param = {
  233. id: this.data.cardData.couponOrderId,
  234. cUserId: this.data.cardData.cuserId,
  235. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  236. }
  237. this.setData({
  238. receivedDisabled: true
  239. })
  240. Http.post({
  241. url: config.api.cardAccept,
  242. data: param
  243. })
  244. .then(res => {
  245. tt.showToast({
  246. title: '领取成功!',
  247. icon: 'none',
  248. duration: 2000,
  249. mask: false
  250. });
  251. tt.reLaunch({
  252. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  253. })
  254. })
  255. .catch(err => {
  256. tt.showToast({
  257. title: err.message,
  258. icon: 'none',
  259. duration: 2000,
  260. mask: false
  261. });
  262. that.setData({
  263. receivedDisabled: false
  264. })
  265. })
  266. },
  267. closeAlert() {
  268. this.setData({
  269. showCardOffer: false
  270. })
  271. },
  272. goback: function () {
  273. tt.reLaunch({
  274. url: '/index/index',
  275. })
  276. },
  277. /**
  278. * 点击提交问题单选
  279. */
  280. formSubmit: function (e) {
  281. console.log(e);
  282. let that = this;
  283. /**
  284. * 多选
  285. */
  286. if (e.currentTarget.dataset.flags == 'multi') {
  287. if (that.data.anwserId.length == 0) {
  288. var answserIs = null
  289. } else {
  290. var answserIs = that.data.anwserId.join(",");
  291. }
  292. } else if (e.currentTarget.dataset.flags == 'single') {
  293. var answserIs = e.detail.value;
  294. }
  295. console.log(answserIs)
  296. console.log(e.currentTarget.dataset.questionid)
  297. Http.post({
  298. url: config.api.answerQuestion,
  299. data: {
  300. answer: answserIs,
  301. questionId: e.currentTarget.dataset.questionid
  302. }
  303. })
  304. .then(res => {
  305. that.closeQuestion();
  306. })
  307. .catch(err => {
  308. tt.showToast({
  309. title: err.message,
  310. icon: 'none',
  311. duration: 2000,
  312. mask: false
  313. });
  314. })
  315. },
  316. /**
  317. * 多选
  318. */
  319. checkboxChange: function (e) {
  320. console.log(e)
  321. this.setData({
  322. anwserId: e.detail.value
  323. })
  324. },
  325. closeQuestion: function () {
  326. let that = this;
  327. that.setData({
  328. display: "none",
  329. zIndex: 11,
  330. opacity: 0
  331. })
  332. setTimeout(function () {
  333. that.orderFunc();
  334. }, 500)
  335. },
  336. ifGetUser() {
  337. Http.get({
  338. url: config.api.checkUserStatus,
  339. data: {
  340. token: app.globalData.token
  341. }
  342. }).then(res => {
  343. }).catch(err => {
  344. if (err.code == 11004) {
  345. this.setData({
  346. isGetUser: false
  347. })
  348. }
  349. })
  350. },
  351. setIntervalTime(end_time) {
  352. let that = this;
  353. var EndTime = end_time;
  354. var NowTime = new Date().getTime();
  355. var total_micro_second = EndTime - NowTime || [];
  356. // 渲染倒计时时钟
  357. let obj = that.dateformat(total_micro_second);
  358. if (total_micro_second > 0) {
  359. that.setData({
  360. clock: obj,
  361. day: obj.a1,
  362. hour: obj.b1,
  363. min: obj.c1,
  364. sec: obj.d1,
  365. })
  366. } else {
  367. that.setData({
  368. clock: "00",
  369. day: "00",
  370. hour: "00",
  371. min: "00",
  372. sec: "00",
  373. })
  374. //如果倒计时结束,需要重新查询一下券的状态
  375. // 给getDetail一个标识
  376. that.getDetail(that.data.id, 'endclock');
  377. }
  378. total_micro_second -= 1000;
  379. },
  380. countdown: function (end_time) {
  381. let that = this;
  382. that.setIntervalTime(end_time);
  383. that.data.setInterval = setInterval(function () {
  384. that.setIntervalTime(end_time);
  385. }, 1000)
  386. },
  387. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  388. dateformat(micro_second) {
  389. // 总秒数
  390. var second = Math.floor(micro_second / 1000);
  391. // 天数
  392. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  393. // 小时
  394. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  395. // 分钟
  396. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  397. // 秒
  398. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  399. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  400. return {
  401. a1: day,
  402. b1: hr,
  403. c1: min,
  404. d1: sec
  405. }
  406. },
  407. /**
  408. * 获取用户信息
  409. */
  410. onLoad(options) {
  411. console.log(options);
  412. this.setData({
  413. mouldType: app.globalData.mouldType,
  414. })
  415. let that = this;
  416. if (options.g) {
  417. app.globalData.havePlayEd1 = true;
  418. }
  419. tt.showLoading({
  420. title: "加载中..."
  421. });
  422. that.setData({
  423. onshow: false
  424. })
  425. if (options && (options.id || options.couponIds)) {
  426. that.getDetail(options.id, 'notendclock');
  427. }
  428. that.setData({
  429. couponChannelId: options.id,
  430. });
  431. },
  432. getHtml(couponChannelId) {
  433. Http.get({
  434. url: config.api.couponHtmlDetail,
  435. data: {
  436. couponChannelId: couponChannelId
  437. }
  438. }).then(res => {
  439. console.log(res)
  440. if (res.code == 200 && res.data.html) {
  441. this.setData({
  442. curHtml: decodeURI(res.data.html)
  443. })
  444. app.globalData.curHtml = this.data.curHtml;
  445. console.log(app.globalData.curHtml)
  446. }
  447. })
  448. },
  449. getDetail: function (couponChannelId, flag) {
  450. let that = this;
  451. var parmer = {
  452. url: config.api.getSnapshot,
  453. data: {orderId:couponChannelId}
  454. };
  455. Http.get(parmer)
  456. .then(res => {
  457. //aaa
  458. if (res.data.contentType != undefined && res.data.contentType == 1) {
  459. //获取图文展示详情html
  460. this.setData({
  461. contentType: res.data.contentType
  462. })
  463. this.getHtml(couponChannelId);
  464. }
  465. that.setData({
  466. couponId: res.data.couponId
  467. })
  468. that.setData({
  469. showPage: true
  470. })
  471. if (res && res.data && res.data.detailPicture) {
  472. that.setData({
  473. detailPicture: JSON.parse(res.data.detailPicture)
  474. })
  475. }
  476. if (res && res.data && res.data.coverPicture) {
  477. that.setData({
  478. coverPicture: JSON.parse(res.data.coverPicture)
  479. })
  480. }
  481. if (res && res.data && res.data.conditions) {
  482. that.setData({
  483. limitCondition: JSON.parse(res.data.conditions).type
  484. })
  485. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  486. that.setData({
  487. minLimit: JSON.parse(res.data.conditions).min
  488. })
  489. }
  490. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  491. that.setData({
  492. maxLimit: JSON.parse(res.data.conditions).max
  493. })
  494. }
  495. }
  496. /**
  497. * 将优惠券优惠卡的详情的BarTitle
  498. * 设置成券的名称
  499. */
  500. // tt.setNavigationBarTitle({
  501. // title: res.data.title
  502. // })
  503. that.setData({
  504. barTitle: res.data.title
  505. })
  506. var EndTime = res.data.validStartDate;
  507. var NowTime = new Date().getTime();
  508. /**
  509. * activityStatus==0 活动未开始
  510. * activityStatus==1 活动已开始
  511. * flag == endclock 说明倒计时已经结束
  512. */
  513. if (res.data.endTime && res.data.beginTime) {
  514. that.setData({
  515. begin_time: res.data.beginTime,
  516. end_time: res.data.endTime,
  517. activityStatus: res.data.activityStatus ? res.data.activityStatus : ''
  518. })
  519. if (res.data.activityStatus == 0 && flag != 'endclock') {
  520. that.countdown(res.data.beginTime);
  521. } else if (res.data.activityStatus != 0 && flag != 'endclock') {
  522. that.countdown(res.data.endTime);
  523. } else {
  524. clearInterval(that.data.setInterval)
  525. }
  526. if (res.data.activityStatus == 0) {
  527. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  528. if (util.timechuo(beginTime).indexOf('-') == 0) {
  529. that.setData({
  530. beginTime: "活动已结束",
  531. });
  532. } else {
  533. that.setData({
  534. beginTime: util.timechuo(beginTime)
  535. });
  536. }
  537. } else {
  538. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  539. if (util.timechuo(endTime).indexOf('-') == 0) {
  540. that.setData({
  541. endtime: "活动已结束",
  542. });
  543. } else {
  544. that.setData({
  545. endtime: util.timechuo(endTime)
  546. });
  547. }
  548. }
  549. }
  550. tt.hideLoading();
  551. that.setData({
  552. data: res.data,
  553. merchantVoList: res.data.merchantVoList
  554. });
  555. if (res.data.type == 10) {
  556. that.setData({
  557. salePriceStr: res.data.salePriceStr,
  558. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  559. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  560. priceStr: res.data.priceStr,
  561. tailPriceStr: res.data.tailPriceStr,
  562. origPriceStr: res.data.origPriceStr
  563. })
  564. }
  565. if (res.data.validType == 1) {
  566. that.setData({
  567. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  568. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  569. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  570. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  571. });
  572. } else {
  573. if (res.data.validDays) {
  574. that.setData({
  575. validDays: res.data.validDays
  576. });
  577. }
  578. }
  579. if(res.data.itemGroup){
  580. let tempObj = that.data.data
  581. tempObj.itemGroup = JSON.parse(tempObj.itemGroup)
  582. that.setData({
  583. data:tempObj
  584. })
  585. console.log(that.data.data,"data");
  586. }
  587. if (res.data.productAttrs && res.data.skuAttrs) {
  588. let tempObj = that.data.data
  589. tempObj.productAttrs = JSON.parse(tempObj.productAttrs)
  590. tempObj.skuAttrs = JSON.parse(tempObj.skuAttrs)
  591. tempObj.productAttrs.map(item => {
  592. if (item.key == "appointment") {
  593. let tempAppoinObj = JSON.parse(item.data)
  594. if (tempAppoinObj.need_appointment) {
  595. let subscribeSing = "";
  596. if (tempAppoinObj.ahead_time_type == 1) {
  597. subscribeSing = `需提前${tempAppoinObj.ahead_day_num}天致电商家预约`
  598. } else if (tempAppoinObj.ahead_time_type == 2) {
  599. subscribeSing = `需提前${tempAppoinObj.ahead_hour_num}小时致电商家预约`
  600. } else if (tempAppoinObj.ahead_time_type == 3) {
  601. subscribeSing = `需提前${tempAppoinObj.ahead_minute_num}分钟致电商家预约`
  602. }
  603. tempObj.subscribeSing = subscribeSing
  604. }
  605. }
  606. if (item.key == "Notification") {
  607. if (item.data != '') {
  608. tempObj.curLsit = JSON.parse(item.data)
  609. }
  610. }
  611. if (item.key == "bring_out_meal") {
  612. tempObj.besides = item.data
  613. }
  614. if (item.key == "free_pack") {
  615. tempObj.pack = item.data
  616. }
  617. if (item.key == "superimposed_discounts") {
  618. tempObj.superimposed_discounts = item.data
  619. }
  620. if (item.key == "private_room") {
  621. tempObj.private_room = item.data
  622. }
  623. if (item.key == "rec_person_num_max") {
  624. tempObj.rec_person_num_max = item.data
  625. }
  626. if (item.key == 'Description') {
  627. tempObj.Description = JSON.parse(item.data)
  628. }
  629. if (item.key == "can_no_use_date") {
  630. tempObj.can_no_use_date = JSON.parse(item.data)
  631. }
  632. })
  633. tempObj.skuAttrs.map(item => {
  634. if (item.key == "commodity") {
  635. if (item.data != '') {
  636. tempObj.itemGroup = JSON.parse(item.data)
  637. }
  638. }
  639. })
  640. this.setData({
  641. data: tempObj
  642. })
  643. }
  644. }).catch(err => {
  645. tt.showToast({
  646. title: err.message,
  647. icon: 'none',
  648. duration: 2000,
  649. mask: false
  650. });
  651. })
  652. },
  653. onShow() {
  654. this.ifGetUser()//判断是否授权抖音
  655. this.setData({
  656. mouldType: app.globalData.mouldType,
  657. showbutton: false,
  658. showbutton1: false
  659. })
  660. if (this.data.end_time && this.data.activityStatus != 0) {
  661. this.countdown(this.data.end_time)
  662. } else if (this.data.begin_time && this.data.activityStatus == 0) {
  663. this.countdown(this.data.begin_time)
  664. }
  665. },
  666. onUnload: function () {
  667. let that = this;
  668. clearInterval(that.data.setInterval)
  669. },
  670. onHide: function () {
  671. let that = this;
  672. clearInterval(that.data.setInterval)
  673. },
  674. // 下拉刷新
  675. onPullDownRefresh: function () {
  676. this.getDetail(this.data.couponChannelId);
  677. tt.stopPullDownRefresh()
  678. },
  679. onReachBottom: function () {
  680. this.setData({
  681. page: this.data.page + 1
  682. })
  683. }
  684. });