index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. <template>
  2. <z-paging
  3. class="page fault"
  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.faultReporting") }}
  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="search"
  27. :placeholder="`${$t('common.searchHint')}}`"
  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.faultTotal }}
  38. </view>
  39. <view class="statistics-title">
  40. {{ $t("fault.faultTotal") }}
  41. </view>
  42. </uni-col>
  43. <uni-col class="statistics-item flex-col align-center">
  44. <view class="statistics-count font-BiaoTiHei">
  45. {{ statistics.finished }}
  46. </view>
  47. <view class="statistics-title">
  48. {{ $t("status.processed") }}
  49. </view>
  50. </uni-col>
  51. <uni-col class="statistics-item flex-col align-center">
  52. <view class="statistics-count font-BiaoTiHei">
  53. {{ statistics.average }}
  54. </view>
  55. <view class="statistics-title">
  56. {{ $t("equipmentMaintenance.averageResolutionTime") }}
  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("fault.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="{
  72. tobeFilled: item.status == 'close',
  73. finished: item.status == 'finished',
  74. }"
  75. >
  76. <view class="module-name">
  77. {{ $t("fault.faultCode") }}: {{ item.failureCode }}
  78. </view>
  79. <view
  80. class="module-status"
  81. :class="{
  82. pending: item.status == 'close',
  83. finished: item.status == 'finished',
  84. turn: item.status == 'trans',
  85. }"
  86. >
  87. <!-- 状态 -->
  88. <span>{{ statusDict[item.status] }}</span>
  89. </view>
  90. </view>
  91. <view class="item-content">
  92. <!-- 故障名称 -->
  93. <view class="item-title flex-row">
  94. <span class="item-title-width">{{ $t("fault.faultName") }}:</span>
  95. <span>{{ item.failureName }}</span>
  96. </view>
  97. <!-- 设备编号 -->
  98. <view class="item-title flex-row">
  99. <span class="item-title-width">{{ $t("device.deviceCode") }}:</span>
  100. <span>{{ item.deviceCode }}</span>
  101. </view>
  102. <!-- 设备名称 -->
  103. <view class="item-title flex-row">
  104. <span class="item-title-width">{{ $t("device.deviceName") }}:</span>
  105. <span>{{ item.deviceName }}</span>
  106. </view>
  107. <!-- 故障时间 -->
  108. <view class="item-title flex-row">
  109. <span class="item-title-width">{{ $t("fault.faultTime") }}:</span>
  110. <span>{{
  111. item.failureTime ? formatDate(item.failureTime) : ""
  112. }}</span>
  113. </view>
  114. <!-- 审核状态 -->
  115. <view class="item-title flex-row">
  116. <span class="item-title-width"
  117. >{{ $t("workOrder.auditStatus") }}:</span
  118. >
  119. <span>{{ auditStatusDict[item.auditStatus] }}</span>
  120. </view>
  121. <!-- 是否解决 -->
  122. <view class="item-title flex-row">
  123. <span class="item-title-width"
  124. >{{ $t("workOrder.isSolved") }}:</span
  125. >
  126. <span>{{
  127. item.ifDeal ? $t("operation.yes") : $t("operation.no")
  128. }}</span>
  129. </view>
  130. <!-- 需要协助 -->
  131. <view class="item-title flex-row">
  132. <span class="item-title-width"
  133. >{{ $t("workOrder.Needassistance") }}:</span
  134. >
  135. <span>{{
  136. item.needHelp ? $t("operation.yes") : $t("operation.no")
  137. }}</span>
  138. </view>
  139. <!-- 工单来源 -->
  140. <!-- <view class="item-title flex-row">
  141. <span class="item-title-width">{{$t('workOrder.workOrderSource')}}:</span>
  142. <span>{{item.maintainType}}</span>
  143. </view> -->
  144. </view>
  145. <view class="item-btn flex-row align-center justify-end">
  146. <!-- 查看详情 -->
  147. <button type="primary" :plain="false" @click="navigatorDetail(item)">
  148. {{ $t("workOrder.viewDetails") }}
  149. </button>
  150. <button
  151. type="primary"
  152. @click="navigatorEdit(item)"
  153. v-if="item.status == 'close'"
  154. >
  155. {{ $t("operation.edit") }}
  156. </button>
  157. <button
  158. type="default"
  159. style="color: #e7000d; background-color: #ffebeb"
  160. @click="onDelete(item)"
  161. v-if="item.status == 'close'"
  162. >
  163. {{ $t("operation.delete") }}
  164. </button>
  165. </view>
  166. </view>
  167. </view>
  168. </z-paging>
  169. </template>
  170. <script setup>
  171. import { ref, reactive, onMounted, getCurrentInstance, nextTick } from "vue";
  172. import { onShow, onLoad } from "@dcloudio/uni-app";
  173. import { getRepairCount } from "@/api/repair";
  174. import { getFaultList, deleteFault, getFaultCount } from "@/api/fault";
  175. import dayjs from "dayjs";
  176. import { useDataDictStore } from "@/store/modules/dataDict";
  177. // 引用全局变量$t
  178. const { appContext } = getCurrentInstance();
  179. const t = appContext.config.globalProperties.$t;
  180. const { getDataDictList } = useDataDictStore();
  181. // 状态
  182. const statusDict = reactive({});
  183. getDataDictList("pms_failure_status").map((item) => {
  184. statusDict[item.value] = item.label;
  185. });
  186. console.log("statusDict", statusDict);
  187. // 审核状态
  188. const auditStatusDict = reactive({});
  189. getDataDictList("crm_audit_status").map((item) => {
  190. auditStatusDict[item.value] = item.label;
  191. });
  192. console.log("auditStatusDict", auditStatusDict);
  193. // --- 列表 ---start---
  194. const search = ref("");
  195. const paging = ref(null);
  196. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  197. const dataList = ref([]);
  198. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  199. const queryList = (pageNo, pageSize) => {
  200. // 此处请求仅为演示,请替换为自己项目中的请求
  201. getFaultList({
  202. pageNo,
  203. pageSize,
  204. commonParam: search.value,
  205. })
  206. .then((res) => {
  207. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  208. paging.value.complete(res.data.list);
  209. })
  210. .catch((res) => {
  211. // 如果请求失败写paging.value.complete(false);
  212. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  213. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  214. paging.value.complete(false);
  215. });
  216. };
  217. const onSearch = () => {
  218. paging.value.reload();
  219. };
  220. const formatDate = (time) => {
  221. return dayjs(time).format("YYYY-MM-DD HH:mm:ss");
  222. };
  223. // -- end --
  224. // 获取顶部统计数量
  225. const statistics = reactive({});
  226. const getCount = async () => {
  227. await getFaultCount().then((res) => {
  228. statistics.faultTotal = res.data?.failureTotal || 0;
  229. });
  230. await getRepairCount().then((res) => {
  231. const { failureStatus } = res.data;
  232. console.log("failureStatus", failureStatus);
  233. statistics.finished = failureStatus?.finished || 0;
  234. statistics.average = 1.2;
  235. });
  236. };
  237. const navigatorDetail = (item) => {
  238. uni.navigateTo({
  239. url: "/pages/fault/detail?id=" + item.id,
  240. });
  241. };
  242. const navigatorEdit = (item) => {
  243. uni.navigateTo({
  244. url: "/pages/fault/edit?id=" + item.id,
  245. });
  246. };
  247. const onCreate = () => {
  248. uni.navigateTo({
  249. url: "/pages/fault/create",
  250. });
  251. };
  252. const onDelete = (item) => {
  253. uni.showModal({
  254. title: t("api.message"),
  255. content: t("operation.deleteConfirm"),
  256. success: function (res) {
  257. if (res.confirm) {
  258. console.log("用户点击确定");
  259. deleteFault({
  260. id: item.id,
  261. }).then((res) => {
  262. uni.showToast({
  263. title: t("operation.success"),
  264. icon: "none",
  265. });
  266. paging.value.reload();
  267. });
  268. } else if (res.cancel) {
  269. console.log("用户点击取消");
  270. }
  271. },
  272. });
  273. };
  274. const navigatorBack = () => {
  275. uni.navigateBack();
  276. };
  277. onShow(() => {
  278. getCount();
  279. nextTick(() => {
  280. onSearch();
  281. });
  282. });
  283. </script>
  284. <style lang="scss" scoped>
  285. @import "@/style/work-order.scss";
  286. </style>