抖音c端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

1561 righe
45 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. },
  100. /**
  101. * 显示分享弹框
  102. */
  103. showshare: function () {
  104. this.setData({
  105. isshowposter: true,
  106. })
  107. },
  108. getCouponList: function (id) { //获取其他活动
  109. let that = this;
  110. let data;
  111. data = {
  112. status: 0,
  113. merchantIds: id,
  114. pageNum: that.data.page,
  115. pageSize: 5,
  116. }
  117. Http.post({
  118. url: config.api.listByMerchant,
  119. data: data
  120. }).then(res => {
  121. if (res.data.page.list <= 0) {
  122. return
  123. }
  124. let dataLsit = []
  125. // dataLsit = that.data.couponList
  126. dataLsit = res.data.page.list
  127. dataLsit.map((item, index) => {
  128. if (item.id == that.data.couponChannelId) {
  129. dataLsit.splice(index, 1)
  130. }
  131. })
  132. if (that.data.page > 1) {
  133. let tmpeLsit = that.data.couponList
  134. tmpeLsit.push(...dataLsit)
  135. that.setData({
  136. couponList: tmpeLsit,
  137. })
  138. } else {
  139. that.setData({
  140. couponList: dataLsit,
  141. })
  142. }
  143. // if (res.data && res.data.qrCode){
  144. // that.setData({
  145. // qrCode: res.data.qrCode,
  146. // })
  147. // }
  148. })
  149. .catch(err => {
  150. tt.showToast({
  151. title: err.errMsg,
  152. icon: 'none',
  153. duration: 2000,
  154. mask: false
  155. });
  156. })
  157. },
  158. setPhone(paramData) {//子组件调用这个方法说明手机号已经授权成功
  159. this.setData({
  160. showBox: paramData.detail,
  161. })
  162. tt.showToast({
  163. title: '授权成功', // 内容
  164. icon: 'none', // 图标
  165. success: (res) => {
  166. },
  167. fail: (res) => {
  168. },
  169. });
  170. },
  171. setBox(paramData) {
  172. this.setData({
  173. showBox: paramData.detail
  174. })
  175. tt.showToast({
  176. title: '取消授权', // 内容
  177. icon: 'none', // 图标
  178. success: (res) => {
  179. },
  180. fail: (res) => {
  181. },
  182. });
  183. },
  184. /**
  185. * 隐藏分享弹框
  186. */
  187. hidemodal: function () {
  188. this.setData({
  189. isshowposter: false,
  190. })
  191. },
  192. /**
  193. * 显示分享海报
  194. */
  195. /* showPoster: function() {
  196. //跳转到海报生成页
  197. console.log(this.data.canIUse)
  198. // return;
  199. tt.navigateTo({
  200. url: `/pages/canvas/index?couponChannelId=${this.data.data.id}`
  201. })
  202. }, */
  203. showPoster: function () {
  204. //跳转到海报生成页
  205. let that = this;
  206. Http.get({
  207. url: config.api.checkUserStatus,
  208. data: {
  209. token: app.globalData.token
  210. }
  211. }).then(res => {
  212. tt.navigateTo({
  213. url: `/pages/canvas/index?couponChannelId=${that.data.data.id}`
  214. })
  215. }).catch(err => {
  216. console.log(err)
  217. if (err.code == 11004) {
  218. // 用户昵称未授权
  219. tt.redirectTo({
  220. url: `/pages/getuserinfo/getuserinfo?couponChannelId=${that.data.data.id}&fromflag=poster`
  221. })
  222. }
  223. })
  224. },
  225. swiperChange: function (e) {
  226. this.setData({
  227. swiperCurrent: e.detail.current
  228. });
  229. },
  230. gohome(e) {
  231. console.log(e.currentTarget.dataset.id, "123")
  232. tt.navigateTo({
  233. url: `/pages/fillIndent/fillIndent?couponChannelId=${e.currentTarget.dataset.couponchannelid}&couponId=${e.currentTarget.dataset.couponid}&shippingtype=${e.currentTarget.dataset.shippingtype}`,
  234. })
  235. },
  236. gochild(e) {
  237. let id = e.currentTarget.dataset.id
  238. tt.navigateTo({
  239. url: `/pages/coupon/childDetail/childDetail?couponIds=${id}`,
  240. })
  241. },
  242. //获取当前登录用户信息
  243. getUserInfo: function () {
  244. let that = this;
  245. // 获取用户信息
  246. Http.get({
  247. url: config.api.getScore,
  248. data: {}
  249. })
  250. .then(res => {
  251. console.log(res)
  252. that.getQueryCardStatus()
  253. if (that.data.cardData.cuserId != res.data.id) {
  254. console.log(2222, 6666)
  255. that.setData({
  256. isSamePeople: false
  257. })
  258. }
  259. })
  260. },
  261. //获取卡转赠状态
  262. getQueryCardStatus() {
  263. let that = this;
  264. let param = {
  265. id: this.data.cardData.couponOrderId,
  266. cUserId: this.data.cardData.cuserId,
  267. updateDate: util.formatTime(Number(that.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  268. }
  269. Http.get({
  270. url: config.api.queryCardStatus,
  271. data: param
  272. })
  273. .then(res => {
  274. console.log(res, 333333333333)
  275. })
  276. .catch(err => {
  277. that.setData({
  278. isReceived: true,
  279. statusText: err.message
  280. })
  281. })
  282. },
  283. receiveCard() {
  284. let that = this;
  285. let param = {
  286. id: this.data.cardData.couponOrderId,
  287. cUserId: this.data.cardData.cuserId,
  288. updateDate: util.formatTime(Number(this.data.cardData.updateDate), "yyyy-MM-dd hh:mm:ss")
  289. }
  290. this.setData({
  291. receivedDisabled: true
  292. })
  293. Http.post({
  294. url: config.api.cardAccept,
  295. data: param
  296. })
  297. .then(res => {
  298. tt.showToast({
  299. title: '领取成功!',
  300. icon: 'none',
  301. duration: 2000,
  302. mask: false
  303. });
  304. tt.reLaunch({
  305. url: '/pages/complete/index?couponOrderId=' + this.data.cardData.couponOrderId,
  306. })
  307. })
  308. .catch(err => {
  309. tt.showToast({
  310. title: err.message,
  311. icon: 'none',
  312. duration: 2000,
  313. mask: false
  314. });
  315. that.setData({
  316. receivedDisabled: false
  317. })
  318. })
  319. },
  320. closeAlert() {
  321. this.setData({
  322. showCardOffer: false
  323. })
  324. },
  325. goback: function () {
  326. tt.reLaunch({
  327. url: '/index/index',
  328. })
  329. },
  330. /**
  331. * 点击提交问题单选
  332. */
  333. formSubmit: function (e) {
  334. console.log(e);
  335. let that = this;
  336. /**
  337. * 多选
  338. */
  339. if (e.currentTarget.dataset.flags == 'multi') {
  340. if (that.data.anwserId.length == 0) {
  341. var answserIs = null
  342. } else {
  343. var answserIs = that.data.anwserId.join(",");
  344. }
  345. } else if (e.currentTarget.dataset.flags == 'single') {
  346. var answserIs = e.detail.value;
  347. }
  348. console.log(answserIs)
  349. console.log(e.currentTarget.dataset.questionid)
  350. Http.post({
  351. url: config.api.answerQuestion,
  352. data: {
  353. answer: answserIs,
  354. questionId: e.currentTarget.dataset.questionid
  355. }
  356. })
  357. .then(res => {
  358. that.closeQuestion();
  359. })
  360. .catch(err => {
  361. tt.showToast({
  362. title: err.message,
  363. icon: 'none',
  364. duration: 2000,
  365. mask: false
  366. });
  367. })
  368. },
  369. /**
  370. * 多选
  371. */
  372. checkboxChange: function (e) {
  373. console.log(e)
  374. this.setData({
  375. anwserId: e.detail.value
  376. })
  377. },
  378. closeQuestion: function () {
  379. let that = this;
  380. that.setData({
  381. display: "none",
  382. zIndex: 11,
  383. opacity: 0
  384. })
  385. setTimeout(function () {
  386. that.orderFunc();
  387. }, 500)
  388. },
  389. ifGetUser() {
  390. Http.get({
  391. url: config.api.checkUserStatus,
  392. data: {
  393. token: app.globalData.token
  394. }
  395. }).then(res => {
  396. }).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. let that = this;
  410. app.globalData.previewFlag = true
  411. /* 判断是否授权*/
  412. Http.get({
  413. url: config.api.checkUserStatus,
  414. data: {
  415. token: app.globalData.token
  416. }
  417. }).then(res => {
  418. Http.get({
  419. url: config.api.checkPhoneStatus,
  420. }).then(res => {
  421. tt.showLoading();
  422. if (e.currentTarget.dataset.type == 51 || e.currentTarget.dataset.type == 50) {
  423. tt.navigateTo({
  424. url: '/pages/integralmall/payIntegcoupondetail/index?couponChannelId=' + that.data.couponChannelId + '&couponId=' + that.data.couponId,
  425. })
  426. } else {
  427. let formId = e.detail.formId ? e.detail.formId : "";
  428. var discount = e.currentTarget.dataset.discount;
  429. that.setData({
  430. queueData: null,
  431. showbutton: true,
  432. formId: formId
  433. })
  434. Http.get({
  435. url: config.api.getQuestion,
  436. data: {
  437. couponType: JSON.stringify(that.data.data.type)
  438. }
  439. }).then(res => {
  440. tt.hideLoading();
  441. if (res.data == undefined) {
  442. // 立即购买
  443. that.orderFunc(discount);
  444. that.setData({
  445. flag: false
  446. })
  447. } else if (res.data) {
  448. var animation = tt.createAnimation({});
  449. animation.translate((that.data.widthScreen - that.data.widthScreen), 0).scale(1).opacity(1).step({
  450. duration: 500
  451. })
  452. that.setData({
  453. queueData: animation.export(),
  454. zIndex: 9,
  455. opacity: 1,
  456. display: "block",
  457. questionnaire: JSON.parse(res.data.content),
  458. questionId: res.data.id
  459. });
  460. }
  461. }).catch(err => {
  462. tt.hideLoading();
  463. tt.showToast({
  464. title: err.message,
  465. icon: 'none',
  466. duration: 2000,
  467. mask: false
  468. });
  469. })
  470. }
  471. }).catch(err => {
  472. app.globalData.type = ''
  473. app.globalData.skipUrl = ""
  474. app.globalData.skip = 'navigateBack'
  475. if (app.globalData.ifCongPh == 1) {
  476. tt.navigateTo({
  477. url: '/pages/getPhone/getPhone?skipUrl=1',
  478. });
  479. } else {
  480. this.setData({
  481. showBox: true
  482. })
  483. }
  484. })
  485. }).catch(err => {
  486. app.globalData.type = ''
  487. if (err.code == 11004) {//未授权抖音
  488. tt.navigateTo({
  489. url: `/pages/getuserinfo/getuserinfo?fromflag=coupondetail&couponChannelIdflag=${this.data.couponChannelId}`,
  490. });
  491. }
  492. })
  493. },
  494. setIntervalTime(end_time) {
  495. let that = this;
  496. var EndTime = end_time;
  497. var NowTime = new Date().getTime();
  498. var total_micro_second = EndTime - NowTime || [];
  499. // 渲染倒计时时钟
  500. let obj = that.dateformat(total_micro_second);
  501. if (total_micro_second > 0) {
  502. that.setData({
  503. clock: obj,
  504. day: obj.a1,
  505. hour: obj.b1,
  506. min: obj.c1,
  507. sec: obj.d1,
  508. })
  509. } else {
  510. that.setData({
  511. clock: "00",
  512. day: "00",
  513. hour: "00",
  514. min: "00",
  515. sec: "00",
  516. })
  517. //如果倒计时结束,需要重新查询一下券的状态
  518. // 给getDetail一个标识
  519. that.getDetail(that.data.couponChannelId, 'endclock');
  520. }
  521. total_micro_second -= 1000;
  522. },
  523. countdown: function (end_time) {
  524. let that = this;
  525. that.setIntervalTime(end_time);
  526. that.data.setInterval = setInterval(function () {
  527. that.setIntervalTime(end_time);
  528. }, 1000)
  529. },
  530. // 时间格式化输出,如11:03 25:19 每1s都会调用一次
  531. dateformat(micro_second) {
  532. // 总秒数
  533. var second = Math.floor(micro_second / 1000);
  534. // 天数
  535. var day = Math.floor(second / 3600 / 24) < 10 ? "0" + Math.floor(second / 3600 / 24) : Math.floor(second / 3600 / 24);
  536. // 小时
  537. var hr = Math.floor(second / 3600 % 24) < 10 ? "0" + Math.floor(second / 3600 % 24) : Math.floor(second / 3600 % 24);
  538. // 分钟
  539. var min = Math.floor(second / 60 % 60) < 10 ? "0" + Math.floor(second / 60 % 60) : Math.floor(second / 60 % 60);
  540. // 秒
  541. var sec = Math.floor(second % 60) < 10 ? "0" + Math.floor(second % 60) : Math.floor(second % 60);
  542. // return day + "天" + hr + "小时" + min + "分钟" + sec + "秒";
  543. return {
  544. a1: day,
  545. b1: hr,
  546. c1: min,
  547. d1: sec
  548. }
  549. },
  550. /**
  551. * 获取用户信息
  552. */
  553. onLoad(options) {
  554. console.log(options);
  555. this.setData({
  556. mouldType: app.globalData.mouldType,
  557. })
  558. let that = this;
  559. if (options.g) {
  560. app.globalData.havePlayEd1 = true;
  561. }
  562. tt.showLoading({
  563. title: "加载中..."
  564. });
  565. that.setData({
  566. onshow: false
  567. })
  568. if (options && (options.couponChannelId || options.couponIds)) {
  569. if (options.couponIds) {
  570. this.setData({
  571. couponIds: options.couponIds
  572. })
  573. that.getDetail(options.couponIds, 'notendclock');
  574. } else {
  575. that.getDetail(options.couponChannelId, 'notendclock');
  576. that.getSupId(options.couponChannelId)
  577. }
  578. }
  579. /**
  580. * 转赠判断
  581. */
  582. if (options.cuserId) {
  583. this.setData({
  584. showCardOffer: true,
  585. cardData: options
  586. })
  587. this.getUserInfo()
  588. }
  589. that.setData({
  590. couponChannelId: options.couponChannelId,
  591. title: that.data.data.title ? that.data.data.title : '',
  592. });
  593. if (options.cardType) {
  594. that.setData({
  595. cardType: options.cardType
  596. })
  597. }
  598. },
  599. getHtml(couponChannelId) {
  600. Http.get({
  601. url: config.api.couponHtmlDetail,
  602. data: {
  603. couponChannelId: couponChannelId
  604. }
  605. }).then(res => {
  606. console.log(res)
  607. if (res.code == 200 && res.data.html) {
  608. this.setData({
  609. curHtml: decodeURI(res.data.html)
  610. })
  611. app.globalData.curHtml = this.data.curHtml;
  612. console.log(app.globalData.curHtml)
  613. }
  614. })
  615. },
  616. getSupId(id) {
  617. Http.get({
  618. url: config.api.getSpuid,
  619. data: { id: id }
  620. }).then(res => {
  621. if (res.data) {
  622. this.setData({
  623. spuIdObj: res.data
  624. })
  625. }
  626. }).catch(err => {
  627. // tt.showToast({
  628. // title: err.message,
  629. // icon: 'none',
  630. // duration: 2000,
  631. // mask: false
  632. // });
  633. })
  634. },
  635. getCouponPriceAndStock(couponChannelId) {//获取券价格与库存
  636. Http.get({
  637. url: config.api.couponPriceAndStock,
  638. data: {
  639. couponChannelId
  640. }
  641. }).then(res => {
  642. let tempBoj = JSON.parse(res.data)
  643. console.log(tempBoj, "$");
  644. this.setData({
  645. priceAndStockObj: tempBoj
  646. })
  647. })
  648. },
  649. getCouponMerchant(couponChannelId) {//获取适用门店
  650. Http.get({
  651. url: config.api.couponMerchant,
  652. data: {
  653. couponChannelId: couponChannelId
  654. }
  655. }).then(res => {
  656. if (res.data && res.data.length) {
  657. let merchantVoList = res.data
  658. let idList = []
  659. merchantVoList.map(item => {
  660. idList.push(item.id)
  661. })
  662. this.setData({
  663. idList: idList
  664. })
  665. this.getCouponList(idList) //获取推荐列表
  666. }
  667. this.setData({
  668. merchantVoList: res.data
  669. })
  670. })
  671. },
  672. getDetail: function (couponChannelId, flag) {
  673. let that = this;
  674. let data = {};
  675. that.getCouponMerchant(couponChannelId);//获取适用门店
  676. that.getCouponPriceAndStock(couponChannelId);//获取券价格和库存
  677. if (that.data.couponIds) {
  678. data.couponId = couponChannelId
  679. } else {
  680. data.couponChannelId = couponChannelId
  681. }
  682. var parmer = {
  683. url: config.api.newCouponDetail,
  684. data: data
  685. };
  686. Http.get(parmer)
  687. .then(res => {
  688. //aaa
  689. if (res.data.contentType != undefined && res.data.contentType == 1) {
  690. //获取图文展示详情html
  691. this.setData({
  692. contentType: res.data.contentType
  693. })
  694. this.getHtml(couponChannelId);
  695. }
  696. that.setData({
  697. couponId: res.data.couponId
  698. })
  699. that.setData({
  700. showPage: true
  701. })
  702. if (res && res.data && res.data.detailPicture) {
  703. that.setData({
  704. detailPicture: JSON.parse(res.data.detailPicture)
  705. })
  706. }
  707. if (res && res.data && res.data.coverPicture) {
  708. that.setData({
  709. coverPicture: JSON.parse(res.data.coverPicture)
  710. })
  711. }
  712. if (res && res.data && res.data.conditions) {
  713. that.setData({
  714. limitCondition: JSON.parse(res.data.conditions).type
  715. })
  716. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).min || JSON.parse(res.data.conditions).min == 0)) {
  717. that.setData({
  718. minLimit: JSON.parse(res.data.conditions).min
  719. })
  720. }
  721. if (JSON.parse(res.data.conditions).type == 2 && (JSON.parse(res.data.conditions).max) || JSON.parse(res.data.conditions).max == 0) {
  722. that.setData({
  723. maxLimit: JSON.parse(res.data.conditions).max
  724. })
  725. }
  726. }
  727. /**
  728. * 将优惠券优惠卡的详情的BarTitle
  729. * 设置成券的名称
  730. */
  731. // tt.setNavigationBarTitle({
  732. // title: res.data.title
  733. // })
  734. that.setData({
  735. barTitle: res.data.title
  736. })
  737. tt.setNavigationBarTitle({
  738. title: res.data.title,
  739. success() {
  740. console.log("setNavigationBarTitle 调用成功");
  741. },
  742. fail(res) {
  743. console.log(`setNavigationBarTitle 调用失败:`, res.errMsg);
  744. },
  745. });
  746. var EndTime = res.data.validStartDate;
  747. var NowTime = new Date().getTime();
  748. /**
  749. * activityStatus==0 活动未开始
  750. * activityStatus==1 活动已开始
  751. * flag == endclock 说明倒计时已经结束
  752. */
  753. if (res.data.endTime && res.data.beginTime) {
  754. that.setData({
  755. begin_time: res.data.beginTime,
  756. end_time: res.data.endTime,
  757. activityStatus: res.data.actStatus ? res.data.actStatus : ''
  758. })
  759. if (res.data.actStatus == 0 && flag != 'endclock') {
  760. that.countdown(res.data.beginTime);
  761. } else if (res.data.actStatus != 0 && flag != 'endclock') {
  762. that.countdown(res.data.endTime);
  763. } else {
  764. clearInterval(that.data.setInterval)
  765. }
  766. if (res.data.actStatus == 0) {
  767. var beginTime = util.formatTime(res.data.beginTime, "yyyy-MM-dd hh:mm:ss");
  768. if (util.timechuo(beginTime).indexOf('-') == 0) {
  769. that.setData({
  770. beginTime: "活动已结束",
  771. });
  772. } else {
  773. that.setData({
  774. beginTime: util.timechuo(beginTime)
  775. });
  776. }
  777. } else {
  778. var endTime = util.formatTime(res.data.endTime, "yyyy-MM-dd hh:mm:ss");
  779. if (util.timechuo(endTime).indexOf('-') == 0) {
  780. that.setData({
  781. endtime: "活动已结束",
  782. });
  783. } else {
  784. that.setData({
  785. endtime: util.timechuo(endTime)
  786. });
  787. }
  788. }
  789. }
  790. tt.hideLoading();
  791. that.setData({
  792. data: res.data,
  793. });
  794. if (res.data.type == 10) {
  795. that.setData({
  796. salePriceStr: res.data.salePriceStr,
  797. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  798. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  799. priceStr: res.data.priceStr,
  800. tailPriceStr: res.data.tailPriceStr,
  801. origPriceStr: res.data.origPriceStr
  802. })
  803. }
  804. if (res.data.validType == 1) {
  805. that.setData({
  806. validStartDate: util.formatTime(res.data.validStartDate, "yyyy-MM-dd"),
  807. validEndDate: util.formatTime(res.data.validEndDate, "yyyy-MM-dd"),
  808. pickStartDate: util.formatTime(res.data.pickStartDate, "yyyy-MM-dd"),
  809. pickEndDate: util.formatTime(res.data.pickEndDate, "yyyy-MM-dd"),
  810. });
  811. } else {
  812. if (res.data.validDays) {
  813. that.setData({
  814. validDays: res.data.validDays
  815. });
  816. }
  817. }
  818. if (res.data.itemGroup) {
  819. let tempObj = this.data.data
  820. tempObj.itemGroup = JSON.parse(tempObj.itemGroup)
  821. this.setData({
  822. data: tempObj
  823. })
  824. console.log(this.data.data, "data");
  825. }
  826. if (res.data.productAttrs && res.data.skuAttrs) {
  827. let tempObj = this.data.data
  828. tempObj.productAttrs = JSON.parse(tempObj.productAttrs)
  829. tempObj.skuAttrs = JSON.parse(tempObj.skuAttrs)
  830. tempObj.productAttrs.map(item => {
  831. if (item.key == "Notification") {
  832. if (item.data != '') {
  833. tempObj.curLsit = JSON.parse(item.data)
  834. }
  835. }
  836. if (item.key == "bring_out_meal") {
  837. tempObj.besides = item.data
  838. }
  839. if (item.key == "free_pack") {
  840. tempObj.pack = item.data
  841. }
  842. if (item.key == "superimposed_discounts") {
  843. tempObj.superimposed_discounts = item.data
  844. }
  845. if (item.key == "private_room") {
  846. tempObj.private_room = item.data
  847. }
  848. if (item.key == "rec_person_num_max") {
  849. tempObj.rec_person_num_max = item.data
  850. }
  851. if (item.key == 'Description') {
  852. tempObj.Description = JSON.parse(item.data)
  853. }
  854. if (item.key == "can_no_use_date") {
  855. tempObj.can_no_use_date = JSON.parse(item.data)
  856. }
  857. })
  858. tempObj.skuAttrs.map(item => {
  859. if (item.key == "commodity") {
  860. if (item.data != '') {
  861. tempObj.itemGroup = JSON.parse(item.data)
  862. }
  863. }
  864. })
  865. this.setData({
  866. data: tempObj
  867. })
  868. console.log(this.data.data, "data");
  869. }
  870. }).catch(err => {
  871. tt.showToast({
  872. title: err.message,
  873. icon: 'none',
  874. duration: 2000,
  875. mask: false
  876. });
  877. })
  878. },
  879. /**
  880. * 邀请好友继续砍价
  881. */
  882. inviteFriend: function (e) {
  883. let that = this;
  884. let formId = e.detail.formId;
  885. that.setData({
  886. formId: formId,
  887. showbutton1: true
  888. })
  889. that.orderFunc("discount");
  890. },
  891. /**
  892. * 支付订单更新
  893. */
  894. payOrderUpdate: (orderId, payOrderId, status, reason, type, _this, composeOrderType) => {
  895. let that = this;
  896. // 支付成功
  897. Http.post({
  898. url: config.api.payOrderUpdate,
  899. data: {
  900. payOrderId: payOrderId,
  901. composeOrderId: orderId,
  902. status: status,
  903. reason: reason
  904. }
  905. })
  906. .then(res => {
  907. tt.hideLoading()
  908. // 有价券
  909. if (!type && type != 'free') {
  910. tt.navigateTo({
  911. url: `/pages/order/detail/index?orderId=${orderId
  912. }`
  913. });
  914. } else if (type == 'free') {
  915. tt.navigateTo({
  916. url: `/pages/order/detail/index?orderId=${orderId
  917. }`
  918. });
  919. }
  920. })
  921. .catch(err => {
  922. console.log(err);
  923. if (!type) {
  924. setTimeout(function () {
  925. _this.payOrderUpdate(orderId, payOrderId, status, reason, type, _this, composeOrderType);
  926. }, 2000)
  927. }
  928. })
  929. },
  930. checkPhoneStatus: function () {
  931. let that = this;
  932. Http.get({
  933. url: config.api.checkPhoneStatus,
  934. data: {}
  935. })
  936. .then(res => {
  937. console.log(666, '授权成功!')
  938. that.receiveCard()
  939. })
  940. .catch(err => {
  941. if (err.code == 11005) {
  942. /**
  943. * 手机号没有授权,将值传到用户手机号授权的页面
  944. *
  945. */
  946. tt.redirectTo({
  947. 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,
  948. });
  949. } else if (err.code == 11006) {
  950. // 用户手机已加密
  951. tt.redirectTo({
  952. 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,
  953. });
  954. } else {
  955. tt.showToast({
  956. title: err.message,
  957. icon: 'none',
  958. duration: 2000,
  959. mask: false
  960. });
  961. }
  962. })
  963. },
  964. // 券包支付
  965. /**
  966. * 发起支付
  967. */
  968. orderFunc(discount) {
  969. tt.navigateTo({
  970. url: `/pages/coupon/confirmation/confirmation?couponChannelId=${this.data.couponChannelId}`,
  971. })
  972. return
  973. let that = this;
  974. tt.showLoading({
  975. title: "加载中..."
  976. });
  977. that.setData({
  978. showbutton: true,
  979. showbutton1: true
  980. })
  981. Http.get({
  982. url: config.api.checkUserStatus,
  983. data: {
  984. token: app.globalData.token
  985. }
  986. }).then(res => {
  987. Http.get({
  988. url: config.api.checkPhoneStatus,
  989. data: {}
  990. }).then(res => {
  991. if ((!tt.canIUse('createOrder')) || that.data.data.type == 50 || that.data.priceAndStockObj.salePrice == 0) {
  992. //积分券和免费券
  993. // 发起砍价
  994. if (discount == 'discount') {
  995. var data = {
  996. couponChannelId: "" + that.data.couponChannelId,
  997. couponId: "" + that.data.couponId,
  998. formId: "" + that.data.formId,
  999. press: true
  1000. }
  1001. } else if (discount == 'discount1') {
  1002. var data = {
  1003. couponChannelId: "" + that.data.couponChannelId,
  1004. couponId: "" + that.data.couponId,
  1005. formId: "" + that.data.formId,
  1006. press: false
  1007. }
  1008. } else if (that.data.couponChannelId == null) {
  1009. var data = {
  1010. couponId: "" + that.data.couponId,
  1011. formId: "" + that.data.formId,
  1012. };
  1013. } else {
  1014. var data = {
  1015. couponChannelId: "" + that.data.couponChannelId,
  1016. couponId: "" + that.data.couponId,
  1017. formId: "" + that.data.formId,
  1018. }
  1019. }
  1020. console.log(data, "data")
  1021. let url = ""
  1022. let tempObj;
  1023. let tempArr = []
  1024. if (that.data.data.type == 12) {
  1025. url = config.api.couponPackageSave
  1026. tempObj = {
  1027. signleOrder: {
  1028. couponChannelId: "" + that.data.couponChannelId,
  1029. couponId: "" + that.data.couponId,
  1030. formId: "" + that.data.formId,
  1031. },
  1032. count: "1"
  1033. }
  1034. tempArr.push(tempObj)
  1035. } else {
  1036. url = config.api.orderSave
  1037. }
  1038. /**
  1039. * orderSave 下单
  1040. */
  1041. Http.post({
  1042. url: url,
  1043. data: that.data.data.type == 12 ? JSON.stringify(tempArr) : data
  1044. }).then(res => {
  1045. if (discount != 'discount') {
  1046. if (typeof (res) != "undefined") {
  1047. let orderId = "" + res.data.mainOrderId;
  1048. that.setData({
  1049. orderId: orderId,
  1050. composeOrderType: res.data.composeOrderType
  1051. });
  1052. if (res.data.payment > 0) {
  1053. // 支付金额不为0
  1054. /**
  1055. * 支付订单创建
  1056. */
  1057. Http.post({
  1058. url: config.api.payOrderCreate,
  1059. data: {
  1060. orderId: orderId,
  1061. composeOrderType: res.data.composeOrderType
  1062. }
  1063. }).then(res => {
  1064. var payOrderId = "" + res.data.outOrderNo;
  1065. tt.hideLoading();
  1066. tt.pay({
  1067. service: 5,
  1068. orderInfo: {
  1069. order_id: res.data.orderId,
  1070. order_token: res.data.token,
  1071. },
  1072. success: res => {
  1073. tt.showLoading({
  1074. title: '订单正在处理中...',
  1075. })
  1076. if (res.code === 0) {
  1077. that.payOrderUpdate(that.data.orderId, payOrderId, 1, '', '', that, that.data.composeOrderType);
  1078. if (res.errMsg == "requestPayment:ok") {
  1079. /**
  1080. * 用户支付成功以后跳转到券包列表
  1081. */
  1082. if (that.data.cardType == 100) {
  1083. tt.setStorage({
  1084. key: 'couponNum2',
  1085. data: "couponNum2"
  1086. })
  1087. } else if (that.data.data.type != 5 && that.data.cardType != 100) {
  1088. tt.setStorage({
  1089. key: 'couponNum',
  1090. data: "couponNum"
  1091. })
  1092. }
  1093. }
  1094. }
  1095. else if (res.code === 1) {
  1096. that.setData({
  1097. showbutton: false
  1098. })
  1099. tt.hideLoading();
  1100. tt.showToast({
  1101. title: '支付超时', // 内容
  1102. icon: "none"
  1103. });
  1104. } else if (res.code === 2) {
  1105. that.setData({
  1106. showbutton: false
  1107. })
  1108. tt.hideLoading();
  1109. tt.showToast({
  1110. title: '支付失败', // 内容
  1111. icon: "none"
  1112. });
  1113. } else if (res.code === 3) {
  1114. that.setData({
  1115. showbutton: false
  1116. })
  1117. tt.hideLoading();
  1118. tt.showToast({
  1119. title: '支付关闭', // 内容
  1120. icon: "none"
  1121. });
  1122. } else if (res.code === 4) {
  1123. that.setData({
  1124. showbutton: false
  1125. })
  1126. tt.hideLoading();
  1127. tt.showToast({
  1128. title: '支付取消', // 内容
  1129. icon: "none"
  1130. });
  1131. } else if (res.code === 9) {
  1132. that.setData({
  1133. showbutton: false
  1134. })
  1135. tt.hideLoading();
  1136. tt.showToast({
  1137. title: '订单状态开发者自行获取', // 内容
  1138. icon: "none"
  1139. });
  1140. }
  1141. },
  1142. fail: res => {
  1143. tt.hideLoading();
  1144. /**
  1145. * 支付失败,需要更新订单的状态
  1146. */
  1147. that.payOrderUpdate(that.data.orderId, payOrderId, 2, '', 'fail', that, that.data.composeOrderType);
  1148. that.setData({
  1149. showbutton: false
  1150. })
  1151. return;
  1152. },
  1153. complete: res => { }
  1154. });
  1155. /// End payment --------
  1156. })
  1157. .catch(err => {
  1158. tt.hideLoading();
  1159. tt.showToast({
  1160. title: err.message,
  1161. icon: 'none',
  1162. duration: 2000,
  1163. mask: false
  1164. });
  1165. })
  1166. } else {
  1167. // 免费券
  1168. that.payOrderUpdate(orderId, "0", 1, '', 'free', that, that.data.composeOrderType);
  1169. if (that.data.cardType == 100) {
  1170. tt.setStorage({
  1171. key: 'couponNum2',
  1172. data: "couponNum2"
  1173. })
  1174. } else if (that.data.data.type != "5" && that.data.cardType != 100) {
  1175. tt.setStorage({
  1176. key: 'couponNum',
  1177. data: "couponNum"
  1178. })
  1179. }
  1180. }
  1181. }
  1182. } else {
  1183. if (res) {
  1184. tt.navigateTo({
  1185. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${res.data.mainOrderId}&composeOrderType=${res.data.composeOrderType}`,
  1186. })
  1187. }
  1188. }
  1189. })
  1190. } else {
  1191. //有价券
  1192. console.log(tt.canIUse('createOrder'), "是否支持2.0js-api");
  1193. if (tt.canIUse('createOrder')) {
  1194. //支持 支付2.0 js-api
  1195. let tempCallbackData = {}
  1196. tempCallbackData[that.data.data.couponChannel.ttSpuId] = that.data.data.couponChannel.id
  1197. let options = {
  1198. callbackData: tempCallbackData,
  1199. goodsList: [
  1200. {
  1201. quantity: 1, // 购买数量 必填
  1202. price: that.data.priceAndStockObj.salePrice, // 商品价格 必填
  1203. goodsName: that.data.data.title, // 商品名称 必填
  1204. goodsPhoto: that.data.data.coverImg, // 商品图片链接 必填
  1205. goodsId: that.data.data.couponChannel.ttSpuId, // 商品ID 必填
  1206. goodsType: 1, // 商品类型 必填
  1207. goodsLabels: ['过期退', '随时退', '免预约'], // 商品标签 非必填
  1208. dateRule: '', // 使用规则 非必填
  1209. },
  1210. ],
  1211. payment: {
  1212. totalAmount: that.data.priceAndStockObj.salePrice, // 订单总价 必填
  1213. },
  1214. success: res => {
  1215. tt.hideLoading();
  1216. that.setData({
  1217. showbutton: false,
  1218. showbutton1: false
  1219. })
  1220. const { orderId, outOrderNo } = res;
  1221. that.setData({ orderId, outOrderNo });
  1222. that.payOrderUpdate(outOrderNo, outOrderNo, 1, '', '', that, '');
  1223. },
  1224. fail: res => {
  1225. const { orderId, outOrderNo, errNo, errMsg, errLogId } = res;
  1226. if (errLogId) {
  1227. tt.hideLoading();
  1228. that.setData({
  1229. showbutton: false,
  1230. showbutton1: false
  1231. })
  1232. console.log('预下单失败', errNo, errMsg, errLogId);
  1233. }
  1234. if (orderId || outOrderNo) {
  1235. tt.hideLoading();
  1236. that.setData({
  1237. showbutton: false,
  1238. showbutton1: false
  1239. })
  1240. console.log('支付失败', errNo, errMsg, orderId, outOrderNo);
  1241. console.log(that.payOrderUpdate, "payOrderUpdate");
  1242. that.payOrderUpdate(outOrderNo,outOrderNo,2,'','fail')
  1243. }
  1244. },
  1245. }
  1246. console.log(options, "options");
  1247. tt.createOrder(options)
  1248. } else {
  1249. //不支持 支付2.0 js -api
  1250. }
  1251. }
  1252. }).catch(err => {
  1253. tt.hideLoading()
  1254. that.setData({
  1255. showbutton: false,
  1256. showbutton1: false
  1257. })
  1258. if (err.code == 2011) {
  1259. tt.showToast({
  1260. title: "商户信息没找到",
  1261. image: './../../../assets/images/fail.png',
  1262. duration: 2000,
  1263. mask: false
  1264. });
  1265. } else if (err.code == 2013) {
  1266. tt.showToast({
  1267. title: "商户信息禁用",
  1268. image: './../../../assets/images/fail.png',
  1269. duration: 2000,
  1270. mask: false
  1271. });
  1272. } else if (err.code == 3000) {
  1273. tt.showToast({
  1274. title: "库存不足",
  1275. image: './../../../assets/images/fail.png',
  1276. duration: 2000,
  1277. mask: false
  1278. });
  1279. } else if (err.code == 3001) {
  1280. tt.showToast({
  1281. title: "您已超过限购",
  1282. image: './../../../assets/images/fail.png',
  1283. duration: 2000,
  1284. mask: false
  1285. });
  1286. } else if (err.code == 3002) {
  1287. tt.showToast({
  1288. title: "订单失败",
  1289. image: './../../../assets/images/fail.png',
  1290. duration: 2000,
  1291. mask: false
  1292. });
  1293. } else if (err.code == 3003) {
  1294. tt.showToast({
  1295. title: "订单不存在",
  1296. image: './../../../assets/images/fail.png',
  1297. duration: 2000,
  1298. mask: false
  1299. });
  1300. } else if (err.code == 3004) {
  1301. tt.showToast({
  1302. title: "订单不存在",
  1303. image: './../../../assets/images/fail.png',
  1304. duration: 2000,
  1305. mask: false
  1306. });
  1307. } else if (err.code == 4003) {
  1308. tt.showToast({
  1309. title: "卡券已作废",
  1310. image: './../../../assets/images/fail.png',
  1311. duration: 2000,
  1312. mask: false
  1313. });
  1314. } else if (err.code == 3012) {
  1315. that.getUnPaidOrder(that.data.couponId);
  1316. } else if (err.code == 11005) {
  1317. /**
  1318. * 将值传到用户手机号授权的页面
  1319. *
  1320. */
  1321. tt.redirectTo({
  1322. url: "/pages/getphoneInfo/index?couponChannelId=" +
  1323. that.data.couponChannelId
  1324. });
  1325. } else if (err.code == 11006) {
  1326. // 用户手机已加密
  1327. tt.redirectTo({
  1328. url: "/pages/phoneinput/phoneinput?couponChannelId=" +
  1329. that.data.couponChannelId
  1330. });
  1331. } else {
  1332. tt.showToast({
  1333. title: err.message,
  1334. icon: 'none',
  1335. duration: 2000,
  1336. mask: false
  1337. });
  1338. }
  1339. })
  1340. }).catch(err => {
  1341. console.log(err)
  1342. if (err.code == 11004) {
  1343. tt.redirectTo({
  1344. url: `/pages/getuserinfo/getuserinfo?fromflag=coupondetail&couponChannelIdflag=${that.data.couponChannelId}`,
  1345. })
  1346. } else {
  1347. tt.showToast({
  1348. title: err.message,
  1349. icon: "none",
  1350. duration: 2500
  1351. })
  1352. }
  1353. })
  1354. },
  1355. // 获得未支付的订单
  1356. getUnPaidOrder(couponId) {
  1357. let that = this;
  1358. Http.get({
  1359. url: config.api.getUnPaidOrder,
  1360. data: {
  1361. couponId: couponId
  1362. }
  1363. }).then(res => {
  1364. that.setData({
  1365. disOrderNumber: res.data.orderNumber,
  1366. composeOrderType: res.data.composeOrderType
  1367. })
  1368. if (res.data && res.data.pressEndDate) {
  1369. that.setData({
  1370. dispressEndDate: true
  1371. })
  1372. } else {
  1373. that.setData({
  1374. dispressEndDate: false
  1375. })
  1376. }
  1377. if (that.data.dispressEndDate) {
  1378. tt.showModal({
  1379. title: '提示',
  1380. content: "您有未支付订单,请到“我的-我的砍价”进行支付",
  1381. confirmText: "我的砍价",
  1382. success: function (res) {
  1383. if (res.confirm) {
  1384. tt.navigateTo({
  1385. url: `/pages/bargain/bargainDatail/bargainDatail?orderId=${that.data.disOrderNumber}&composeOrderType=${that.data.composeOrderType}`,
  1386. })
  1387. }
  1388. }
  1389. })
  1390. } else {
  1391. tt.showModal({
  1392. title: '提示',
  1393. content: '您有未支付订单,请先进行支付',
  1394. confirmText: "去支付",
  1395. success: function (res1) {
  1396. if (res1.confirm) {
  1397. if (that.data.composeOrderType > 0) {//券包
  1398. tt.navigateTo({
  1399. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}`,
  1400. })
  1401. } else {
  1402. tt.navigateTo({
  1403. url: `/pages/order/detail/index?orderId=${res.data.composeOrderId}`,
  1404. })
  1405. }
  1406. }
  1407. }
  1408. })
  1409. }
  1410. }).catch(error => {
  1411. tt.showToast({
  1412. title: error.message,
  1413. icon: "none",
  1414. duration: 3000
  1415. })
  1416. })
  1417. },
  1418. onShow() {
  1419. this.ifGetUser()//判断是否授权抖音
  1420. this.setData({
  1421. mouldType: app.globalData.mouldType,
  1422. showbutton: false,
  1423. showbutton1: false
  1424. })
  1425. if (this.data.end_time && this.data.activityStatus != 0) {
  1426. this.countdown(this.data.end_time)
  1427. } else if (this.data.begin_time && this.data.activityStatus == 0) {
  1428. this.countdown(this.data.begin_time)
  1429. }
  1430. },
  1431. onUnload: function () {
  1432. let that = this;
  1433. clearInterval(that.data.setInterval)
  1434. },
  1435. onHide: function () {
  1436. let that = this;
  1437. clearInterval(that.data.setInterval)
  1438. },
  1439. onShareAppMessage: function (options) {
  1440. app.globalData.previewFlag = true
  1441. var that = this;
  1442. console.log(options)
  1443. var shareObj = {
  1444. title: that.data.data.title,
  1445. path: `/pages/index/index?couponChannelId=${that.data.couponChannelId}`,
  1446. success: function (res) {
  1447. if (res.errMsg == 'shareAppMessage:ok') { }
  1448. },
  1449. fail: function (err) {
  1450. // if (err.errMsg == 'shareAppMessage:fail cancel') { } else if (err.errMsg == 'shareAppMessage:fail') { }
  1451. }
  1452. };
  1453. // 来自页面内的按钮的转发
  1454. if (options.from == 'button' && options.channel != 'video') {
  1455. var eData = options.target.dataset.id;
  1456. shareObj.path = `/pages/index/index?couponChannelId=${eData}&frommd=JC`;
  1457. } else
  1458. if (options.channel == 'video') {
  1459. // return {
  1460. // channel: 'video', // 必写 video
  1461. //     templateId: '',   // 分享的模版 id (如果未设置就是默认,下面会说如何设置)
  1462. // title: `${that.data.barTitle}`,     // 分享的标题
  1463. // desc: `${that.data.data.dyTitle}`,     // 分享的内容介绍目前没有用
  1464. //     path: `/pages/index/index`,  // 分享的路径
  1465. // extra: {
  1466. // videoTopics: [ that.data.data.dyTitle] // 只有抖音才会有的属性
  1467. // },
  1468. // }
  1469. shareObj.channel = 'video';
  1470. shareObj.title = `${that.data.data.title}`;
  1471. shareObj.extra = {
  1472. spu_id: that.data.spuIdObj.spuId
  1473. }
  1474. }
  1475. console.log(shareObj)
  1476. // 返回shareObj
  1477. return shareObj;
  1478. },
  1479. // onShareAppMessage: function(e) {
  1480. // console.log("onShareAppMessage", e);
  1481. // return {
  1482. // channel: 'video',
  1483. // title: "测试小程序分享",
  1484. // desc: "这是默认的分享文案,用户可以直接发送,也可以在发布器内修改",
  1485. // extra: {
  1486. // spu_id:"7091460633887279111" //开发者在抖音开放平台设置的商品id
  1487. // },
  1488. // success: function(e) {
  1489. // console.log("分享成功");
  1490. // },
  1491. // fail: function(e) {
  1492. // console.log(e,"分享成功失败")
  1493. // }
  1494. // };
  1495. // },
  1496. // 下拉刷新
  1497. onPullDownRefresh: function () {
  1498. this.getDetail(this.data.couponChannelId);
  1499. tt.stopPullDownRefresh()
  1500. },
  1501. onReachBottom: function () {
  1502. this.setData({
  1503. page: this.data.page + 1
  1504. })
  1505. if (this.data.idList.length > 0) {
  1506. this.getCouponList(this.data.idList)
  1507. }
  1508. }
  1509. });