accident.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <view class="accident-list">
  3. <!-- 搜索 -->
  4. <view class="search-row">
  5. <input class="search-input" v-model="searchName" placeholder="事故事件名称" />
  6. <button class="search-btn" @click="handleSearch">搜索</button>
  7. </view>
  8. <u-list @scrolltolower="loadMore" class="list-content">
  9. <view v-for="(item, idx) in listData" :key="item.id" class="card-wrapper">
  10. <myCard :item="item" :index="idx + 1" :btnList="getBtnList(item)" :columns="cardColumns"
  11. :title="item.acdntName" :status="getStatusLabel(item.approvalStatus)" @goDetail="goDetail"
  12. @edit="handleEdit(item)" @handleSubmit="handleSubmit(item)" @handleDelete="handleDelete(item)" />
  13. </view>
  14. <view style="height: 20rpx"></view>
  15. <view v-if="loading" class="load-more">加载中...</view>
  16. <view v-if="isEnd && listData.length > 0" class="load-more">没有更多了</view>
  17. <u-empty v-if="!loading && listData.length === 0" text="暂无数据" />
  18. </u-list>
  19. <!-- 新增按钮 -->
  20. <view class="add-btn" @click="handleAdd">
  21. <u-icon name="plus" color="#fff" size="40"></u-icon>
  22. </view>
  23. <!-- 弹窗 -->
  24. <accidentDialog ref="dialogRef" @reload="reloadList" />
  25. <!-- <processSubmitDialog ref="processSubmitRef" @reload="reloadList" /> -->
  26. <u-toast ref="uToast" />
  27. </view>
  28. </template>
  29. <script>
  30. import myCard from "@/components/myCard.vue";
  31. import accidentDialog from "./accidentDialog.vue";
  32. import {
  33. processInstanceCreateAPI,
  34. processInstancePage
  35. } from '@/api/wt/index.js'
  36. import {
  37. getList,
  38. remove
  39. } from "@/api/accidentReport/index.js";
  40. import {
  41. reviewStatusEnum
  42. } from "@/enum/dict";
  43. export default {
  44. components: {
  45. myCard,
  46. accidentDialog
  47. },
  48. data() {
  49. return {
  50. searchName: "",
  51. deptId: null,
  52. listData: [],
  53. page: 1,
  54. size: 10,
  55. isEnd: false,
  56. loading: false,
  57. cardColumns: [
  58. [{
  59. prop: "acdntCode",
  60. label: "编码",
  61. className: "perce100"
  62. }],
  63. [{
  64. prop: "acdntPlace",
  65. label: "发生地点",
  66. className: "perce100"
  67. }],
  68. [{
  69. prop: "dutyUnitName",
  70. label: "责任单位",
  71. className: "perce50"
  72. },
  73. {
  74. prop: "acdntLevelName",
  75. label: "事故级别",
  76. className: "perce50"
  77. },
  78. ],
  79. [{
  80. prop: "occurrenceTime",
  81. label: "发生时间",
  82. className: "perce100"
  83. }],
  84. [{
  85. label: "操作",
  86. prop: "action",
  87. type: "action",
  88. className: "perce100",
  89. }, ],
  90. ],
  91. };
  92. },
  93. mounted() {
  94. this.getList();
  95. },
  96. methods: {
  97. onDeptConfirm(data) {
  98. const id = data[0];
  99. this.deptId = id;
  100. const findDept = (list) => {
  101. for (const item of list) {
  102. if (item.id === id) return item.name;
  103. if (item.children) {
  104. const found = findDept(item.children);
  105. if (found) return found;
  106. }
  107. }
  108. return null;
  109. };
  110. this.deptName = findDept(this.deptList) || "责任单位";
  111. this.page = 1;
  112. this.isEnd = false;
  113. this.getList();
  114. },
  115. getStatusLabel(status) {
  116. return reviewStatusEnum.find(item => item.value == status).label
  117. },
  118. getBtnList(item) {
  119. const btns = [];
  120. const canEdit = [0, 3].includes(item.approvalStatus);
  121. if (canEdit) {
  122. btns.push({
  123. name: "编辑",
  124. apiName: "edit",
  125. btnType: "primary",
  126. judge: [{
  127. // authorities: 'ehs:accidentIncidents:update'
  128. }],
  129. });
  130. btns.push({
  131. name: "提交",
  132. apiName: "handleSubmit",
  133. btnType: "success",
  134. judge: [{
  135. // authorities: 'ehs:accidentIncidents:update'
  136. }],
  137. });
  138. btns.push({
  139. name: "删除",
  140. apiName: "handleDelete",
  141. btnType: "danger",
  142. judge: [{
  143. // authorities: 'ehs:accidentIncidents:delete'
  144. }],
  145. });
  146. }
  147. return btns;
  148. },
  149. goDetail(item) {
  150. this.$refs.dialogRef.open(item, "view");
  151. },
  152. handleAdd() {
  153. this.$refs.dialogRef.open(null, "add");
  154. },
  155. handleEdit(item) {
  156. this.$refs.dialogRef.open(item, "edit");
  157. },
  158. async handleSubmit(row) {
  159. //后台不提供接口
  160. let list = await processInstancePage({
  161. pageNo: 1,
  162. pageSize: 1,
  163. reset: true,
  164. key: 'ehs_accident_incidents'
  165. })
  166. let params = {
  167. businessId: row.id,
  168. businessKey: 'ehs_accident_incidents',
  169. formCreateUserId: row.createUserId,
  170. processDefinitionId: list.list[0].processDefinition.id,
  171. variables: {
  172. businessCode: row.acdntCode,
  173. businessName: row.acdntName,
  174. businessType: row.acdntTypeName
  175. },
  176. }
  177. await processInstanceCreateAPI(params)
  178. uni.showModal({
  179. title: `提交成功`,
  180. content: '',
  181. confirmText: '确认',
  182. showCancel: false, // 是否显示取消按钮,默认为 true
  183. success: () => {
  184. this.reloadList();
  185. }
  186. })
  187. },
  188. async handleDelete(item) {
  189. const res = await uni.showModal({
  190. title: "提示",
  191. content: "确认删除该事故记录吗?",
  192. });
  193. console.log(res, 'dsds')
  194. if (res[1].confirm) {
  195. try {
  196. await remove([item.id]);
  197. uni.showToast({
  198. title: "删除成功",
  199. icon: "success"
  200. });
  201. this.reloadList();
  202. } catch (e) {
  203. this.$refs.uToast.show({
  204. type: "error",
  205. message: e.message
  206. });
  207. }
  208. }
  209. },
  210. handleSearch() {
  211. this.page = 1;
  212. this.isEnd = false;
  213. this.getList();
  214. },
  215. reloadList() {
  216. this.page = 1;
  217. this.isEnd = false;
  218. this.getList();
  219. },
  220. async getList() {
  221. if (this.loading || this.isEnd) return;
  222. this.loading = true;
  223. try {
  224. const params = {
  225. pageNum: this.page,
  226. size: this.size,
  227. acdntName: this.searchName || undefined,
  228. dutyUnitId: this.deptId || undefined,
  229. };
  230. const res = await getList(params);
  231. const list = res.list || [];
  232. if (this.page === 1) this.listData = list;
  233. else this.listData = this.listData.concat(list);
  234. this.isEnd =
  235. list.length < this.size || this.listData.length >= res.count;
  236. this.page += 1;
  237. } catch (e) {
  238. this.$refs.uToast.show({
  239. type: "error",
  240. message: e.message || "加载失败",
  241. });
  242. } finally {
  243. this.loading = false;
  244. }
  245. },
  246. loadMore() {
  247. if (!this.isEnd && !this.loading) this.getList();
  248. },
  249. },
  250. };
  251. </script>
  252. <style lang="scss" scoped>
  253. .accident-list {
  254. .search-row {
  255. display: flex;
  256. align-items: center;
  257. gap: 12rpx;
  258. padding: 16rpx 0;
  259. background: #fff;
  260. border-radius: 24rpx;
  261. padding: 16rpx 20rpx;
  262. margin-bottom: 16rpx;
  263. .search-input {
  264. flex: 1;
  265. height: 60rpx;
  266. background: #f5f7fb;
  267. border-radius: 48rpx;
  268. padding: 0 20rpx;
  269. font-size: 26rpx;
  270. }
  271. .dept-btn {
  272. display: flex;
  273. align-items: center;
  274. height: 60rpx;
  275. padding: 0 20rpx;
  276. background: #e8edf4;
  277. border-radius: 48rpx;
  278. color: #2979ff;
  279. font-size: 24rpx;
  280. gap: 4rpx;
  281. .arrow {
  282. font-size: 18rpx;
  283. }
  284. }
  285. .search-btn {
  286. height: 60rpx;
  287. padding: 0 28rpx;
  288. background: $theme-color;
  289. border-radius: 48rpx;
  290. color: #fff;
  291. font-size: 26rpx;
  292. line-height: 60rpx;
  293. }
  294. }
  295. .list-content {
  296. height: calc(100vh - 300rpx);
  297. }
  298. .card-wrapper {
  299. margin-top: 16rpx;
  300. }
  301. .add-btn {
  302. position: fixed;
  303. bottom: 120rpx;
  304. right: 40rpx;
  305. width: 100rpx;
  306. height: 100rpx;
  307. border-radius: 50%;
  308. background: $theme-color;
  309. display: flex;
  310. align-items: center;
  311. justify-content: center;
  312. box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.15);
  313. z-index: 999;
  314. }
  315. .load-more {
  316. text-align: center;
  317. font-size: 26rpx;
  318. color: #aaa;
  319. padding: 20rpx 0;
  320. }
  321. }
  322. </style>