snapshotDialog.vue 11 KB

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