snapshotDialog.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. <template>
  2. <u-popup
  3. :show="visible"
  4. :round="0"
  5. :closeOnClickOverlay="false"
  6. :zIndex="99999"
  7. @close="handleCancel"
  8. class="u-popup-my"
  9. >
  10. <view class="popup-content">
  11. <view class="popup-header">
  12. <text class="popup-title">{{ dialogTitle }}</text>
  13. <view class="close-btn" @click="handleCancel">×</view>
  14. </view>
  15. <scroll-view class="popup-body" scroll-y>
  16. <view class="page">
  17. <view class="card-a">
  18. <!-- 头部 -->
  19. <view class="a-header">
  20. <text class="a-main-title">随手拍记录</text>
  21. </view>
  22. <!-- 基础信息 -->
  23. <view class="card-section">
  24. <view class="section-title">📝 基础信息</view>
  25. <view class="info-list">
  26. <view class="info-item">
  27. <text class="info-label">问题描述</text>
  28. <textarea
  29. v-if="canEdit"
  30. class="info-textarea"
  31. v-model="formData.description"
  32. placeholder="请输入问题描述"
  33. :disabled="!canEdit"
  34. />
  35. <text v-else class="info-value readonly">{{
  36. formData.description
  37. }}</text>
  38. </view>
  39. <view class="info-item">
  40. <text class="info-label">问题所在位置</text>
  41. <input
  42. v-if="canEdit"
  43. class="info-input"
  44. v-model="formData.location"
  45. placeholder="请输入位置"
  46. :disabled="!canEdit"
  47. />
  48. <text v-else class="info-value readonly">{{
  49. formData.location
  50. }}</text>
  51. </view>
  52. <view class="info-item">
  53. <text class="info-label">问题所属部门</text>
  54. <view
  55. class="info-value"
  56. :class="{ disabled: !canEdit }"
  57. @click="title != '详情' && $refs.treePicker._show()"
  58. >
  59. {{ formData.problemDeptName || "请选择" }}
  60. </view>
  61. </view>
  62. <view class="info-item">
  63. <text class="info-label">随手拍图片</text>
  64. <fileMain
  65. v-model="formData.attachment"
  66. :type="canEdit ? '' : 'view'"
  67. />
  68. </view>
  69. </view>
  70. </view>
  71. <!-- 上报信息 -->
  72. <view class="card-section">
  73. <view class="section-title">👤 上报信息</view>
  74. <view class="info-list">
  75. <view class="info-item">
  76. <text class="info-label">上报人</text>
  77. <text class="info-value readonly">{{
  78. formData.reporterName
  79. }}</text>
  80. </view>
  81. <view class="info-item">
  82. <text class="info-label">上报人部门</text>
  83. <text class="info-value readonly">{{
  84. formData.reporterDeptName
  85. }}</text>
  86. </view>
  87. <view class="info-item" v-if="!canEdit">
  88. <text class="info-label">处理结果</text>
  89. <view >
  90. <text
  91. v-if="formData.handleResult == 0"
  92. class="status-pending"
  93. >待处理</text
  94. >
  95. <text
  96. v-else
  97. class="status-link"
  98. :class="{
  99. 'status-done': formData.handleResult == 1,
  100. 'status-discard': formData.handleResult == 2,
  101. }"
  102. @click="handleViewResult"
  103. >{{ getResultLabel(formData.handleResult) }}(点击查看)</text
  104. >
  105. </view>
  106. </view>
  107. </view>
  108. </view>
  109. </view>
  110. </view>
  111. </scroll-view>
  112. <view class="popup-footer">
  113. <template v-if="isView">
  114. <u-button type="default" @click="handleCancel">关闭</u-button>
  115. </template>
  116. <template v-else-if="isHandle">
  117. <u-button type="default" @click="handleDiscard">废弃</u-button>
  118. <u-button type="primary" @click="handleRectify">下发整改</u-button>
  119. </template>
  120. <template v-else>
  121. <u-button type="default" @click="handleCancel">取消</u-button>
  122. <u-button type="primary" @click="handleSubmit" :loading="loading"
  123. >保存</u-button
  124. >
  125. </template>
  126. </view>
  127. </view>
  128. <u-toast ref="uToast"></u-toast>
  129. <ba-tree-picker
  130. ref="treePicker"
  131. key="verify"
  132. :multiple="false"
  133. @select-change="searchDeptNodeClick"
  134. title="选择部门"
  135. :localdata="classificationList"
  136. valueKey="id"
  137. textKey="name"
  138. childrenKey="children"
  139. />
  140. </u-popup>
  141. </template>
  142. <script>
  143. import { getById, save, update } from "@/api/snapshot/index.js";
  144. import fileMain from "@/pages/doc/index.vue";
  145. import { listOrganizations } from "@/api/common.js";
  146. import { toTreeData } from "@/utils/utils.js";
  147. export default {
  148. emits: ["reload", "rectify", "discard"],
  149. components: {
  150. fileMain,
  151. },
  152. data() {
  153. return {
  154. visible: false,
  155. loading: false,
  156. dialogType: "add",
  157. formData: this.getDefaultForm(),
  158. classificationList: [],
  159. resultOptions: [
  160. {
  161. value: 1,
  162. label: "下发整改",
  163. },
  164. {
  165. value: 2,
  166. label: "废弃",
  167. },
  168. ],
  169. };
  170. },
  171. computed: {
  172. dialogTitle() {
  173. const map = {
  174. add: "新增随手拍",
  175. edit: "编辑随手拍",
  176. view: "随手拍详情",
  177. handle: "随手拍处理",
  178. };
  179. return map[this.dialogType] || "随手拍";
  180. },
  181. isView() {
  182. return this.dialogType === "view";
  183. },
  184. isHandle() {
  185. return this.dialogType === "handle";
  186. },
  187. canEdit() {
  188. return ["add", "edit"].includes(this.dialogType);
  189. },
  190. },
  191. methods: {
  192. getDefaultForm() {
  193. return {
  194. id: "",
  195. description: "",
  196. location: "",
  197. problemDeptId: "",
  198. problemDeptName: "",
  199. attachment: [],
  200. reporterId: "",
  201. reporterName: "",
  202. reporterDeptId: "",
  203. reporterDeptName: "",
  204. handleResult: 0,
  205. handleOpinion: "",
  206. invHazardId: "",
  207. };
  208. },
  209. async getTreeList() {
  210. const data = await listOrganizations({});
  211. let treeList = toTreeData({
  212. data: data || [],
  213. idField: "id",
  214. parentIdField: "parentId",
  215. });
  216. this.classificationList = treeList;
  217. },
  218. async open(type, row = null) {
  219. console.log(row, "type");
  220. this.dialogType = type;
  221. if (row && row.id && ["edit", "view", "handle"].includes(type)) {
  222. try {
  223. const data = await getById(row.id);
  224. this.formData = {
  225. ...data,
  226. attachment: data.attachment || [],
  227. };
  228. } catch (e) {
  229. console.error(e);
  230. }
  231. } else {
  232. this.formData = this.getDefaultForm();
  233. const userInfo = uni.getStorageSync("userInfo") || {};
  234. this.formData.reporterName = userInfo.name || "";
  235. this.formData.reporterId = userInfo.userId || "";
  236. this.formData.reporterDeptName = userInfo.groupName || "";
  237. this.formData.reporterDeptId = userInfo.groupId || "";
  238. }
  239. this.getTreeList();
  240. this.visible = true;
  241. },
  242. //选择部门(搜索)
  243. async searchDeptNodeClick(id, name, type) {
  244. this.formData.problemDeptId = id[0];
  245. this.formData.problemDeptName = name;
  246. },
  247. handleCancel() {
  248. this.visible = false;
  249. this.resetForm();
  250. },
  251. resetForm() {
  252. this.formData = this.getDefaultForm();
  253. },
  254. getResultLabel(result) {
  255. const item = this.resultOptions.find((opt) => opt.value == result);
  256. return item ? item.label : "待处理";
  257. },
  258. previewImage(url) {
  259. uni.previewImage({
  260. urls: [url],
  261. });
  262. },
  263. handleViewResult() {
  264. if (this.formData.handleResult == 2) {
  265. this.$emit("discard", this.formData, "view");
  266. } else if (this.formData.handleResult == 1 && this.formData.invHazardId) {
  267. uni.navigateTo({
  268. url: `/pages/hazard/detail?id=${this.formData.invHazardId}`,
  269. });
  270. }
  271. },
  272. async handleSubmit() {
  273. // 简单校验
  274. if (!this.formData.description) {
  275. this.$refs.uToast.show({
  276. type: "error",
  277. message: "请输入问题描述",
  278. });
  279. return;
  280. }
  281. if (!this.formData.location) {
  282. this.$refs.uToast.show({
  283. type: "error",
  284. message: "请输入问题所在位置",
  285. });
  286. return;
  287. }
  288. const api = this.dialogType === "add" ? save : update;
  289. this.loading = true;
  290. try {
  291. await api(this.formData);
  292. this.$refs.uToast.show({
  293. type: "success",
  294. message: this.dialogType === "add" ? "新增成功" : "编辑成功",
  295. });
  296. this.visible = false;
  297. this.$emit("reload");
  298. this.resetForm();
  299. } catch (e) {
  300. console.error(e);
  301. } finally {
  302. this.loading = false;
  303. }
  304. },
  305. handleRectify() {
  306. this.$emit("rectify", this.formData);
  307. this.visible = false;
  308. },
  309. handleDiscard() {
  310. this.$emit("discard", this.formData);
  311. this.visible = false;
  312. },
  313. },
  314. };
  315. </script>
  316. <style lang="scss" scoped>
  317. .popup-content {
  318. width: 100vw;
  319. height: calc(100vh - 100px);
  320. background: #fff;
  321. border-radius: 0;
  322. display: flex;
  323. flex-direction: column;
  324. background-color: #eff2f7;
  325. }
  326. .popup-header {
  327. display: flex;
  328. justify-content: space-between;
  329. align-items: center;
  330. padding: 30rpx;
  331. border-bottom: 1rpx solid #e5e5e5;
  332. background: #fff;
  333. .popup-title {
  334. font-size: 36rpx;
  335. font-weight: bold;
  336. color: #333;
  337. }
  338. .close-btn {
  339. width: 60rpx;
  340. height: 60rpx;
  341. display: flex;
  342. align-items: center;
  343. justify-content: center;
  344. font-size: 60rpx;
  345. color: #999;
  346. line-height: 1;
  347. }
  348. }
  349. .popup-body {
  350. flex: 1;
  351. overflow-y: auto;
  352. padding: 28rpx;
  353. }
  354. .page {
  355. font-family:
  356. system-ui,
  357. -apple-system,
  358. "Segoe UI",
  359. Roboto,
  360. Helvetica,
  361. sans-serif;
  362. }
  363. .card-a {
  364. background: #ffffff;
  365. border-radius: 48rpx;
  366. box-shadow: 0 12rpx 40rpx rgba(0, 0, 0, 0.05);
  367. overflow: hidden;
  368. }
  369. .a-header {
  370. background: linear-gradient(135deg, #e8f5e9 0%, #f1f8e9 100%);
  371. padding: 40rpx 32rpx 24rpx;
  372. text-align: center;
  373. .a-main-title {
  374. font-size: 36rpx;
  375. font-weight: 800;
  376. color: #2e7d32;
  377. }
  378. }
  379. .card-section {
  380. padding: 30rpx 32rpx;
  381. border-bottom: 2rpx solid #f0f2f5;
  382. &:last-child {
  383. border-bottom: none;
  384. }
  385. }
  386. .section-title {
  387. font-size: 30rpx;
  388. font-weight: 700;
  389. color: #1f2a44;
  390. margin-bottom: 24rpx;
  391. padding-left: 16rpx;
  392. border-left: 6rpx solid #4caf50;
  393. }
  394. .info-list {
  395. display: flex;
  396. flex-direction: column;
  397. gap: 28rpx;
  398. }
  399. .info-item {
  400. display: flex;
  401. flex-direction: column;
  402. gap: 8rpx;
  403. }
  404. .info-label {
  405. font-size: 26rpx;
  406. font-weight: 600;
  407. color: #6c7a91;
  408. }
  409. .info-value {
  410. font-size: 28rpx;
  411. font-weight: 500;
  412. color: #1e2a3a;
  413. padding: 16rpx 20rpx;
  414. border-radius: 24rpx;
  415. border: 2rpx solid #e9edf2;
  416. background: #fff;
  417. &.readonly {
  418. color: #999;
  419. background: #f5f5f5;
  420. }
  421. }
  422. .info-input,
  423. .info-textarea {
  424. font-size: 28rpx;
  425. color: #1e2a3a;
  426. height: 60rpx;
  427. padding: 16rpx 20rpx;
  428. border-radius: 24rpx;
  429. border: 2rpx solid #e9edf2;
  430. background: #fff;
  431. }
  432. .info-textarea {
  433. min-height: 160rpx;
  434. }
  435. .image-list {
  436. display: flex;
  437. flex-wrap: wrap;
  438. gap: 16rpx;
  439. image {
  440. width: 160rpx;
  441. height: 160rpx;
  442. border-radius: 16rpx;
  443. background: #f5f5f5;
  444. object-fit: cover;
  445. }
  446. }
  447. .status-pending {
  448. color: #e6a23c;
  449. background: #fff3e0;
  450. padding: 8rpx 20rpx;
  451. border-radius: 32rpx;
  452. font-size: 26rpx;
  453. display: inline-block;
  454. }
  455. .status-done {
  456. color: #67c23a;
  457. background: #e0f3e8;
  458. padding: 8rpx 20rpx;
  459. border-radius: 32rpx;
  460. font-size: 26rpx;
  461. display: inline-block;
  462. }
  463. .status-discard {
  464. color: #f56c6c;
  465. background: #fef0f0;
  466. padding: 8rpx 20rpx;
  467. border-radius: 32rpx;
  468. font-size: 26rpx;
  469. display: inline-block;
  470. }
  471. .status-link {
  472. text-decoration: none;
  473. }
  474. .popup-footer {
  475. display: flex;
  476. padding: 20rpx 30rpx;
  477. border-top: 1rpx solid #e5e5e5;
  478. background: #fff;
  479. gap: 20rpx;
  480. /deep/ .u-button {
  481. flex: 1;
  482. }
  483. }
  484. </style>