couponList.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <view class="content">
  3. <u-tabs-swiper ref="uTabs" :active-color="mainColor" :list="tabList" :current="current" @change="tabsChange"
  4. :is-scroll="false"></u-tabs-swiper>
  5. <swiper :current="swiperCurrent" @transition="transition" @animationfinish="animationfinish" class="swiper-box">
  6. <swiper-item class="swiper-item" v-for="(item, index1) in tabList" :key="index1">
  7. <scroll-view scroll-y class="scroll-box" @scrolltolower="handleLoadMore" :refresher-enabled="true"
  8. :refresher-triggered="triggered" :refresher-threshold="100" refresher-background="white" @refresherrefresh="onRefresh"
  9. @refresherrestore="onRestore">
  10. <template v-if="current != 3">
  11. <u-card :show-head="false" :show-foot="false" padding="0px" margin="10px" borderRadius="40" v-for="(site, index2) in item.tableList"
  12. :key="index2" class="class-card">
  13. <view class="class-content" slot="body">
  14. <view class="class-info-img">
  15. <u-image width="60px" height="60px" :src="site.url" shape="circle"></u-image>
  16. </view>
  17. <view class="class-info-content">
  18. <view class="class-info-label">{{site.name}}¥{{site.amount}}</view>
  19. <view class="class-info-text">{{site.typeValue}}&nbsp;&nbsp;{{site.content}}</view>
  20. <view class="class-info-text">{{site.endDate}}&nbsp;&nbsp;到期</view>
  21. </view>
  22. <view class="card-mask" v-if="index1 == 1"></view>
  23. <view class="out-date" v-if="index1 == 2">已用</view>
  24. </view>
  25. </u-card>
  26. <u-divider v-if="item.isOver" bg-color="transparent">没有更多了</u-divider>
  27. </template>
  28. <template v-else>
  29. <view class="content-info">
  30. <view style="background: #fff;">
  31. <u-form ref="form" label-width="80">
  32. <u-form-item label="学员:" right-icon="arrow-right" required @click.native="studentShow = true">
  33. <u-input v-model="studentName" placeholder="请选择学员" disabled @click="studentShow = true" />
  34. </u-form-item>
  35. </u-form>
  36. </view>
  37. <view class="share-img">
  38. <u-image width="60vw" height="60vw" :src="qrcodeUrl" ></u-image>
  39. <view class="share-class">共{{ classes }}节课</view>
  40. </view>
  41. </view>
  42. </template>
  43. </scroll-view>
  44. </swiper-item>
  45. </swiper>
  46. <u-picker mode="selector" v-model="studentShow" :range="studentList" range-key="childName" @confirm="handleStudentClick"></u-picker>
  47. <u-top-tips ref="uTips"></u-top-tips>
  48. </view>
  49. </template>
  50. <script>
  51. import {
  52. mapGetters
  53. } from 'vuex'
  54. const NET = require('@/utils/request')
  55. const API = require('@/config/api')
  56. export default {
  57. computed: {
  58. ...mapGetters([
  59. 'mainColor',
  60. 'handleCustomStyle',
  61. 'handleDefaultCustomStyle',
  62. ])
  63. },
  64. data() {
  65. return {
  66. triggered: false,
  67. tabList: [{
  68. name: '可用',
  69. isOver: false,
  70. pageIndex: 1,
  71. tableList: [],
  72. }, {
  73. name: '过期',
  74. isOver: false,
  75. pageIndex: 1,
  76. tableList: [],
  77. }, {
  78. name: '使用记录',
  79. isOver: false,
  80. pageIndex: 1,
  81. tableList: [],
  82. },{
  83. name: '赠送课时券',
  84. isOver: false,
  85. pageIndex: 1,
  86. tableList: [],
  87. }],
  88. current: 0,
  89. swiperCurrent: 0,
  90. // 学生id
  91. studentId: '',
  92. // 学生姓名
  93. studentName: '',
  94. studentShow: '',
  95. studentList: [],
  96. // 二维码
  97. qrcodeUrl: '',
  98. // 课时
  99. classes: 0
  100. }
  101. },
  102. onLoad() {
  103. this.getTableList(0)
  104. this.getTableList(1)
  105. this.getTableList(2)
  106. this.getCouponList()
  107. },
  108. onReady() {},
  109. methods: {
  110. // 获取可用优惠券列表
  111. getCouponList() {
  112. NET.request(API.getUserStudent, {
  113. userId: uni.getStorageSync('userData').userId }, 'POST').then( res => {
  114. if(res.status == 10000) {
  115. this.studentList = res.data
  116. if(this.studentList.length) {
  117. this.handleStudentClick(0)
  118. }
  119. }
  120. })
  121. },
  122. // 选择学生
  123. handleStudentClick(args) {
  124. this.studentId = this.studentList[args].studentId
  125. this.studentName = this.studentList[args].childName
  126. this.getInfo()
  127. },
  128. // 根据学员获取二维码和剩余课时
  129. getInfo() {
  130. NET.request(API.studentQRcode, { studentId: this.studentId },'POST').then(res => {
  131. if(res.status == 10000) {
  132. this.qrcodeUrl = res.data
  133. }
  134. })
  135. NET.request(API.getGiveLessons, { studentId: this.studentId },'POST').then(res => {
  136. console.log(res);
  137. if(res.status == 10000) {
  138. console.log(res.data);
  139. this.classes = res.data.length
  140. }
  141. })
  142. },
  143. // tab页面切换
  144. tabsChange(index) {
  145. this.swiperCurrent = index;
  146. },
  147. // swiper-item左右移动,通知tabs的滑块跟随移动
  148. transition(e) {
  149. let dx = e.detail.dx;
  150. this.$refs.uTabs.setDx(dx);
  151. },
  152. // swiper滑动结束,分别设置tabs和swiper的状态
  153. animationfinish(e) {
  154. let current = e.detail.current;
  155. this.$refs.uTabs.setFinishCurrent(current);
  156. this.swiperCurrent = current;
  157. this.current = current;
  158. },
  159. // 下拉刷新
  160. onRefresh() {
  161. if (!this.triggered) {
  162. this.triggered = true
  163. this.tabList[this.current].isOver = false
  164. this.tabList[this.current].pageIndex = 1
  165. this.tabList[this.current].tableList = []
  166. this.getTableList(this.current, 'refresh')
  167. }
  168. },
  169. // 重置下拉刷新状态
  170. onRestore() {
  171. this.triggered = 'restore'
  172. this.triggered = false
  173. },
  174. // 懒加载
  175. handleLoadMore() {
  176. if (!this.tabList[this.current].isOver) {
  177. this.tabList[this.current].pageIndex++
  178. this.getTableList(this.current)
  179. }
  180. },
  181. // 获取列表数据
  182. getTableList(index, refresh) {
  183. NET.request(API.getCouponList, {
  184. status: index,
  185. page: this.tabList[index].pageIndex,
  186. size: 10,
  187. }, 'POST').then(res => {
  188. this.triggered = false
  189. this.tabList[index].tableList = this.tabList[index].tableList.concat(res.data.row)
  190. this.tabList[index].isOver = res.data.row.length != 10
  191. }).catch(error => {
  192. this.triggered = false
  193. this.$refs.uTips.show({
  194. title: error.message,
  195. type: 'warning',
  196. })
  197. })
  198. }
  199. },
  200. }
  201. </script>
  202. <style>
  203. page {
  204. width: 100%;
  205. height: 100%;
  206. background-color: #f7f7f7;
  207. }
  208. </style>
  209. <style lang="scss" scoped>
  210. @import "@/static/css/themes.scss";
  211. .content {
  212. width: 100%;
  213. float: left;
  214. .swiper-box {
  215. height: calc(100vh - 34px);
  216. .swiper-item {
  217. height: calc(100vh - 34px);
  218. .scroll-box {
  219. width: 100%;
  220. height: calc(100vh - 34px);
  221. padding-bottom: 10px;
  222. box-sizing: border-box;
  223. .class-card {
  224. .class-content {
  225. padding: 10px 15px;
  226. display: flex;
  227. align-items: center;
  228. position: relative;
  229. }
  230. .class-info-img {
  231. width: 60px;
  232. height: 60px;
  233. margin-right: 10px;
  234. }
  235. .class-info-content {
  236. flex: 1;
  237. }
  238. .class-info-label {
  239. font-size: 16px;
  240. color: #000000;
  241. word-break: break-all;
  242. margin-bottom: 5px;
  243. }
  244. .class-info-text {
  245. color: #999999;
  246. margin-bottom: 5px;
  247. }
  248. .card-mask {
  249. width: 100%;
  250. height: 100%;
  251. position: absolute;
  252. left: 0;
  253. top: 0;
  254. background-color: rgba(0, 0, 0, 0.3);
  255. }
  256. .out-date {
  257. font-size: 10px;
  258. color: #ff9900;
  259. margin-bottom: 5px;
  260. position: absolute;
  261. right: 8px;
  262. bottom: 3px;
  263. }
  264. }
  265. }
  266. }
  267. }
  268. }
  269. .content-info {
  270. width: 100%;
  271. height: 100%;
  272. float: left;
  273. position: relative;
  274. border-top: 1px solid #eee;
  275. .share-img {
  276. top: 40%;
  277. left: 50%;
  278. transform: translate(-50%, -50%);
  279. position: absolute;
  280. .share-class {
  281. margin-top: 20rpx;
  282. text-align: center;
  283. }
  284. }
  285. }
  286. </style>