PatrolWorkOrderDisposeForm.vue 17 KB

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