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

1113 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. },
  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}`,
  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);
  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. }
  809. }).catch(err => {
  810. tt.showToast({
  811. title: err.message,
  812. icon: 'none',
  813. duration: 2000,
  814. mask: false
  815. });
  816. })
  817. },
  818. /**
  819. * 邀请好友继续砍价
  820. */
  821. inviteFriend: function (e) {
  822. let that = this;
  823. let formId = e.detail.formId;
  824. that.setData({
  825. formId: formId,
  826. showbutton1: true
  827. })
  828. that.orderFunc("discount");
  829. },
  830. /**
  831. * 支付订单更新
  832. */
  833. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this, composeOrderType) => {
  834. let that = this;
  835. // 支付成功
  836. Http.post({
  837. url: config.api.payOrderUpdate,
  838. data: {
  839. payOrderId: payOrderId,
  840. composeOrderId: orderId,
  841. status: status,
  842. reason: reason
  843. }
  844. })
  845. .then(res => {
  846. tt.hideLoading()
  847. // 有价券
  848. if (!type && type != 'free') {
  849. tt.navigateTo({
  850. url: `/pages/order/detail/index?orderId=${orderId
  851. }`
  852. });
  853. } else if (type == 'free') {
  854. tt.navigateTo({
  855. url: `/pages/order/detail/index?orderId=${orderId
  856. }`
  857. });
  858. }
  859. })
  860. .catch(err => {
  861. console.log(err);
  862. if (!type) {
  863. setTimeout(function () {
  864. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  865. }, 2000)
  866. }
  867. })
  868. },
  869. checkPhoneStatus: function () {
  870. let that = this;
  871. Http.get({
  872. url: config.api.checkPhoneStatus,
  873. data: {}
  874. })
  875. .then(res => {
  876. console.log(666, '授权成功!')
  877. that.receiveCard()
  878. })
  879. .catch(err => {
  880. if (err.code == 11005) {
  881. /**
  882. * 手机号没有授权,将值传到用户手机号授权的页面
  883. *
  884. */
  885. tt.redirectTo({
  886. 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,
  887. });
  888. } else if (err.code == 11006) {
  889. // 用户手机已加密
  890. tt.redirectTo({
  891. 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,
  892. });
  893. } else {
  894. tt.showToast({
  895. title: err.message,
  896. icon: 'none',
  897. duration: 2000,
  898. mask: false
  899. });
  900. }
  901. })
  902. },
  903. // 券包支付
  904. /**
  905. * 发起支付
  906. */
  907. orderFunc(discount) {
  908. tt.navigateTo({
  909. url: `/pages/coupon/confirmation/confirmation?couponChannelId=${this.data.couponChannelId}`,
  910. })
  911. // return
  912. },
  913. // 获得未支付的订单
  914. getUnPaidOrder(couponId) {
  915. let that = this;
  916. Http.get({
  917. url: config.api.getUnPaidOrder,
  918. data: {
  919. couponId: couponId
  920. }
  921. }).then(res => {
  922. that.setData({
  923. disOrderNumber: res.data.orderNumber,
  924. composeOrderType: res.data.composeOrderType
  925. })
  926. if (res.data && res.data.pressEndDate) {
  927. that.setData({
  928. dispressEndDate: true
  929. })
  930. } else {
  931. that.setData({
  932. dispressEndDate: false
  933. })
  934. }
  935. if (that.data.dispressEndDate) {
  936. tt.showModal({
  937. title: '提示',
  938. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  939. confirmText: "我的砍价",
  940. success: function (res) {
  941. if (res.confirm) {
  942. tt.navigateTo({
  943. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}&composeOrderType=${that.data.composeOrderType}`,
  944. })
  945. }
  946. }
  947. })
  948. } else {
  949. tt.showModal({
  950. title: '提示',
  951. content: '您有未支付订单,请先进行支付',
  952. confirmText: "去支付",
  953. success: function (res1) {
  954. if (res1.confirm) {
  955. if (that.data.composeOrderType > 0) { //券包
  956. tt.navigateTo({
  957. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}`,
  958. })
  959. } else {
  960. tt.navigateTo({
  961. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}`,
  962. })
  963. }
  964. }
  965. }
  966. })
  967. }
  968. }).catch(error => {
  969. tt.showToast({
  970. title: error.message,
  971. icon: "none",
  972. duration: 3000
  973. })
  974. })
  975. },
  976. onShow() {
  977. this.ifGetUser() //判断是否授权抖音
  978. this.setData({
  979. mouldType: app.globalData.mouldType,
  980. showbutton: false,
  981. showbutton1: false
  982. })
  983. if (this.data.end_time && this.data.activityStatus != 0) {
  984. this.countdown(this.data.end_time)
  985. } else if (this.data.begin_time && this.data.activityStatus == 0) {
  986. this.countdown(this.data.begin_time)
  987. }
  988. },
  989. onUnload: function () {
  990. let that = this;
  991. clearInterval(that.data.setInterval)
  992. },
  993. onHide: function () {
  994. let that = this;
  995. clearInterval(that.data.setInterval)
  996. },
  997. onShareAppMessage: function (options) {
  998. app.globalData.previewFlag = true
  999. var that = this;
  1000. console.log(options)
  1001. var shareObj = {
  1002. title: that.data.data.title,
  1003. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  1004. success: function (res) {
  1005. if (res.errMsg == 'shareAppMessage:ok') {}
  1006. },
  1007. fail: function (err) {
  1008. // if (err.errMsg == 'shareAppMessage:fail cancel') { } else if (err.errMsg == 'shareAppMessage:fail') { }
  1009. }
  1010. };
  1011. // 来自页面内的按钮的转发
  1012. if (options.from == 'button' && options.channel != 'video') {
  1013. var eData = options.target.dataset.id;
  1014. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  1015. } else
  1016. if (options.channel == 'video') {
  1017. // return {
  1018. // channel: 'video', // 必写 video
  1019. //     templateId: '',   // 分享的模版 id (如果未设置就是默认,下面会说如何设置)
  1020. // title: `${that.data.barTitle}`,     // 分享的标题
  1021. // desc: `${that.data.data.dyTitle}`,     // 分享的内容介绍目前没有用
  1022. //     path: `/pages/index/index`,  // 分享的路径
  1023. // extra: {
  1024. // videoTopics: [ that.data.data.dyTitle] // 只有抖音才会有的属性
  1025. // },
  1026. // }
  1027. shareObj.channel = 'video';
  1028. shareObj.title = `${that.data.data.title}`;
  1029. shareObj.extra = {
  1030. spu_id: that.data.spuIdObj.spuId
  1031. }
  1032. }
  1033. console.log(shareObj)
  1034. // 返回shareObj
  1035. return shareObj;
  1036. },
  1037. // onShareAppMessage: function(e) {
  1038. // console.log("onShareAppMessage", e);
  1039. // return {
  1040. // channel: 'video',
  1041. // title: "测试小程序分享",
  1042. // desc: "这是默认的分享文案,用户可以直接发送,也可以在发布器内修改",
  1043. // extra: {
  1044. // spu_id:"7091460633887279111" //开发者在抖音开放平台设置的商品id
  1045. // },
  1046. // success: function(e) {
  1047. // console.log("分享成功");
  1048. // },
  1049. // fail: function(e) {
  1050. // console.log(e,"分享成功失败")
  1051. // }
  1052. // };
  1053. // },
  1054. // 下拉刷新
  1055. onPullDownRefresh: function () {
  1056. this.getDetail(this.data.couponChannelId);
  1057. tt.stopPullDownRefresh()
  1058. },
  1059. onReachBottom: function () {
  1060. this.setData({
  1061. page: this.data.page + 1
  1062. })
  1063. if (this.data.idList.length > 0) {
  1064. this.getCouponList(this.data.idList)
  1065. }
  1066. }
  1067. });