PatrolWorkOrderForm.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661
  1. <template>
  2. <view>
  3. <cu-custom :backUrl="'/pages/index/index?id=apps'" :isBack="true" bgColor="bg-gradual-blue" v-if="!nodeFlag">
  4. <block slot="content">建筑垃圾巡视</block>
  5. </cu-custom>
  6. <!-- First Section: 巡视工单 to 联系方式 -->
  7. <view class="form-section">
  8. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="!nodeFlag">
  9. <u-form-item label="巡视工单" prop="no">
  10. <u--input v-model="inputForm.no" :disabled="true" placeholder="工单编号" clearable></u--input>
  11. </u-form-item>
  12. <u-form-item label="处理单位" borderBottom prop="processingUnit" :required="true" v-if="!disFlag">
  13. <jp-picker v-model="inputForm.processingUnit" rangeKey="label" rangeValue="value" :range="processingUnits" @input="getOfficeOnHamlet"></jp-picker>
  14. </u-form-item>
  15. <u-form-item label="处理单位" borderBottom prop="processingUnitName" :required="true" v-else-if="disFlag">
  16. <u--input v-model="inputForm.processingUnitName" :disabled="true" placeholder="处理单位" clearable></u--input>
  17. </u-form-item>
  18. <u-form-item label="清运专员" prop="clearUserName">
  19. <u--input v-model="inputForm.clearUserName" :disabled="true" placeholder="清运专员" clearable></u--input>
  20. </u-form-item>
  21. <u-form-item label="联系方式" prop="clearUserMobile">
  22. <u--input v-model="inputForm.clearUserMobile" :disabled="true" placeholder="联系方式" clearable></u--input>
  23. </u-form-item>
  24. </u--form>
  25. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="nodeFlag">
  26. <u-form-item label="巡视工单" prop="no">
  27. <u--input v-model="inputForm.no" :disabled="true" placeholder="工单编号" clearable></u--input>
  28. </u-form-item>
  29. <u-form-item label="处理单位" borderBottom prop="processingUnit" :required="true" v-if="!disFlag">
  30. <jp-picker v-model="inputForm.processingUnit" rangeKey="label" rangeValue="value" :range="processingUnits" @input="getOfficeOnHamlet"></jp-picker>
  31. </u-form-item>
  32. <u-form-item label="处理单位" borderBottom prop="processingUnitName" :required="true" v-else-if="disFlag">
  33. <u--input v-model="inputForm.processingUnitName" :disabled="true" placeholder="处理单位" clearable></u--input>
  34. </u-form-item>
  35. <u-form-item label="清运专员" prop="clearUserName">
  36. <u--input v-model="inputForm.clearUserName" :disabled="true" placeholder="清运专员" clearable></u--input>
  37. </u-form-item>
  38. <u-form-item label="联系方式" prop="clearUserMobile">
  39. <u--input v-model="inputForm.clearUserMobile" :disabled="true" placeholder="联系方式" clearable></u--input>
  40. </u-form-item>
  41. </u--form>
  42. </view>
  43. <!-- Second Section: 上传图片 -->
  44. <view class="form-section" v-if="!nodeFlag">
  45. <text class="u-demo-block__title">现场照片</text>
  46. <view class="u-page__upload-item">
  47. <u-upload
  48. :fileList="fileList1"
  49. @afterRead="afterRead"
  50. @delete="deletePic"
  51. name="1"
  52. multiple
  53. :maxCount="10"
  54. ></u-upload>
  55. </view>
  56. </view>
  57. <!-- Second Section: 上传图片 -->
  58. <view class="form-section" v-if="nodeFlag">
  59. <text class="u-demo-block__title">清理前照片</text>
  60. <view class="u-page__upload-item">
  61. <u-upload
  62. :disabled="true"
  63. :fileList="fileList1"
  64. name="1"
  65. multiple
  66. :maxCount="10"
  67. ></u-upload>
  68. </view>
  69. </view>
  70. <!-- Second Section: 上传图片 -->
  71. <view class="form-section" v-if="nodeFlag">
  72. <text class="u-demo-block__title">清理中照片</text>
  73. <view class="u-page__upload-item" v-if="showFlag">
  74. <u-upload
  75. :disabled="true"
  76. :fileList="fileList2"
  77. name="2"
  78. multiple
  79. :maxCount="10"
  80. ></u-upload>
  81. </view>
  82. <view class="u-page__upload-item" v-else>
  83. <u-upload
  84. :fileList="fileList2"
  85. @afterRead="afterRead"
  86. @delete="deletePic"
  87. name="2"
  88. multiple
  89. :maxCount="10"
  90. ></u-upload>
  91. </view>
  92. </view>
  93. <!-- Second Section: 上传图片 -->
  94. <view class="form-section" v-if="nodeFlag">
  95. <text class="u-demo-block__title">清理后照片</text>
  96. <view class="u-page__upload-item" v-if="showFlag">
  97. <u-upload
  98. :disabled="true"
  99. :fileList="fileList3"
  100. name="3"
  101. multiple
  102. :maxCount="10"
  103. ></u-upload>
  104. </view>
  105. <view class="u-page__upload-item" v-else>
  106. <u-upload
  107. :fileList="fileList3"
  108. @afterRead="afterRead"
  109. @delete="deletePic"
  110. name="3"
  111. multiple
  112. :maxCount="10"
  113. ></u-upload>
  114. </view>
  115. </view>
  116. <!-- Third Section: 备注 -->
  117. <view class="form-section">
  118. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="!nodeFlag">
  119. <u-form-item label="备注" borderBottom prop="remarks">
  120. <u--textarea placeholder='请填写备注' :maxlength="500" v-model="inputForm.remarks"></u--textarea>
  121. </u-form-item>
  122. <view class="button-container">
  123. <u-button
  124. text="提交"
  125. size="large"
  126. type="primary"
  127. @click="saveForm"
  128. ></u-button>
  129. </view>
  130. <!-- 遮罩层 -->
  131. <view v-if="isProcessing" class="mask"></view>
  132. </u--form>
  133. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="nodeFlag">
  134. <u-form-item label="备注" borderBottom prop="remarks">
  135. <u--textarea placeholder='请填写备注' :maxlength="500" :disabled="true" v-model="inputForm.remarks"></u--textarea>
  136. </u-form-item>
  137. <view class="button-container" v-if="!showFlag">
  138. <u-button
  139. text="确认"
  140. size="large"
  141. type="primary"
  142. @click="savePhoto"
  143. ></u-button>
  144. </view>
  145. </u--form>
  146. </view>
  147. </view>
  148. </template>
  149. <script>
  150. import overService from '@/api/garbageClearance/overService'
  151. import {mapState, mapMutations, mapActions} from 'vuex'
  152. import * as $auth from "../../common/auth";
  153. import { EventBus } from '@/store/eventBus.js';
  154. export default {
  155. components: {
  156. },
  157. computed: mapState({
  158. userInfo: (state) => state.user.userInfo,
  159. avatar: (state) => state.user.avatar
  160. }),
  161. data () {
  162. return {
  163. disFlag: true, // 启用动态获取处理单位则设置为false
  164. showFlag: false,
  165. isProcessing: false, // 遮罩层
  166. uploadFlag: true, // 上传判定值
  167. processingUnits: [],
  168. fileList1: [],
  169. fileList2: [],
  170. fileList3: [],
  171. nodeFlag: false,
  172. inputForm: {
  173. id: '',
  174. no: '',
  175. processingUnit: '',
  176. processingUnitName: '',
  177. clearUserId: '',
  178. clearUserName: '',
  179. clearUserMobile: '',
  180. remarks: '',
  181. },
  182. rules: {
  183. 'processingUnit': [
  184. {
  185. required: true,
  186. message: '处理单位不能为空',
  187. trigger: ['blur', 'change']
  188. }
  189. ],
  190. }
  191. }
  192. },
  193. // 页面加载时执行
  194. async created() {
  195. if('乡镇巡查员' === this.userInfo.roleNames){
  196. this.disFlag = false
  197. // 不动态获取 根据当前登录人去查
  198. await overService.getOfficeOnHamlet()
  199. .then(data => {
  200. this.processingUnits = []
  201. for (const value of data) {
  202. this.processingUnits.push({
  203. label: value.officeName,
  204. value: value.officeId
  205. });
  206. }
  207. })
  208. .catch(e => {
  209. throw e;
  210. });
  211. }
  212. if(!this.nodeFlag){
  213. let data = await overService.getMaxNo();
  214. if (data) {
  215. let newNo = parseInt(data, 10) + 1;
  216. this.inputForm.no = 'XS-J' + newNo;
  217. } else {
  218. // 获取当前年份
  219. let nowY = new Date().getFullYear();
  220. this.inputForm.no = 'XS-J' + nowY + '0001';
  221. }
  222. // 如果要使用动态获取处理单位则设置为true
  223. if (false) {
  224. let units = await overService.getProcessingUnit();
  225. let childs = units[0].children;
  226. if (childs) {
  227. this.processingUnits = []; // 初始化数组
  228. for (let i = 0; i < childs.length; i++) {
  229. this.processingUnits.push({
  230. label: childs[i].name,
  231. value: childs[i].id
  232. });
  233. }
  234. }
  235. }
  236. this.inputForm.processingUnit = this.userInfo.officeDTO.id
  237. this.inputForm.processingUnitName = this.userInfo.officeDTO.name
  238. // 不动态获取 根据当前登录人去查
  239. await overService.getUserInfoByOffId(this.userInfo.officeDTO.id)
  240. .then(data => {
  241. this.inputForm.clearUserId = data.id
  242. this.inputForm.clearUserName = data.name
  243. this.inputForm.clearUserMobile = data.mobile
  244. })
  245. .catch(e => {
  246. throw e;
  247. });
  248. }
  249. },
  250. props: {
  251. status: {
  252. type: String,
  253. default: ''
  254. }
  255. },
  256. watch: {
  257. },
  258. onLoad(options) {
  259. // 从 options 中获取 id 参数
  260. this.showFlag = options.showFlag;
  261. this.id = options.id;
  262. // 这里可以调用初始化方法
  263. this.init(this.id);
  264. },
  265. methods: {
  266. async init (id) {
  267. if(id){
  268. this.nodeFlag = true
  269. this.inputForm.id = id
  270. if (id) {
  271. await overService.queryById(id).then((data) => {
  272. this.inputForm = this.recover(this.inputForm, data)
  273. if (data.beforeFileList) {
  274. this.fileList1 = []
  275. data.beforeFileList.forEach(
  276. (item) => {
  277. const newItem = {
  278. attachmentName: item.name,
  279. fileSize: item.size,
  280. url: item.temporaryUrl,
  281. type: item.type, // 如果不需要,可以不写
  282. };
  283. this.fileList1.push(newItem);
  284. }
  285. );
  286. }
  287. if (data.betweenFileList) {
  288. this.fileList2 = []
  289. data.betweenFileList.forEach(
  290. (item) => {
  291. const newItem = {
  292. attachmentName: item.name,
  293. fileSize: item.size,
  294. url: item.temporaryUrl,
  295. type: item.type, // 如果不需要,可以不写
  296. };
  297. this.fileList2.push(newItem);
  298. }
  299. );
  300. }
  301. if (data.afterFileList) {
  302. this.fileList3 = []
  303. data.afterFileList.forEach(
  304. (item) => {
  305. const newItem = {
  306. attachmentName: item.name,
  307. fileSize: item.size,
  308. url: item.temporaryUrl,
  309. type: item.type, // 如果不需要,可以不写
  310. };
  311. this.fileList3.push(newItem);
  312. }
  313. );
  314. }
  315. })
  316. }
  317. }
  318. },
  319. formatDate(date) {
  320. const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
  321. const year = dateNew.getFullYear();
  322. const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
  323. const day = dateNew.getDate().toString().padStart(2, '0');
  324. return `${year}-${month}-${day}`;
  325. },
  326. isEmpty(value) {
  327. let result = false;
  328. if (value == null || value == undefined) {
  329. result = true;
  330. }
  331. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  332. result = true;
  333. }
  334. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  335. result = true;
  336. }
  337. return result;
  338. },
  339. isNotEmpty (value) {
  340. return !this.isEmpty(value)
  341. },
  342. /**
  343. * 判断是否为空
  344. */
  345. isNull(val) {
  346. if (val instanceof Array) {
  347. if (val.length === 0) return true;
  348. } else if (val instanceof Object) {
  349. if (JSON.stringify(val) === "{}") return true;
  350. } else {
  351. if (
  352. val === "null" ||
  353. val == null ||
  354. val === "undefined" ||
  355. val === undefined ||
  356. val === ""
  357. )
  358. return true;
  359. return false;
  360. }
  361. return false;
  362. },
  363. formatDateNew(date) {
  364. const year = date.getFullYear();
  365. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  366. const day = date.getDate().toString().padStart(2, '0');
  367. const hours = date.getHours().toString().padStart(2, '0');
  368. const minutes = date.getMinutes().toString().padStart(2, '0');
  369. const seconds = date.getSeconds().toString().padStart(2, '0');
  370. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  371. },
  372. saveForm(callback) {
  373. this.isProcessing = true; // 显示遮罩层
  374. return new Promise((resolve, reject) => {
  375. // 表单规则验证
  376. // ...
  377. let errors = [];
  378. if(!this.uploadFlag){
  379. errors.push("图片未上传完成,请等待上传完后在提交")
  380. }
  381. if (this.fileList1 && this.fileList1.length > 0) {
  382. // 将 fileList1 中的每个文件对象的属性名调整为新的属性名
  383. this.inputForm.fileList1 = this.fileList1.map(file => {
  384. return {
  385. attachmentName: file.name,
  386. fileSize: file.size,
  387. url: file.url,
  388. type: file.type, // 如果不需要,可以不写
  389. attachmentFlag: 'before', // 如果不需要,可以不写
  390. };
  391. });
  392. }
  393. if (errors.length > 0) {
  394. // 存在错误,显示提示信息
  395. errors.forEach(error => {
  396. uni.showToast({
  397. title: error,
  398. icon: 'none',
  399. duration: 2000
  400. });
  401. });
  402. this.isProcessing = false;
  403. reject('Form validation failed');
  404. } else {
  405. // 所有验证通过,执行保存操作
  406. this.$refs.inputForm.validate().then(() => {
  407. uni.showLoading();
  408. overService.save(this.inputForm).then(data => {
  409. uni.showToast({
  410. title: "提交成功",
  411. icon: "success",
  412. duration: 1000 // 提示持续时间为1秒(1000毫秒)
  413. });
  414. // 延迟1秒后再跳转到上一页
  415. setTimeout(() => {
  416. this.isProcessing = false; // 显示遮罩层
  417. resolve('Form saved successfully');
  418. uni.navigateBack({
  419. delta: 1
  420. });
  421. }, 1000);
  422. }).catch(error => {
  423. reject('Save operation failed');
  424. });
  425. }).catch(() => {
  426. reject('Form validation failed');
  427. });
  428. }
  429. });
  430. },
  431. savePhoto() {
  432. return new Promise((resolve, reject) => {
  433. let errors = [];
  434. if(!this.uploadFlag){
  435. errors.push("图片未上传完成,请等待上传完后在提交")
  436. }
  437. if (this.fileList2 && this.fileList2.length > 0) {
  438. // 将 fileList1 中的每个文件对象的属性名调整为新的属性名
  439. this.inputForm.fileList2 = this.fileList2.map(file => {
  440. return {
  441. attachmentName: file.name,
  442. fileSize: file.size,
  443. url: file.url,
  444. type: file.type, // 如果不需要,可以不写
  445. attachmentFlag: 'between', // 如果不需要,可以不写
  446. };
  447. });
  448. }
  449. if (this.fileList3 && this.fileList3.length > 0) {
  450. // 将 fileList1 中的每个文件对象的属性名调整为新的属性名
  451. this.inputForm.fileList3 = this.fileList3.map(file => {
  452. return {
  453. attachmentName: file.name,
  454. fileSize: file.size,
  455. url: file.url,
  456. type: file.type, // 如果不需要,可以不写
  457. attachmentFlag: 'after', // 如果不需要,可以不写
  458. };
  459. });
  460. }
  461. if (errors.length > 0) {
  462. // 存在错误,显示提示信息
  463. errors.forEach(error => {
  464. uni.showToast({
  465. title: error,
  466. icon: 'none',
  467. duration: 2000
  468. });
  469. });
  470. this.isProcessing = false;
  471. reject('Form validation failed');
  472. } else {
  473. //数据保存
  474. this.$refs.inputForm.validate().then(() => {
  475. uni.showLoading();
  476. overService.savePhoto(this.inputForm).then(data => {
  477. EventBus.$emit('refreshPhoto');
  478. uni.showToast({
  479. title: "提交成功",
  480. icon: "success",
  481. duration: 1000 // 提示持续时间为1秒(1000毫秒)
  482. });
  483. // 延迟1秒后再跳转到上一页
  484. setTimeout(() => {
  485. this.isProcessing = false; // 显示遮罩层
  486. resolve('Form saved successfully');
  487. uni.navigateBack({
  488. delta: 1
  489. });
  490. }, 1000);
  491. }).catch(error => {
  492. reject('Save operation failed');
  493. });
  494. }).catch(() => {
  495. reject('Form validation failed');
  496. });
  497. }
  498. });
  499. },
  500. // 删除图片
  501. deletePic(event) {
  502. this[`fileList${event.name}`].splice(event.index, 1)
  503. },
  504. // 新增图片
  505. async afterRead(event) {
  506. try {
  507. this.uploadFlag = false
  508. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  509. let lists = [].concat(event.file)
  510. let fileListLen = this[`fileList${event.name}`].length
  511. lists.map((item) => {
  512. this[`fileList${event.name}`].push({
  513. ...item,
  514. status: 'uploading',
  515. message: '上传中'
  516. })
  517. })
  518. for (let i = 0; i < lists.length; i++) {
  519. const result = await this.uploadFilePromise(lists[i].url, fileListLen)
  520. let item = this[`fileList${event.name}`][fileListLen]
  521. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  522. status: 'success',
  523. message: '',
  524. url: result
  525. }))
  526. fileListLen++
  527. }
  528. this.uploadFlag = true
  529. } catch (error) {
  530. console.error('上传失败:', error);
  531. } finally {
  532. this.uploadFlag = true
  533. }
  534. },
  535. uploadFilePromise(url, index) {
  536. return new Promise((resolve, reject) => {
  537. let a = uni.uploadFile({
  538. url: 'http://localhost:8000/app/file/webUpload/fileUpload', // 仅为示例,非真实的接口地址
  539. filePath: url,
  540. name: 'file',
  541. formData: {
  542. user: this.$store.state.user.userInfo
  543. },
  544. header: {
  545. 'token': $auth.getUserToken(),
  546. },
  547. success: (res) => {
  548. // this.fileList1[index].url = url
  549. setTimeout(() => {
  550. const dataObj = JSON.parse(res.data);
  551. const url = dataObj.url;
  552. resolve(url);
  553. }, 1000);
  554. },
  555. fail: (err) => {
  556. console.error('Upload failed:', err);
  557. }
  558. });
  559. })
  560. },
  561. getOfficeOnHamlet(value){
  562. // 根据组织ID 获取 该村的 村支书
  563. overService.getUserInfoByOffId(value)
  564. .then(data => {
  565. this.inputForm.clearUserId = data.id
  566. this.inputForm.clearUserName = data.name
  567. this.inputForm.clearUserMobile = data.mobile
  568. })
  569. .catch(e => {
  570. throw e;
  571. });
  572. }
  573. }
  574. }
  575. </script>
  576. <style>
  577. .form-section {
  578. padding: 10px 15px;
  579. margin-bottom: 10px;
  580. background-color: #ffffff;
  581. border-radius: 5px;
  582. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  583. }
  584. .u-page__upload-item {
  585. margin-top: 10px;
  586. }
  587. .button-container {
  588. margin-top: 20px;
  589. text-align: center;
  590. }
  591. .cu-form-group .title {
  592. min-width: 100px;
  593. }
  594. /* 遮罩层样式 */
  595. .mask {
  596. position: fixed;
  597. top: 0;
  598. left: 0;
  599. width: 100%;
  600. height: 100%;
  601. background-color: rgba(0, 0, 0, 0.05); /* 半透明遮罩 */
  602. z-index: 9999; /* 确保遮罩层在最顶层 */
  603. }
  604. </style>