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

445 lines
17 KiB

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