coupons.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <view>
  3. <!--mine/coupons/coupons.wxml-->
  4. <view class="tab bgfff dflex">
  5. <view :class="'li ' + (currentTab == 0 ? 'active' : '')" data-current="0" @tap="tab">未使用({{couponCount.unUse ? couponCount.unUse : 0}})</view>
  6. <view :class="'li ' + (currentTab == 1 ? 'active' : '')" data-current="1" @tap="tab">已使用({{couponCount.used ? couponCount.used : 0}})</view>
  7. <view :class="'li ' + (currentTab == 2 ? 'active' : '')" data-current="2" @tap="tab">已失效({{couponCount.invalid ? couponCount.invalid : 0}})</view>
  8. </view>
  9. <navigator url="/product/couponList/index" hover-class="none" class="ling ddflex">
  10. <image :src="config.mainIconPath ? picUrlss + config.mainIconPath+'quan.png' : '../static/mine/images/quan.png'" class="quan-img"></image>
  11. <view class="fflex">去领券中心</view>
  12. <image src="../../static/pages/images/rico.png" class="rico"></image>
  13. </navigator>
  14. <block v-if="pageList.length > 0">
  15. <view class="list">
  16. <view :class="'li' + (item.couponType === 3 ? ' tong' : '') + (currentTab == 0 ? '' : ' hui')" v-for="(item, index) in pageList" :key="index">
  17. <view class="info dflex">
  18. <image :src="item.couponIcon" mode="aspectFill" class="info-img" v-if="item.couponIcon"></image>
  19. <view class="flex">
  20. <view class="title">{{item.couponType === 3 ? '通用券' : item.couponType === 1 ? '满减券' : item.couponType === 4 ? '免除券':'代金券'}}-{{item.couponTitle}}</view>
  21. <view class="time">有效期至{{item.couponEnd}}</view>
  22. </view>
  23. <view class="info-r" v-if="item.couponType != 4">
  24. <view class="money"><text>¥</text>{{item.couponAmount}}</view>
  25. <view class="man">{{item.couponBrief}}</view>
  26. </view>
  27. </view>
  28. <view class="li-bot dflex">
  29. <view class="check dflex flex" @click="checks(item,index)">查看详情
  30. <!-- <view class="xian">限青岛大虾</view> -->
  31. <image src="../static/mine/images/bico1.png" v-if="item.couponType === 3"></image>
  32. <image src="../static/mine/images/bico.png" v-else></image>
  33. </view>
  34. <!-- <image :src="'../static/mine/images/' + (item.couponType === 3 ? 'ma_white' : 'ma_dark') + '.png'" class="ma"></image> -->
  35. <view class="yong dflex" @tap="toIndex" v-if="currentTab == 0">去使用</view>
  36. <view class="yi" v-else>
  37. <image src="../static/mine/images/yishiyong.png" class="yipic" v-if="currentTab == 1"></image>
  38. <image src="../static/mine/images/yishixiao.png" class="yipic" v-else></image>
  39. </view>
  40. </view>
  41. <view class="infos" v-if="item.isShow">
  42. <view>1.使用时间:{{item.couponStart}}至{{item.couponEnd}}</view>
  43. <view v-if="item.couponBrief">2.使用范围:{{item.couponBrief}}</view>
  44. <view v-if="item.useActionsList && item.useActionsList.length > 0" class="i-pro">{{item.couponBrief?'3':'2'}}.指定产品:
  45. <text v-for="(it,idx) in item.useActionsList" :key="idx" @click="toDetail(it)">{{it.name}}</text>
  46. </view>
  47. </view>
  48. </view>
  49. </view>
  50. <!-- <view :class="'list ' + (currentTab == 0 ? 'show' : 'hide')">
  51. <view v-for="(item, index) in pageList" :key="index" class="li" @tap="toIndex">
  52. <view class="lit">
  53. <image :src="picUrlss+'yhq_wei.png'" class="lqbg" v-if="item.couponState==1"></image>
  54. <image :src="picUrlss+'yiguoqi.png'" class="lqbg"
  55. v-if="item.couponState==2||item.couponState==3"></image>
  56. <view class="lits dflex">
  57. <view class="left"><text>¥</text><text class="jine">{{item.couponAmount}}</text>元</view>
  58. <view class="tong flex">
  59. <view>{{item.couponType === 1 ? '满减券' : '代金券'}}</view>
  60. <text>{{item.couponBrief}}</text>
  61. </view>
  62. <view class="lqbtn" v-if="item.couponState==1">立即使用</view>
  63. <view class="lqbtn" v-if="item.couponState==2">已使用</view>
  64. <view class="lqbtn" v-if="item.couponState==3">已过期</view>
  65. </view>
  66. </view>
  67. <view class="dflex bot">
  68. <view class="right">
  69. <view>使用日期:{{item.couponStart}}至{{item.couponEnd}}</view>
  70. <view>适用范围:{{item.couponTitle}}</view>
  71. </view>
  72. <image src="/static/pages/images/erweima.png" class="erweima" v-if="item.couponState==1">
  73. </image>
  74. <image src="/static/pages/images/yhq-ygq.png" class="erweima"
  75. v-if="item.couponState==2||item.couponState==3"></image>
  76. </view>
  77. </view>
  78. </view>
  79. <view :class="'list ' + (currentTab == 1 ? 'show' : 'hide')">
  80. <view v-for="(item, index) in pageList" :key="index" class="li fail">
  81. <view class="lit">
  82. <image :src="picUrlss+'yhq_yi.png'" class="lqbg"></image>
  83. <view class="lits dflex">
  84. <view class="left"><text>¥</text><text class="jine">{{item.couponAmount}}</text>元</view>
  85. <view class="tong flex">
  86. <view>{{item.couponType === 1 ? '满减券' : '代金券'}}</view>
  87. <text>{{item.couponBrief}}</text>
  88. </view>
  89. </view>
  90. </view>
  91. <view class="right">
  92. <view>使用日期:{{item.couponStart}}至{{item.couponEnd}}</view>
  93. <view>适用范围:{{item.couponTitle}}</view>
  94. </view>
  95. <image src="/static/pages/images/guoqi.png" class="guoqi"></image>
  96. </view>
  97. </view> -->
  98. </block>
  99. <view class="nodata" v-if="ishow">
  100. <image :src="picUrlss+'empty_yhq.png'"></image>
  101. <text>暂无优惠券</text>
  102. </view>
  103. </view>
  104. </template>
  105. <script>
  106. // mine/coupons/coupons.js
  107. const req = require("../../utils/request.js");
  108. const app = getApp();
  109. export default {
  110. data() {
  111. return {
  112. picUrlss: req.public.picUrls,
  113. currentTab: 0,
  114. form: {
  115. page: 1,
  116. limit: 10,
  117. couponState: 1
  118. },
  119. pageList: [],
  120. isLoad: true,
  121. ishow: false,
  122. couponCount: '',
  123. config: {}
  124. };
  125. },
  126. components: {},
  127. props: {},
  128. onShow: function() {
  129. this.config = JSON.parse(req.getStorage('configRes'));
  130. this.form.page = 1;
  131. this.isLoad = true;
  132. this.setData({
  133. pageList: []
  134. });
  135. this.loadCoupon();
  136. this.getCount();
  137. },
  138. onReachBottom() {
  139. this.form.page++;
  140. this.loadCoupon();
  141. },
  142. methods: {
  143. tab(e) {
  144. let that = this;
  145. const index = e.currentTarget.dataset.current;
  146. if (that.currentTab === index) {
  147. return false;
  148. }
  149. that.setData({
  150. currentTab: index
  151. });
  152. console.log('currentTab==' + that.currentTab)
  153. that.form.couponState = index == 0 ? 1 : index == 1 ? 2 : 3;
  154. // console.log(index, that.form.couponState);
  155. that.form.page = 1;
  156. that.isLoad = true;
  157. that.setData({
  158. pageList: []
  159. });
  160. that.loadCoupon();
  161. },
  162. getCount(){
  163. req.getRequest('/api/v3/coupon/count',{},data=>{
  164. this.couponCount = data;
  165. })
  166. },
  167. loadCoupon() {
  168. let isShowLoading = false;
  169. if (this.form.page == 1 && !isShowLoading) {
  170. req.loadIng('加载中');
  171. isShowLoading = true;
  172. }
  173. if (!this.isLoad) return false;
  174. this.isLoad = false;
  175. let that = this;
  176. req.getRequest('/api/coupon/user', this.form, data => {
  177. if (data && data.length == 10) this.isLoad = true;
  178. if (that.form.page > 1) data = that.pageList.concat(data);
  179. data.map(it=>{
  180. it.isShow = false;
  181. return it;
  182. })
  183. that.setData({
  184. pageList: data
  185. });
  186. if (!this.pageList || data.length <= 0) {
  187. that.setData({
  188. ishow: true
  189. });
  190. } else {
  191. that.setData({
  192. ishow: false
  193. });
  194. }
  195. if (isShowLoading) {
  196. uni.hideLoading();
  197. isShowLoading = false;
  198. }
  199. });
  200. },
  201. toIndex() {
  202. app.globalData.openHome();
  203. },
  204. checks(item,index){
  205. let pageList = this.pageList;
  206. if(pageList[index].isShow){
  207. pageList[index].isShow = false;
  208. }else{
  209. pageList.map(it=>{
  210. it.isShow = false;
  211. return it;
  212. });
  213. pageList[index].isShow = true;
  214. }
  215. },
  216. toDetail(it){
  217. uni.navigateTo({
  218. url: '/product/detail/detail?id=' + it.id + '&merchantId=' + req.getStorage('MERCHANT').id
  219. })
  220. }
  221. }
  222. };
  223. </script>
  224. <style>
  225. @import "./coupons.css";
  226. </style>