swiper-list-item.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <!-- 在这个文件对每个tab对应的列表进行渲染 -->
  2. <template>
  3. <view class="content">
  4. <z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="false">
  5. <view class="coupon-list-item" v-for="(item, index) in dataList" :key="index">
  6. <view class="coupon-list-item-top">
  7. <view class="clit-left">
  8. <view class="clit-left-top"
  9. >¥<text>{{ item.couponContent }}</text></view
  10. >
  11. <view class="clit-left-bottom">{{ Number(item.threshold) > 0 ? `停车时长满${item.threshold}分钟` : '无门槛' }}</view>
  12. </view>
  13. <view class="clit-center">
  14. <view>{{ item.couponName }}</view>
  15. <view>{{ item.vehicleNo }}</view>
  16. </view>
  17. <template v-if="Number(item.status) === 0">
  18. <view class="clit-right">
  19. <u-button class="clit-right-btn" type="primary" size="default" @click="goToUse(item)">立即使用</u-button>
  20. </view>
  21. </template>
  22. <template v-else-if="Number(item.status) === 1">
  23. <view class="clit-right">
  24. <u-image width="128rpx" height="128rpx" src="/static/img/have-used-icon.svg"/>
  25. </view>
  26. </template>
  27. <template v-else-if="Number(item.status) === 2">
  28. <view class="clit-right">
  29. <u-image width="128rpx" height="128rpx" src="/static/img/have-overdued-icon.svg"/>
  30. </view>
  31. </template>
  32. </view>
  33. <view class="coupon-list-item-bottom">
  34. <view class="coupon-list-item-bottom-left">
  35. 适用停车点:
  36. <template v-if="item.parkList.length > 1"> 适用多个停车点 </template>
  37. <template v-else> 仅限{{ item.parkList.map((item) => item.parkName).join('、') }} </template>
  38. </view>
  39. <template v-if="Number(item.status) === 0">
  40. <view class="coupon-list-item-bottom-right">有效期:{{ calcValidity(item.startTime, item.endTime) }} </view>
  41. </template>
  42. <template v-else>
  43. <view class="coupon-list-item-bottom-right">已失效</view>
  44. </template>
  45. </view>
  46. <template v-if="item.parkList.length > 1">
  47. <view class="clibl-point">
  48. <u-read-more
  49. text-indent="0"
  50. show-height="0"
  51. :toggle="true"
  52. :shadow-style="{ backgroundImage: 'none' }"
  53. fontSize="20rpx"
  54. close-text="展开所有停车点"
  55. >
  56. <view class="clibl-point-content">{{ item.parkList.map((item) => item.parkName).join('、') }}</view>
  57. </u-read-more>
  58. </view>
  59. </template>
  60. </view>
  61. </z-paging>
  62. </view>
  63. </template>
  64. <script>
  65. export default {
  66. data() {
  67. return {
  68. dataList: [],
  69. firstLoaded: false
  70. };
  71. },
  72. props: {
  73. tabIndex: {
  74. type: Number,
  75. default: function () {
  76. return 0;
  77. }
  78. },
  79. currentIndex: {
  80. type: Number,
  81. default: function () {
  82. return 0;
  83. }
  84. }
  85. },
  86. watch: {
  87. currentIndex: {
  88. handler(newVal) {
  89. if (newVal === this.tabIndex) {
  90. //懒加载,当滑动到当前的item时,才去加载
  91. if (!this.firstLoaded) {
  92. setTimeout(() => {
  93. this.$refs.paging.reload();
  94. }, 100);
  95. }
  96. }
  97. },
  98. immediate: true
  99. }
  100. },
  101. methods: {
  102. queryList(pageNo, pageSize) {
  103. const params = {
  104. pageNo: pageNo,
  105. pageSize: pageSize,
  106. status: this.currentIndex
  107. };
  108. this.$u.api
  109. .couponListApi(params)
  110. .then((res) => {
  111. this.$refs.paging.complete(res.data.rows);
  112. this.firstLoaded = true;
  113. })
  114. .catch((res) => {
  115. this.$refs.paging.complete(false);
  116. });
  117. },
  118. /**
  119. * 重载数据
  120. * @date 2022-12-23
  121. * @returns {any}
  122. */
  123. reloadData() {
  124. this.$refs.paging.reload();
  125. },
  126. goToUse(item) {
  127. this.$u.route({
  128. url: 'pages/payLists/payLists'
  129. });
  130. },
  131. /**
  132. * 计算剩余时间
  133. * @date 2022-12-23
  134. * @param {any} datetime
  135. * @returns {any}
  136. */
  137. calcValidity(startTime, endTime) {
  138. let endTimeStr = new Date(endTime).valueOf(),
  139. nowTimeStr = new Date(startTime).valueOf() < Date.now() ? Date.now() : new Date(startTime).valueOf(),
  140. remainTimeStr = endTimeStr - nowTimeStr,
  141. day = Math.floor(remainTimeStr / (1000 * 3600 * 24)),
  142. dayOver = remainTimeStr % (1000 * 3600 * 24),
  143. hours = Math.floor(dayOver / (3600 * 1000)),
  144. hourOver = dayOver % (3600 * 1000),
  145. minutes = Math.floor(hourOver / (60 * 1000));
  146. return `${day}天${hours}小时${minutes}分`;
  147. }
  148. }
  149. };
  150. </script>
  151. <style lang="scss" scoped>
  152. /* 注意:父节点需要固定高度,z-paging的height:100%才会生效 */
  153. .content {
  154. height: 100%;
  155. }
  156. .coupon-list-item {
  157. background-color: #fff;
  158. border-radius: 17rpx;
  159. box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.08);
  160. padding: 20rpx 0;
  161. margin-bottom: 30rpx;
  162. &-top {
  163. display: flex;
  164. justify-content: space-between;
  165. align-items: center;
  166. padding: 26rpx 30rpx 37rpx;
  167. border-bottom: 1px solid #eeeeee;
  168. .clit-left {
  169. color: #ff6d6d;
  170. font-size: 24rpx;
  171. width: 30%;
  172. &-top {
  173. margin-bottom: 10rpx;
  174. text {
  175. font-size: 60rpx;
  176. }
  177. }
  178. &-bottom {
  179. width: 100%;
  180. overflow: hidden;
  181. white-space: nowrap;
  182. text-overflow: ellipsis;
  183. }
  184. }
  185. .clit-center {
  186. font-size: 20rpx;
  187. color: #333;
  188. width: 40%;
  189. margin-left: 2%;
  190. view:first-child {
  191. width: 100%;
  192. font-size: 32rpx;
  193. color: #666;
  194. font-weight: 500;
  195. overflow: hidden;
  196. white-space: nowrap;
  197. text-overflow: ellipsis;
  198. margin-bottom: 16rpx;
  199. }
  200. }
  201. .clit-right {
  202. margin-left: 2%;
  203. &-btn {
  204. background-color: #ff6d6d;
  205. }
  206. }
  207. }
  208. &-bottom {
  209. font-size: 20rpx;
  210. color: #999999;
  211. display: flex;
  212. justify-content: space-between;
  213. padding: 10rpx 30rpx 0;
  214. }
  215. .clibl-point {
  216. margin-top: 20rpx;
  217. font-size: 22rpx;
  218. &-content {
  219. font-size: 22rpx;
  220. padding: 0 30rpx;
  221. }
  222. }
  223. }
  224. </style>