snapshotList.vue 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. <template>
  2. <view class="mainBox">
  3. <uni-nav-bar
  4. fixed="true"
  5. statusBar="true"
  6. left-icon="back"
  7. :title="navTitle"
  8. @clickLeft="back"
  9. />
  10. <!-- 搜索区域 -->
  11. <view class="top-wrapper">
  12. <uni-forms :modelValue="where" label-width="100px" class="search-form">
  13. <uni-forms-item label="处理结果">
  14. <uni-data-select
  15. v-model="where.handleResult"
  16. :localdata="resultOptions"
  17. placeholder="全部"
  18. clearable
  19. />
  20. </uni-forms-item>
  21. </uni-forms>
  22. <button class="search_btn" @click="handleSearch">搜索</button>
  23. </view>
  24. <view class="wrapper">
  25. <u-list @scrolltolower="scrolltolower" class="listContent">
  26. <view
  27. v-for="(item, idx) in tableList"
  28. :key="item.id"
  29. style="position: relative"
  30. >
  31. <myCard
  32. :item="item"
  33. :index="idx + 1"
  34. :btnList="currentBtnList"
  35. :columns="currentColumns"
  36. :title="item.description"
  37. :status="statusMap[item.handleResult]"
  38. @goDetail="goDetail"
  39. @edit="handleEdit(item)"
  40. @handleDelete="handleDelete(item)"
  41. @handleProcess="handleProcess(item)"
  42. />
  43. </view>
  44. <view style="width: 100%; height: 40rpx"></view>
  45. <view style="margin-top: 20vh" v-if="tableList.length == 0">
  46. <u-empty iconSize="150" textSize="32" text="暂无数据" />
  47. </view>
  48. </u-list>
  49. </view>
  50. <!-- 新增/编辑/查看/处理弹窗 -->
  51. <snapshot-dialog
  52. ref="snapshotDialog"
  53. @reload="reloadList"
  54. @rectify="onRectify"
  55. @discard="onDiscard"
  56. />
  57. <!-- 废弃弹窗(仅管理模式) -->
  58. <discard-dialog
  59. v-if="mode === 'manage'"
  60. ref="discardDialogRef"
  61. @confirm="doDiscard"
  62. />
  63. <hazard-dialog
  64. ref="hazardDialogRef"
  65. @reload="reloadList"
  66. />
  67. <!-- 新增按钮(仅我的随手拍) -->
  68. <view v-if="mode === 'my'" class="add" @click="handleAdd">
  69. <u-icon name="plus" color="#fff"></u-icon>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. import myCard from "@/components/myCard.vue";
  75. import snapshotDialog from "./snapshotDialog.vue";
  76. import HazardDialog from "@/pages/ehs/hazardManagement/hazardDialog.vue";
  77. import discardDialog from "./discardDialog.vue";
  78. import { getList, remove, discard, handle } from "@/api/snapshot/index.js";
  79. export default {
  80. components: {
  81. myCard,
  82. snapshotDialog,
  83. discardDialog,
  84. HazardDialog,
  85. },
  86. props: {
  87. mode: {
  88. type: String,
  89. default: "my",
  90. validator: (v) => ["my", "manage"].includes(v),
  91. },
  92. },
  93. data() {
  94. return {
  95. where: {
  96. handleResult: "",
  97. },
  98. resultOptions: [
  99. {
  100. value: 0,
  101. text: "待处理",
  102. },
  103. {
  104. value: 1,
  105. text: "下发整改",
  106. },
  107. {
  108. value: 2,
  109. text: "废弃",
  110. },
  111. ],
  112. statusMap: {
  113. 0: "待处理",
  114. 1: "已整改",
  115. 2: "已废弃",
  116. },
  117. tableList: [],
  118. page: 1,
  119. size: 10,
  120. isEnd: false,
  121. userInfo: {},
  122. currentId: null,
  123. };
  124. },
  125. computed: {
  126. navTitle() {
  127. return this.mode === "my" ? "我的随手拍" : "随手拍管理";
  128. },
  129. currentColumns() {
  130. return [
  131. [
  132. {
  133. prop: "location",
  134. label: "位置",
  135. className: "perce100",
  136. },
  137. ],
  138. [
  139. {
  140. prop: "problemDeptName",
  141. label: "所属部门",
  142. className: "perce100",
  143. },
  144. ],
  145. [
  146. {
  147. prop: "reporterName",
  148. label: "上报人",
  149. className: "perce100",
  150. },
  151. ],
  152. [
  153. {
  154. prop: "createTime",
  155. label: "上报时间",
  156. className: "perce100",
  157. },
  158. ],
  159. [
  160. {
  161. prop: "handleResult",
  162. label: "处理结果",
  163. className: "perce100",
  164. formatter: (row) => this.statusMap[row.handleResult],
  165. },
  166. ],
  167. [
  168. {
  169. label: "操作:",
  170. prop: "action",
  171. type: "action",
  172. className: "perce100",
  173. },
  174. ],
  175. ];
  176. },
  177. currentBtnList() {
  178. if (this.mode === "my") {
  179. return [
  180. {
  181. name: "编辑",
  182. apiName: "edit",
  183. btnType: "primary",
  184. judge: [
  185. {
  186. fn: (item) => item.handleResult === 0,
  187. },
  188. ],
  189. },
  190. {
  191. name: "删除",
  192. apiName: "handleDelete",
  193. btnType: "danger",
  194. judge: [
  195. {
  196. fn: (item) => item.handleResult === 0,
  197. },
  198. ],
  199. },
  200. ];
  201. } else {
  202. return [
  203. {
  204. name: "处理",
  205. apiName: "handleProcess",
  206. btnType: "primary",
  207. judge: [
  208. {
  209. fn: (item) => item.handleResult === 0,
  210. },
  211. ],
  212. },
  213. ];
  214. }
  215. },
  216. },
  217. created() {
  218. this.userInfo = uni.getStorageSync("userInfo") || {};
  219. this.getList();
  220. },
  221. methods: {
  222. back() {
  223. uni.navigateBack();
  224. },
  225. // 列表查看详情
  226. goDetail(item) {
  227. this.$refs.snapshotDialog.open("view", item);
  228. },
  229. // 新增(仅 my 模式)
  230. handleAdd() {
  231. this.$refs.snapshotDialog.open("add");
  232. },
  233. // 编辑(my 模式按钮)
  234. handleEdit(row) {
  235. this.$refs.snapshotDialog.open("edit", row);
  236. },
  237. // 删除(my 模式按钮)
  238. async handleDelete(row) {
  239. const res = await uni.showModal({
  240. title: "提示",
  241. content: "确认删除该记录吗?",
  242. });
  243. if (res[1].confirm) {
  244. await remove([row.id]);
  245. uni.showToast({
  246. title: "删除成功",
  247. icon: "success",
  248. });
  249. this.reloadList();
  250. }
  251. },
  252. // 处理(manage 模式按钮)
  253. handleProcess(row) {
  254. this.$refs.snapshotDialog.open("handle", row);
  255. },
  256. // 下发整改(manage 模式)
  257. onRectify(data, type) {
  258. if (type === "view") {
  259. this.$refs.hazardDialogRef.open("view", data);
  260. return;
  261. }
  262. this.currentId = data.id;
  263. this.$refs.hazardDialogRef &&
  264. this.$refs.hazardDialogRef.open("add", "", "report", {
  265. sourceType: 4,
  266. sourceId: data.id,
  267. sourceName: "随手拍",
  268. foundUserName: data.reporterName,
  269. foundUserId: data.reporterId,
  270. foundTime: data.createTime,
  271. description: data.location + data.description,
  272. reportAttachments: data.attachment,
  273. title: data.location + data.description,
  274. });
  275. },
  276. // 废弃(manage 模式)
  277. onDiscard(data, type) {
  278. this.$refs.discardDialogRef.open(data, type);
  279. },
  280. doDiscard({ id, handleOpinion }) {
  281. discard({
  282. id,
  283. handleOpinion,
  284. }).then(() => {
  285. uni.showToast({
  286. title: "废弃成功",
  287. icon: "success",
  288. });
  289. this.reloadList();
  290. });
  291. },
  292. // 通用方法
  293. reloadList() {
  294. this.page = 1;
  295. this.isEnd = false;
  296. this.getList();
  297. },
  298. handleSearch() {
  299. this.page = 1;
  300. this.isEnd = false;
  301. this.getList();
  302. },
  303. async getList() {
  304. if (this.isEnd) return;
  305. uni.showLoading({
  306. title: "加载中",
  307. });
  308. try {
  309. const baseData = {
  310. pageNum: this.page,
  311. size: this.size,
  312. handleResult:
  313. this.where.handleResult !== ""
  314. ? this.where.handleResult
  315. : undefined,
  316. };
  317. // 不同模式参数不同
  318. if (this.mode === "my") {
  319. baseData.reporterId = this.userInfo.userId;
  320. }
  321. const res = await getList(baseData);
  322. const newList = this.mode === "my" ? res.list || [] : res.list || [];
  323. if (this.page === 1) this.tableList = newList;
  324. else this.tableList.push(...newList);
  325. if (this.mode === "my") {
  326. this.isEnd = this.tableList.length >= res.count;
  327. } else {
  328. this.isEnd = newList.length < this.size;
  329. }
  330. this.page += 1;
  331. } catch (e) {
  332. console.error(e);
  333. } finally {
  334. uni.hideLoading();
  335. }
  336. },
  337. scrolltolower() {
  338. if (!this.isEnd) this.getList();
  339. },
  340. },
  341. };
  342. </script>
  343. <style lang="scss" scoped>
  344. @import "../../common-style.scss";
  345. </style>