CollectForm.vue 42 KB

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