index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <z-paging class="page repair" ref="paging" v-model="dataList" @query="queryList">
  3. <!-- z-paging默认铺满全屏,此时页面所有view都应放在z-paging标签内,否则会被盖住 -->
  4. <!-- 需要固定在页面顶部的view请通过slot="top"插入,包括自定义的导航栏 -->
  5. <template #top>
  6. <view class="page-top">
  7. <view class="page-back"></view>
  8. <view class="uni-page-head navgator justify-center align-center">
  9. <view class="nav-back" @click="navigatorBack()">
  10. <uni-icons type="left"></uni-icons>
  11. </view>
  12. <view class="nav-title">
  13. {{ $t('equipmentMaintenance.title') }}
  14. </view>
  15. </view>
  16. <view class="page-content">
  17. <view class="content-search">
  18. <uni-easyinput prefixIcon="search" confirmType="search" v-model="search" :placeholder="$t('common.searchHint')" @confirm="onSearch"></uni-easyinput>
  19. </view>
  20. <uni-row class="content-statistics flex-row align-center justify-around">
  21. <!-- 已完成 -->
  22. <uni-col class="statistics-item flex-col align-center">
  23. <view class="statistics-count font-BiaoTiHei">
  24. {{ statistics.total }}
  25. </view>
  26. <view class="statistics-title">
  27. {{ $t('status.finished') }}
  28. </view>
  29. </uni-col>
  30. <!-- 待填写 -->
  31. <uni-col class="statistics-item flex-col align-center">
  32. <view class="statistics-count font-BiaoTiHei">
  33. {{ statistics.todo }}
  34. </view>
  35. <view class="statistics-title">
  36. {{ $t('status.tobeFilled') }}
  37. </view>
  38. </uni-col>
  39. <!-- 平均解决时间 -->
  40. <uni-col class="statistics-item flex-col align-center">
  41. <view class="statistics-count font-BiaoTiHei">
  42. {{ statistics.average }}
  43. </view>
  44. <view class="statistics-title">
  45. {{ $t('equipmentMaintenance.averageResolutionTime') }}
  46. </view>
  47. </uni-col>
  48. </uni-row>
  49. <button class="full-btn" type="primary" @click="onCreate">
  50. <uni-icons type="plusempty"></uni-icons>
  51. {{ $t('equipmentMaintenance.createButton') }}
  52. </button>
  53. </view>
  54. </view>
  55. </template>
  56. <view class="paging-list">
  57. <view class="item" v-for="(item, index) in dataList" :key="index">
  58. <view class="item-module flex-row align-center justify-between" :class="{ tobeFilled: item.status == 'tx' }">
  59. <view class="module-name">{{ $t('equipmentMaintenance.repairCode') }}: {{ item.failureCode }}</view>
  60. <view class="module-status" :class="{ pending: item.status == 'tx' }" v-if="statusDict[item.status]">
  61. <!-- 状态 -->
  62. <span>{{ statusDict[item.status] }}</span>
  63. </view>
  64. </view>
  65. <view class="item-content">
  66. <!-- 设备编号 -->
  67. <view class="item-title flex-row">
  68. <span class="item-title-width">{{ $t('device.deviceCode') }}:</span>
  69. <span>{{ item.deviceCode }}</span>
  70. </view>
  71. <!-- 设备名称 -->
  72. <view class="item-title flex-row">
  73. <span class="item-title-width">{{ $t('device.deviceName') }}:</span>
  74. <span>{{ item.deviceName }}</span>
  75. </view>
  76. <!-- 故障名称 -->
  77. <view class="item-title flex-row">
  78. <span class="item-title-width">{{ $t('fault.faultName') }}:</span>
  79. <span>{{ item.failureName }}</span>
  80. </view>
  81. <!-- 故障时间 -->
  82. <view class="item-title flex-row">
  83. <span class="item-title-width">{{ $t('fault.faultTime') }}:</span>
  84. <span>
  85. {{ item.failureTime ? formatDate(item.failureTime) : '' }}
  86. </span>
  87. </view>
  88. <!-- 维修开始时间 -->
  89. <view class="item-title flex-row">
  90. <span class="item-title-width">{{ $t('equipmentMaintenance.maintenanceStartTime') }}:</span>
  91. <span>
  92. {{ item.maintainStartTime ? formatDate(item.maintainStartTime) : '' }}
  93. </span>
  94. </view>
  95. <!-- 执行时间 -->
  96. <view class="item-title flex-row">
  97. <span class="item-title-width">{{ $t('workOrder.executionTime') }}:</span>
  98. <span>
  99. {{ item.executeDate ? formatDate(item.executeDate) : '' }}
  100. </span>
  101. </view>
  102. <!-- 审核状态 -->
  103. <view class="item-title flex-row">
  104. <span class="item-title-width">{{ $t('workOrder.auditStatus') }}:</span>
  105. <span>{{ auditStatusDict[item.auditStatus] }}</span>
  106. </view>
  107. <!-- 是否停机 -->
  108. <view class="item-title flex-row">
  109. <span class="item-title-width">{{ $t('equipmentMaintenance.isStop') }}:</span>
  110. <span :class="{ 'color-red': item.ifStop }">
  111. {{ item.ifStop ? $t('operation.yes') : $t('operation.no') }}
  112. </span>
  113. </view>
  114. <!-- 工单来源 -->
  115. <view class="item-title flex-row">
  116. <span class="item-title-width">{{ $t('workOrder.workOrderSource') }}:</span>
  117. <span>{{ item.maintainType }}</span>
  118. </view>
  119. </view>
  120. <view class="item-btn flex-row align-center justify-end" v-if="companyInfo.data !== 'rh'">
  121. <button type="primary" :plain="false" v-if="item.status !== 'tx'" @click="onView(item)">
  122. {{ $t('workOrder.viewDetails') }}
  123. </button>
  124. <button type="primary" v-else @click="onEdit(item)">
  125. {{ $t('operation.fill') }}
  126. </button>
  127. </view>
  128. <view class="item-btn flex-row align-center justify-end" v-else>
  129. <button type="primary" :plain="false" @click="onView(item)">
  130. {{ $t('workOrder.viewDetails') }}
  131. </button>
  132. <button type="primary" :plain="false" v-if="item.status === 'personnel' && userInfo.id === item.maintainPerson" @click="changeMethod(item)">维修方式</button>
  133. <button type="primary" @click="onEdit(item)" v-if="item.status === 'tx' && (item.auditStatus === 20 || item.auditStatus === null)">
  134. {{ $t('operation.fill') }}
  135. </button>
  136. </view>
  137. </view>
  138. </view>
  139. </z-paging>
  140. <uni-popup type="dialog" ref="chooseMethodRef" @close="cancelRepairMethod">
  141. <view class="popup-content">
  142. <view class="popup-title">维修方式</view>
  143. <view class="form-item">
  144. <text class="label">*</text>
  145. <text class="label-text">维修方式</text>
  146. <picker @change="onPickerChange" :value="selectedValue" :range="methodOptions">
  147. <view class="picker-view">
  148. {{ methodOptions[selectedValue] || '请选择维修方式' }}
  149. </view>
  150. </picker>
  151. <!-- <uni-data-select
  152. :clear="false"
  153. v-model="selectedValue"
  154. :localdata="methodOptions"
  155. @change="onPickerChange"
  156. >
  157. </uni-data-select> -->
  158. </view>
  159. <view class="form-item">
  160. <text class="label">*</text>
  161. <text class="label-text">备注说明</text>
  162. <textarea v-model="repairMethodForm.remark" placeholder="请输入备注说明" class="textarea" maxlength="200"></textarea>
  163. </view>
  164. <view class="popup-footer">
  165. <view class="btn-cancel" @click="cancelRepairMethod">取消</view>
  166. <view class="btn-confirm" @click="submitRepairMethod">确定</view>
  167. </view>
  168. </view>
  169. </uni-popup>
  170. </template>
  171. <script setup>
  172. import { ref, reactive, onMounted, nextTick } from 'vue';
  173. import { onShow } from '@dcloudio/uni-app';
  174. import { getRepairCount, getRepairList, maintainMethod } from '@/api/repair';
  175. import { getLoginUserInfo } from '@/api/login';
  176. import { getDeptName } from '@/api/recordFilling';
  177. import dayjs from 'dayjs';
  178. import { useDataDictStore } from '@/store/modules/dataDict';
  179. // 字典项
  180. const { getDataDictList } = useDataDictStore();
  181. // 状态
  182. const statusDict = reactive({});
  183. getDataDictList('pms_maintain_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. const methodOptions = ref([]); // 使用 ref 创建数组
  193. const methodOptionsMap = reactive({}); // 保存 value -> label 的映射
  194. getDataDictList('maintain_method').forEach((item) => {
  195. methodOptions.value.push(item.label); // 只存储 label 用于显示
  196. methodOptionsMap[item.value] = item.label;
  197. });
  198. console.log('auditStatusDict', auditStatusDict);
  199. // --- 列表 ---start---
  200. const search = ref('');
  201. const paging = ref(null);
  202. // v-model绑定的这个变量不要在分页请求结束中自己赋值,直接使用即可
  203. const dataList = ref([]);
  204. // @query所绑定的方法不要自己调用!!需要刷新列表数据时,只需要调用paging.value.reload()即可
  205. const queryList = (pageNo, pageSize) => {
  206. // 此处请求仅为演示,请替换为自己项目中的请求
  207. getRepairList({
  208. pageNo,
  209. pageSize,
  210. commonParam: search.value
  211. })
  212. .then((res) => {
  213. // 将请求结果通过complete传给z-paging处理,同时也代表请求结束,这一行必须调用
  214. paging.value.complete(res.data.list);
  215. })
  216. .catch((res) => {
  217. // 如果请求失败写paging.value.complete(false);
  218. // 注意,每次都需要在catch中写这句话很麻烦,z-paging提供了方案可以全局统一处理
  219. // 在底层的网络请求抛出异常时,写uni.$emit('z-paging-error-emit');即可
  220. paging.value.complete(false);
  221. });
  222. };
  223. const onSearch = () => {
  224. paging.value.reload();
  225. };
  226. const formatDate = (time) => {
  227. return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
  228. };
  229. // -- end --
  230. // 获取顶部统计数量
  231. const statistics = reactive({});
  232. const getCount = () => {
  233. getRepairCount().then((res) => {
  234. statistics.total = res.data.maintainStatus?.finished || 0;
  235. statistics.todo = res.data.maintainStatus?.tx || 0;
  236. statistics.average = 4.8;
  237. });
  238. };
  239. const currentRepairItem = ref(null); // 当前操作的工单项
  240. const repairMethodForm = ref({
  241. // 表单数据
  242. maintainMethod: '',
  243. remark: ''
  244. });
  245. const chooseMethodRef = ref(null); // 控制弹窗显示
  246. const selectedValue = ref(null);
  247. const changeMethod = (item) => {
  248. console.log('选择维修方式的工单项', item);
  249. // 打开弹窗前先初始化表单数据
  250. currentRepairItem.value = item;
  251. repairMethodForm.value.maintainMethod = '';
  252. repairMethodForm.value.remark = '';
  253. chooseMethodRef.value.open();
  254. };
  255. const submitRepairMethod = () => {
  256. if (!repairMethodForm.value.maintainMethod) {
  257. uni.showToast({
  258. title: '请选择维修方式',
  259. icon: 'none'
  260. });
  261. return;
  262. }
  263. if (!repairMethodForm.value.remark) {
  264. uni.showToast({
  265. title: '请输入备注说明',
  266. icon: 'none'
  267. });
  268. return;
  269. }
  270. // 调用接口
  271. maintainMethod({
  272. id: currentRepairItem.value.id,
  273. maintainMethod: repairMethodForm.value.maintainMethod,
  274. remark: repairMethodForm.value.remark
  275. })
  276. .then((res) => {
  277. uni.showToast({
  278. title: '提交成功',
  279. icon: 'success'
  280. });
  281. chooseMethodRef.value.close();
  282. // 可选:刷新列表或更新当前项状态
  283. onSearch(); // 刷新列表
  284. })
  285. .catch((err) => {
  286. uni.showToast({
  287. title: '提交失败',
  288. icon: 'none'
  289. });
  290. });
  291. };
  292. const cancelRepairMethod = () => {
  293. chooseMethodRef.value.close();
  294. repairMethodForm.value.maintainMethod = '';
  295. repairMethodForm.value.remark = '';
  296. selectedValue.value = null;
  297. };
  298. const onPickerChange = (e) => {
  299. const selectedIndex = e.detail.value;
  300. selectedValue.value = selectedIndex;
  301. // 通过索引找到对应的 value
  302. const selectedLabel = methodOptions.value[selectedIndex];
  303. const selectedKey = Object.keys(methodOptionsMap).find((key) => methodOptionsMap[key] === selectedLabel);
  304. repairMethodForm.value.maintainMethod = selectedKey; // 设置表单值为 key
  305. };
  306. onShow(() => {
  307. getCount();
  308. nextTick(() => {
  309. onSearch();
  310. });
  311. });
  312. const onCreate = () => {
  313. uni.navigateTo({
  314. url: '/pages/repair/create'
  315. });
  316. };
  317. const onEdit = (item) => {
  318. if (companyInfo.value.data === 'rh' && item.maintainPerson === userInfo.value.id && item.status === 'tx') {
  319. uni.showToast({
  320. title: '维修人员无法填写工单',
  321. icon: 'none',
  322. className: 'custom-toast' // 添加自定义类名
  323. });
  324. return;
  325. }
  326. uni.navigateTo({
  327. url: '/pages/repair/edit?id=' + item.id
  328. });
  329. };
  330. const onView = (item) => {
  331. uni.navigateTo({
  332. url: '/pages/repair/detail?id=' + item.id
  333. });
  334. };
  335. const navigatorBack = () => {
  336. uni.navigateBack();
  337. };
  338. const userInfo = ref({});
  339. const companyInfo = ref({});
  340. onMounted(async () => {
  341. userInfo.value = (await getLoginUserInfo()).data;
  342. companyInfo.value = await getDeptName(userInfo.value.dept.id);
  343. useDataDictStore().loadDataDictList();
  344. });
  345. </script>
  346. <style lang="scss" scoped>
  347. @import '@/style/work-order.scss';
  348. .popup-content {
  349. width: 500rpx;
  350. padding: 30rpx;
  351. background-color: #fff;
  352. border-radius: 16rpx;
  353. .popup-title {
  354. font-size: 36rpx;
  355. margin-bottom: 30rpx;
  356. text-align: center;
  357. }
  358. .form-item {
  359. margin-bottom: 40rpx;
  360. .label {
  361. color: red;
  362. font-size: 28rpx;
  363. margin-right: 10rpx;
  364. }
  365. .label-text {
  366. font-size: 28rpx;
  367. color: #333;
  368. }
  369. .picker-view {
  370. margin-top: 10rpx;
  371. padding: 20rpx;
  372. border: 1px solid #ccc;
  373. border-radius: 8rpx;
  374. font-size: 28rpx;
  375. }
  376. .textarea {
  377. width: 95.5%;
  378. height: 150rpx;
  379. padding: 10rpx;
  380. border: 1px solid #ccc;
  381. border-radius: 8rpx;
  382. font-size: 28rpx;
  383. }
  384. }
  385. .popup-footer {
  386. display: flex;
  387. justify-content: flex-end;
  388. gap: 30rpx;
  389. .btn-cancel {
  390. color: #333;
  391. border: none;
  392. }
  393. .btn-confirm {
  394. color: #007aff;
  395. }
  396. }
  397. }
  398. </style>