list.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <van-nav-bar :title="title" :border="false" safe-area-inset-top>
  3. <template #left>
  4. <van-icon
  5. :name="require('@/assets/arrow-left.svg')"
  6. size="24"
  7. @click="backPath"
  8. />
  9. </template>
  10. </van-nav-bar>
  11. <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
  12. <div class="page_info">
  13. <div
  14. class="search_pannel"
  15. v-if="role == 'admin' || role == 'Maintenance'"
  16. >
  17. <van-tabs
  18. v-model:active="dataForm.status"
  19. title-active-color="#2E69EB"
  20. title-inactive-color="#0C1935"
  21. >
  22. <van-tab
  23. :name="item.dictValue"
  24. :title="item.dictLabel"
  25. v-for="item in repairStatusList"
  26. :key="item.dictValue"
  27. :style="{
  28. display: role == 'admin' && item.dictValue == 1 ? '' : 'none',
  29. }"
  30. />
  31. </van-tabs>
  32. </div>
  33. <van-row align="center" class="list_total">
  34. <van-col>共有</van-col>
  35. <v-count-up
  36. :end-val="total"
  37. class="count_up"
  38. options="{ separator: ',' }"
  39. />
  40. <van-col>条记录</van-col>
  41. </van-row>
  42. <div class="info_list">
  43. <van-list
  44. v-model:loading="loading"
  45. :finished="finished"
  46. :error="error"
  47. error-text="请求失败,点击重新加载"
  48. finished-text="没有更多了"
  49. @load="onLoad"
  50. >
  51. <div
  52. v-for="item in dataList"
  53. :key="item.id"
  54. class="list_item"
  55. @click="toPath(item.id)"
  56. >
  57. <template v-if="item.status != 1">
  58. <van-row
  59. align="center"
  60. class="urgency_type"
  61. :style="{
  62. 'background-color': `${
  63. dict_filter(item.urgency, 'urgencyTypeList')['color']
  64. }`,
  65. }"
  66. >
  67. <van-col>{{
  68. `${dict_filter(item.urgency, "urgencyTypeList")["dictLabel"]}`
  69. }}</van-col>
  70. </van-row>
  71. </template>
  72. <van-col class="header">{{ item.repairPosition }}</van-col>
  73. <van-col
  74. >报修类型:{{
  75. `${dict_filter(item.repairType, "repairTypeList")["dictLabel"]}`
  76. }}</van-col
  77. >
  78. <template v-if="item.status == 1">
  79. <van-col>报修时间:{{ item.createDate }}</van-col>
  80. </template>
  81. <template v-if="item.status == 2">
  82. <van-col>指派时间:{{ item.updateDate }}</van-col>
  83. </template>
  84. <template v-if="item.status == 3">
  85. <van-col>维修完成时间:{{ item.repairFinishTime }}</van-col>
  86. </template>
  87. </div>
  88. </van-list>
  89. </div>
  90. </div>
  91. </van-pull-refresh>
  92. </template>
  93. <script>
  94. import Api from "@/utils/api";
  95. import { isEmpty, getDictDataList } from "@/utils/index";
  96. import VCountUp from "../CountUp";
  97. export default {
  98. components: {
  99. "v-count-up": VCountUp,
  100. },
  101. data() {
  102. return {
  103. role: "",
  104. title: "",
  105. repairStatusList: [],
  106. repairTypeList: [],
  107. urgencyTypeList: [],
  108. dataForm: {
  109. status: 1,
  110. page: 1,
  111. limit: 10,
  112. },
  113. total: 0,
  114. dataList: [],
  115. loading: false,
  116. refreshing: false,
  117. finished: false,
  118. };
  119. },
  120. watch: {
  121. "dataForm.status": {
  122. handler(newval, oldval) {
  123. this.onRefresh();
  124. },
  125. deep: true,
  126. },
  127. },
  128. created() {
  129. this.role = localStorage.getItem("role");
  130. if (this.role == "admin") {
  131. this.title = "工单待办";
  132. }
  133. if (this.role == "Maintenance") {
  134. this.title = "报修工单";
  135. }
  136. if (this.role == "Tenant") {
  137. this.title = "报修记录";
  138. this.dataForm.status = "";
  139. }
  140. this.getRepairStatusList();
  141. this.getRepairTypeList();
  142. this.getUrgencyTypeList();
  143. },
  144. methods: {
  145. getRepairStatusList() {
  146. this.repairStatusList = getDictDataList("RepairStatus");
  147. if (this.role == "Maintenance") {
  148. this.repairStatusList = this.repairStatusList.filter(
  149. (item) => item.dictValue != 1
  150. );
  151. }
  152. },
  153. getRepairTypeList() {
  154. this.repairTypeList = getDictDataList("RepairType");
  155. },
  156. getUrgencyTypeList() {
  157. this.urgencyTypeList = getDictDataList("UrgencyType");
  158. },
  159. dict_filter(val, list) {
  160. if (isEmpty(val)) {
  161. return {};
  162. }
  163. return this[list].find((item) => item.dictValue == val);
  164. },
  165. onLoad() {
  166. setTimeout(async () => {
  167. if (this.refreshing) {
  168. this.dataList = [];
  169. this.refreshing = false;
  170. }
  171. await this.getDataList();
  172. this.dataForm.page++; // 分页数加一
  173. }, 100);
  174. },
  175. onRefresh() {
  176. // 清空列表数据
  177. this.finished = false;
  178. this.dataList = [];
  179. // 重新加载数据
  180. // 将 loading 设置为 true,表示处于加载状态
  181. this.total = 0;
  182. this.loading = true;
  183. this.dataForm.page = 1; // 分页数赋值为1
  184. this.onLoad();
  185. },
  186. // 获取列表数据方法
  187. async getDataList() {
  188. Api.repairList(this.dataForm).then((res) => {
  189. if (res.code == 0) {
  190. if (res.data) {
  191. if (res.data.list.length == 0) {
  192. // 判断获取数据条数若等于0
  193. this.dataList = []; // 清空数组
  194. this.finished = true; // 停止加载
  195. }
  196. // 若数据条数不等于0
  197. this.dataList.push(...res.data.list); // 将数据放入list中
  198. this.loading = false; // 加载状态结束
  199. this.total = res.data.total;
  200. // 如果list长度大于等于总数据条数,数据全部加载完成
  201. if (this.dataList.length >= res.data.total) {
  202. this.finished = true; // 结束加载状态
  203. }
  204. } else {
  205. // 判断获取数据条数若等于0
  206. this.dataList = []; // 清空数组
  207. this.finished = true; // 停止加载
  208. }
  209. } else {
  210. this.loading = false; // 加载状态结束
  211. this.finished = true; // 停止加载
  212. }
  213. });
  214. },
  215. toPath(id) {
  216. this.$router.push({
  217. path: "/repair/detail",
  218. query: {
  219. id: id,
  220. },
  221. });
  222. },
  223. backPath() {
  224. this.$router.back();
  225. },
  226. },
  227. };
  228. </script>
  229. <style lang="scss" scoped>
  230. .page_info {
  231. height: 100%;
  232. .search_pannel {
  233. background: #ffffff;
  234. /deep/ {
  235. .van-tabs__line {
  236. --van-tabs-bottom-bar-color: #2e69eb;
  237. }
  238. }
  239. }
  240. .list_total {
  241. padding: 0 16px;
  242. margin: 8px 0;
  243. display: flex;
  244. text-align: left;
  245. .van-col {
  246. height: 16px;
  247. font-size: 12px;
  248. font-weight: 400;
  249. color: #999999;
  250. line-height: 16px;
  251. }
  252. .count_up {
  253. font-size: 16px;
  254. font-weight: 500;
  255. color: #fa5555;
  256. margin: 0 2px;
  257. }
  258. }
  259. .info_list {
  260. padding: 0 16px;
  261. height: calc(100vh - 125px);
  262. overflow: auto;
  263. .list_item {
  264. background: #ffffff;
  265. box-shadow: 0px 0px 10px 0px rgba(153, 153, 153, 0.15);
  266. border-radius: 4px;
  267. margin-bottom: 12px;
  268. padding: 12px 16px;
  269. display: flex;
  270. flex-direction: column;
  271. align-items: flex-start;
  272. position: relative;
  273. &:nth-last-child(1) {
  274. margin-bottom: 0;
  275. }
  276. .van-col {
  277. height: 18px;
  278. font-size: 14px;
  279. color: #999999;
  280. line-height: 18px;
  281. margin-bottom: 4px;
  282. &:nth-last-child(1) {
  283. margin-bottom: 0;
  284. }
  285. }
  286. .header {
  287. height: 22px;
  288. font-size: 16px;
  289. color: #0c1935;
  290. line-height: 22px;
  291. margin-bottom: 8px;
  292. }
  293. .urgency_type {
  294. position: absolute;
  295. top: 0;
  296. right: 0;
  297. height: 24px;
  298. padding: 0 12px;
  299. border-radius: 0px 4px 0px 10px;
  300. .van-col {
  301. font-size: 12px;
  302. font-weight: 400;
  303. color: #ffffff;
  304. line-height: 16px;
  305. }
  306. }
  307. }
  308. }
  309. }
  310. </style>