index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. <template>
  2. <z-paging
  3. class="page inspection"
  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("inspection.title") }}
  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.total }}
  38. </view>
  39. <view class="statistics-title">
  40. {{ $t("inspection.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.finished }}
  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. </view>
  61. </view>
  62. </template>
  63. <view class="paging-list">
  64. <view class="item" v-for="(item, index) in dataList" :key="index">
  65. <view
  66. class="item-module flex-row align-center justify-between"
  67. :class="{ tobeFilled: item.result == 1 ,ignore: item.status == 'ignore'}"
  68. >
  69. <!-- 工单编号 -->
  70. <view class="module-name">
  71. {{ $t("workOrder.workOrderNumber") }}: {{ item.inspectOrderCode }}
  72. </view>
  73. <view
  74. class="module-status"
  75. :class="{ finished: item.status == 'finished',ignore: item.status == 'ignore'}"
  76. >
  77. <span>{{ statusDict[item.status] ? statusDict[item.status] : "" }}</span>
  78. </view>
  79. </view>
  80. <view class="item-content">
  81. <!-- 工单名称 -->
  82. <view class="item-title flex-row">
  83. <span class="item-title-width"
  84. >{{ $t("workOrder.workOrderName") }}:</span
  85. >
  86. <span>{{ item.inspectOrderTitle }}</span>
  87. </view>
  88. <view class="item-title flex-row">
  89. <!-- 工单状态(1待执行 2已执行) -->
  90. <span class="item-title-width">{{ $t("workOrder.workOrderStatus") }}:</span>
  91. <span>{{ statusDict[item.status] ? statusDict[item.status] : "" }}</span>
  92. </view>
  93. <view class="item-title flex-row">
  94. <!-- 工单类型(1计划生成 2临时新建) -->
  95. <span class="item-title-width"
  96. >{{ $t("workOrder.workOrdertype") }}:</span
  97. >
  98. <span>{{ item.type }}</span>
  99. </view>
  100. <!-- 负责人 -->
  101. <view class="item-title flex-row">
  102. <span class="item-title-width"
  103. >{{ $t("workOrder.responsiblePerson") }}:</span
  104. >
  105. <span>{{ item.chargeName }}</span>
  106. </view>
  107. <!-- 应检设备数 -->
  108. <view class="item-title flex-row">
  109. <span class="item-title-width"
  110. >{{ $t("inspection.equipmentNum") }}:</span
  111. >
  112. <span>{{ item.deviceCount }}</span>
  113. </view>
  114. <!-- 漏检设备数 -->
  115. <view class="item-title flex-row">
  116. <span class="item-title-width">{{ $t("inspection.misNum") }}:</span>
  117. <span class="color-green">{{ item.needDevice }}</span>
  118. </view>
  119. <!-- 异常设备数 -->
  120. <view class="item-title flex-row">
  121. <span class="item-title-width"
  122. >{{ $t("inspection.abnormalNum") }}:</span
  123. >
  124. <span class="color-red">{{ item.exceptionCount }}</span>
  125. </view>
  126. <!-- 创建时间 -->
  127. <view class="item-title flex-row">
  128. <span class="item-title-width"
  129. >{{ $t("operation.createTime") }}:</span
  130. >
  131. <span>{{
  132. item.createTime ? formatDate(item.createTime) : ""
  133. }}</span>
  134. </view>
  135. <!-- 执行时间 -->
  136. <view class="item-title flex-row">
  137. <span class="item-title-width">
  138. {{ $t("workOrder.executionTime") }}:
  139. </span>
  140. <span>
  141. {{ item.executeDate ? formatDate(item.executeDate) : "" }}
  142. </span>
  143. </view>
  144. </view>
  145. <view class="item-btn flex-row align-center justify-end">
  146. <button type="primary" :plain="true" @click="navigatorDetail(item)">
  147. {{ $t("workOrder.viewDetails") }}
  148. </button>
  149. <button
  150. type="primary"
  151. class="btn-ignore"
  152. :plain="false"
  153. v-if="item.status == 'todo'"
  154. @click="handleIgnore(item)"
  155. >
  156. {{ $t("operation.ignore") }}
  157. </button>
  158. <button
  159. type="primary"
  160. :plain="false"
  161. v-if="item.status == 'todo'"
  162. @click="navigatorEdit(item)"
  163. >
  164. {{ $t("operation.fill") }}
  165. </button>
  166. </view>
  167. </view>
  168. </view>
  169. </z-paging>
  170. <!-- 忽略输入弹窗 -->
  171. <uni-popup
  172. class="ignore-unipopup"
  173. ref="ignorePopupRef"
  174. type="bottom"
  175. :animation="false"
  176. :mask-click="false"
  177. borderRadius="10px 10px 10px 10px"
  178. >
  179. <view class="ignore-popup-box">
  180. <view>
  181. <uni-row class="flex-row align-center">
  182. <uni-col class="ignore-popup-title" :span="22">
  183. {{ $t("operation.ignoreReason") }}
  184. </uni-col>
  185. <uni-col :span="2">
  186. <uni-icons
  187. type="closeempty"
  188. size="20"
  189. color="#999"
  190. @click="closeIgnorePopup"
  191. ></uni-icons>
  192. </uni-col>
  193. </uni-row>
  194. </view>
  195. <view class="ignore-popup-content">
  196. <uni-easyinput
  197. type="textarea"
  198. class="ignore-popup-textarea"
  199. :placeholder="
  200. $t('operation.PleaseFillIn') + $t('operation.ignoreReason')
  201. "
  202. v-model="ignoreReason"
  203. ></uni-easyinput>
  204. </view>
  205. <view class="ignore-popup-btn">
  206. <button type="primary" @click="confirmIgnore">
  207. {{ $t("operation.submit") }}
  208. </button>
  209. </view>
  210. </view>
  211. </uni-popup>
  212. </template>
  213. <script setup>
  214. import { ref, reactive, onMounted, getCurrentInstance, nextTick, warn } from "vue";
  215. import { onShow } from "@dcloudio/uni-app";
  216. import {
  217. getInspectCount,
  218. getInspectOrderList,
  219. inspectOrderIgnore,
  220. } from "@/api/inspection";
  221. import dayjs from "dayjs";
  222. import { useDataDictStore } from "@/store/modules/dataDict";
  223. // 引用全局变量$t
  224. const { appContext } = getCurrentInstance();
  225. const t = appContext.config.globalProperties.$t;
  226. const { getDataDictList } = useDataDictStore();
  227. // 状态
  228. const statusDict = reactive({});
  229. getDataDictList("pms_inspect_order_status").map((item) => {
  230. statusDict[item.value] = item.label;
  231. });
  232. console.log("statusDict", statusDict);
  233. // 审核状态
  234. const auditStatusDict = reactive({});
  235. getDataDictList("crm_audit_status").map((item) => {
  236. auditStatusDict[item.value] = item.label;
  237. });
  238. console.log("auditStatusDict", auditStatusDict);
  239. // --- 列表 ---start---
  240. const search = ref("");
  241. const paging = ref(null);
  242. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  243. const dataList = ref([]);
  244. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  245. const queryList = (pageNo, pageSize) => {
  246. // 此处请求仅为演示,请替换为自己项目中的请求
  247. getInspectOrderList({
  248. pageNo,
  249. pageSize,
  250. commonParam: search.value,
  251. })
  252. .then((res) => {
  253. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  254. paging.value.complete(res.data.list);
  255. })
  256. .catch((res) => {
  257. // 如果请求失败写paging.value.complete(false);
  258. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  259. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  260. paging.value.complete(false);
  261. });
  262. };
  263. const onSearch = () => {
  264. paging.value.reload();
  265. };
  266. const formatDate = (time) => {
  267. return dayjs(time).format("YYYY-MM-DD HH:mm:ss");
  268. };
  269. // -- end --
  270. // 获取顶部统计数量
  271. const statistics = reactive({});
  272. const getCount = async () => {
  273. getInspectCount().then((res) => {
  274. const { data } = res;
  275. statistics.total = data?.total || 0;
  276. statistics.todo = data?.todo || 0;
  277. statistics.finished = statistics.total - statistics.todo;
  278. });
  279. };
  280. // 忽略弹窗
  281. const ignorePopupRef = ref(null);
  282. // 忽略巡检项
  283. const ignoreItem = ref(null);
  284. // 忽略理由
  285. const ignoreReason = ref("");
  286. const handleIgnore = (item) => {
  287. ignoreItem.value = item;
  288. ignorePopupRef.value.open();
  289. };
  290. const closeIgnorePopup = () => {
  291. ignorePopupRef.value.close();
  292. ignoreReason.value = "";
  293. };
  294. // 忽略弹窗确认
  295. const confirmIgnore = (e) => {
  296. console.log("🚀 ~ confirmIgnore ~ e:", e);
  297. if (!ignoreReason.value) {
  298. uni.showToast({
  299. title: t("operation.PleaseFillIn") + t("operation.ignoreReason"),
  300. icon: "none",
  301. });
  302. return;
  303. }
  304. // 调用接口忽略巡检项
  305. inspectOrderIgnore({
  306. id: ignoreItem.value.id,
  307. reason: ignoreReason.value,
  308. })
  309. .then((res) => {
  310. console.log("🚀 ~ confirmIgnore ~ res:", res)
  311. if (res.code == 0) {
  312. uni.showToast({
  313. title: t("operation.success"),
  314. icon: "success",
  315. });
  316. closeIgnorePopup();
  317. nextTick(() => {
  318. getCount();
  319. onSearch();
  320. });
  321. }
  322. })
  323. .catch((res) => {
  324. uni.showToast({
  325. title: res.message || t("operation.failed"),
  326. icon: "none",
  327. });
  328. });
  329. };
  330. const navigatorDetail = (item) => {
  331. uni.navigateTo({
  332. url: "/pages/inspection/detail?id=" + item.id,
  333. });
  334. };
  335. const navigatorEdit = (item) => {
  336. uni.navigateTo({
  337. url: "/pages/inspection/edit?id=" + item.id,
  338. });
  339. };
  340. const navigatorBack = () => {
  341. uni.navigateBack();
  342. };
  343. onShow(() => {
  344. console.log("inspection - onShow");
  345. getCount();
  346. nextTick(() => {
  347. onSearch();
  348. });
  349. });
  350. </script>
  351. <style lang="scss" scoped>
  352. @import "@/style/work-order.scss";
  353. .btn-ignore {
  354. margin-left: 10px;
  355. background-color: #e6a23c !important;
  356. border-color: #e6a23c !important;
  357. color: #fff;
  358. }
  359. .ignore-popup-box {
  360. padding: 20px;
  361. background: #fff;
  362. border-radius: 10px 10px 0 0;
  363. }
  364. .ignore-popup-title {
  365. text-align: center;
  366. }
  367. .ignore-popup-close {
  368. text-align: right;
  369. }
  370. .ignore-popup-content {
  371. margin: 15px;
  372. }
  373. </style>