抖音c端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

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