PatrolWorkOrderForm.vue 17 KB

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