PatrolWorkOrderAuditForm.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410
  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">
  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. </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. :disabled="true"
  32. :fileList="fileList1"
  33. name="1"
  34. multiple
  35. :maxCount="10"
  36. ></u-upload>
  37. </view>
  38. </view>
  39. <!-- Third Section: 备注 -->
  40. <view class="form-section">
  41. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm">
  42. <u-form-item label="备注" borderBottom prop="remarks">
  43. <u--textarea placeholder='请填写备注' :maxlength="500" :disabled="true" v-model="inputForm.remarks"></u--textarea>
  44. </u-form-item>
  45. </u--form>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import overService from '@/api/garbageClearance/overService'
  51. import {mapState, mapMutations, mapActions} from 'vuex'
  52. import * as $auth from "../../common/auth";
  53. import { EventBus } from '@/store/eventBus.js';
  54. import taskService from "@/api/flowable/taskService"
  55. export default {
  56. components: {
  57. },
  58. computed: mapState({
  59. userInfo: (state) => state.user.userInfo,
  60. avatar: (state) => state.user.avatar
  61. }),
  62. data () {
  63. return {
  64. disFlag: true, // 启用动态获取处理单位则设置为false
  65. isProcessing: false, // 遮罩层
  66. processingUnits: [],
  67. fileList1: [],
  68. fileList2: [],
  69. fileList3: [],
  70. nodeFlag: false,
  71. inputForm: {
  72. id: '',
  73. no: '',
  74. processingUnit: '',
  75. processingUnitName: '',
  76. clearUserId: '',
  77. clearUserName: '',
  78. clearUserMobile: '',
  79. remarks: '',
  80. },
  81. rules: {
  82. 'processingUnit': [
  83. {
  84. required: true,
  85. message: '处理单位不能为空',
  86. trigger: ['blur', 'change']
  87. }
  88. ],
  89. }
  90. }
  91. },
  92. // 页面加载时执行
  93. async created() {
  94. if('乡镇巡查员' === this.userInfo.roleNames){
  95. this.disFlag = false
  96. // 不动态获取 根据当前登录人去查
  97. await overService.getOfficeOnHamlet()
  98. .then(data => {
  99. this.processingUnits = []
  100. for (const value of data) {
  101. this.processingUnits.push({
  102. label: value.officeName,
  103. value: value.officeId
  104. });
  105. }
  106. })
  107. .catch(e => {
  108. throw e;
  109. });
  110. }
  111. if(!this.nodeFlag){
  112. let data = await overService.getMaxNo();
  113. this.inputForm.no = data;
  114. /*if (data) {
  115. let newNo = parseInt(data, 10) + 1;
  116. this.inputForm.no = 'XS-J' + newNo;
  117. } else {
  118. // 获取当前年份
  119. let nowY = new Date().getFullYear();
  120. this.inputForm.no = 'XS-J' + nowY + '0001';
  121. }*/
  122. // 如果要使用动态获取处理单位则设置为true
  123. if (false) {
  124. let units = await overService.getProcessingUnit();
  125. let childs = units[0].children;
  126. if (childs) {
  127. this.processingUnits = []; // 初始化数组
  128. for (let i = 0; i < childs.length; i++) {
  129. this.processingUnits.push({
  130. label: childs[i].name,
  131. value: childs[i].id
  132. });
  133. }
  134. }
  135. }
  136. this.inputForm.processingUnit = this.userInfo.officeDTO.id
  137. this.inputForm.processingUnitName = this.userInfo.officeDTO.name
  138. // 不动态获取 根据当前登录人去查
  139. await overService.getUserInfoByOffId(this.userInfo.officeDTO.id)
  140. .then(data => {
  141. this.inputForm.clearUserId = data.id
  142. this.inputForm.clearUserName = data.name
  143. this.inputForm.clearUserMobile = data.mobile
  144. })
  145. .catch(e => {
  146. throw e;
  147. });
  148. }
  149. },
  150. props: {
  151. businessId: {
  152. type: String,
  153. default: ''
  154. },
  155. formReadOnly: {
  156. type: Boolean,
  157. default: false
  158. },
  159. status: {
  160. type: String,
  161. default: ''
  162. }
  163. },
  164. watch: {
  165. 'businessId': {
  166. handler (newVal) {
  167. if (this.businessId) {
  168. this.init(this.businessId)
  169. } else {
  170. this.$nextTick(() => {
  171. // this.$refs.inputForm.reset()
  172. })
  173. }
  174. },
  175. immediate: true,
  176. deep: false
  177. },
  178. },
  179. onLoad(options) {
  180. // 从 options 中获取 id 参数
  181. this.id = options.id;
  182. // 这里可以调用初始化方法
  183. this.init(this.id);
  184. },
  185. methods: {
  186. async init (id) {
  187. if(id){
  188. this.nodeFlag = true
  189. this.inputForm.id = id
  190. if (id) {
  191. const data = await overService.queryById(id);
  192. console.log(data)
  193. this.inputForm = this.recover(this.inputForm, data)
  194. // 处理文件列表
  195. if (data.beforeFileList) {
  196. this.fileList1 = data.beforeFileList.map(item => ({
  197. attachmentName: item.name,
  198. fileSize: item.size,
  199. url: item.temporaryUrl,
  200. type: item.type // 如果不需要,可以不写
  201. }));
  202. }
  203. if (data.betweenFileList) {
  204. this.fileList2 = data.betweenFileList.map(item => ({
  205. attachmentName: item.name,
  206. fileSize: item.size,
  207. url: item.temporaryUrl,
  208. type: item.type // 如果不需要,可以不写
  209. }));
  210. }
  211. if (data.afterFileList) {
  212. this.fileList3 = data.afterFileList.map(item => ({
  213. attachmentName: item.name,
  214. fileSize: item.size,
  215. url: item.temporaryUrl,
  216. type: item.type // 如果不需要,可以不写
  217. }));
  218. }
  219. }
  220. }
  221. },
  222. formatDate(date) {
  223. const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
  224. const year = dateNew.getFullYear();
  225. const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
  226. const day = dateNew.getDate().toString().padStart(2, '0');
  227. return `${year}-${month}-${day}`;
  228. },
  229. isEmpty(value) {
  230. let result = false;
  231. if (value == null || value == undefined) {
  232. result = true;
  233. }
  234. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  235. result = true;
  236. }
  237. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  238. result = true;
  239. }
  240. return result;
  241. },
  242. isNotEmpty (value) {
  243. return !this.isEmpty(value)
  244. },
  245. /**
  246. * 判断是否为空
  247. */
  248. isNull(val) {
  249. if (val instanceof Array) {
  250. if (val.length === 0) return true;
  251. } else if (val instanceof Object) {
  252. if (JSON.stringify(val) === "{}") return true;
  253. } else {
  254. if (
  255. val === "null" ||
  256. val == null ||
  257. val === "undefined" ||
  258. val === undefined ||
  259. val === ""
  260. )
  261. return true;
  262. return false;
  263. }
  264. return false;
  265. },
  266. formatDateNew(date) {
  267. const year = date.getFullYear();
  268. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  269. const day = date.getDate().toString().padStart(2, '0');
  270. const hours = date.getHours().toString().padStart(2, '0');
  271. const minutes = date.getMinutes().toString().padStart(2, '0');
  272. const seconds = date.getSeconds().toString().padStart(2, '0');
  273. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  274. },
  275. saveForm(callback) {
  276. this.isProcessing = true; // 显示遮罩层
  277. return new Promise((resolve, reject) => {
  278. // 表单规则验证
  279. // ...
  280. let errors = [];
  281. if (this.fileList1 && this.fileList1.length > 0) {
  282. // 将 fileList1 中的每个文件对象的属性名调整为新的属性名
  283. this.inputForm.fileList1 = this.fileList1.map(file => {
  284. return {
  285. attachmentName: file.name,
  286. fileSize: file.size,
  287. url: file.url,
  288. type: file.type, // 如果不需要,可以不写
  289. attachmentFlag: 'before', // 如果不需要,可以不写
  290. };
  291. });
  292. }
  293. if (errors.length > 0) {
  294. // 存在错误,显示提示信息
  295. errors.forEach(error => {
  296. uni.showToast({
  297. title: error,
  298. icon: 'none',
  299. duration: 2000
  300. });
  301. });
  302. this.isProcessing = false;
  303. reject('Form validation failed');
  304. } else {
  305. // 所有验证通过,执行保存操作
  306. this.$refs.inputForm.validate().then(() => {
  307. uni.showLoading();
  308. this.inputForm.status = '5'
  309. overService.save(this.inputForm).then(data => {
  310. uni.showToast({
  311. title: "提交成功",
  312. icon: "success",
  313. duration: 1000 // 提示持续时间为1秒(1000毫秒)
  314. });
  315. // 延迟1秒后再跳转到上一页
  316. setTimeout(() => {
  317. this.isProcessing = false; // 显示遮罩层
  318. callback(data.businessTable, data.businessId);
  319. resolve('Form saved successfully');
  320. uni.navigateBack({
  321. delta: 1
  322. });
  323. }, 1000);
  324. }).catch(error => {
  325. reject('Save operation failed');
  326. });
  327. }).catch(() => {
  328. reject('Form validation failed');
  329. });
  330. }
  331. });
  332. },
  333. getOfficeOnHamlet(value){
  334. // 根据组织ID 获取 该村的 村支书
  335. overService.getUserInfoByOffId(value)
  336. .then(data => {
  337. this.inputForm.clearUserId = data.id
  338. this.inputForm.clearUserName = data.name
  339. this.inputForm.clearUserMobile = data.mobile
  340. })
  341. .catch(e => {
  342. throw e;
  343. });
  344. }
  345. }
  346. }
  347. </script>
  348. <style>
  349. .form-section {
  350. padding: 10px 15px;
  351. margin-bottom: 10px;
  352. background-color: #ffffff;
  353. border-radius: 5px;
  354. box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  355. }
  356. .u-page__upload-item {
  357. margin-top: 10px;
  358. }
  359. .button-container {
  360. margin-top: 20px;
  361. text-align: center;
  362. }
  363. .cu-form-group .title {
  364. min-width: 100px;
  365. }
  366. /* 遮罩层样式 */
  367. .mask {
  368. position: fixed;
  369. top: 0;
  370. left: 0;
  371. width: 100%;
  372. height: 100%;
  373. background-color: rgba(0, 0, 0, 0.05); /* 半透明遮罩 */
  374. z-index: 9999; /* 确保遮罩层在最顶层 */
  375. }
  376. </style>