抖音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.

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