mescrollUni-item.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <template>
  2. <!--
  3. swiper中的transfrom会使fixed失效,此时用height固定高度;
  4. swiper中无法触发mescroll-mixins.js的onPageScroll和onReachBottom方法,只能用mescroll-uni,不能用mescroll-body
  5. -->
  6. <!-- ref动态生成: 字节跳动小程序编辑器不支持一个页面存在相同的ref (如不考虑字节跳动小程序可固定值为 ref="mescrollRef") -->
  7. <!-- top的高度等于悬浮菜单tabs的高度 -->
  8. <mescroll-uni :ref="'mescrollRef' + i" @init="mescrollInit" :height="height" :down="downOption" @down="downCallback"
  9. :up="upOption" @up="upCallback" @emptyclick="emptyClick">
  10. <view class="flex-row justify-center">
  11. <view class="flex-col">
  12. <view class="flex-col" v-for="(item,index) in list" :key="index" >
  13. <view class="flex-row justify-start quan" :class="item.state == '0'?'row-list':'listBackground'">
  14. <view class="h-text flex-col justify-center ">
  15. <view class="money">
  16. <text class="money" v-if="item.discountsType == 2">{{item.discount}}折</text>
  17. <text class="money" v-else>{{`减` + item.discountsPrice}}</text>
  18. </view>
  19. <view class="desc">
  20. <text>满{{item.reachPrice}}可用</text>
  21. </view>
  22. </view>
  23. <view class="h-center-content flex-col justify-around">
  24. <view class="h-value">
  25. <text>{{item.name}}</text>
  26. </view>
  27. <!-- <view class="title">-->
  28. <!-- 使用平台:<text v-if="item.strategyType == '0'">全平台</text>-->
  29. <!-- <text v-else-if="item.strategyType == '1'">个人优惠卷</text>-->
  30. <!-- </view>-->
  31. <view>
  32. <view class="title" v-if="item.isLimit === 1" >
  33. 可用次数/总次数:{{item.degree}}/{{item.totalDegree}}
  34. </view>
  35. <view class="title" v-else>
  36. 可用次数/总次数:不限使用次数
  37. </view>
  38. </view>
  39. <view class="title">
  40. 到期时间:{{item.endTime.substring(0,10)}}
  41. </view>
  42. <view class="title flex-row">
  43. <text @click="showRemark(item)">使用说明</text>
  44. <u-icon v-if="item.id == showRemarkId" name="arrow-down-fill" color="" size="12"></u-icon>
  45. <u-icon v-else name="play-right-fill" color="" size="12"></u-icon>
  46. </view>
  47. </view>
  48. <view class="h-right-content flex-col justify-center">
  49. <view v-if="item.state == 0" ></view>
  50. <!-- <view @click="gotoUseCoupon(item)" v-if="item.state == 0" class="h-btn-value-use">立即使用</view>-->
  51. <!-- <view @click="gotoReceiveCoupon()" v-else-if="index == 1" class="h-btn-value-receive">立即领取</view> -->
  52. <view v-else-if="item.state == 1" class="h-btn-img">
  53. <image class="h-btn-img" src="/static/coupon/u2109.png" mode=""></image>
  54. </view>
  55. <view v-else class="h-btn-img">
  56. <image class="h-btn-img" color="#999999" src="/static/coupon/u2108.png" mode=""></image>
  57. </view>
  58. </view>
  59. </view>
  60. <view v-if="showRemarkId == item.id" class="remark" style="text-indent:unset">
  61. <view class="remarkText">
  62. <view v-if="item.unavailableWeeklyTimes || item.unavailableTimeRanges">
  63. 不可用日期:
  64. <view v-if="item.unavailableWeeklyTimes">{{ parseWeeklyTimes(item.unavailableWeeklyTimes) }}</view>
  65. <view v-if="item.unavailableTimeRanges">{{ parseTimeRanges(item.unavailableTimeRanges) }}</view>
  66. </view>
  67. <view v-if="item.delayEffectiveDays > 0">
  68. 生效时间:
  69. <text>购买后{{item.delayEffectiveDays}}天生效</text>
  70. </view>
  71. <view>
  72. 可用门店:<text>{{item.useStoreDesc}}</text>
  73. </view>
  74. <view>
  75. 适用项目:<text>{{item.useServiceDesc}}</text>
  76. </view>
  77. <view v-if="item.remark !=null">
  78. 使用说明:<text>{{item.remark}}</text>
  79. </view>
  80. <text v-else class="remarkText">该优惠券暂无使用说明</text>
  81. </view>
  82. </view>
  83. </view>
  84. </view>
  85. </view>
  86. </mescroll-uni>
  87. </template>
  88. <script>
  89. import MescrollMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mescroll-mixins.js";
  90. import MescrollMoreItemMixin from "@/uni_modules/mescroll-uni/components/mescroll-uni/mixins/mescroll-more-item.js"
  91. export default {
  92. mixins: [MescrollMixin, MescrollMoreItemMixin], // 注意此处还需使用MescrollMoreItemMixin (必须写在MescrollMixin后面)
  93. components: {
  94. },
  95. data() {
  96. return {
  97. showRemarkId:'',
  98. downOption: {
  99. auto: false // 不自动加载 (mixin已处理第一个tab触发downCallback)
  100. },
  101. upOption: {
  102. auto: false, // 不自动加载
  103. // page: {
  104. // num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
  105. // size: 10 // 每页数据的数量
  106. // },
  107. noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
  108. empty: {
  109. icon: '/static/imageIcon/empty.png',
  110. tip: '暂无内容', // 提示
  111. // btnText: '去看看'
  112. },
  113. textNoMore: '没有更多了'
  114. },
  115. list: [],
  116. }
  117. },
  118. props: {
  119. i: Number, // 每个tab页的专属下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
  120. index: { // 当前tab的下标 (除了支付宝小程序必须在这里定义, 其他平台都可不用写, 因为已在MescrollMoreItemMixin定义)
  121. type: Number,
  122. default() {
  123. return 0
  124. }
  125. },
  126. dataTime: {
  127. type: String,
  128. default() {
  129. return ''
  130. }
  131. },
  132. tabs: { // 为了请求数据,演示用,可根据自己的项目判断是否要传
  133. type: Array,
  134. default() {
  135. return []
  136. }
  137. },
  138. height: [Number, String], // mescroll的高度
  139. },
  140. watch: {
  141. },
  142. computed: {
  143. // 解析 unavailableWeeklyTimes,将 "3,4,5" 转换为 ["星期二", "星期三", "星期四"]
  144. parseWeeklyTimes() {
  145. return function(times) {
  146. if (!times) return '';
  147. const arr = times.split(',');
  148. const weekMap = {
  149. '1': '星期日',
  150. '2': '星期一',
  151. '3': '星期二',
  152. '4': '星期三',
  153. '5': '星期四',
  154. '6': '星期五',
  155. '7': '星期六'
  156. };
  157. return arr.map(item => weekMap[item]).join('、');
  158. };
  159. },
  160. // 解析 unavailableTimeRanges,将 JSON 字符串转换为可读格式
  161. parseTimeRanges() {
  162. return function(ranges) {
  163. if (!ranges) return '';
  164. try {
  165. const arr = JSON.parse(ranges);
  166. return arr.map(item => {
  167. const begin = item.beginTime?.split?.(' ')?.[0] || '';
  168. const end = item.endTime?.split?.(' ')?.[0] || '';
  169. return begin && end ? `${begin} - ${end}` : '';
  170. }).filter(Boolean).join(';');
  171. } catch (e) {
  172. return '';
  173. }
  174. };
  175. }
  176. },
  177. created() {
  178. },
  179. methods: {
  180. showRemark(item){
  181. if (this.showRemarkId == item.id ){
  182. this.showRemarkId = ''
  183. }else {
  184. this.showRemarkId = item.id
  185. }
  186. },
  187. /*下拉刷新的回调 */
  188. downCallback() {
  189. // 这里加载你想下拉刷新的数据, 比如刷新轮播数据
  190. // loadSwiper();
  191. // 下拉刷新的回调,默认重置上拉加载列表为第一页 (自动执行 page.num=1, 再触发upCallback方法 )
  192. this.mescroll.resetUpScroll()
  193. },
  194. /*上拉加载的回调: 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10 */
  195. upCallback(page) {
  196. //联网加载数据
  197. let httpData = {
  198. pageNum: page.num,
  199. pageSize: 10,
  200. type: this.index
  201. }
  202. this.$api.getMyCouponList(httpData).then((res) => {
  203. //联网成功的回调,隐藏下拉刷新和上拉加载的状态;
  204. this.mescroll.endSuccess(res.data.rows.length, res.data.rows.length === 10);
  205. //设置列表数据
  206. if (page.num === 1) this.list = []; //如果是第一页需手动制空列表
  207. this.list = this.list.concat(res.data.rows); //追加新数据
  208. console.log(this.list)
  209. }).catch((err) => {
  210. //联网失败, 结束加载
  211. this.mescroll.endErr();
  212. })
  213. },
  214. //点击空布局按钮的回调
  215. emptyClick() {
  216. uni.showToast({
  217. title: '点击了按钮,具体逻辑自行实现'
  218. })
  219. },
  220. // 搜索
  221. doSearch() {
  222. this.list = []; // 先清空列表,显示加载进度
  223. this.mescroll.resetUpScroll();
  224. },
  225. gotoUseCoupon(item){
  226. console.log(item)
  227. }
  228. }
  229. }
  230. </script>
  231. <style>
  232. @import '/common/css/common.css';
  233. @import './index.rpx.css';
  234. </style>