index.vue 8.1 KB

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