CollectForm.vue 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <template>
  2. <view>
  3. <cu-custom :backUrl="'/pages/index/index'" :isBack="true" bgColor="bg-gradual-blue" >
  4. <block slot="content">领用申请</block>
  5. </cu-custom>
  6. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-if="!nodeFlag">
  7. <u-form-item label="领用编号" borderBottom prop="collectNo">
  8. <u--input placeholder='自动生成' v-model="inputForm.collectNo" disabled></u--input>
  9. </u-form-item>
  10. <u-form-item label="经办人" borderBottom prop="handledBy">
  11. <u--input placeholder='' v-model="inputForm.handledBy" disabled></u--input>
  12. </u-form-item>
  13. <u-form-item label="经办人部门" borderBottom prop="handledByOfficeName">
  14. <u--input placeholder='' v-model="inputForm.handledByOfficeName" disabled></u--input>
  15. </u-form-item>
  16. <u-form-item label="领用时间" borderBottom prop="collectDate" :required="true">
  17. <el-date-picker
  18. v-model="inputForm.collectDate"
  19. type="date"
  20. placeholder="请选择领用时间"
  21. style="width:100%"
  22. size="default"
  23. placement="bottom-start"
  24. clearable>
  25. </el-date-picker>
  26. </u-form-item>
  27. <u-form-item label="备注" borderBottom prop="remarks">
  28. <u--textarea placeholder='请填写备注信息' :rows="5" :maxlength="500" v-model="inputForm.remarks" ></u--textarea>
  29. </u-form-item>
  30. <el-row :gutter="15" :key="index_experience" v-for="(item,index_experience) in this.inputForm.detailInfos">
  31. <el-col :span="24">
  32. <el-form-item label="" >
  33. <el-divider content-position="left"> 领用详情 {{index_experience + 1}}</el-divider>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :span="24">
  37. <u-form-item label="领用人" :prop="'detailInfos[' + index_experience + '].recipientAgent'" :required="true"
  38. :rules="[
  39. ]">
  40. <el-input v-model="inputForm.detailInfos[index_experience].recipientAgent" placeholder="请选择领用人" @focus="openUserPullForm(index_experience)" clearable></el-input>
  41. </u-form-item>
  42. <u-form-item label="领用人部门" :prop="'detailInfos[' + index_experience + '].recipientOffice'"
  43. :rules="[
  44. ]">
  45. <el-input v-model="inputForm.detailInfos[index_experience].recipientOffice" placeholder="" clearable></el-input>
  46. </u-form-item>
  47. <u-form-item label="领用类型" :prop="'detailInfos[' + index_experience + '].collectType'" :required="true"
  48. :rules="[
  49. ]">
  50. <el-input v-model="inputForm.detailInfos[index_experience].collectType" placeholder="请选择领用类型" @focus="showPicker(index_experience)" clearable></el-input>
  51. </u-form-item>
  52. <u-form-item label="物品名称" :prop="'detailInfos[' + index_experience + '].goodsName'" :required="true"
  53. :rules="[
  54. ]">
  55. <el-input v-model="inputForm.detailInfos[index_experience].goodsName" placeholder="请选择物品名称" @focus="showGoods(index_experience)" clearable></el-input>
  56. </u-form-item>
  57. <u-form-item label="领用数量" :prop="'detailInfos[' + index_experience + '].collectNumber'" :required="true"
  58. :rules="[
  59. ]">
  60. <el-input v-model="inputForm.detailInfos[index_experience].collectNumber" placeholder="请选择领用数量" clearable></el-input>
  61. </u-form-item>
  62. <u-form-item label="库存数量" :prop="'detailInfos[' + index_experience + '].surplusNumber'"
  63. :rules="[
  64. ]">
  65. <el-input v-model="inputForm.detailInfos[index_experience].surplusNumber" :disabled="true" clearable></el-input>
  66. </u-form-item>
  67. <u-form-item label="单位" :prop="'detailInfos[' + index_experience + '].company'"
  68. :rules="[
  69. ]">
  70. <el-input v-model="inputForm.detailInfos[index_experience].company" placeholder="请输入单位" clearable></el-input>
  71. </u-form-item>
  72. <u-form-item label="备注" :prop="'detailInfos[' + index_experience + '].remarks'"
  73. :rules="[
  74. ]">
  75. <el-input v-model="inputForm.detailInfos[index_experience].remarks" placeholder="请输入备注" clearable></el-input>
  76. </u-form-item>
  77. <u-form-item label="文件上传">
  78. <el-upload
  79. class="upload-demo"
  80. :action="`http://localhost:2800/api/public-modules-server/oss/file/webUpload/upload`"
  81. :on-remove="(file, fileList) => handleRemove(file, fileList, index_experience,'detail')"
  82. :file-list="fileList3[index_experience]"
  83. :on-success="(response, file, fileList) => handleUploadSuccess(response, file, fileList,index_experience,'detail')"
  84. :limit="3">
  85. <el-button size="small" type="primary">点击上传</el-button>
  86. <div slot="tip" class="el-upload__tip">只能上传不超过 3 个文件</div>
  87. </el-upload>
  88. </u-form-item>
  89. </el-col>
  90. <el-col :span="24" style="text-align: center">
  91. <u-form-item label="" >
  92. <el-button style="width: 100%" type="danger" @click="removeRow(index_experience)" plain>删除领用详情 {{index_experience + 1}}</el-button>
  93. </u-form-item>
  94. </el-col>
  95. </el-row>
  96. <u-form-item label="" >
  97. <el-button style="width: 100%" type="primary" @click="addRow()" plain>新增领用详情</el-button>
  98. </u-form-item>
  99. <u-form-item label="附件">
  100. <el-upload
  101. class="upload-demo"
  102. :action="`http://localhost:2800/api/public-modules-server/oss/file/webUpload/upload`"
  103. :on-remove="(file, fileList) => handleRemove(file, fileList, '','')"
  104. :file-list="inputForm.files"
  105. :on-success="(response, file, fileList) => handleUploadSuccess(response, file, fileList,'','')"
  106. :limit="3">
  107. <el-button size="small" type="primary">点击上传</el-button>
  108. <div slot="tip" class="el-upload__tip">只能上传不超过 3 个文件</div>
  109. </el-upload>
  110. </u-form-item>
  111. </u--form>
  112. <u--form :model="inputForm" labelWidth="100px" class="u-form" labelPosition="left" :rules="rules" ref="inputForm" v-else-if="nodeFlag">
  113. <u-form-item label="领用编号" borderBottom prop="collectNo">
  114. <u--input placeholder='自动生成' v-model="inputForm.collectNo" :disabled="true"></u--input>
  115. </u-form-item>
  116. <u-form-item label="经办人" borderBottom prop="handledBy">
  117. <u--input placeholder='' v-model="inputForm.handledBy" :disabled="true"></u--input>
  118. </u-form-item>
  119. <u-form-item label="经办人部门" borderBottom prop="handledByOfficeName">
  120. <u--input placeholder='' v-model="inputForm.handledByOfficeName" :disabled="true"></u--input>
  121. </u-form-item>
  122. <u-form-item label="领用时间" borderBottom prop="collectDate" :required="true">
  123. <el-date-picker
  124. :disabled="true"
  125. v-model="inputForm.collectDate"
  126. type="date"
  127. placeholder="请选择领用时间"
  128. style="width:100%"
  129. size="default"
  130. placement="bottom-start"
  131. clearable>
  132. </el-date-picker>
  133. </u-form-item>
  134. <u-form-item label="备注" borderBottom prop="remarks">
  135. <u--textarea placeholder='请填写备注信息' :rows="5" :maxlength="500" v-model="inputForm.remarks" :disabled="true"></u--textarea>
  136. </u-form-item>
  137. <el-row :gutter="15" :key="index_experience" v-for="(item,index_experience) in this.inputForm.detailInfos" >
  138. <el-col :span="24">
  139. <el-form-item label="" >
  140. <el-divider content-position="left"> 领用详情 {{index_experience + 1}}</el-divider>
  141. </el-form-item>
  142. </el-col>
  143. <el-col :span="24">
  144. <u-form-item label="领用人" :prop="'detailInfos[' + index_experience + '].recipientAgent'" :required="true"
  145. :rules="[
  146. ]">
  147. <el-input v-model="inputForm.detailInfos[index_experience].recipientAgent" :disabled="true" placeholder="请选择领用人" @focus="openUserPullForm(index_experience)" clearable></el-input>
  148. </u-form-item>
  149. <u-form-item label="领用人部门" :prop="'detailInfos[' + index_experience + '].recipientOffice'"
  150. :rules="[
  151. ]">
  152. <el-input v-model="inputForm.detailInfos[index_experience].recipientOffice" :disabled="true" placeholder="" clearable></el-input>
  153. </u-form-item>
  154. <u-form-item label="领用类型" :prop="'detailInfos[' + index_experience + '].collectType'" :required="true"
  155. :rules="[
  156. ]">
  157. <el-input v-model="inputForm.detailInfos[index_experience].collectType" :disabled="true" placeholder="请选择领用类型" @focus="showPicker(index_experience)" clearable></el-input>
  158. </u-form-item>
  159. <u-form-item label="物品名称" :prop="'detailInfos[' + index_experience + '].goodsName'" :required="true"
  160. :rules="[
  161. ]">
  162. <el-input v-model="inputForm.detailInfos[index_experience].goodsName" :disabled="true" placeholder="请选择物品名称" @focus="showGoods(index_experience)" clearable></el-input>
  163. </u-form-item>
  164. <u-form-item label="领用数量" :prop="'detailInfos[' + index_experience + '].collectNumber'" :required="true"
  165. :rules="[
  166. ]">
  167. <el-input v-model="inputForm.detailInfos[index_experience].collectNumber" :disabled="true" placeholder="请选择领用数量" clearable></el-input>
  168. </u-form-item>
  169. <u-form-item label="库存数量" :prop="'detailInfos[' + index_experience + '].surplusNumber'"
  170. :rules="[
  171. ]">
  172. <el-input v-model="inputForm.detailInfos[index_experience].surplusNumber" :disabled="true" clearable></el-input>
  173. </u-form-item>
  174. <u-form-item label="单位" :prop="'detailInfos[' + index_experience + '].company'"
  175. :rules="[
  176. ]">
  177. <el-input v-model="inputForm.detailInfos[index_experience].company" :disabled="true" placeholder="请输入单位" clearable></el-input>
  178. </u-form-item>
  179. <u-form-item label="备注" :prop="'detailInfos[' + index_experience + '].remarks'"
  180. :rules="[
  181. ]">
  182. <el-input v-model="inputForm.detailInfos[index_experience].remarks" :disabled="true" placeholder="请输入备注" clearable></el-input>
  183. </u-form-item>
  184. <u-form-item label="文件上传">
  185. <el-upload
  186. class="upload-demo"
  187. :action="`http://localhost:2800/api/public-modules-server/oss/file/webUpload/upload`"
  188. :on-remove="(file, fileList) => handleRemove(file, fileList, index_experience,'detail')"
  189. :file-list="fileList3[index_experience]"
  190. :on-success="(response, file, fileList) => handleUploadSuccess(response, file, fileList,index_experience,'detail')"
  191. :limit="3">
  192. <el-button size="small" :disabled="true" type="primary">点击上传</el-button>
  193. <div slot="tip" class="el-upload__tip">只能上传不超过 3 个文件</div>
  194. </el-upload>
  195. </u-form-item>
  196. </el-col>
  197. <el-col :span="24" style="text-align: center">
  198. <u-form-item label="" >
  199. <el-button style="width: 100%" type="danger" @click="removeRow(index_experience)" disabled plain>删除领用详情 {{index_experience + 1}}</el-button>
  200. </u-form-item>
  201. </el-col>
  202. </el-row>
  203. <u-form-item label="" >
  204. <el-button style="width: 100%" type="primary" @click="addRow()" disabled plain>新增领用详情</el-button>
  205. </u-form-item>
  206. <u-form-item label="附件">
  207. <el-upload
  208. :disabled="true"
  209. class="upload-demo"
  210. :action="`http://localhost:2800/api/public-modules-server/oss/file/webUpload/upload`"
  211. :on-remove="(file, fileList) => handleRemove(file, fileList, '','')"
  212. :file-list="inputForm.files"
  213. :on-success="(response, file, fileList) => handleUploadSuccess(response, file, fileList,'','')"
  214. :limit="3">
  215. <el-button size="small" :disabled="true" type="primary">点击上传</el-button>
  216. <div slot="tip" class="el-upload__tip">只能上传不超过 3 个文件</div>
  217. </el-upload>
  218. </u-form-item>
  219. </u--form>
  220. <ba-tree-picker ref="treePicker" :multiple='false' @select-change="selectChange" title="类型选择"
  221. :localdata="listData" valueKey="value" textKey="label" childrenKey="children" />
  222. <goods-info-picker ref="goodsPicker" :multiple='false' @select-goods-change="selectGoodsChange" title="物品名称"
  223. :localdata="goodsListData" valueKey="value" textKey="label" childrenKey="children" />
  224. </view>
  225. </template>
  226. <script>
  227. import goodsInfoPicker from './GoodsInfoPicker'
  228. import MaterialTypeService from '@/api/materialManagement/MaterialTypeService'
  229. import WareHouseService from '@/api/materialManagement/WareHouseService'
  230. import collectService from '@/api/materialManagement/CollectService'
  231. import CommonApi from '@/api/common/CommonApi'
  232. import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue"
  233. import {mapState, mapMutations, mapActions} from 'vuex'
  234. export default {
  235. components: {
  236. baTreePicker,
  237. goodsInfoPicker
  238. },
  239. computed: mapState({
  240. userInfo: (state) => state.user.userInfo,
  241. avatar: (state) => state.user.avatar
  242. }),
  243. data () {
  244. return {
  245. nodeFlag: false,
  246. loading: false,
  247. listData: [],
  248. fileList3: [],
  249. goodsListData: [],
  250. materialList: [],
  251. searchForm: {
  252. wareHouseType: '',
  253. },
  254. inputForm: {
  255. collectNo: '',
  256. handledBy: '',
  257. handledById: '',
  258. handledByOffice: '',
  259. handledByOfficeName: '',
  260. remarks: '',
  261. detailInfos: [],
  262. files: [], // 附件信息
  263. procInsId: ''
  264. },
  265. rules: {
  266. 'collectDate': [
  267. {
  268. required: true,
  269. message: '领用时间不能为空',
  270. trigger: ['blur', 'change']
  271. }
  272. ],
  273. }
  274. }
  275. },
  276. materialTypeService: null,
  277. wareHouseService: null,
  278. commonApi: null,
  279. // 页面加载时执行
  280. created() {
  281. this.commonApi = new CommonApi()
  282. this.materialTypeService = new MaterialTypeService()
  283. this.wareHouseService = new WareHouseService()
  284. this.materialTypeService.cgList().then((data)=>{
  285. this.materialList = data
  286. }).catch((e)=>{
  287. throw e
  288. })
  289. this.inputForm.handledBy = this.userInfo.name
  290. this.inputForm.handledById = this.userInfo.id
  291. this.inputForm.handledByOffice = this.userInfo.officeDTO.id
  292. this.inputForm.handledByOfficeName = this.userInfo.officeDTO.name
  293. // 监听事件
  294. uni.$on('eventName', (data) => {
  295. // 在这里处理传递过来的数据
  296. //循环遍历领用详情,估计index将用户id与用户名称放入到领用人里面
  297. this.inputForm.detailInfos.forEach((detail,index) => {
  298. if (index === parseInt(data.index)) {
  299. detail.recipientAgent = data.name
  300. detail.recipientAgentId = data.id
  301. detail.recipientOffice = data.officeDTO.name
  302. }
  303. })
  304. });
  305. },
  306. props: {
  307. businessId: {
  308. type: String,
  309. default: ''
  310. },
  311. formReadOnly: {
  312. type: Boolean,
  313. default: false
  314. }
  315. },
  316. watch: {
  317. 'businessId': {
  318. handler (newVal) {
  319. if (this.businessId) {
  320. this.init(this.businessId)
  321. } else {
  322. this.$nextTick(() => {
  323. // this.$refs.inputForm.reset()
  324. })
  325. }
  326. },
  327. immediate: true,
  328. deep: false
  329. }
  330. },
  331. methods: {
  332. // 显示选择器
  333. showPicker(index) {
  334. this.$refs.treePicker._show(index);
  335. },
  336. showGoods(index) {
  337. this.searchForm.wareHouseType = this.inputForm.detailInfos[index].collectTypeId
  338. this.wareHouseService.wareHouseSummaryList({
  339. 'current': 0,
  340. 'size': -1,
  341. 'orders': [],
  342. ...this.searchForm
  343. }).then((data) => {
  344. this.goodsListData = data.records
  345. })
  346. this.$refs.goodsPicker._show(index);
  347. },
  348. //监听选择
  349. selectChange(ids, names, index) {
  350. // this.inputForm.detailInfos.forEach((detail,inde) => {
  351. // if (inde === parseInt(index)) {
  352. // detail.collectType = names
  353. // detail.collectTypeId = ids[0]
  354. // }
  355. // })
  356. this.$set(this.inputForm.detailInfos, index, {
  357. ...this.inputForm.detailInfos[index],
  358. collectType: names,
  359. collectTypeId: ids[0]
  360. });
  361. },
  362. //监听选择
  363. selectGoodsChange(ids, names, index,tradeNumber) {
  364. // this.inputForm.detailInfos.forEach((detail,inde) => {
  365. // if (inde === parseInt(index)) {
  366. // detail.goodsName = names
  367. // detail.tradeNumber = tradeNumber
  368. // }
  369. // })
  370. this.$set(this.inputForm.detailInfos, index, {
  371. ...this.inputForm.detailInfos[index],
  372. goodsName: names,
  373. surplusNumber: tradeNumber
  374. });
  375. },
  376. init (id) {
  377. this.nodeFlag = true
  378. this.inputForm.id = id
  379. if (id) {
  380. collectService.findById(id).then((data) => {
  381. this.commonApi.getTaskNameByProcInsId(data.procInsId).then((data) => {
  382. if (this.isNotEmpty(data)) {
  383. if (data === '重新发起申请' || this.isEmpty(data)) {
  384. this.nodeFlag = false
  385. } else {
  386. this.nodeFlag = true
  387. }
  388. }
  389. })
  390. this.inputForm = this.recover(this.inputForm, data)
  391. this.inputForm.collectDate = new Date(data.collectDate);
  392. this.inputForm.detailInfos.forEach( (item,index) => {
  393. if (this.isNotEmpty(item.fileInfoLost)) {
  394. this.fileList3[index] = []
  395. item.fileInfoLost.forEach( (item,index2) => {
  396. this.fileList3[index].push(item)
  397. })
  398. }
  399. })
  400. })
  401. }
  402. },
  403. buildTree(nodes, parentId = '0') {
  404. const tree = [];
  405. for (const node of nodes) {
  406. if (node.parentId === parentId) {
  407. const children = this.buildTree(nodes, node.id);
  408. if (children.length) {
  409. node.children = children;
  410. }
  411. tree.push(node);
  412. }
  413. }
  414. return tree;
  415. },
  416. formatDate(date) {
  417. const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
  418. const year = dateNew.getFullYear();
  419. const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
  420. const day = dateNew.getDate().toString().padStart(2, '0');
  421. return `${year}-${month}-${day}`;
  422. },
  423. isEmpty(value) {
  424. let result = false;
  425. if (value == null || value == undefined) {
  426. result = true;
  427. }
  428. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  429. result = true;
  430. }
  431. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  432. result = true;
  433. }
  434. return result;
  435. },
  436. isNotEmpty (value) {
  437. return !this.isEmpty(value)
  438. },
  439. /**
  440. * 判断是否为空
  441. */
  442. isNull(val) {
  443. if (val instanceof Array) {
  444. if (val.length === 0) return true;
  445. } else if (val instanceof Object) {
  446. if (JSON.stringify(val) === "{}") return true;
  447. } else {
  448. if (
  449. val === "null" ||
  450. val == null ||
  451. val === "undefined" ||
  452. val === undefined ||
  453. val === ""
  454. )
  455. return true;
  456. return false;
  457. }
  458. return false;
  459. },
  460. addRow() {
  461. // 点击新增按钮时,向表格中添加一行空数据
  462. this.inputForm.detailInfos.push({ recipientAgent: this.userInfo.name,
  463. recipientAgentId: this.userInfo.id, recipientOffice: this.userInfo.officeDTO.name });
  464. let valueData = this.materialList;
  465. // 将扁平数据转换为树形结构
  466. const result = this.buildTree(valueData);
  467. this.listData = result
  468. },
  469. removeRow(index) {
  470. // 点击删除按钮时,从表格中移除指定行
  471. // this.tableData.splice(index, 1);
  472. this.inputForm.detailInfos.splice(index, 1);
  473. },
  474. formatDateNew(date) {
  475. const year = date.getFullYear();
  476. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  477. const day = date.getDate().toString().padStart(2, '0');
  478. const hours = date.getHours().toString().padStart(2, '0');
  479. const minutes = date.getMinutes().toString().padStart(2, '0');
  480. const seconds = date.getSeconds().toString().padStart(2, '0');
  481. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  482. },
  483. // 领用人下拉弹窗
  484. openUserPullForm(index) {
  485. // 点击 "领用人" 输入框时打开userPullForm页面,传入index用于区分不同的行
  486. uni.navigateTo({
  487. url: '/pages/materialManagement/collect/UserPullForm?index=' + index // userPullForm页面的路径
  488. });
  489. },
  490. handleUploadSuccess (res, file, fileList, index, type) {
  491. // 将 fileList 转换为你期望的格式
  492. const formattedFiles = fileList.map(fileItem => {
  493. return {
  494. name: fileItem.name,
  495. size: fileItem.size,
  496. url: '/' + fileItem.response.url,
  497. createBy: this.userInfo,
  498. by: this.userInfo.id,
  499. createTime: this.formatDateNew(new Date())
  500. };
  501. });
  502. if (type === 'detail') {
  503. // 将格式化后的数据设置到 detailInfos 的 fileInfoLost 属性中
  504. this.inputForm.detailInfos[index].fileInfoLost = formattedFiles;
  505. } else {
  506. this.inputForm.files = formattedFiles
  507. }
  508. // 强制更新视图
  509. this.$forceUpdate();
  510. },
  511. handleRemove(file, fileList, index, type) {
  512. // 处理移除文件逻辑
  513. // file 是移除的文件
  514. // fileList 是当前文件列表
  515. const formattedFiles = fileList.map(fileItem => {
  516. return {
  517. name: fileItem.name,
  518. size: fileItem.size,
  519. url: '/' + fileItem.response.url,
  520. createBy: this.userInfo,
  521. by: this.userInfo.id,
  522. createTime: this.formatDateNew(new Date())
  523. };
  524. });
  525. if (type === 'detail') {
  526. this.inputForm.detailInfos[index].fileInfoLost = formattedFiles;
  527. } else {
  528. this.inputForm.files = formattedFiles
  529. }
  530. // 如果你想要更新文件列表,可以在这里更新 inputForm.fileInfoLost
  531. // this.inputForm.fileInfoLost = fileList;
  532. },
  533. saveForm(callback) {
  534. return new Promise((resolve, reject) => {
  535. // 表单规则验证
  536. // ...
  537. let errors = [];
  538. if (this.isNotEmpty(this.inputForm.collectDate)) {
  539. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  540. }
  541. if (this.isEmpty(this.inputForm.detailInfos)) {
  542. errors.push('至少填写一条领用详情信息');
  543. } else {
  544. let i = this.inputForm.detailInfos.length;
  545. for (let j = 0; j < i; j++) {
  546. let k = j + 1;
  547. if (this.isEmpty(this.inputForm.detailInfos[j].recipientAgent)) {
  548. errors.push('领用详情第' + k + '行请选择领用人');
  549. } else if (this.isEmpty(this.inputForm.detailInfos[j].collectType)) {
  550. errors.push('领用详情第' + k + '行请选择领用类型');
  551. } else if (this.isEmpty(this.inputForm.detailInfos[j].goodsName)) {
  552. errors.push('领用详情第' + k + '行请选择物品名称');
  553. } else if (this.isEmpty(this.inputForm.detailInfos[j].collectNumber)) {
  554. errors.push('领用详情第' + k + '行请输入领用数量');
  555. }
  556. }
  557. }
  558. if (errors.length > 0) {
  559. // 存在错误,显示提示信息
  560. errors.forEach(error => {
  561. uni.showToast({
  562. title: error,
  563. icon: 'none',
  564. duration: 2000
  565. });
  566. });
  567. // reject('Form validation failed');
  568. } else {
  569. // 所有验证通过,执行保存操作
  570. this.$refs.inputForm.validate().then(() => {
  571. uni.showLoading();
  572. this.inputForm.status = '2';
  573. collectService.save(this.inputForm).then(data => {
  574. callback(data.businessTable, data.businessId,this.inputForm);
  575. resolve('Form saved successfully');
  576. }).catch(error => {
  577. // reject('Save operation failed');
  578. });
  579. }).catch(() => {
  580. // reject('Form validation failed');
  581. });
  582. }
  583. });
  584. },
  585. // 修改状态
  586. async updateStatusById (type, callback) {
  587. if (type === 'reject' || type === 'reback') {
  588. collectService.findById(this.inputForm.id).then((data) => {
  589. if (data.status !== '2') { // status的值不等于“审核中”,就弹出提示
  590. this.loading = false
  591. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  592. throw new Error()
  593. } else {
  594. if (type === 'reject') {
  595. // 驳回
  596. this.inputForm.status = '4'
  597. }
  598. if (type === 'reback') {
  599. // 撤回
  600. this.inputForm.status = '3'
  601. }
  602. if (type === 'reject' || type === 'reback') {
  603. let param = {status: this.inputForm.status, id: this.inputForm.id}
  604. collectService.updateStatusById(param).then(() => {
  605. this.loading = false
  606. callback()
  607. })
  608. }
  609. }
  610. })
  611. } else if (type === 'hold') {
  612. collectService.findById(this.inputForm.id).then((data) => {
  613. if (data.status !== '4') { // status的值不等于“驳回”就弹出提示
  614. this.loading = false
  615. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  616. throw new Error()
  617. } else {
  618. // 终止
  619. let param = {status: '1', id: this.inputForm.id}
  620. collectService.updateStatusById(param).then(() => {
  621. this.loading = false
  622. callback()
  623. })
  624. }
  625. })
  626. }
  627. },
  628. reapplyForm (callback) {
  629. this.loading = true
  630. collectService.findById(this.inputForm.id).then((data) => {
  631. if (data.status !== '4') { // 审核状态不是“驳回”,就弹出提示
  632. this.loading = false
  633. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  634. throw new Error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  635. } else {
  636. this.startFormTrue(callback)
  637. }
  638. })
  639. },
  640. // 送审
  641. async startFormTrue (callback) {
  642. if (this.isNotEmpty(this.inputForm.collectDate)) {
  643. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  644. }
  645. this.$refs.inputForm.validate().then(res => {
  646. this.inputForm.status = '2'
  647. collectService.save(this.inputForm).then((data) => {
  648. this.inputForm.id = data.businessId
  649. callback(data.businessTable, data.businessId, this.inputForm)
  650. this.$refs.inputForm.resetFields()
  651. this.loading = false
  652. }).catch(() => {
  653. this.$refs.inputForm.resetFields()
  654. }).catch((e) => {
  655. })
  656. })
  657. },
  658. // 通过
  659. async agreeForm (callback) {
  660. if (this.isNotEmpty(this.inputForm.collectDate)) {
  661. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  662. }
  663. console.log('this.inputForm', this.inputForm)
  664. this.$refs.inputForm.validate().then(res => {
  665. this.commonApi.getTaskNameByProcInsId(this.inputForm.procInsId).then((data) => {
  666. if (this.isNotEmpty(data)) {
  667. if (data === '仓库管理员审核') {
  668. this.inputForm.status = '5'
  669. }
  670. }
  671. collectService.save(this.inputForm).then((data) => {
  672. callback(data.businessTable, data.businessId, this.inputForm)
  673. this.$refs.inputForm.resetFields()
  674. this.loading = false
  675. }).catch(() => {
  676. this.loading = false
  677. this.$refs.inputForm.resetFields()
  678. })
  679. })
  680. })
  681. },
  682. }
  683. }
  684. </script>
  685. <style>
  686. .cu-form-group .title {
  687. min-width: calc(4em + 40px);
  688. }
  689. </style>