my.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <mescroll-body ref="mescrollRef" :sticky="true" @init="mescrollInit" :down="{ use: false }" :up="upOption" @up="upCallback">
  3. <!-- 分类列表tab -->
  4. <view class="tabs-wrapper">
  5. <scroll-view class="scroll-view" scroll-x>
  6. <view class="tab-item" :class="{ active: curId == '' }" @click="onSwitchTab('')">
  7. <view class="value"><text>全部</text></view>
  8. </view>
  9. <!-- tab列表 -->
  10. <view class="tab-item" :class="{ active: curId == item.key }" @click="onSwitchTab(item.key)"
  11. v-for="(item, index) in statusList" :key="index">
  12. <view class="value"><text>{{ item.name }}</text></view>
  13. </view>
  14. </scroll-view>
  15. </view>
  16. <!-- 预约列表 -->
  17. <view class="book-list">
  18. <view class="book-item" v-for="(item, index) in list.content" :key="index" @click="onView(item.id)">
  19. <block>
  20. <view class="flex-box">
  21. <view class="book-item-title">
  22. <text>{{ item.bookName }}</text>
  23. </view>
  24. <view class="book-content">
  25. <view class="contacts">姓名:{{ item.contact }}</view>
  26. <view class="time">时间:{{ item.serviceDate }} {{ item.serviceTime }}</view>
  27. </view>
  28. <view class="book-item-footer m-top10">
  29. <text class="book-views f-24 col-8">{{ item.createTime | timeFormat('yyyy-mm-dd hh:MM') }}</text>
  30. <view class="btn-cancel" v-if="item.status == 'A'" @click="onView(item.id)">取消</view>
  31. <view class="btn-view" @click="onView(item.id)">详情</view>
  32. </view>
  33. </view>
  34. </block>
  35. </view>
  36. </view>
  37. </mescroll-body>
  38. </template>
  39. <script>
  40. import MescrollBody from '@/components/mescroll-uni/mescroll-body.vue'
  41. import MescrollMixin from '@/components/mescroll-uni/mescroll-mixins'
  42. import * as BookApi from '@/api/book'
  43. import { getEmptyPaginateObj, getMoreListData } from '@/utils/app'
  44. const pageSize = 15
  45. export default {
  46. components: {
  47. MescrollBody
  48. },
  49. mixins: [MescrollMixin],
  50. data() {
  51. return {
  52. // 状态列表
  53. statusList: [],
  54. // 预约列表
  55. list: getEmptyPaginateObj(),
  56. // 当前选中的分类id (0则代表首页)
  57. curId: '',
  58. // 上拉加载配置
  59. upOption: {
  60. // 首次自动执行
  61. auto: true,
  62. // 每页数据的数量; 默认10
  63. page: { size: pageSize },
  64. // 数量要大于3条才显示无更多数据
  65. noMoreSize: 3,
  66. }
  67. }
  68. },
  69. /**
  70. * 生命周期函数--监听页面加载
  71. */
  72. onLoad(options) {
  73. const app = this;
  74. if (options.status) {
  75. app.curId = options.status;
  76. }
  77. },
  78. methods: {
  79. /**
  80. * 上拉加载的回调 (页面初始化时也会执行一次)
  81. * 其中page.num:当前页 从1开始, page.size:每页数据条数,默认10
  82. * @param {Object} page
  83. */
  84. upCallback(page) {
  85. const app = this;
  86. // 设置列表数据
  87. app.getMyBookList(page.num)
  88. .then(list => {
  89. const curPageLen = list.content.length;
  90. const totalSize = list.content.totalElements;
  91. app.mescroll.endBySize(curPageLen, totalSize);
  92. })
  93. .catch(() => app.mescroll.endErr());
  94. },
  95. /**
  96. * 获取预约列表
  97. * @param {Number} pageNo 页码
  98. */
  99. getMyBookList(pageNo = 1) {
  100. const app = this;
  101. return new Promise((resolve, reject) => {
  102. BookApi.myBookList({ status: app.curId, page: pageNo }, { load: false })
  103. .then(result => {
  104. // 合并新数据
  105. const newList = result.data;
  106. app.list.content = getMoreListData(newList, app.list, pageNo);
  107. app.statusList = result.data.statusList;
  108. resolve(newList);
  109. })
  110. .catch(result => reject());
  111. })
  112. },
  113. // 切换选择的分类
  114. onSwitchTab(status) {
  115. const app = this;
  116. // 切换当前的状态
  117. app.curId = status;
  118. // 刷新列表数据
  119. app.list = getEmptyPaginateObj();
  120. app.mescroll.resetUpScroll();
  121. },
  122. // 取消预约
  123. onCancel(myBookId) {
  124. const app = this;
  125. uni.showModal({
  126. title: "提示",
  127. content: "您确定要取消该预约吗?",
  128. success({ confirm }) {
  129. confirm && app.doCancel(myBookId)
  130. }
  131. });
  132. },
  133. // 确认取消预约
  134. doCancel(myBookId) {
  135. const app = this;
  136. BookApi.cancel(myBookId)
  137. .then(result => {
  138. app.getPageData()
  139. })
  140. },
  141. // 跳转详情页
  142. onView(myBookId) {
  143. this.$navTo('pages/book/bookDetail', { myBookId });
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="scss" scoped>
  149. /* 顶部选项卡 */
  150. .container {
  151. min-height: 100vh;
  152. }
  153. .tabs-wrapper {
  154. position: sticky;
  155. top: var(--window-top);
  156. display: flex;
  157. width: 100%;
  158. height: 88rpx;
  159. color: #333;
  160. font-size: 28rpx;
  161. background: #fff;
  162. border-bottom: 1rpx solid #e4e4e4;
  163. z-index: 100;
  164. overflow: hidden;
  165. white-space: nowrap;
  166. }
  167. .tab-item {
  168. display: inline-block;
  169. padding: 0 15rpx;
  170. text-align: center;
  171. height: 87rpx;
  172. line-height: 88rpx;
  173. box-sizing: border-box;
  174. .value {
  175. height: 100%;
  176. }
  177. &.active .value {
  178. color: #fd4a5f;
  179. border-bottom: 4rpx solid #fd4a5f;
  180. font-weight: bold;
  181. }
  182. }
  183. /* 预约列表 */
  184. .book-list {
  185. padding-top: 20rpx;
  186. line-height: 1;
  187. background: #f7f7f7;
  188. }
  189. .book-item {
  190. margin: 0rpx 10rpx 20rpx 10rpx;
  191. padding: 30rpx;
  192. background: #fff;
  193. border-radius: 20rpx;
  194. min-height: 280rpx;
  195. &:last-child {
  196. margin-bottom: 0;
  197. }
  198. .book-item-title {
  199. font-size: 32rpx;
  200. color: #333;
  201. font-weight: bold;
  202. line-height: 40rpx;
  203. }
  204. .book-content {
  205. margin: 30rpx 0rpx 30rpx 0rpx;
  206. .contacts {
  207. margin-bottom: 20rpx;
  208. }
  209. }
  210. .book-item-footer {
  211. .btn-cancel {
  212. width: 100rpx;
  213. border-radius: 8rpx;
  214. padding: 10rpx 14rpx;
  215. font-size: 28rpx;
  216. color: #fff;
  217. text-align: center;
  218. border: 1rpx solid #fff;
  219. float: right;
  220. background: #f9211c;
  221. }
  222. .btn-view {
  223. width: 100rpx;
  224. border-radius: 8rpx;
  225. padding: 10rpx 14rpx;
  226. font-size: 28rpx;
  227. color: #fff;
  228. text-align: center;
  229. border: 1rpx solid #fff;
  230. float: right;
  231. background: $fuint-theme;
  232. }
  233. }
  234. }
  235. </style>