list.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. <template>
  2. <view class="inspect-list">
  3. <view class="list" v-if="records.length">
  4. <view class="item" v-for="item in records" :key="item.taskId" @click="goDetail(item)">
  5. <view class="top">
  6. <view class="left">
  7. <view class="name">{{ item.planName || '巡检任务' }}</view>
  8. <text class="rect-tag" v-if="item.rectStatus === 1 || item.rectStatus === 2">待整改</text>
  9. <text class="rect-tag done" v-if="item.rectStatus === 3">已整改</text>
  10. </view>
  11. <view class="pass" :class="{ good: item.passFlag == 1, bad: item.passFlag == 0 }">{{ passText(item) }}</view>
  12. </view>
  13. <view class="meta">
  14. <text class="date">{{ formatDate(item.taskDate) }}</text>
  15. <text class="inspector" v-if="item.inspectorName">巡检员:{{ item.inspectorName }}</text>
  16. </view>
  17. <view class="meta status-row">
  18. <text class="status-tag" :style="statusStyle(item.status)">{{ statusText(item.status) }}</text>
  19. </view>
  20. <view class="score" v-if="item.totalScore != null">
  21. 综合得分:<b>{{ fmtScore(item.totalScore) }}</b>
  22. <text class="max">/{{ fmtScore(item.maxScore) }}</text>
  23. </view>
  24. <view class="score" v-else>. . .</view>
  25. </view>
  26. <view class="loadmore" @click="loadMore" v-if="hasMore">{{ loading ? '加载中…' : '上拉加载更多' }}</view>
  27. <view class="loadmore" v-else-if="records.length">已加载全部</view>
  28. </view>
  29. <view class="empty" v-else-if="!loading">
  30. <image src="/static/imgs/empty/empty2x.png" class="empty-img" mode="widthFix"></image>
  31. <text>暂无巡检记录</text>
  32. </view>
  33. </view>
  34. </template>
  35. <script>
  36. import { mapState } from 'vuex';
  37. export default {
  38. data() {
  39. return {
  40. listUrl: '/inspectApi/getMyInspectList',
  41. records: [],
  42. currentPage: 1,
  43. pageSize: 20,
  44. total: 0,
  45. loading: false
  46. }
  47. },
  48. computed: {
  49. ...mapState(['storeInfo']),
  50. hasMore() {
  51. return this.total > this.records.length
  52. }
  53. },
  54. methods: {
  55. loadData() {
  56. this.loading = true
  57. var dateStr = (new Date()).getTime();
  58. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  59. this.requst({
  60. url: this.listUrl,
  61. data: {
  62. timestamp: dateStr,
  63. sign: sign,
  64. storeId: this.storeInfo.storeId,
  65. storeUserId: this.storeInfo.storeUserId,
  66. currentPage: this.currentPage,
  67. pageSize: this.pageSize
  68. },
  69. success: res => {
  70. if (res.data.rtnBean.rtnCode == 0) {
  71. let list = (res.data.list || [])
  72. let page = res.data.page || {}
  73. this.total = page.totalRecords || list.length
  74. this.records = this.currentPage === 1 ? list : this.records.concat(list)
  75. } else if (res.data.rtnBean.rtnMsg) {
  76. this.$api.msg(res.data.rtnBean.rtnMsg)
  77. }
  78. this.loading = false
  79. uni.stopPullDownRefresh()
  80. },
  81. fail: () => {
  82. this.loading = false
  83. uni.stopPullDownRefresh()
  84. }
  85. })
  86. },
  87. loadMore() {
  88. if (this.loading || !this.hasMore) return
  89. this.currentPage++
  90. this.loadData()
  91. },
  92. goDetail(item) {
  93. uni.navigateTo({ url: '/pages/inspect/detail?id=' + item.taskId })
  94. },
  95. formatDate(v) {
  96. if (!v) return ''
  97. let d = new Date(v)
  98. let p = n => (n < 10 ? '0' + n : n)
  99. return d.getFullYear() + '-' + p(d.getMonth() + 1) + '-' + p(d.getDate())
  100. },
  101. fmtScore(v) {
  102. return Number(v || 0)
  103. },
  104. passText(item) {
  105. if (item.status != 3) return ''
  106. return item.passFlag == 1 ? '及格' : '不及格'
  107. },
  108. statusText(v) {
  109. return { 1: '待执行', 2: '执行中', 3: '已完成', 4: '已取消', 5: '已超期' }[v] || ''
  110. },
  111. statusStyle(v) {
  112. var map = {
  113. 1: { color: '#909399', bg: '#f4f4f5' },
  114. 2: { color: '#409EFF', bg: '#ecf5ff' },
  115. 3: { color: '#67C23A', bg: '#f0f9eb' },
  116. 4: { color: '#F56C6C', bg: '#fef0f0' },
  117. 5: { color: '#E6A23C', bg: '#fdf6ec' }
  118. }
  119. var s = map[v] || { color: '#909399', bg: '#f4f4f5' }
  120. return { color: s.color, background: s.bg }
  121. }
  122. },
  123. onPullDownRefresh() {
  124. this.currentPage = 1
  125. this.records = []
  126. this.loadData()
  127. },
  128. onReachBottom() {
  129. this.loadMore()
  130. },
  131. onLoad() {
  132. this.loadData()
  133. }
  134. }
  135. </script>
  136. <style lang="scss" scoped>
  137. .inspect-list {
  138. min-height: 100vh;
  139. background-color: #f5f5f5;
  140. }
  141. .list {
  142. padding: 20rpx;
  143. .item {
  144. background: #fff;
  145. border-radius: 16rpx;
  146. padding: 24rpx;
  147. margin-bottom: 20rpx;
  148. .top {
  149. @include between;
  150. margin-bottom: 12rpx;
  151. .left {
  152. @include flexStart;
  153. flex: 1;
  154. .name {
  155. font-size: 32rpx;
  156. font-weight: bold;
  157. color: $text-color;
  158. }
  159. .rect-tag {
  160. margin-left: 12rpx;
  161. font-size: $font-sm;
  162. padding: 2rpx 12rpx;
  163. border-radius: 20rpx;
  164. color: #E6A23C;
  165. background: #fdf6ec;
  166. &.done {
  167. color: #67C23A;
  168. background: #f0f9eb;
  169. }
  170. }
  171. }
  172. .pass {
  173. flex-shrink: 0;
  174. font-size: $font-sm;
  175. padding: 4rpx 14rpx;
  176. border-radius: 20rpx;
  177. color: #909399;
  178. background: #f4f4f5;
  179. &.good {
  180. color: #67c23a;
  181. background: #f0f9eb;
  182. }
  183. &.bad {
  184. color: #f56c6c;
  185. background: #fef0f0;
  186. }
  187. }
  188. }
  189. .meta {
  190. @include between;
  191. color: $desc-color;
  192. font-size: $font-sm;
  193. margin-bottom: 6rpx;
  194. .inspector {
  195. text-align: right;
  196. }
  197. &.status-row {
  198. margin-bottom: 10rpx;
  199. .status-tag {
  200. font-size: 22rpx;
  201. padding: 2rpx 12rpx;
  202. border-radius: 16rpx;
  203. }
  204. }
  205. }
  206. .score {
  207. font-size: $font-base;
  208. color: $text-color;
  209. b {
  210. font-size: 36rpx;
  211. color: $theme-color;
  212. }
  213. .max {
  214. color: $desc-color;
  215. font-size: $font-sm;
  216. }
  217. }
  218. }
  219. .loadmore {
  220. text-align: center;
  221. color: $desc-color;
  222. font-size: $font-sm;
  223. padding: 20rpx 0;
  224. }
  225. }
  226. .empty {
  227. display: flex;
  228. flex-direction: column;
  229. align-items: center;
  230. justify-content: center;
  231. padding-top: 200rpx;
  232. color: #cdcdcd;
  233. font-size: $font-lg;
  234. .empty-img {
  235. width: 240rpx;
  236. margin-bottom: 30rpx;
  237. }
  238. }
  239. </style>