DisposeRubbishForm.vue 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888
  1. <template>
  2. <view>
  3. <cu-custom :backUrl="'/pages/index/index?id=apps'" :isBack="true" bgColor="bg-gradual-blue">
  4. <block slot="content">建筑垃圾清运处理</block>
  5. </cu-custom>
  6. <!-- First Section: 巡查工单 to 联系方式 -->
  7. <view class="form-section">
  8. <!-- 遮罩层 -->
  9. <view v-if="isProcessing" class="mask"></view>
  10. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="!nodeFlag">
  11. <u-form-item label="清运编号" prop="no">
  12. <u--input v-model="inputForm.no" :disabled="true" placeholder="工单编号" clearable></u--input>
  13. </u-form-item>
  14. <u-form-item label="所属单位" prop="processingUnitName" :required="true" v-if="disFlag">
  15. <u--input v-model="inputForm.processingUnitName" :disabled="true" placeholder="所属单位" clearable></u--input>
  16. </u-form-item>
  17. <u-form-item label="村负责人" prop="clearUserName">
  18. <u--input v-model="inputForm.clearUserName" :disabled="true" placeholder="村负责人" clearable></u--input>
  19. </u-form-item>
  20. <u-form-item label="联系方式" prop="clearUserMobile">
  21. <u--input v-model="inputForm.clearUserMobile" :disabled="true" placeholder="联系方式" clearable></u--input>
  22. </u-form-item>
  23. <u-form-item label="处理方式" prop="disposeType" :required="true">
  24. <jp-picker v-model="inputForm.disposeType" rangeKey="label" rangeValue="value" :range="[
  25. { label: '转运调剂处理', value: '1' },
  26. { label: '自行处理', value: '2' },
  27. ]" ></jp-picker>
  28. </u-form-item>
  29. <u-form-item label="垃圾站点" prop="rubbishStation">
  30. <u--input v-model="inputForm.rubbishStation" :disabled="true" placeholder="垃圾站点" clearable></u--input>
  31. </u-form-item>
  32. <template>
  33. <div>
  34. <u-form-item
  35. v-for="(item, index_workOver) in inputForm.workOverNoList"
  36. :key="index_workOver"
  37. :label="`巡查工单 ${index_workOver + 1}`"
  38. :required="true"
  39. :prop="'workOverNoList[' + index_workOver + '].no'"
  40. >
  41. <div style="width: 100%" @click="showWorkOver(index_workOver)">
  42. <u--input v-model="inputForm.workOverNoList[index_workOver].no" readonly
  43. style="pointer-events: none;"
  44. placeholder="请选择巡查工单编号" @focus="showWorkOver(index_workOver)" clearable></u--input>
  45. <view >
  46. <text class="u-demo-block__title">{{inputForm.workOverNoList[index_workOver].no}}清理前照片</text>
  47. <view class="u-page__upload-item">
  48. <u-upload
  49. :disabled="true"
  50. :fileList="getFileList(index_workOver)"
  51. @afterRead="afterRead"
  52. name="1"
  53. multiple
  54. :maxCount="10"
  55. ></u-upload>
  56. </view>
  57. </view>
  58. <u-button type="error" text="删除" @click="removeRow(index_workOver)"></u-button>
  59. </div>
  60. </u-form-item>
  61. </div>
  62. </template>
  63. <u-form-item label="" >
  64. <u-button style="width: 100%" type="primary" @click="addRow()" plain>新增巡查工单</u-button>
  65. </u-form-item>
  66. </u--form>
  67. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="nodeFlag">
  68. <u-form-item label="清运编号" prop="no">
  69. <u--input v-model="inputForm.no" :disabled="true" placeholder="工单编号" clearable></u--input>
  70. </u-form-item>
  71. <u-form-item label="所属单位" prop="processingUnitName" :required="true" v-if="disFlag">
  72. <u--input v-model="inputForm.processingUnitName" :disabled="true" placeholder="所属单位" clearable></u--input>
  73. </u-form-item>
  74. <u-form-item label="村负责人" prop="clearUserName">
  75. <u--input v-model="inputForm.clearUserName" :disabled="true" placeholder="村负责人" clearable></u--input>
  76. </u-form-item>
  77. <u-form-item label="联系方式" prop="clearUserMobile">
  78. <u--input v-model="inputForm.clearUserMobile" :disabled="true" placeholder="联系方式" clearable></u--input>
  79. </u-form-item>
  80. <u-form-item label="处理方式" prop="disposeType" :required="true" >
  81. <jp-picker v-model="inputForm.disposeType" rangeKey="label" :disabled="true" rangeValue="value" :range="[
  82. { label: '转运调剂处理', value: '1' },
  83. { label: '自行处理', value: '2' },
  84. ]" ></jp-picker>
  85. </u-form-item>
  86. <u-form-item label="垃圾站点" prop="rubbishStation">
  87. <u--input v-model="inputForm.rubbishStation" :disabled="true" placeholder="垃圾站点" clearable></u--input>
  88. </u-form-item>
  89. <template>
  90. <div>
  91. <u-form-item
  92. v-for="(item, index_workOver) in inputForm.workOverNoList"
  93. :key="index_workOver"
  94. :label="`巡查工单 ${index_workOver + 1}`"
  95. :required="true"
  96. :prop="'workOverNoList[' + index_workOver + '].no'"
  97. >
  98. <u--input
  99. v-model="inputForm.workOverNoList[index_workOver].no"
  100. :disabled="true"
  101. placeholder="请选择巡查工单编号">
  102. </u--input>
  103. <u-button type="primary" style="width: 20%" text="处理" @click="disposeWorkOver(inputForm.workOverNoList[index_workOver].id)" v-if="!weighFlag"></u-button>
  104. </u-form-item>
  105. </div>
  106. </template>
  107. </u--form>
  108. </view>
  109. <!-- Second Section: 上传图片 -->
  110. <view class="form-section" v-if="nodeFlag">
  111. <text class="u-demo-block__title">清理前照片</text>
  112. <view class="u-page__upload-item">
  113. <u-upload
  114. :disabled="true"
  115. :fileList="fileList1"
  116. @afterRead="afterRead"
  117. name="1"
  118. multiple
  119. :maxCount="10"
  120. ></u-upload>
  121. </view>
  122. </view>
  123. <!-- Second Section: 上传图片 -->
  124. <view class="form-section" v-if="nodeFlag">
  125. <text class="u-demo-block__title">清理中照片</text>
  126. <view class="u-page__upload-item">
  127. <u-upload
  128. :disabled="true"
  129. :fileList="fileList2"
  130. @afterRead="afterRead"
  131. name="2"
  132. multiple
  133. :maxCount="10"
  134. ></u-upload>
  135. </view>
  136. </view>
  137. <!-- Second Section: 上传图片 -->
  138. <view class="form-section" v-if="nodeFlag">
  139. <text class="u-demo-block__title">清理后照片</text>
  140. <view class="u-page__upload-item">
  141. <u-upload
  142. :disabled="true"
  143. :fileList="fileList3"
  144. @afterRead="afterRead"
  145. name="3"
  146. multiple
  147. :maxCount="10"
  148. ></u-upload>
  149. </view>
  150. </view>
  151. <!-- Third Section: 备注 -->
  152. <view class="form-section" v-if="!nodeFlag">
  153. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" >
  154. <u-form-item label="备注" borderBottom prop="remarks">
  155. <u--textarea placeholder='请填写备注' :maxlength="500" v-model="inputForm.remarks"></u--textarea>
  156. </u-form-item>
  157. <!--<view class="button-container">
  158. <u-button
  159. text="提交"
  160. size="large"
  161. type="primary"
  162. @click="saveForm"
  163. ></u-button>
  164. </view>-->
  165. </u--form>
  166. </view>
  167. <!-- Third Section: 备注 -->
  168. <view class="form-section" v-if="nodeFlag || weighFlag">
  169. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" >
  170. <u-form-item label="备注" borderBottom prop="remarks">
  171. <u--textarea placeholder='请填写备注' :disabled="true" :maxlength="500" v-model="inputForm.remarks"></u--textarea>
  172. </u-form-item>
  173. </u--form>
  174. </view>
  175. <view class="form-section" v-if="weighFlag">
  176. <span style="color: #4396fd;">现场信息登记</span>
  177. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm">
  178. <u-form-item label="重量(t)" prop="weight" :required="true">
  179. <u--input
  180. @change="weightChange"
  181. v-model="inputForm.weight"
  182. @input="handleInput('weight', $event)"
  183. placeholder="重量"
  184. clearable
  185. ></u--input>
  186. </u-form-item>
  187. <u-form-item label="运输里程(km)" prop="transportMileage" :required="true">
  188. <u--input
  189. :disabled="true"
  190. v-model="inputForm.transportMileage"
  191. @input="handleInput('transportMileage', $event)"
  192. placeholder="运输里程"
  193. clearable
  194. ></u--input>
  195. </u-form-item>
  196. <u-form-item label="补贴(元)" prop="subsidy" :required="true">
  197. <u--input
  198. :disabled="true"
  199. v-model="inputForm.subsidy"
  200. @input="handleInput('subsidy', $event)"
  201. placeholder="补贴"
  202. clearable
  203. ></u--input>
  204. </u-form-item>
  205. </u--form>
  206. </view>
  207. <!-- Second Section: 上传图片 -->
  208. <view class="form-section" v-if="weighFlag">
  209. <text style="color: black">过磅现场照片</text>
  210. <view class="u-page__upload-item" >
  211. <text class="u-demo-block__title">照片上传</text>
  212. <u-upload
  213. :fileList="fileList4"
  214. @afterRead="afterRead"
  215. @delete="deletePic"
  216. name="4"
  217. multiple
  218. :maxCount="10"
  219. ></u-upload>
  220. </view>
  221. </view>
  222. <WorkOverChoose ref="workOverChoose" @input="selectWorkOverChange" title="报告项目选择"/>
  223. </view>
  224. </template>
  225. <script>
  226. import disposeRubbishService from '@/api/garbageClearance/disposeRubbishService'
  227. import overService from '@/api/garbageClearance/overService'
  228. import WorkOverChoose from './WorkOverChoose'
  229. import taskService from "@/api/flowable/taskService"
  230. import {mapState, mapMutations, mapActions} from 'vuex'
  231. import * as $auth from "../../common/auth";
  232. import { EventBus } from '@/store/eventBus.js';
  233. export default {
  234. components: {
  235. WorkOverChoose,
  236. },
  237. computed: mapState({
  238. userInfo: (state) => state.user.userInfo,
  239. avatar: (state) => state.user.avatar
  240. }),
  241. data () {
  242. return {
  243. disFlag: true, // 启用动态获取处理单位则设置为false
  244. isProcessing: false, // 遮罩层
  245. uploadFlag: true, // 上传判定值
  246. processingUnits: [],
  247. taskName: '', //当前节点处理人节点名称
  248. fileList1: [],
  249. fileList2: [],
  250. fileList3: [],
  251. fileList4: [],
  252. nodeFlag: false,
  253. weighFlag: false, // 过磅管理员看到的信息
  254. inputForm: {
  255. programId: '',
  256. programIds: [],
  257. no: '',
  258. processingUnit: '',
  259. processingUnitName: '',
  260. clearUserId: '',
  261. clearUserName: '',
  262. clearUserMobile: '',
  263. remarks: '',
  264. status: '',
  265. workOverNoList: [],
  266. disposeType: '',
  267. rubbishStation: '',
  268. weight: '',
  269. transportMileage: '',
  270. subsidy: '',
  271. subsidyUnitPrice: '',
  272. },
  273. rules: {
  274. 'processingUnit': [
  275. {
  276. required: true,
  277. message: '处理单位不能为空',
  278. trigger: ['blur', 'change']
  279. }
  280. ],
  281. }
  282. }
  283. },
  284. // 页面加载时执行
  285. async created() {
  286. EventBus.$on('refreshPhoto', this.refreshPhoto);
  287. if(!this.nodeFlag){
  288. let data = await disposeRubbishService.getMaxNo();
  289. if (data) {
  290. let newNo = parseInt(data, 10) + 1;
  291. this.inputForm.no = newNo;
  292. } else {
  293. // 获取当前年份
  294. let nowY = new Date().getFullYear();
  295. this.inputForm.no = nowY + '0001';
  296. }
  297. //获取垃圾站点信息
  298. let rubbishStation = await disposeRubbishService.getRubbishStation();
  299. this.inputForm.rubbishStation = rubbishStation;
  300. this.inputForm.processingUnit = this.userInfo.officeDTO.id
  301. this.inputForm.processingUnitName = this.userInfo.officeDTO.name
  302. // 不动态获取 根据当前登录人去查
  303. await overService.getUserInfoByOffId(this.userInfo.officeDTO.id)
  304. .then(data => {
  305. this.inputForm.clearUserId = data.id
  306. this.inputForm.clearUserName = data.name
  307. this.inputForm.clearUserMobile = data.mobile
  308. })
  309. .catch(e => {
  310. throw e;
  311. });
  312. }
  313. },
  314. props: {
  315. businessId: {
  316. type: String,
  317. default: ''
  318. },
  319. formReadOnly: {
  320. type: Boolean,
  321. default: false
  322. },
  323. status: {
  324. type: String,
  325. default: ''
  326. }
  327. },
  328. watch: {
  329. 'businessId': {
  330. handler (newVal) {
  331. if (this.businessId) {
  332. this.init(this.businessId)
  333. } else {
  334. this.$nextTick(() => {
  335. // this.$refs.inputForm.reset()
  336. })
  337. }
  338. },
  339. immediate: true,
  340. deep: false
  341. },
  342. },
  343. methods: {
  344. weightChange(weight) {
  345. const product = parseFloat(weight) * parseFloat(this.inputForm.transportMileage) * parseFloat(this.inputForm.subsidyUnitPrice);
  346. this.inputForm.subsidy = Math.round(product * 100) / 100;
  347. },
  348. handleMouseDown(event) {
  349. event.preventDefault(); // 防止选择文本
  350. this.$refs.input.focus(); // 使 input 获得焦点
  351. },
  352. getFileList(index_workOver) {
  353. // 返回当前行的文件列表
  354. return this.inputForm.workOverNoList[index_workOver].photos || [];
  355. },
  356. handleInput(field, value) {
  357. // Ensure value is a string and sanitize input
  358. value = value.toString();
  359. // Regular expression to match numbers with up to 2 decimal places and ensure positive value
  360. const regex = /^(?!.*[a-zA-Z])\-?\d+(\.\d{0,2})?$/;
  361. // Format the value based on regex
  362. const match = value.match(regex);
  363. let formattedValue = (match && match[0]) || '';
  364. // Ensure the value is positive
  365. if (parseFloat(formattedValue) < 0) {
  366. formattedValue = '';
  367. }
  368. // Update input form based on the field
  369. this.inputForm[field] = formattedValue;
  370. },
  371. async init(id) {
  372. this.nodeFlag = true;
  373. this.inputForm.id = id;
  374. if (id) {
  375. // 使用 await 等待查询结果
  376. const data = await disposeRubbishService.queryById(id);
  377. // 获取当前节点流程信息,并等待其执行完成
  378. const taskName = await taskService.getTaskNameByProcInsId(data.procInsId);
  379. this.taskName = taskName
  380. // 根据任务名称处理逻辑
  381. if (this.isNotEmpty(taskName)) {
  382. if (taskName === '发起人重新申请' || this.isEmpty(taskName)) {
  383. this.nodeFlag = false;
  384. } else if (taskName === '过磅专员处理') {
  385. this.nodeFlag = true;
  386. this.weighFlag = true;
  387. //在此处获取发起地区的距离以及计算方式
  388. }
  389. }
  390. // 恢复表单数据
  391. this.inputForm = this.recover(this.inputForm, data);
  392. // 处理文件列表
  393. if (data.fileList1) {
  394. this.fileList1 = data.fileList1.map(item => ({
  395. attachmentName: item.name,
  396. fileSize: item.size,
  397. url: item.temporaryUrl,
  398. type: item.type // 如果不需要,可以不写
  399. }));
  400. }
  401. if (data.fileList2) {
  402. this.fileList2 = data.fileList2.map(item => ({
  403. attachmentName: item.name,
  404. fileSize: item.size,
  405. url: item.temporaryUrl,
  406. type: item.type // 如果不需要,可以不写
  407. }));
  408. }
  409. if (data.fileList3) {
  410. this.fileList3 = data.fileList3.map(item => ({
  411. attachmentName: item.name,
  412. fileSize: item.size,
  413. url: item.temporaryUrl,
  414. type: item.type // 如果不需要,可以不写
  415. }));
  416. }
  417. }
  418. }
  419. ,
  420. async selectWorkOverChange(rows, index) {
  421. //判定index所在行是否有数据,若有数据,则需要将数据从programIds 和 workOverNoList 进行删除
  422. var flag = false;
  423. if(this.inputForm.programIds.length>index ){
  424. var result= this.inputForm.programIds[index]
  425. if(result){
  426. flag = true
  427. }
  428. }
  429. if (rows.length > 0) {
  430. // 遍历 rows 数组
  431. for (const [rowIndex, item] of rows.entries()) {
  432. if(flag) {
  433. flag = false
  434. this.inputForm.programIds[index] = item.id
  435. }
  436. const uniqueIds = [...new Set([...this.inputForm.programIds, item.id])];
  437. // 更新 programIds 数组
  438. this.inputForm.programIds = uniqueIds;
  439. console.log(this.inputForm.programIds)
  440. }
  441. const programIdString = this.inputForm.programIds.join(','); // 用逗号分隔
  442. await overService.getPhotoListByIdAndAttachmentFlag(programIdString,'before').then(data => {
  443. this.inputForm.workOverNoList = [];
  444. // 将数据填充到 workOverNoList
  445. data.forEach((item) => {
  446. // 创建新的工作项
  447. let workOverItem = { no: item.no };
  448. // 处理 fileList1 数据
  449. if (item.fileList1) {
  450. workOverItem.photos = item.fileList1.map(file => ({
  451. url: file.temporaryUrl,
  452. type: file.type
  453. }));
  454. }
  455. // 将新的工作项添加到 workOverNoList
  456. this.inputForm.workOverNoList.push(workOverItem);
  457. });
  458. }).catch(() => {
  459. reject('数据错误');
  460. });
  461. }
  462. },
  463. addRow() {
  464. this.inputForm.workOverNoList.push({ recipientAgent: this.userInfo.name,
  465. recipientAgentId: this.userInfo.id, recipientOffice: this.userInfo.officeDTO.name });
  466. },
  467. // 显示 项目选择器
  468. showWorkOver(index) {
  469. this.$refs.workOverChoose.init(index);
  470. },
  471. // 显示 项目选择器
  472. disposeWorkOver(id) {
  473. if(this.inputForm.status === '2'){
  474. uni.navigateTo({
  475. url: '/pages/edt/PatrolWorkOrderForm?id='+id
  476. })
  477. }else{
  478. this.toEdit(this.inputForm)
  479. }
  480. },
  481. //刷信photo获取对应的id
  482. refreshPhoto() {
  483. disposeRubbishService.queryById(this.inputForm.id).then((data) => {
  484. if (data.fileList1) {
  485. this.fileList1 = []
  486. data.fileList1.forEach(
  487. (item) => {
  488. const newItem = {
  489. attachmentName: item.name,
  490. fileSize: item.size,
  491. url: item.temporaryUrl,
  492. type: item.type, // 如果不需要,可以不写
  493. };
  494. this.fileList1.push(newItem);
  495. }
  496. );
  497. }
  498. if (data.fileList2) {
  499. this.fileList2 = []
  500. data.fileList2.forEach(
  501. (item) => {
  502. const newItem = {
  503. attachmentName: item.name,
  504. fileSize: item.size,
  505. url: item.temporaryUrl,
  506. type: item.type, // 如果不需要,可以不写
  507. };
  508. this.fileList2.push(newItem);
  509. }
  510. );
  511. }
  512. if (data.fileList3) {
  513. this.fileList3 = []
  514. data.fileList3.forEach(
  515. (item) => {
  516. const newItem = {
  517. attachmentName: item.name,
  518. fileSize: item.size,
  519. url: item.temporaryUrl,
  520. type: item.type, // 如果不需要,可以不写
  521. };
  522. this.fileList3.push(newItem);
  523. }
  524. );
  525. }
  526. })
  527. },
  528. removeRow(index) {
  529. // 点击删除按钮时,从表格中移除指定行
  530. this.inputForm.programIds.splice(index, 1);
  531. this.inputForm.workOverNoList.splice(index, 1);
  532. //重新获取巡查工单信息
  533. this.insertRefreshPhoto()
  534. },
  535. //刷信photo获取对应的id
  536. insertRefreshPhoto() {
  537. disposeRubbishService.getByWorkOverId(this.inputForm.programIds).then((data) => {
  538. if (data) {
  539. this.fileList1 = []
  540. data.forEach(
  541. (item) => {
  542. const newItem = {
  543. attachmentName: item.name,
  544. fileSize: item.size,
  545. url: item.temporaryUrl,
  546. type: item.type, // 如果不需要,可以不写
  547. };
  548. this.fileList1.push(newItem);
  549. }
  550. );
  551. }
  552. })
  553. },
  554. formatDate(date) {
  555. const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
  556. const year = dateNew.getFullYear();
  557. const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
  558. const day = dateNew.getDate().toString().padStart(2, '0');
  559. return `${year}-${month}-${day}`;
  560. },
  561. isEmpty(value) {
  562. let result = false;
  563. if (value == null || value == undefined) {
  564. result = true;
  565. }
  566. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  567. result = true;
  568. }
  569. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  570. result = true;
  571. }
  572. return result;
  573. },
  574. isNotEmpty (value) {
  575. return !this.isEmpty(value)
  576. },
  577. /**
  578. * 判断是否为空
  579. */
  580. isNull(val) {
  581. if (val instanceof Array) {
  582. if (val.length === 0) return true;
  583. } else if (val instanceof Object) {
  584. if (JSON.stringify(val) === "{}") return true;
  585. } else {
  586. if (
  587. val === "null" ||
  588. val == null ||
  589. val === "undefined" ||
  590. val === undefined ||
  591. val === ""
  592. )
  593. return true;
  594. return false;
  595. }
  596. return false;
  597. },
  598. formatDateNew(date) {
  599. const year = date.getFullYear();
  600. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  601. const day = date.getDate().toString().padStart(2, '0');
  602. const hours = date.getHours().toString().padStart(2, '0');
  603. const minutes = date.getMinutes().toString().padStart(2, '0');
  604. const seconds = date.getSeconds().toString().padStart(2, '0');
  605. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  606. },
  607. saveForm(callback) {
  608. this.isProcessing = true; // 显示遮罩层
  609. return new Promise((resolve, reject) => {
  610. // 表单规则验证
  611. // ...
  612. let errors = [];
  613. if(!this.uploadFlag){
  614. errors.push("图片未上传完成,请等待上传完后在提交")
  615. }
  616. if(!this.inputForm.disposeType){
  617. errors.push("请选择处理方式")
  618. }
  619. if(this.inputForm.programId && !this.inputForm.programIds){
  620. this.inputForm.programIds = []
  621. let fruitsArray = this.inputForm.programId.split(',');
  622. this.inputForm.programIds = fruitsArray
  623. }
  624. if(!this.inputForm.programId && this.inputForm.programIds){
  625. const programIdString = this.inputForm.programIds.join(','); // 用逗号分隔
  626. this.inputForm.programId = programIdString
  627. }
  628. if(this.inputForm.programIds.length == 0){
  629. errors.push("请选择巡查工单")
  630. }
  631. if(this.weighFlag){
  632. if(!this.inputForm.weight){
  633. errors.push("请填写重量")
  634. }
  635. if(!this.inputForm.transportMileage){
  636. errors.push("请填写运输里程")
  637. }
  638. if(!this.inputForm.subsidy){
  639. errors.push("请填写补贴金额")
  640. }
  641. }
  642. if (errors.length > 0) {
  643. // 存在错误,显示提示信息
  644. errors.forEach(error => {
  645. this.isProcessing = false; // 显示遮罩层
  646. uni.showToast({
  647. title: error,
  648. icon: 'none',
  649. duration: 2000
  650. });
  651. });
  652. this.isProcessing = false;
  653. reject('Form validation failed');
  654. } else {
  655. // 所有验证通过,执行保存操作
  656. this.$refs.inputForm.validate().then(() => {
  657. uni.showLoading();
  658. if(this.weighFlag){
  659. this.inputForm.status = '5'
  660. }else{
  661. if(this.inputForm.disposeType === '1'){
  662. this.inputForm.status = '2'
  663. }else if(this.inputForm.disposeType === '2'){
  664. if(this.taskName){
  665. this.inputForm.status = '5'
  666. }else{
  667. this.inputForm.status = '2'
  668. }
  669. }else{
  670. this.inputForm.status = '2'
  671. }
  672. }
  673. this.inputForm.fileList4 = this.fileList4
  674. disposeRubbishService.save(this.inputForm).then(data => {
  675. uni.showToast({
  676. title: "提交成功",
  677. icon: "success",
  678. duration: 1000 // 提示持续时间为1秒(1000毫秒)
  679. });
  680. // 延迟1秒后再跳转到上一页
  681. setTimeout(() => {
  682. this.isProcessing = false; // 显示遮罩层
  683. callback(data.businessTable, data.businessId,this.inputForm,this.inputForm.disposeType);
  684. uni.navigateBack({
  685. delta: 1
  686. });
  687. }, 1000);
  688. resolve('Form saved successfully');
  689. }).catch(error => {
  690. reject('Save operation failed');
  691. });
  692. }).catch(() => {
  693. reject('Form validation failed');
  694. });
  695. }
  696. });
  697. },
  698. // 删除图片
  699. deletePic(event) {
  700. this[`fileList${event.name}`].splice(event.index, 1)
  701. },
  702. // 新增图片
  703. async afterRead(event) {
  704. try {
  705. this.uploadFlag = false
  706. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  707. let lists = [].concat(event.file)
  708. let fileListLen = this[`fileList${event.name}`].length
  709. lists.map((item) => {
  710. this[`fileList${event.name}`].push({
  711. ...item,
  712. status: 'uploading',
  713. message: '上传中'
  714. })
  715. })
  716. for (let i = 0; i < lists.length; i++) {
  717. const result = await this.uploadFilePromise(lists[i].url, fileListLen)
  718. let item = this[`fileList${event.name}`][fileListLen]
  719. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  720. status: 'success',
  721. message: '',
  722. url: result
  723. }))
  724. fileListLen++
  725. }
  726. this.uploadFlag = true
  727. } catch (error) {
  728. console.error('上传失败:', error);
  729. } finally {
  730. this.uploadFlag = true
  731. }
  732. },
  733. uploadFilePromise(url, index) {
  734. return new Promise((resolve, reject) => {
  735. let a = uni.uploadFile({
  736. url: 'http://dttz.xgccpm.cn/api/app/file/webUpload/fileUpload', // 仅为示例,非真实的接口地址
  737. filePath: url,
  738. name: 'file',
  739. formData: {
  740. user: this.$store.state.user.userInfo
  741. },
  742. header: {
  743. 'token': $auth.getUserToken(),
  744. },
  745. success: (res) => {
  746. // this.fileList1[index].url = url
  747. setTimeout(() => {
  748. const dataObj = JSON.parse(res.data);
  749. const url = dataObj.url;
  750. resolve(url);
  751. }, 1000);
  752. },
  753. fail: (err) => {
  754. console.error('Upload failed:', err);
  755. }
  756. });
  757. })
  758. },
  759. getUserInfoByOffId(){
  760. // 根据组织ID 获取 该村的 村支书
  761. overService.getUserInfoByOffId(this.inputForm.processingUnit)
  762. .then(data => {
  763. this.inputForm.clearUserId = data.id
  764. this.inputForm.clearUserName = data.name
  765. this.inputForm.clearUserMobile = data.mobile
  766. })
  767. .catch(e => {
  768. throw e;
  769. });
  770. }
  771. }
  772. }
  773. </script>
  774. <style>
  775. .form-section {
  776. padding: 10px 15px;
  777. margin-bottom: 10px;
  778. background-color: #ffffff;
  779. border-radius: 5px;
  780. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  781. }
  782. .u-page__upload-item {
  783. margin-top: 10px;
  784. }
  785. .button-container {
  786. margin-top: 20px;
  787. text-align: center;
  788. }
  789. .cu-form-group .title {
  790. min-width: 100px;
  791. }
  792. /* 遮罩层样式 */
  793. .mask {
  794. position: fixed;
  795. top: 0;
  796. left: 0;
  797. width: 100%;
  798. height: 100%;
  799. background-color: rgba(0, 0, 0, 0.05); /* 半透明遮罩 */
  800. z-index: 9999; /* 确保遮罩层在最顶层 */
  801. }
  802. </style>