CollectForm.vue 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  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. <u-form-item label="" >
  33. <el-divider content-position="left"> 领用详情 {{index_experience + 1}}</el-divider>
  34. </u-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. <u-form-item label="" >
  140. <el-divider content-position="left"> 领用详情 {{index_experience + 1}}</el-divider>
  141. </u-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. <user-select ref="userPicker" @input="handleEvent"></user-select>
  221. <ba-tree-picker ref="treePicker" :multiple='false' @select-change="selectChange" title="类型选择"
  222. :localdata="listData" valueKey="value" textKey="label" childrenKey="children" />
  223. <goods-info-picker ref="goodsPicker" :multiple='false' @select-goods-change="selectGoodsChange" title="物品名称"
  224. :localdata="goodsListData" valueKey="value" textKey="label" childrenKey="children" />
  225. </view>
  226. </template>
  227. <script>
  228. import userSelect from '@/components/user-select/user-select-radio.vue'
  229. import goodsInfoPicker from './GoodsInfoPicker'
  230. import MaterialTypeService from '@/api/materialManagement/MaterialTypeService'
  231. import WareHouseService from '@/api/materialManagement/WareHouseService'
  232. import collectService from '@/api/materialManagement/CollectService'
  233. import CommonApi from '@/api/common/CommonApi'
  234. import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue"
  235. import {mapState, mapMutations, mapActions} from 'vuex'
  236. export default {
  237. components: {
  238. userSelect,
  239. baTreePicker,
  240. goodsInfoPicker
  241. },
  242. computed: mapState({
  243. userInfo: (state) => state.user.userInfo,
  244. avatar: (state) => state.user.avatar
  245. }),
  246. data () {
  247. return {
  248. nodeFlag: false,
  249. loading: false,
  250. listData: [],
  251. fileList3: [],
  252. goodsListData: [],
  253. materialList: [],
  254. searchForm: {
  255. wareHouseType: '',
  256. },
  257. inputForm: {
  258. collectNo: '',
  259. handledBy: '',
  260. handledById: '',
  261. handledByOffice: '',
  262. handledByOfficeName: '',
  263. remarks: '',
  264. detailInfos: [],
  265. files: [], // 附件信息
  266. procInsId: ''
  267. },
  268. rules: {
  269. 'collectDate': [
  270. {
  271. required: true,
  272. message: '领用时间不能为空',
  273. trigger: ['blur', 'change']
  274. }
  275. ],
  276. }
  277. }
  278. },
  279. materialTypeService: null,
  280. wareHouseService: null,
  281. commonApi: null,
  282. // 页面加载时执行
  283. created() {
  284. this.commonApi = new CommonApi()
  285. this.materialTypeService = new MaterialTypeService()
  286. this.wareHouseService = new WareHouseService()
  287. this.materialTypeService.cgList().then((data)=>{
  288. this.materialList = data
  289. }).catch((e)=>{
  290. throw e
  291. })
  292. this.inputForm.handledBy = this.userInfo.name
  293. this.inputForm.handledById = this.userInfo.id
  294. this.inputForm.handledByOffice = this.userInfo.officeDTO.id
  295. this.inputForm.handledByOfficeName = this.userInfo.officeDTO.name
  296. // 监听事件
  297. uni.$on('eventName', (data) => {
  298. // 在这里处理传递过来的数据
  299. //循环遍历领用详情,估计index将用户id与用户名称放入到领用人里面
  300. this.inputForm.detailInfos.forEach((detail,index) => {
  301. if (index === parseInt(data.index)) {
  302. detail.recipientAgent = data.name
  303. detail.recipientAgentId = data.id
  304. detail.recipientOffice = data.officeDTO.name
  305. }
  306. })
  307. });
  308. },
  309. props: {
  310. businessId: {
  311. type: String,
  312. default: ''
  313. },
  314. formReadOnly: {
  315. type: Boolean,
  316. default: false
  317. }
  318. },
  319. watch: {
  320. 'businessId': {
  321. handler (newVal) {
  322. if (this.businessId) {
  323. this.init(this.businessId)
  324. } else {
  325. this.$nextTick(() => {
  326. // this.$refs.inputForm.reset()
  327. })
  328. }
  329. },
  330. immediate: true,
  331. deep: false
  332. }
  333. },
  334. methods: {
  335. handleEvent(data,index,type) {
  336. // 在这里处理子组件传递过来的数据
  337. this.inputForm.detailInfos[index].recipientAgentId = data.id
  338. this.inputForm.detailInfos[index].recipientAgent = data.label
  339. this.inputForm.detailInfos[index].recipientOffice = data.parentLabel
  340. this.inputForm.detailInfos[index].deptId = data.parentId
  341. // 进行进一步处理...
  342. },
  343. // 显示选择器
  344. showPicker(index) {
  345. this.$refs.treePicker._show(index);
  346. },
  347. showGoods(index) {
  348. this.searchForm.wareHouseType = this.inputForm.detailInfos[index].collectTypeId
  349. this.wareHouseService.wareHouseSummaryList({
  350. 'current': 0,
  351. 'size': -1,
  352. 'orders': [],
  353. ...this.searchForm
  354. }).then((data) => {
  355. this.goodsListData = data.records
  356. })
  357. this.$refs.goodsPicker._show(index);
  358. },
  359. //监听选择
  360. selectChange(ids, names, index) {
  361. // this.inputForm.detailInfos.forEach((detail,inde) => {
  362. // if (inde === parseInt(index)) {
  363. // detail.collectType = names
  364. // detail.collectTypeId = ids[0]
  365. // }
  366. // })
  367. this.$set(this.inputForm.detailInfos, index, {
  368. ...this.inputForm.detailInfos[index],
  369. collectType: names,
  370. collectTypeId: ids[0]
  371. });
  372. },
  373. //监听选择
  374. selectGoodsChange(ids, names, index,tradeNumber) {
  375. // this.inputForm.detailInfos.forEach((detail,inde) => {
  376. // if (inde === parseInt(index)) {
  377. // detail.goodsName = names
  378. // detail.tradeNumber = tradeNumber
  379. // }
  380. // })
  381. this.$set(this.inputForm.detailInfos, index, {
  382. ...this.inputForm.detailInfos[index],
  383. goodsName: names,
  384. surplusNumber: tradeNumber
  385. });
  386. },
  387. init (id) {
  388. this.nodeFlag = true
  389. this.inputForm.id = id
  390. if (id) {
  391. collectService.findById(id).then((data) => {
  392. this.commonApi.getTaskNameByProcInsId(data.procInsId).then((data) => {
  393. if (this.isNotEmpty(data)) {
  394. if (data === '重新发起申请' || this.isEmpty(data)) {
  395. this.nodeFlag = false
  396. } else {
  397. this.nodeFlag = true
  398. }
  399. }
  400. })
  401. this.inputForm = this.recover(this.inputForm, data)
  402. this.inputForm.collectDate = new Date(data.collectDate);
  403. this.inputForm.detailInfos.forEach( (item,index) => {
  404. if (this.isNotEmpty(item.fileInfoLost)) {
  405. this.fileList3[index] = []
  406. item.fileInfoLost.forEach( (item,index2) => {
  407. this.fileList3[index].push(item)
  408. })
  409. }
  410. })
  411. })
  412. }
  413. },
  414. buildTree(nodes, parentId = '0') {
  415. const tree = [];
  416. for (const node of nodes) {
  417. if (node.parentId === parentId) {
  418. const children = this.buildTree(nodes, node.id);
  419. if (children.length) {
  420. node.children = children;
  421. }
  422. tree.push(node);
  423. }
  424. }
  425. return tree;
  426. },
  427. formatDate(date) {
  428. const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
  429. const year = dateNew.getFullYear();
  430. const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
  431. const day = dateNew.getDate().toString().padStart(2, '0');
  432. return `${year}-${month}-${day}`;
  433. },
  434. isEmpty(value) {
  435. let result = false;
  436. if (value == null || value == undefined) {
  437. result = true;
  438. }
  439. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  440. result = true;
  441. }
  442. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  443. result = true;
  444. }
  445. return result;
  446. },
  447. isNotEmpty (value) {
  448. return !this.isEmpty(value)
  449. },
  450. /**
  451. * 判断是否为空
  452. */
  453. isNull(val) {
  454. if (val instanceof Array) {
  455. if (val.length === 0) return true;
  456. } else if (val instanceof Object) {
  457. if (JSON.stringify(val) === "{}") return true;
  458. } else {
  459. if (
  460. val === "null" ||
  461. val == null ||
  462. val === "undefined" ||
  463. val === undefined ||
  464. val === ""
  465. )
  466. return true;
  467. return false;
  468. }
  469. return false;
  470. },
  471. addRow() {
  472. // 点击新增按钮时,向表格中添加一行空数据
  473. this.inputForm.detailInfos.push({ recipientAgent: this.userInfo.name,
  474. recipientAgentId: this.userInfo.id, recipientOffice: this.userInfo.officeDTO.name });
  475. let valueData = this.materialList;
  476. // 将扁平数据转换为树形结构
  477. const result = this.buildTree(valueData);
  478. this.listData = result
  479. },
  480. removeRow(index) {
  481. // 点击删除按钮时,从表格中移除指定行
  482. // this.tableData.splice(index, 1);
  483. this.inputForm.detailInfos.splice(index, 1);
  484. },
  485. formatDateNew(date) {
  486. const year = date.getFullYear();
  487. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  488. const day = date.getDate().toString().padStart(2, '0');
  489. const hours = date.getHours().toString().padStart(2, '0');
  490. const minutes = date.getMinutes().toString().padStart(2, '0');
  491. const seconds = date.getSeconds().toString().padStart(2, '0');
  492. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  493. },
  494. // 领用人下拉弹窗
  495. openUserPullForm(index) {
  496. // 点击 "领用人" 输入框时打开userPullForm页面,传入index用于区分不同的行
  497. // uni.navigateTo({
  498. // url: '/pages/materialManagement/collect/UserPullForm?index=' + index // userPullForm页面的路径
  499. // });
  500. this.$refs.userPicker.open(index,"");
  501. },
  502. handleUploadSuccess (res, file, fileList, index, type) {
  503. // 将 fileList 转换为你期望的格式
  504. const formattedFiles = fileList.map(fileItem => {
  505. return {
  506. name: fileItem.name,
  507. size: fileItem.size,
  508. url: '/' + fileItem.response.url,
  509. createBy: this.userInfo,
  510. by: this.userInfo.id,
  511. createTime: this.formatDateNew(new Date())
  512. };
  513. });
  514. if (type === 'detail') {
  515. // 将格式化后的数据设置到 detailInfos 的 fileInfoLost 属性中
  516. this.inputForm.detailInfos[index].fileInfoLost = formattedFiles;
  517. } else {
  518. this.inputForm.files = formattedFiles
  519. }
  520. // 强制更新视图
  521. this.$forceUpdate();
  522. },
  523. handleRemove(file, fileList, index, type) {
  524. // 处理移除文件逻辑
  525. // file 是移除的文件
  526. // fileList 是当前文件列表
  527. const formattedFiles = fileList.map(fileItem => {
  528. return {
  529. name: fileItem.name,
  530. size: fileItem.size,
  531. url: '/' + fileItem.response.url,
  532. createBy: this.userInfo,
  533. by: this.userInfo.id,
  534. createTime: this.formatDateNew(new Date())
  535. };
  536. });
  537. if (type === 'detail') {
  538. this.inputForm.detailInfos[index].fileInfoLost = formattedFiles;
  539. } else {
  540. this.inputForm.files = formattedFiles
  541. }
  542. // 如果你想要更新文件列表,可以在这里更新 inputForm.fileInfoLost
  543. // this.inputForm.fileInfoLost = fileList;
  544. },
  545. saveForm(callback) {
  546. return new Promise((resolve, reject) => {
  547. // 表单规则验证
  548. // ...
  549. let errors = [];
  550. if (this.isNotEmpty(this.inputForm.collectDate)) {
  551. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  552. }
  553. if (this.isEmpty(this.inputForm.detailInfos)) {
  554. errors.push('至少填写一条领用详情信息');
  555. } else {
  556. let i = this.inputForm.detailInfos.length;
  557. for (let j = 0; j < i; j++) {
  558. let k = j + 1;
  559. if (this.isEmpty(this.inputForm.detailInfos[j].recipientAgent)) {
  560. errors.push('领用详情第' + k + '行请选择领用人');
  561. } else if (this.isEmpty(this.inputForm.detailInfos[j].collectType)) {
  562. errors.push('领用详情第' + k + '行请选择领用类型');
  563. } else if (this.isEmpty(this.inputForm.detailInfos[j].goodsName)) {
  564. errors.push('领用详情第' + k + '行请选择物品名称');
  565. } else if (this.isEmpty(this.inputForm.detailInfos[j].collectNumber)) {
  566. errors.push('领用详情第' + k + '行请输入领用数量');
  567. }
  568. }
  569. }
  570. if (errors.length > 0) {
  571. // 存在错误,显示提示信息
  572. errors.forEach(error => {
  573. uni.showToast({
  574. title: error,
  575. icon: 'none',
  576. duration: 2000
  577. });
  578. });
  579. // reject('Form validation failed');
  580. } else {
  581. // 所有验证通过,执行保存操作
  582. this.$refs.inputForm.validate().then(() => {
  583. uni.showLoading();
  584. this.inputForm.status = '2';
  585. collectService.save(this.inputForm).then(data => {
  586. callback(data.businessTable, data.businessId,this.inputForm);
  587. resolve('Form saved successfully');
  588. }).catch(error => {
  589. // reject('Save operation failed');
  590. });
  591. }).catch(() => {
  592. // reject('Form validation failed');
  593. });
  594. }
  595. });
  596. },
  597. // 修改状态
  598. async updateStatusById (type, callback) {
  599. if (type === 'reject' || type === 'reback') {
  600. collectService.findById(this.inputForm.id).then((data) => {
  601. if (data.status !== '2') { // status的值不等于“审核中”,就弹出提示
  602. this.loading = false
  603. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  604. throw new Error()
  605. } else {
  606. if (type === 'reject') {
  607. // 驳回
  608. this.inputForm.status = '4'
  609. }
  610. if (type === 'reback') {
  611. // 撤回
  612. this.inputForm.status = '3'
  613. }
  614. if (type === 'reject' || type === 'reback') {
  615. let param = {status: this.inputForm.status, id: this.inputForm.id}
  616. collectService.updateStatusById(param).then(() => {
  617. this.loading = false
  618. callback()
  619. })
  620. }
  621. }
  622. })
  623. } else if (type === 'hold') {
  624. collectService.findById(this.inputForm.id).then((data) => {
  625. if (data.status !== '4') { // status的值不等于“驳回”就弹出提示
  626. this.loading = false
  627. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  628. throw new Error()
  629. } else {
  630. // 终止
  631. let param = {status: '1', id: this.inputForm.id}
  632. collectService.updateStatusById(param).then(() => {
  633. this.loading = false
  634. callback()
  635. })
  636. }
  637. })
  638. }
  639. },
  640. reapplyForm (callback) {
  641. this.loading = true
  642. collectService.findById(this.inputForm.id).then((data) => {
  643. if (data.status !== '4') { // 审核状态不是“驳回”,就弹出提示
  644. this.loading = false
  645. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  646. throw new Error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  647. } else {
  648. this.startFormTrue(callback)
  649. }
  650. })
  651. },
  652. // 送审
  653. async startFormTrue (callback) {
  654. if (this.isNotEmpty(this.inputForm.collectDate)) {
  655. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  656. }
  657. this.$refs.inputForm.validate().then(res => {
  658. this.inputForm.status = '2'
  659. collectService.save(this.inputForm).then((data) => {
  660. this.inputForm.id = data.businessId
  661. callback(data.businessTable, data.businessId, this.inputForm)
  662. this.$refs.inputForm.resetFields()
  663. this.loading = false
  664. }).catch(() => {
  665. this.$refs.inputForm.resetFields()
  666. }).catch((e) => {
  667. })
  668. })
  669. },
  670. // 通过
  671. async agreeForm (callback) {
  672. if (this.isNotEmpty(this.inputForm.collectDate)) {
  673. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  674. }
  675. this.$refs.inputForm.validate().then(res => {
  676. this.commonApi.getTaskNameByProcInsId(this.inputForm.procInsId).then((data) => {
  677. if (this.isNotEmpty(data)) {
  678. if (data === '仓库管理员审核') {
  679. this.inputForm.status = '5'
  680. }
  681. }
  682. collectService.save(this.inputForm).then((data) => {
  683. callback(data.businessTable, data.businessId, this.inputForm)
  684. this.$refs.inputForm.resetFields()
  685. this.loading = false
  686. }).catch(() => {
  687. this.loading = false
  688. this.$refs.inputForm.resetFields()
  689. })
  690. })
  691. })
  692. },
  693. }
  694. }
  695. </script>
  696. <style>
  697. .cu-form-group .title {
  698. min-width: calc(4em + 40px);
  699. }
  700. </style>