coupon.vue 9.0 KB

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