coupon - 副本.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <view>
  3. <!--product/coupon/coupon.wxml-->
  4. <view class="list" v-if="pageList.length > 0">
  5. <block v-for="(item, index) in pageList" :key="index">
  6. <!-- //选择使用优惠券 -->
  7. <view class="li" @tap="item.isUse?chooseCoupon(index):''" :data-index="index" v-if="isChoose">
  8. <view class="lit">
  9. <image :src="picUrlss+'yhq_wei.png'" class="lqbg" v-if="item.isUse"></image>
  10. <image :src="picUrlss+'yhq_yi.png'" class="lqbg" v-else></image>
  11. <view class="lits dflex">
  12. <view class="left"><text>¥</text><text class="jine">{{item.couponAmount}}</text>元</view>
  13. <view class="tong flex">
  14. <view>{{item.couponType === 1 ? '满减券' : '代金券'}}</view>
  15. <text>{{item.couponBrief}}</text>
  16. </view>
  17. <view class="lqbtn" v-if="!isChoose">立即使用</view>
  18. </view>
  19. </view>
  20. <view class="right">
  21. <view>使用日期:{{item.couponStart}}至{{item.couponEnd}}</view>
  22. <view>适用范围:{{item.couponTitle}}</view>
  23. <image src="/product/static/product/image/yhq_gq.png" v-if="!item.isUse" class="guoqi"></image>
  24. <!-- <image src="/pages/images/erweima.png"></image> -->
  25. </view>
  26. </view>
  27. <!-- //领取优惠券 -->
  28. <view v-else class="li"
  29. @tap="item.userCount >= item.userReceive&&item.userCount!=0&&item.userReceive!=-1 ? toIndex(index) : recieveCoupon(index)"
  30. :data-index="index">
  31. <view class="lit">
  32. <!-- 用户已经张数>= 优惠券领取次数限制 并且用户已经张数不等于0,优惠券领取次数限制不等于无限次数-->
  33. <image :src="picUrlss+'yhq_yi.png'" class="lqbg"
  34. v-if="item.userCount >= item.userReceive&&item.userCount!=0&&item.userReceive!=-1"></image>
  35. <image :src="picUrlss+'yhq_wei.png'" class="lqbg" v-else></image>
  36. <view class="lits dflex">
  37. <view class="left"><text>¥</text><text class="jine">{{item.couponAmount}}</text>元</view>
  38. <view class="tong flex">
  39. <view>{{item.couponType === 1 ? '满减券' : '代金券'}}</view>
  40. <text>{{item.couponBrief}}</text>
  41. </view>
  42. <view class="lqbtn" v-if="!isChoose">
  43. {{item.userCount >= item.userReceive&&item.userCount!=0&&item.userReceive!=-1 ? '已领取' : '立即领取'}}
  44. </view>
  45. </view>
  46. </view>
  47. <view class="right">
  48. <view>使用日期:{{item.couponStart}}至{{item.couponEnd}}</view>
  49. <view>适用范围:{{item.couponTitle}}</view>
  50. </view>
  51. <!-- <view class="left"><text>{{item.couponAmount}}</text>元</view>
  52. <view class="right flex">
  53. <view>{{item.couponType === 1 ? '满减券' : '代金券'}}</view>
  54. <view>订单满{{item.couponFull}}元减{{item.couponAmount}}</view>
  55. </view> -->
  56. </view>
  57. </block>
  58. </view>
  59. <view class="nodata" v-if="ishow">
  60. <image :src="picUrlss+'empty_yhq.png'"></image>
  61. <text>暂无优惠券</text>
  62. </view>
  63. <view class="placeholder-view" :style="'height:' + (bottomBlankHeight + 120) + 'rpx'" v-if="isChoose">
  64. <view class="bot" :style="'padding-bottom:' + bottomBlankHeight + 'rpx'">
  65. <view class="confirm " @tap="noUsecoupon">不使用优惠券</view>
  66. </view>
  67. </view>
  68. <view class="placeholder-view" :style="'height:' + (bottomBlankHeight + 120) + 'rpx'" v-else>
  69. <view class="bot" :style="'padding-bottom:' + bottomBlankHeight + 'rpx'">
  70. <view class="confirm " @tap="toCoupon">查看我的优惠券</view>
  71. </view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. const req = require("../../utils/request.js");
  77. const app = getApp();
  78. export default {
  79. data() {
  80. return {
  81. picUrlss: req.public.picUrls,
  82. form: {
  83. page: 1,
  84. limit: 10
  85. },
  86. pageList: [],
  87. isLoad: true,
  88. isChoose: false,
  89. bottomBlankHeight: app.globalData.isIPhoneX ? 68 : 0,
  90. ishow: false,
  91. couponIndex: "",
  92. userInfo: {},
  93. productId: ''
  94. };
  95. },
  96. components: {},
  97. props: {},
  98. onLoad: function(options) {
  99. if(options.productId){
  100. this.productId = options.productId
  101. }
  102. if (options.isChoose) {
  103. let pages = getCurrentPages();
  104. var prevPage = pages[pages.length - 2];
  105. // console.log(prevPage,prevPage.data.couponList);
  106. this.setData({
  107. pageList: prevPage.data.couponList,
  108. isChoose: options.isChoose
  109. });
  110. } else {
  111. if(this.productId){
  112. this.loadProductCoupon()
  113. }else{
  114. this.loadCoupon();
  115. }
  116. }
  117. },
  118. onShow(){
  119. this.getMy();
  120. },
  121. onReachBottom() {
  122. if (!this.isChoose) {
  123. this.form.page++;
  124. if(this.productId){
  125. this.loadProductCoupon()
  126. }else{
  127. this.loadCoupon();
  128. }
  129. }
  130. },
  131. methods: {
  132. getMy() {
  133. req.getRequest('/api/user/my', {}, data => {
  134. this.userInfo = data;
  135. });
  136. },
  137. loadProductCoupon(isLoading) {
  138. let isShowLoading = false;
  139. let that = this;
  140. if (!this.isLoad) return false;
  141. this.isLoad = false;
  142. let form = that.form;
  143. if(this.productId){
  144. form.productId = this.productId;
  145. }
  146. if (form.page == 1 && !isShowLoading && !isLoading) {
  147. req.loadIng('加载中');
  148. isShowLoading = true;
  149. }
  150. req.getRequest('/api/coupon/listV2', form, data => {
  151. // console.log(data);
  152. if (data && data.length >= 10) that.isLoad = true;
  153. if (that.form.page > 1) data = that.pageList.concat(data);
  154. that.setData({
  155. pageList: data
  156. });
  157. if (data.length <= 0) {
  158. that.setData({
  159. ishow: true
  160. });
  161. } else {
  162. that.setData({
  163. ishow: false
  164. });
  165. }
  166. if (isShowLoading) {
  167. uni.hideLoading();
  168. isShowLoading = false;
  169. }
  170. });
  171. },
  172. loadCoupon(isLoading) {
  173. let isShowLoading = false;
  174. if (this.form.page == 1 && !isShowLoading && !isLoading) {
  175. req.loadIng('加载中');
  176. isShowLoading = true;
  177. }
  178. // console.log(!this.isLoad);
  179. if (!this.isLoad) return false;
  180. this.isLoad = false;
  181. let that = this;
  182. req.getRequest('/api/coupon/list', that.form, data => {
  183. // console.log(data);
  184. if (data && data.length >= 10) that.isLoad = true;
  185. if (that.form.page > 1) data = that.pageList.concat(data);
  186. that.setData({
  187. pageList: data
  188. });
  189. if (data.length <= 0) {
  190. that.setData({
  191. ishow: true
  192. });
  193. } else {
  194. that.setData({
  195. ishow: false
  196. });
  197. }
  198. if (isShowLoading) {
  199. uni.hideLoading();
  200. isShowLoading = false;
  201. }
  202. });
  203. },
  204. recieveCoupon(index) {
  205. let _ts = this;
  206. if(!_ts.userInfo.mobile){
  207. uni.navigateTo({
  208. url: '/pages/authorize/authorize?bindmobile=' + 1
  209. })
  210. return false;
  211. }
  212. // let index = e.currentTarget.dataset.index;
  213. const coupon = _ts.pageList[index];
  214. if (coupon.userReceive > -1 && coupon.userCount >= coupon.userReceive) {
  215. return req.msg('超出优惠券领取限制,无法领取');
  216. }
  217. req.postRequest('/api/coupon/receive', {
  218. id: coupon.id
  219. }, res => {
  220. // console.log(res);
  221. req.msg('领取成功', () => {
  222. // console.log("11111111111111");
  223. let isLoading = true;
  224. _ts.loadCoupon(isLoading);
  225. });
  226. });
  227. },
  228. chooseCoupon(index) {
  229. // let index = event.currentTarget.dataset.index;
  230. // console.log(index);
  231. let pages = getCurrentPages();
  232. var prevPage = pages[pages.length - 2];
  233. prevPage.$vm.setData({
  234. couponIndex: index
  235. });
  236. uni.navigateBack();
  237. },
  238. toIndex() {
  239. // app.globalData.switchTab('pages/index/index');
  240. if (req.header.appId == 'ZQ1VK5oc17I387E') {
  241. app.globalData.switchTab('pages/timelyDelivery/index')
  242. } else {
  243. app.globalData.switchTab('pages/index/index')
  244. }
  245. },
  246. noUsecoupon() {
  247. let pages = getCurrentPages();
  248. var prevPage = pages[pages.length - 2];
  249. prevPage.$vm.setData({
  250. couponIndex: false
  251. });
  252. uni.navigateBack();
  253. },
  254. toCoupon() {
  255. uni.navigateTo({
  256. url: '/mine/coupons/coupons'
  257. })
  258. }
  259. }
  260. };
  261. </script>
  262. <style>
  263. @import "./coupon.css";
  264. </style>