index.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <z-paging
  3. class="page maintence"
  4. ref="paging"
  5. v-model="dataList"
  6. @query="queryList"
  7. >
  8. <!-- z-paging默认铺满全屏,此时页面所有view都应放在z-paging标签内,否则会被盖住 -->
  9. <!-- 需要固定在页面顶部的view请通过slot="top"插入,包括自定义的导航栏 -->
  10. <template #top>
  11. <view class="page-top">
  12. <view class="page-back"></view>
  13. <view class="uni-page-head navgator justify-center align-center">
  14. <view class="nav-back" @click="navigatorBack()">
  15. <uni-icons type="left"></uni-icons>
  16. </view>
  17. <view class="nav-title">
  18. {{ $t("home.maintenanceWorkOrder") }}
  19. </view>
  20. </view>
  21. <view class="page-content">
  22. <view class="content-search">
  23. <uni-easyinput
  24. prefixIcon="search"
  25. confirmType="search"
  26. v-model="name"
  27. :placeholder="$t('operation.searchText')"
  28. @confirm="onSearch"
  29. >
  30. </uni-easyinput>
  31. </view>
  32. <uni-row
  33. class="content-statistics flex-row align-center justify-around"
  34. >
  35. <uni-col class="statistics-item flex-col align-center">
  36. <view class="statistics-count font-BiaoTiHei">
  37. {{ statistics.total }}
  38. </view>
  39. <view class="statistics-title">
  40. {{ $t("maintenanceWorkOrder.totalWorkOrders") }}
  41. </view>
  42. </uni-col>
  43. <uni-col class="statistics-item flex-col align-center">
  44. <view class="statistics-count font-BiaoTiHei">
  45. {{ statistics.done }}
  46. </view>
  47. <view class="statistics-title">
  48. {{ $t("workOrder.executed") }}
  49. </view>
  50. </uni-col>
  51. <uni-col class="statistics-item flex-col align-center">
  52. <view class="statistics-count font-BiaoTiHei">
  53. {{ statistics.todo }}
  54. </view>
  55. <view class="statistics-title">
  56. {{ $t("workOrder.pending") }}
  57. </view>
  58. </uni-col>
  59. </uni-row>
  60. <button class="full-btn" type="primary" @click="onCreate">
  61. <uni-icons type="plusempty"></uni-icons>
  62. {{ $t("maintenanceWorkOrder.createButton") }}
  63. </button>
  64. </view>
  65. </view>
  66. </template>
  67. <view class="paging-list">
  68. <view class="item" v-for="(item, index) in dataList" :key="index">
  69. <view
  70. class="item-module flex-row align-center justify-between"
  71. :class="{ tobeFilled: item.result == 1 }"
  72. >
  73. <view class="module-name">
  74. {{ $t("workOrder.workOrderNumber") }}: {{ item.orderNumber }}
  75. </view>
  76. <view class="module-status" :class="{ pending: item.result == 1 }">
  77. <!-- 保养结果(1待执行 2已执行) -->
  78. <span>{{ resultDict[item.result] }}</span>
  79. </view>
  80. </view>
  81. <view class="item-content">
  82. <view class="item-title flex-row">
  83. <span class="item-title-width"
  84. >{{ $t("workOrder.workOrderName") }}:</span
  85. >
  86. <span>{{ item.name }}</span>
  87. </view>
  88. <view class="item-title flex-row">
  89. <!-- 保养结果(1待执行 2已执行) -->
  90. <span class="item-title-width"
  91. >{{ $t("maintenanceWorkOrder.status") }}:</span
  92. >
  93. <span>{{ resultDict[item.result] }}</span>
  94. </view>
  95. <view class="item-title flex-row">
  96. <!-- 工单类型(1计划生成 2临时新建) -->
  97. <span class="item-title-width"
  98. >{{ $t("workOrder.workOrdertype") }}:</span
  99. >
  100. <span>{{ typeDict[item.type] }}</span>
  101. </view>
  102. <!-- 负责人 -->
  103. <view class="item-title flex-row">
  104. <span class="item-title-width"
  105. >{{ $t("workOrder.responsiblePerson") }}:</span
  106. >
  107. <span>{{ item.responsiblePersonName }}</span>
  108. </view>
  109. <!-- 实际保养开始时间 -->
  110. <!-- <view class="item-title flex-row">
  111. <span class="item-title-width"
  112. >{{
  113. $t("maintenanceWorkOrder.actualMaintenanceStartTime")
  114. }}:</span
  115. >
  116. <span>{{
  117. item.actualStartTime ? formatDate(item.actualStartTime) : ""
  118. }}</span>
  119. </view> -->
  120. <!-- 实际保养结束时间 -->
  121. <!-- <view class="item-title flex-row">
  122. <span class="item-title-width"
  123. >{{ $t("maintenanceWorkOrder.actualEndTime") }}:</span
  124. >
  125. <span>{{
  126. item.actualEndTime ? formatDate(item.actualEndTime) : ""
  127. }}</span>
  128. </view> -->
  129. <!-- 创建时间 -->
  130. <view class="item-title flex-row">
  131. <span class="item-title-width"
  132. >{{ $t("operation.createTime") }}:</span
  133. >
  134. <span>{{
  135. item.createTime ? formatDate(item.createTime) : ""
  136. }}</span>
  137. </view>
  138. <!-- 填写时间 -->
  139. <view class="item-title flex-row">
  140. <span class="item-title-width"
  141. >{{ $t("operation.fillTime") }}:</span
  142. >
  143. <span v-if="item.result == 2">{{ item.updateTime ? formatDate(item.updateTime) : "" }}</span>
  144. </view>
  145. <!-- 是否延期 -->
  146. <view class="item-title flex-row">
  147. <span class="item-title-width"
  148. >{{ $t("maintenanceWorkOrder.isPostponed") }}:</span
  149. >
  150. <span></span>
  151. </view>
  152. <!-- 距离保养 -->
  153. <view class="item-title flex-row">
  154. <span class="item-title-width"
  155. >{{ $t("maintenanceWorkOrder.timeToMaintenance") }}:</span
  156. >
  157. <span
  158. :class="{
  159. 'color-red': item.mainDistance
  160. ? item.mainDistance.indexOf('-') == 0
  161. : 0,
  162. 'color-green': item.mainDistance
  163. ? item.mainDistance.indexOf('-') < 0
  164. : 0,
  165. }"
  166. >{{ item.mainDistance }}</span
  167. >
  168. </view>
  169. </view>
  170. <view class="item-btn flex-row align-center justify-end">
  171. <!-- 查看详情 -->
  172. <button
  173. type="primary"
  174. :plain="false"
  175. v-if="item.result == 2"
  176. @click="onView(item)"
  177. >
  178. {{ $t("workOrder.viewDetails") }}
  179. </button>
  180. <!-- 去保养 -->
  181. <button type="primary" v-if="item.result == 1" @click="onEdit(item)">
  182. {{ $t("maintenanceWorkOrder.maintenanceButton") }}
  183. </button>
  184. </view>
  185. </view>
  186. </view>
  187. </z-paging>
  188. </template>
  189. <script setup>
  190. import { ref, reactive, onMounted, nextTick } from "vue";
  191. import { onLoad, onShow, onHide, onUnload } from "@dcloudio/uni-app";
  192. import { getMaintenanceCount, getMaintenanceList } from "@/api/maintenance";
  193. import dayjs from "dayjs";
  194. import { useDataDictStore } from "@/store/modules/dataDict";
  195. // --字典项--
  196. const { getDataDictList } = useDataDictStore();
  197. // 保养状态
  198. const resultDict = reactive({});
  199. getDataDictList("pms_main_work_order_result").map((item) => {
  200. resultDict[item.value] = item.label;
  201. });
  202. console.log("resultDict", resultDict);
  203. // 工单类型
  204. const typeDict = reactive({});
  205. getDataDictList("pms_main_work_order_type").map((item) => {
  206. typeDict[item.value] = item.label;
  207. });
  208. console.log("typeDict", typeDict);
  209. // --- 列表 ---start---
  210. const name = ref("");
  211. const paging = ref(null);
  212. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  213. const dataList = ref([]);
  214. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  215. const queryList = (pageNo, pageSize) => {
  216. // 此处请求仅为演示,请替换为自己项目中的请求
  217. getMaintenanceList({
  218. pageNo,
  219. pageSize,
  220. name: name.value,
  221. })
  222. .then((res) => {
  223. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  224. paging.value.complete(res.data.list);
  225. })
  226. .catch((res) => {
  227. // 如果请求失败写paging.value.complete(false);
  228. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  229. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  230. paging.value.complete(false);
  231. });
  232. };
  233. const onSearch = () => {
  234. paging.value.reload();
  235. };
  236. const formatDate = (time) => {
  237. return dayjs(time).format("YYYY-MM-DD HH:mm:ss");
  238. };
  239. // -- end --
  240. // 获取顶部统计数量
  241. const statistics = reactive({});
  242. const getCount = () => {
  243. getMaintenanceCount().then((res) => {
  244. statistics.total = res.data?.total || 0;
  245. statistics.todo = res.data?.todo || 0;
  246. statistics.done = res.data.total - res.data.todo;
  247. });
  248. };
  249. onMounted(() => {
  250. console.log("maintenance-onMounted");
  251. });
  252. onShow((options) => {
  253. console.log("maintenance-onShow", options);
  254. getCount();
  255. nextTick(() => {
  256. onSearch();
  257. });
  258. });
  259. onLoad((options) => {
  260. console.log("maintenance-onload", options);
  261. });
  262. const onCreate = () => {
  263. uni.navigateTo({
  264. url: "/pages/maintenance/create",
  265. });
  266. };
  267. const onEdit = (item) => {
  268. uni.navigateTo({
  269. url: "/pages/maintenance/edit?id=" + item.id,
  270. });
  271. };
  272. const onView = (item) => {
  273. uni.navigateTo({
  274. url: "/pages/maintenance/detail?id=" + item.id,
  275. });
  276. };
  277. const navigatorBack = () => {
  278. uni.navigateBack();
  279. };
  280. </script>
  281. <style lang="scss" scoped>
  282. @import "@/style/work-order.scss";
  283. </style>