accident.vue 7.4 KB

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