DisposeRubbishForm.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483
  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. <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="所属单位" prop="processingUnitName" :required="true" v-if="disFlag">
  13. <u--input v-model="inputForm.processingUnitName" :disabled="true" placeholder="处理单位" clearable></u--input>
  14. </u-form-item>
  15. <u-form-item label="清运专员" prop="clearUserName">
  16. <u--input v-model="inputForm.clearUserName" :disabled="true" placeholder="清运专员" clearable></u--input>
  17. </u-form-item>
  18. <u-form-item label="联系方式" prop="clearUserMobile">
  19. <u--input v-model="inputForm.clearUserMobile" :disabled="true" placeholder="联系方式" clearable></u--input>
  20. </u-form-item>
  21. <u-form-item label="处理单位" prop="disposeType" :required="true">
  22. <jp-picker v-model="inputForm.disposeType" rangeKey="label" rangeValue="value" :range="[
  23. { label: '转运调剂处理', value: '1' },
  24. { label: '自行处理', value: '2' },
  25. ]" ></jp-picker>
  26. </u-form-item>
  27. <u-form-item label="垃圾站点" prop="rubbishStation">
  28. <u--input v-model="inputForm.rubbishStation" :disabled="true" placeholder="垃圾站点" clearable></u--input>
  29. </u-form-item>
  30. <u-row :key="index_workOver" v-for="(item,index_workOver) in this.inputForm.workOverNoList">
  31. <u-form-item :label="`巡视工单 ${index_workOver + 1}`" :required="true" :prop="'workOverNoList[' + index_workOver + '].no'"
  32. :rules="[
  33. ]">
  34. <u--input v-model="inputForm.workOverNoList[index_workOver].no" placeholder="请选择巡视工单编号" @focus="showWorkOver(index_workOver)" clearable></u--input>
  35. </u-form-item>
  36. <u-form-item label="" >
  37. <u-button type="error" text="删除" @click="removeRow(index_workOver)"></u-button>
  38. </u-form-item>
  39. </u-row>
  40. <u-form-item label="" >
  41. <u-button style="width: 100%" type="primary" @click="addRow()" plain>新增基本信息</u-button>
  42. </u-form-item>
  43. </u--form>
  44. </view>
  45. <!-- Second Section: 上传图片 -->
  46. <view class="form-section">
  47. <text class="u-demo-block__title">现场照片</text>
  48. <view class="u-page__upload-item">
  49. <u-upload
  50. :fileList="fileList1"
  51. @afterRead="afterRead"
  52. @delete="deletePic"
  53. name="1"
  54. multiple
  55. :maxCount="10"
  56. ></u-upload>
  57. </view>
  58. </view>
  59. <!-- Third Section: 备注 -->
  60. <view class="form-section">
  61. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="!nodeFlag">
  62. <u-form-item label="备注" borderBottom prop="remarks">
  63. <u--textarea placeholder='请填写备注' :maxlength="500" v-model="inputForm.remarks"></u--textarea>
  64. </u-form-item>
  65. <!--<view class="button-container">
  66. <u-button
  67. text="提交"
  68. size="large"
  69. type="primary"
  70. @click="saveForm"
  71. ></u-button>
  72. </view>-->
  73. </u--form>
  74. </view>
  75. <WorkOverChoose ref="workOverChoose" @input="selectProjectChange" title="报告项目选择"/>
  76. </view>
  77. </template>
  78. <script>
  79. import disposeRubbishService from '@/api/garbageClearance/disposeRubbishService'
  80. import overService from '@/api/garbageClearance/overService'
  81. import WorkOverChoose from './WorkOverChoose'
  82. import {mapState, mapMutations, mapActions} from 'vuex'
  83. import * as $auth from "../../common/auth";
  84. export default {
  85. components: {
  86. WorkOverChoose,
  87. },
  88. computed: mapState({
  89. userInfo: (state) => state.user.userInfo,
  90. avatar: (state) => state.user.avatar
  91. }),
  92. data () {
  93. return {
  94. disFlag: true, // 启用动态获取处理单位则设置为false
  95. processingUnits: [],
  96. fileList1: [],
  97. nodeFlag: false,
  98. inputForm: {
  99. no: '',
  100. processingUnit: '',
  101. processingUnitName: '',
  102. clearUserId: '',
  103. clearUserName: '',
  104. clearUserMobile: '',
  105. remarks: '',
  106. workOverNoList: [],
  107. disposeType: '',
  108. rubbishStation: '',
  109. },
  110. rules: {
  111. 'processingUnit': [
  112. {
  113. required: true,
  114. message: '处理单位不能为空',
  115. trigger: ['blur', 'change']
  116. }
  117. ],
  118. }
  119. }
  120. },
  121. // 页面加载时执行
  122. async created() {
  123. let data = await disposeRubbishService.getMaxNo();
  124. if (data) {
  125. let newNo = parseInt(data, 10) + 1;
  126. this.inputForm.no = 'XJ-J' + newNo;
  127. } else {
  128. // 获取当前年份
  129. let nowY = new Date().getFullYear();
  130. this.inputForm.no = 'XJ-J' + nowY + '0001';
  131. }
  132. // 如果要使用动态获取处理单位则设置为true
  133. if (false) {
  134. let units = await overService.getProcessingUnit();
  135. let childs = units[0].children;
  136. if (childs) {
  137. this.processingUnits = []; // 初始化数组
  138. for (let i = 0; i < childs.length; i++) {
  139. this.processingUnits.push({
  140. label: childs[i].name,
  141. value: childs[i].id
  142. });
  143. }
  144. }
  145. }
  146. this.inputForm.processingUnit = this.userInfo.officeDTO.id
  147. this.inputForm.processingUnitName = this.userInfo.officeDTO.name
  148. // 不动态获取 根据当前登录人去查
  149. await overService.getUserInfoByOffId(this.userInfo.officeDTO.id)
  150. .then(data => {
  151. this.inputForm.clearUserId = data.id
  152. this.inputForm.clearUserName = data.name
  153. this.inputForm.clearUserMobile = data.mobile
  154. })
  155. .catch(e => {
  156. throw e;
  157. });
  158. },
  159. props: {
  160. status: {
  161. type: String,
  162. default: ''
  163. }
  164. },
  165. watch: {
  166. },
  167. methods: {
  168. init (id) {
  169. this.nodeFlag = true
  170. this.inputForm.id = id
  171. /*if (id) {
  172. financeInvoiceService.queryById(id).then((data) => {
  173. if (this.status === 'testSee') {
  174. this.nodeFlag = true
  175. this.testFlag = true
  176. } else {
  177. this.commonApi.getTaskNameByProcInsId(data.procInsId).then((data) => {
  178. if (this.isNotEmpty(data)) {
  179. if (data === '发起人重新申请' || this.isEmpty(data)) {
  180. this.nodeFlag = false
  181. } else if (data === '发票管理员审核'){
  182. this.nodeFlag = true
  183. this.addFlag = true
  184. }
  185. }else {
  186. this.testFlag = true
  187. this.addFlag = true
  188. console.log('没有')
  189. }
  190. })
  191. }
  192. this.inputForm = this.recover(this.inputForm, data)
  193. if (this.inputForm.workAttachmentDtoList) {
  194. this.inputForm.workAttachmentDtoList.forEach( (item,index) => {
  195. this.$set(this.showFileList, index, true);
  196. })
  197. }
  198. let i = this.inputForm.financeInvoiceBaseDTOList.length
  199. let sun = 0
  200. for (let j = 0; j < i; j++) {
  201. sun = (100*sun + 100* this.inputForm.financeInvoiceBaseDTOList[j].account)/100
  202. }
  203. this.inputForm.accountTotal = sun
  204. this.inputForm.billingDate = this.formatDate(new Date())
  205. if ( !this.nodeFlag && this.status !== 'testSee') {
  206. this.inputForm.financeInvoiceDetailDTOList.push({
  207. code: '',
  208. number: '',
  209. account: sun,
  210. rate: '',
  211. amount: '',
  212. tax: '',
  213. allAmount: ''
  214. })
  215. }
  216. if (!this.isEmpty(this.inputForm.billingWorkplaceRealId)) {
  217. this.bankList = []
  218. workClientService.queryById(this.inputForm.billingWorkplaceRealId).then((data) => {
  219. if (this.isNotEmpty(data.cwWorkClientBillingDTOList)) {
  220. data.cwWorkClientBillingDTOList.forEach(i => {
  221. i.ourBank = i.accountHolder
  222. let test = {label: i.ourBank, value: i.id, account: i.account}
  223. this.bankList.push(test)
  224. this.$set(this.inputForm, 'openBank', i.id);
  225. })
  226. } else {
  227. this.bankList = []
  228. }
  229. })
  230. }
  231. })
  232. }*/
  233. },
  234. addRow() {
  235. this.inputForm.workOverNoList.push({ recipientAgent: this.userInfo.name,
  236. recipientAgentId: this.userInfo.id, recipientOffice: this.userInfo.officeDTO.name });
  237. },
  238. // 显示 项目选择器
  239. showWorkOver(index) {
  240. this.$refs.workOverChoose.init(index);
  241. },
  242. removeRow(type,index) {
  243. // 点击删除按钮时,从表格中移除指定行
  244. this.inputForm.workOverNoList.splice(index, 1);
  245. },
  246. formatDate(date) {
  247. const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
  248. const year = dateNew.getFullYear();
  249. const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
  250. const day = dateNew.getDate().toString().padStart(2, '0');
  251. return `${year}-${month}-${day}`;
  252. },
  253. isEmpty(value) {
  254. let result = false;
  255. if (value == null || value == undefined) {
  256. result = true;
  257. }
  258. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  259. result = true;
  260. }
  261. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  262. result = true;
  263. }
  264. return result;
  265. },
  266. isNotEmpty (value) {
  267. return !this.isEmpty(value)
  268. },
  269. /**
  270. * 判断是否为空
  271. */
  272. isNull(val) {
  273. if (val instanceof Array) {
  274. if (val.length === 0) return true;
  275. } else if (val instanceof Object) {
  276. if (JSON.stringify(val) === "{}") return true;
  277. } else {
  278. if (
  279. val === "null" ||
  280. val == null ||
  281. val === "undefined" ||
  282. val === undefined ||
  283. val === ""
  284. )
  285. return true;
  286. return false;
  287. }
  288. return false;
  289. },
  290. formatDateNew(date) {
  291. const year = date.getFullYear();
  292. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  293. const day = date.getDate().toString().padStart(2, '0');
  294. const hours = date.getHours().toString().padStart(2, '0');
  295. const minutes = date.getMinutes().toString().padStart(2, '0');
  296. const seconds = date.getSeconds().toString().padStart(2, '0');
  297. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  298. },
  299. saveForm(callback) {
  300. return new Promise((resolve, reject) => {
  301. // 表单规则验证
  302. // ...
  303. let errors = [];
  304. if (this.fileList1 && this.fileList1.length > 0) {
  305. // 将 fileList1 中的每个文件对象的属性名调整为新的属性名
  306. this.inputForm.fileList1 = this.fileList1.map(file => {
  307. return {
  308. attachmentName: file.name,
  309. fileSize: file.size,
  310. url: file.url,
  311. type: file.type, // 如果不需要,可以不写
  312. };
  313. });
  314. }
  315. if (errors.length > 0) {
  316. // 存在错误,显示提示信息
  317. errors.forEach(error => {
  318. uni.showToast({
  319. title: error,
  320. icon: 'none',
  321. duration: 2000
  322. });
  323. });
  324. reject('Form validation failed');
  325. } else {
  326. // 所有验证通过,执行保存操作
  327. this.$refs.inputForm.validate().then(() => {
  328. uni.showLoading();
  329. overService.save(this.inputForm).then(data => {
  330. uni.showToast({title:"提交成功", icon:"success"});
  331. // 返回上一页
  332. uni.navigateBack({
  333. delta: 1
  334. });
  335. resolve('Form saved successfully');
  336. }).catch(error => {
  337. reject('Save operation failed');
  338. });
  339. }).catch(() => {
  340. reject('Form validation failed');
  341. });
  342. }
  343. });
  344. },
  345. // 删除图片
  346. deletePic(event) {
  347. this[`fileList${event.name}`].splice(event.index, 1)
  348. },
  349. // 新增图片
  350. async afterRead(event) {
  351. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  352. let lists = [].concat(event.file)
  353. let fileListLen = this[`fileList${event.name}`].length
  354. lists.map((item) => {
  355. this[`fileList${event.name}`].push({
  356. ...item,
  357. status: 'uploading',
  358. message: '上传中'
  359. })
  360. })
  361. for (let i = 0; i < lists.length; i++) {
  362. const result = await this.uploadFilePromise(lists[i].url, fileListLen)
  363. let item = this[`fileList${event.name}`][fileListLen]
  364. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  365. status: 'success',
  366. message: '',
  367. url: result
  368. }))
  369. fileListLen++
  370. }
  371. },
  372. uploadFilePromise(url, index) {
  373. console.log($auth.getUserToken())
  374. return new Promise((resolve, reject) => {
  375. let a = uni.uploadFile({
  376. url: 'http://localhost:8000/app/file/webUpload/fileUpload', // 仅为示例,非真实的接口地址
  377. filePath: url,
  378. name: 'file',
  379. formData: {
  380. user: this.$store.state.user.userInfo
  381. },
  382. header: {
  383. 'token': $auth.getUserToken(),
  384. },
  385. success: (res) => {
  386. // this.fileList1[index].url = url
  387. setTimeout(() => {
  388. const dataObj = JSON.parse(res.data);
  389. const url = dataObj.url;
  390. resolve(url);
  391. }, 1000);
  392. },
  393. fail: (err) => {
  394. console.error('Upload failed:', err);
  395. }
  396. });
  397. })
  398. },
  399. getUserInfoByOffId(){
  400. // 根据组织ID 获取 该村的 村支书
  401. overService.getUserInfoByOffId(this.inputForm.processingUnit)
  402. .then(data => {
  403. this.inputForm.clearUserId = data.id
  404. this.inputForm.clearUserName = data.name
  405. this.inputForm.clearUserMobile = data.mobile
  406. })
  407. .catch(e => {
  408. throw e;
  409. });
  410. }
  411. }
  412. }
  413. </script>
  414. <style>
  415. .form-section {
  416. padding: 10px 15px;
  417. margin-bottom: 10px;
  418. background-color: #ffffff;
  419. border-radius: 5px;
  420. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  421. }
  422. .u-page__upload-item {
  423. margin-top: 10px;
  424. }
  425. .button-container {
  426. margin-top: 20px;
  427. text-align: center;
  428. }
  429. .cu-form-group .title {
  430. min-width: 100px;
  431. }
  432. </style>