抖音c端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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