index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view>
  3. <view class="list" v-if="pageList.length>0">
  4. <block v-for="(item,index) in pageList" :key="index">
  5. <!-- //选择使用优惠券 -->
  6. <view class="li ddflex" @tap="item.isUse?chooseCoupon(index):''" :data-index="index" v-if="isChoose">
  7. <image src="/product/static/product/image/yhq_gq.png" v-if="!item.isUse" class="guoqi"></image>
  8. <view class="name">
  9. <block v-if="item.title">{{item.title}}</block>
  10. <block v-else>{{item.couponType === 3 ? '通用券':item.couponType === 1 ? '满减券' : '代金券'}}</block>
  11. </view>
  12. <view class="info fflex ddflex">
  13. <image :src="item.couponIcon" mode="aspectFill" v-if="item.couponIcon"></image>
  14. <view class="fflex">
  15. <view class="tit">{{item.couponTitle}}</view>
  16. <view class="time">有效期至{{item.couponEnd}}</view>
  17. </view>
  18. </view>
  19. <view class="info-r ddflex">
  20. <view class="money"><text>¥</text>{{item.couponAmount}}</view>
  21. <view class="man">{{item.couponBrief}}</view>
  22. </view>
  23. </view>
  24. <!-- 领取优惠券 -->
  25. <view class="li ddflex" @click="item.userCount >= item.userReceive&&item.userCount!=0&&item.userReceive!=-1 ? toIndex(item,index) : recieveCoupon(item,index)" v-else>
  26. <view class="name">
  27. <block v-if="item.title">{{item.title}}</block>
  28. <block v-else>{{item.couponType === 3 ? '通用券':item.couponType === 1 ? '满减券' : '代金券'}}</block>
  29. </view>
  30. <view class="info fflex ddflex">
  31. <image :src="item.couponIcon?item.couponIcon:picUrlss+'coupon_default.png'" mode="aspectFill"></image>
  32. <view class="fflex">
  33. <view class="tit">{{item.couponTitle}}</view>
  34. <view class="time">有效期至{{item.couponEnd}}</view>
  35. </view>
  36. </view>
  37. <view class="info-r ddflex">
  38. <view class="money"><text>¥</text>{{item.couponAmount}}</view>
  39. <view class="man">{{item.couponBrief}}</view>
  40. <view class="btn">{{item.userCount >= item.userReceive&&item.userCount!=0&&item.userReceive!=-1 ? '已领取' : '立即领'}}</view>
  41. </view>
  42. </view>
  43. </block>
  44. </view>
  45. <view class="nodata" v-else>
  46. <image :src="picUrlss+'empty_yhq.png'"></image>
  47. <text>暂无优惠券</text>
  48. </view>
  49. <view style="height: 135rpx;"></view>
  50. <view class="bot ddflex">
  51. <view class="ddflex no fflex" @click="noUsecoupon" v-if="isChoose">不使用优惠券</view>
  52. <block v-else>
  53. <view class="ddflex" @click="jumpUrl('/product/exchange/index')"><image src="../static/product/image/quan_dhm.png"></image>兑换</view>
  54. <view class="ddflex" @click="jumpUrl('/mine/coupons/coupons')"><image src="../static/product/image/quan_wd.png"></image>我的券</view>
  55. </block>
  56. </view>
  57. </view>
  58. </template>
  59. <script>
  60. const req = require("../../utils/request.js");
  61. const app = getApp();
  62. export default {
  63. data() {
  64. return {
  65. picUrlss: req.public.picUrls,
  66. opt: {},
  67. form: {
  68. page: 1,
  69. limit: 10
  70. },
  71. pageList: [],
  72. isLoad: true,
  73. isChoose: false,
  74. bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
  75. ishow: false,
  76. couponIndex: "",
  77. userInfo: {},
  78. productId: '',
  79. };
  80. },
  81. components: {},
  82. props: {},
  83. onLoad: function(options) {
  84. this.opt = options;
  85. if(options.productId){
  86. this.productId = options.productId
  87. }
  88. if (options.isChoose) {
  89. let pages = getCurrentPages();
  90. var prevPage = pages[pages.length - 2];
  91. // console.log(prevPage,prevPage.data.couponList);
  92. this.setData({
  93. pageList: prevPage.data.couponList,
  94. isChoose: options.isChoose
  95. });
  96. } else {
  97. if(this.productId){
  98. this.loadProductCoupon()
  99. }else{
  100. this.loadCoupon();
  101. }
  102. }
  103. },
  104. onShow(){
  105. this.getMy();
  106. },
  107. onReachBottom() {
  108. this.form.page++
  109. this.loadCoupon();
  110. },
  111. methods: {
  112. getMy() {
  113. req.getRequest('/api/user/my', {}, data => {
  114. this.userInfo = data;
  115. });
  116. },
  117. loadProductCoupon(isLoading) {
  118. let isShowLoading = false;
  119. let that = this;
  120. if (!this.isLoad) return false;
  121. this.isLoad = false;
  122. let form = that.form;
  123. if(this.productId){
  124. form.productId = this.productId;
  125. }
  126. if (form.page == 1 && !isShowLoading && !isLoading) {
  127. req.loadIng('加载中');
  128. isShowLoading = true;
  129. }
  130. req.getRequest('/api/coupon/listV2', form, data => {
  131. // console.log(data);
  132. if (data && data.length >= 10) that.isLoad = true;
  133. if (that.form.page > 1) data = that.pageList.concat(data);
  134. that.setData({
  135. pageList: data
  136. });
  137. if (data.length <= 0) {
  138. that.setData({
  139. ishow: true
  140. });
  141. } else {
  142. that.setData({
  143. ishow: false
  144. });
  145. }
  146. if (isShowLoading) {
  147. uni.hideLoading();
  148. isShowLoading = false;
  149. }
  150. });
  151. },
  152. loadCoupon() {
  153. if(!this.isLoad) return false;
  154. this.isLoad = false;
  155. let form = this.form;
  156. form.bindType = 'use'
  157. if(this.opt.couponType) form.couponType = this.opt.couponType;// 5新人券 6品牌券 7供应商券 3其它通用
  158. else delete form.couponType;
  159. if(this.opt.categoryId){
  160. form.categoryId = this.opt.categoryId;
  161. }
  162. if(this.opt.specialId){
  163. form.specialId = this.opt.specialId;
  164. }
  165. req.getRequest('/api/coupon/list', form, data => {
  166. if(data&&data.length >= 10) this.isLoad = true;
  167. if(form.page > 1) data = this.pageList.concat(data);
  168. this.pageList = data;
  169. });
  170. },
  171. recieveCoupon(item,index) {
  172. let _ts = this;
  173. if(!_ts.userInfo.mobile){
  174. uni.navigateTo({
  175. url: '/pages/authorize/authorize?bindmobile=' + 1
  176. })
  177. return false;
  178. }
  179. // let index = e.currentTarget.dataset.index;
  180. const coupon = item;
  181. if (coupon.userReceive > -1 && coupon.userCount >= coupon.userReceive) {
  182. return req.msg('超出优惠券领取限制,无法领取');
  183. }
  184. req.postRequest('/api/coupon/receive', {
  185. id: coupon.id
  186. }, res => {
  187. // console.log(res);
  188. req.msg('领取成功', () => {
  189. // console.log("11111111111111");
  190. let isLoading = true;
  191. this.pageList[index].userCount++;
  192. // _ts.loadCoupon(isLoading);
  193. });
  194. });
  195. },
  196. chooseCoupon(index) {
  197. // let index = event.currentTarget.dataset.index;
  198. // console.log(index);
  199. let pages = getCurrentPages();
  200. var prevPage = pages[pages.length - 2];
  201. prevPage.$vm.setData({
  202. couponIndex: index
  203. });
  204. uni.navigateBack();
  205. },
  206. toIndex() {
  207. // app.globalData.switchTab('pages/index/index');
  208. return req.msg('不可重复领取')
  209. // if (req.header.appId == 'ZQ1VK5oc17I387E') {
  210. // app.globalData.switchTab('pages/timelyDelivery/index')
  211. // } else {
  212. // app.globalData.switchTab('pages/index/index')
  213. // }
  214. },
  215. noUsecoupon() {
  216. let pages = getCurrentPages();
  217. var prevPage = pages[pages.length - 2];
  218. prevPage.$vm.setData({
  219. couponIndex: false
  220. });
  221. uni.navigateBack();
  222. },
  223. toCoupon() {
  224. uni.navigateTo({
  225. url: '/mine/coupons/coupons'
  226. })
  227. },
  228. jumpUrl(url){
  229. uni.navigateTo({
  230. url: url
  231. })
  232. }
  233. }
  234. };
  235. </script>
  236. <style>
  237. @import "./index.css";
  238. </style>