金诚优选前端代码
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.

508 lines
15 KiB

  1. <template>
  2. <view id="center">
  3. <!-- <view class="navbar mx-1px-top">
  4. <block v-for="(item, index) in tabList" :key="index" >
  5. <view :id="index" class="navbar-item activity" :hidden="activeIndex != index" :style="'color: ' + config.mainColor" @tap="tabClick">
  6. <view class="navbar-title">{{item.title}}</view>
  7. </view>
  8. <view :id="index" :hidden="activeIndex == index" class="navbar-item" @tap="tabClick">
  9. <view class="navbar-title">{{item.title}}</view>
  10. </view>
  11. </block>
  12. <view class="navbar-slider" :style="'width: ' + width + 'px; transform: translateX(' + sliderOffset + 'px); -webkit-transform: translateX(' + sliderOffset + 'px); background: ' + config.mainColor"></view>
  13. </view> -->
  14. <view class="tab-panel">
  15. <view class="tab-content" v-if="activeIndex == 0">
  16. <view v-if="dataList[0] && dataList[0][0] && dataList[0][0].length">
  17. <view v-for="(items, idx) in dataList[0]" :key="idx" >
  18. <view class="coupon" :data-id="item.id" :data-limit="item.usage_limit" @tap="jumpDetailOn" v-for="(item, index) in dataList[0][idx]" :key="index" v-if="item.is_open">
  19. <view class="coupon-left" :class="is_coupon != 1 ? 'discount' : ''" :style="'background: ' + config.mainColor">
  20. <view class="text-wrap">
  21. <view class="text-box">
  22. <view class="text">
  23. <text class="money" v-if="item.action_type.type == 'cash'"></text>
  24. <span>{{ item.action_type.value }}</span>
  25. <text class="money" v-if="item.action_type.type == 'discount'"></text>
  26. </view>
  27. <text class="label text">{{ item.label }}</text>
  28. </view>
  29. </view>
  30. <view class="dot-wrap">
  31. <view class="dot-item">
  32. </view>
  33. <view class="dot-item">
  34. </view>
  35. <view class="dot-item">
  36. </view>
  37. <view class="dot-item">
  38. </view>
  39. <view class="dot-item">
  40. </view>
  41. <view class="dot-item">
  42. </view>
  43. </view>
  44. </view>
  45. <view class="coupon-right">
  46. <view class="top">
  47. <!-- <span class="type">
  48. <span v-if="item.channel == 'ec'">商城</span>
  49. <span v-else>门店</span>
  50. </span> -->
  51. <text class="info">{{item.title}}</text>
  52. </view>
  53. <view class="bottom">
  54. <view class="bottom-use">
  55. <view class="tiem-box">
  56. <text>{{item.use_start_time}}{{item.use_end_time}}</text>
  57. </view>
  58. <view v-if="is_coupon == 1 && item.usage_limit !=0">
  59. <view class="btn use" :style="'background: ' + config.mainColor + '; border-color: ' + config.mainColor" :data-code="item.code" :data-index="idx" :data-findex="index" v-if="!item.has_get" @tap.stop="getCoupon">
  60. 点击领取
  61. </view>
  62. <view class="btn already" :style="'background: ' + config.mainColor + '; border-color: ' + config.mainColor" v-else :data-id="item.coupon_id" @tap.stop="jumpList">
  63. 去使用
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. <view class="cover" v-if="item.usage_limit ==0">
  70. <view class="big-circle">
  71. <view class="small-circle">
  72. <view :animation="animationData">已领完</view>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <view class="no-list" v-else>
  80. <i class="iconfont icon-youhuiquan"></i>
  81. <view>报告主人这里暂无<span v-if="is_coupon == 1">优惠券~</span><span v-else>促销活动</span></view>
  82. </view>
  83. </view>
  84. <view class="tab-content" v-if="activeIndex == 1">
  85. <view v-if="dataList[1] && dataList[1][0] && dataList[1][0].length">
  86. <view v-for="(items, idx) in dataList[1]" :key="idx">
  87. <view class="coupon" :data-id="item.id" :data-limit="item.usage_limit" @tap="jumpDetail" v-for="(item, index) in dataList[1][idx]" :key="index" v-if="item.is_open">
  88. <view class="coupon-left" :class="is_coupon != 1 ? 'discount' : ''" :style="'background: ' + config.mainColor">
  89. <view class="text-wrap">
  90. <view class="text-box">
  91. <view class="text">
  92. <text class="money" v-if="item.action_type.type == 'cash'"></text>
  93. <span>{{ item.action_type.value }}</span>
  94. <text class="money" v-if="item.action_type.type == 'discount'"></text>
  95. </view>
  96. <text class="label text">{{ item.label }}</text>
  97. </view>
  98. </view>
  99. <view class="dot-wrap">
  100. <view class="dot-item">
  101. </view>
  102. <view class="dot-item">
  103. </view>
  104. <view class="dot-item">
  105. </view>
  106. <view class="dot-item">
  107. </view>
  108. <view class="dot-item">
  109. </view>
  110. <view class="dot-item">
  111. </view>
  112. </view>
  113. </view>
  114. <view class="coupon-right">
  115. <view class="top">
  116. <span class="type">
  117. <span v-if="item.channel == 'ec'">商城</span>
  118. <span v-else>门店</span>
  119. </span>
  120. <text class="info">{{item.title}}</text>
  121. </view>
  122. <view class="bottom">
  123. <view class="bottom-use">
  124. <view class="tiem-box">
  125. <text>{{item.use_start_time}}{{item.use_end_time}}</text>
  126. </view>
  127. <view v-if="is_coupon == 1 && item.usage_limit !=0">
  128. <view class="btn use" :style="'background: ' + config.mainColor + '; border-color: ' + config.mainColor" :data-code="item.code" :data-index="idx" :data-findex="index" v-if="!item.has_get" @tap.stop="getCoupon">
  129. 点击领取
  130. </view>
  131. <view class="btn already" :style="'background: ' + config.mainColor + '; border-color: ' + config.mainColor" v-else :data-id="item.id" @tap.stop="jumpDetail">
  132. 去使用
  133. </view>
  134. </view>
  135. </view>
  136. </view>
  137. </view>
  138. <view class="cover" v-if="item.usage_limit ==0">
  139. <view class="big-circle">
  140. <view class="small-circle">
  141. <view :animation="animationData">已领完</view>
  142. </view>
  143. </view>
  144. </view>
  145. </view>
  146. </view>
  147. </view>
  148. <view v-else class="no-list">
  149. <i class="iconfont icon-youhuiquan"></i>
  150. <view>报告主人这里暂无<span v-if="is_coupon == 1">优惠券~</span><span v-else>促销活动</span></view>
  151. </view>
  152. </view>
  153. </view>
  154. <view class="home" @tap="jumpHome" :style="'background: ' + config.mainColor">
  155. <i class="iconfont icon--shouye"></i>
  156. <view>
  157. 首页
  158. </view>
  159. </view>
  160. </view>
  161. </template>
  162. <script>
  163. import {pageLogin, getUrl,config} from '@/common/js/utils.js';
  164. export default {
  165. data() {
  166. return {
  167. activeIndex: 0,
  168. sliderOffset: 0,
  169. width: 0,
  170. animationData: {},
  171. tabList: [{
  172. title: '线上',
  173. init: false,
  174. page: 0,
  175. more: true
  176. }, {
  177. title: '线下',
  178. init: false,
  179. page: 0,
  180. more: true
  181. }],
  182. dataList: {
  183. 0: [],
  184. 1: []
  185. },
  186. is_coupon: 1,
  187. // 用于判断是否为优惠券 1:优惠券 0:促销折扣
  188. config: ''
  189. };
  190. },
  191. onReachBottom(e) {
  192. var status = this.activeIndex;
  193. var page = this.tabList[status].page + 1;
  194. var tabList = `tabList[${status}]`;
  195. if (this.tabList[status].more) {
  196. this.queryCouponList(status, page);
  197. } else {
  198. wx.showToast({
  199. image: '../../../static/error.png',
  200. title: '再拉也没有啦'
  201. });
  202. }
  203. },
  204. onShow() {
  205. var animation = wx.createAnimation({
  206. duration: 1000,
  207. timingFunction: 'ease'
  208. });
  209. this.animation = animation;
  210. animation.rotate(-30).step();
  211. this.setData({
  212. animationData: animation.export()
  213. });
  214. wx.getSystemInfo({
  215. success: res => {
  216. this.setData({
  217. width: res.windowWidth / this.tabList.length,
  218. sliderOffset: res.windowWidth / this.tabList.length * this.activeIndex
  219. });
  220. }
  221. });
  222. },
  223. onLoad(e) {
  224. // 第三方平台配置颜色
  225. var gbConfig = this.$cookieStorage.get('globalConfig') || '';
  226. this.setData({
  227. config: gbConfig
  228. });
  229. if (e.type) {
  230. this.setData({
  231. activeIndex: e.type
  232. });
  233. }
  234. ;
  235. if (e.is_coupon) {
  236. if (e.is_coupon != 1) {
  237. wx.setNavigationBarTitle({
  238. title: '促销折扣中心'
  239. });
  240. } else {
  241. wx.setNavigationBarTitle({
  242. title: '领券中心'
  243. });
  244. }
  245. this.setData({
  246. is_coupon: e.is_coupon
  247. });
  248. } else {
  249. var referrerInfo = this.$cookieStorage.get('referrerInfo');
  250. if (referrerInfo && referrerInfo.extraData && referrerInfo.extraData.is_coupon == 0) {
  251. wx.setNavigationBarTitle({
  252. title: '促销折扣中心'
  253. });
  254. this.setData({
  255. is_coupon: 0
  256. });
  257. } else {
  258. wx.setNavigationBarTitle({
  259. title: '领券中心'
  260. });
  261. }
  262. }
  263. this.queryCouponList();
  264. },
  265. methods: {
  266. tabClick(e) {
  267. var status = e.currentTarget.id;
  268. this.setData({
  269. sliderOffset: e.currentTarget.offsetLeft,
  270. activeIndex: status
  271. });
  272. if (!this.tabList[status].init) {
  273. this.queryCouponList(status);
  274. }
  275. },
  276. jumpHome() {
  277. wx.switchTab({
  278. url: '/pages/index/index/index'
  279. });
  280. },
  281. // 跳转详情
  282. jumpDetailOn(e) {
  283. var id = e.currentTarget.dataset.id;
  284. var limit = e.currentTarget.dataset.limit;
  285. if (limit == 0) {
  286. return;
  287. }
  288. wx.navigateTo({
  289. url: '/pages/coupon/onDetail/onDetail?id=' + id + '&is_coupon=' + this.is_coupon
  290. });
  291. },
  292. jumpDetail(e) {
  293. var id = e.currentTarget.dataset.id;
  294. var limit = e.currentTarget.dataset.limit;
  295. if (limit == 0) {
  296. return;
  297. }
  298. wx.navigateTo({
  299. url: '/pages/coupon/offDetail/offDetail?id=' + id + '&is_coupon=' + this.is_coupon
  300. });
  301. },
  302. jumpList(e) {
  303. var id = e.currentTarget.dataset.id;
  304. wx.navigateTo({
  305. url: '/pages/coupon/goods/goods?id=' + id
  306. });
  307. },
  308. // 请求优惠券列表
  309. queryCouponList(type = 0, page = 1) {
  310. wx.showLoading({
  311. title: "加载中",
  312. mask: true
  313. });
  314. var token = this.$cookieStorage.get('user_token') || '';
  315. this.$http.get({
  316. api: 'api/discount/list',
  317. header: {
  318. Authorization: token
  319. },
  320. data: {
  321. page,
  322. type,
  323. is_coupon: this.is_coupon
  324. }
  325. }).then(res => {
  326. if (res.statusCode == 200) {
  327. res = res.data;
  328. if (res.status) {
  329. var pages = res.meta.pagination;
  330. var current_page = pages.current_page;
  331. var total_pages = pages.total_pages;
  332. //对象赋值
  333. this.$set(this.dataList[type],page-1,res.data);
  334. this.tabList[type].init=true;
  335. this.tabList[type].page=current_page;
  336. this.tabList[type].more=current_page < total_pages;
  337. } else {
  338. wx.showModal({
  339. content: res.message || '请求失败',
  340. showCancel: false
  341. });
  342. }
  343. } else {
  344. wx.showModal({
  345. content: res.message || '请求失败',
  346. showCancel: false
  347. });
  348. }
  349. wx.hideLoading();
  350. }).catch(rej => {
  351. wx.hideLoading();
  352. console.log(rej);
  353. wx.showModal({
  354. content: res.message || '请求失败',
  355. showCancel: false
  356. });
  357. });
  358. },
  359. // 领取优惠券
  360. getCoupon(e) {
  361. var token = this.$cookieStorage.get('user_token');
  362. var code = e.currentTarget.dataset.code;
  363. var index = e.currentTarget.dataset.index;
  364. var findex = e.currentTarget.dataset.findex;
  365. if (token) {
  366. this.convertCoupon(code, findex, index);
  367. } else {
  368. wx.showModal({
  369. content: '请先登录',
  370. showCancel: false,
  371. success: res => {
  372. if (res.confirm || !res.cancel && !res.confirm) {
  373. pageLogin(getUrl());
  374. }
  375. }
  376. });
  377. }
  378. },
  379. // 领取优惠券接口
  380. convertCoupon(code, findex, index) {
  381. var token = this.$cookieStorage.get('user_token');
  382. var activeIndex = this.activeIndex;
  383. wx.showLoading({
  384. title: "正在领取",
  385. mask: true
  386. });
  387. this.$http.post({
  388. api: 'api/coupon/convert',
  389. header: {
  390. Authorization: token
  391. },
  392. data: {
  393. coupon_code: code
  394. }
  395. }).then(res => {
  396. wx.hideLoading();
  397. if (res.statusCode == 200) {
  398. res = res.data;
  399. if (res.status) {
  400. let list = this.dataList[activeIndex][index];
  401. let item = list[findex];
  402. item.has_get = true;
  403. this.$set(this.dataList[activeIndex],index,list);
  404. wx.showToast({
  405. title: '领取成功'
  406. });
  407. } else {
  408. wx.showToast({
  409. title: res.message || '领取失败',
  410. image: '../../../static/error.png'
  411. });
  412. }
  413. } else {
  414. wx.showToast({
  415. title: '领取失败',
  416. image: '../../../static/error.png'
  417. });
  418. }
  419. }).catch(rej => {
  420. console.log(rej);
  421. wx.showToast({
  422. title: '领取失败',
  423. image: '../../../static/error.png'
  424. });
  425. wx.hideLoading();
  426. });
  427. },
  428. setData: function (obj) {
  429. let that = this;
  430. let keys = [];
  431. let val, data;
  432. Object.keys(obj).forEach(function (key) {
  433. keys = key.split('.');
  434. val = obj[key];
  435. data = that.$data;
  436. keys.forEach(function (key2, index) {
  437. if (index + 1 == keys.length) {
  438. that.$set(data, key2, val);
  439. } else {
  440. if (!data[key2]) {
  441. that.$set(data, key2, {});
  442. }
  443. }
  444. data = data[key2];
  445. });
  446. });
  447. }
  448. },
  449. computed: {},
  450. watch: {}
  451. };
  452. </script>
  453. <style rel="stylesheet/less" lang="less">
  454. @import "center";
  455. </style>