CollectForm.vue 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853
  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://we4k7g.natappfree.cc/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://5hrd5v.natappfree.cc/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://we4k7g.natappfree.cc/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://we4k7g.natappfree.cc/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. status: {
  339. type: String,
  340. default: ''
  341. }
  342. },
  343. watch: {
  344. 'businessId': {
  345. handler (newVal) {
  346. if (this.businessId) {
  347. this.init(this.businessId)
  348. } else {
  349. this.$nextTick(() => {
  350. // this.$refs.inputForm.reset()
  351. })
  352. }
  353. },
  354. immediate: true,
  355. deep: false
  356. }
  357. },
  358. methods: {
  359. // 显示选择器
  360. showPicker(index) {
  361. this.$refs.treePicker._show(index);
  362. },
  363. showGoods(index) {
  364. if (this.isEmpty(this.inputForm.detailInfos[index].collectTypeId)) {
  365. uni.showToast({
  366. title: '请先选择领用类型',
  367. icon: 'none',
  368. duration: 2000
  369. });
  370. } else {
  371. this.searchForm.wareHouseType = this.inputForm.detailInfos[index].collectTypeId
  372. this.wareHouseService.wareHouseSummaryList({
  373. 'current': 0,
  374. 'size': -1,
  375. 'orders': [],
  376. ...this.searchForm
  377. }).then((data) => {
  378. this.goodsListData = data.records
  379. })
  380. this.$refs.goodsPicker._show(index);
  381. }
  382. },
  383. //监听选择
  384. selectChange(ids, names, index) {
  385. // this.inputForm.detailInfos.forEach((detail,inde) => {
  386. // if (inde === parseInt(index)) {
  387. // detail.collectType = names
  388. // detail.collectTypeId = ids[0]
  389. // }
  390. // })
  391. this.$set(this.inputForm.detailInfos, index, {
  392. ...this.inputForm.detailInfos[index],
  393. collectType: names,
  394. collectTypeId: ids[0]
  395. });
  396. },
  397. //监听选择
  398. selectGoodsChange(ids, names, index,tradeNumber) {
  399. // this.inputForm.detailInfos.forEach((detail,inde) => {
  400. // if (inde === parseInt(index)) {
  401. // detail.goodsName = names
  402. // detail.tradeNumber = tradeNumber
  403. // }
  404. // })
  405. this.$set(this.inputForm.detailInfos, index, {
  406. ...this.inputForm.detailInfos[index],
  407. goodsName: names,
  408. surplusNumber: tradeNumber
  409. });
  410. },
  411. init (id) {
  412. this.nodeFlag = true
  413. this.inputForm.id = id
  414. if (id) {
  415. collectService.findById(id).then((data) => {
  416. // 只有从我发起的还有已办事项抄送给我 进入流程页面的时候才会有这个值
  417. if (this.status === 'testSee') {
  418. this.nodeFlag = true
  419. } else {
  420. this.commonApi.getTaskNameByProcInsId(data.procInsId).then((data) => {
  421. if (this.isNotEmpty(data)) {
  422. if (data === '重新发起申请' || this.isEmpty(data)) {
  423. this.nodeFlag = false
  424. } else {
  425. this.nodeFlag = true
  426. }
  427. }
  428. })
  429. }
  430. this.inputForm = this.recover(this.inputForm, data)
  431. this.inputForm.collectDate = new Date(data.collectDate);
  432. if (this.inputForm.files) {
  433. this.inputForm.files.forEach( (item,index) => {
  434. this.$set(this.showFileList, index, true);
  435. })
  436. }
  437. console.log('this.inputForm.detailInfos', this.inputForm.detailInfos)
  438. if (this.isNotEmpty(this.inputForm.detailInfos)){
  439. this.inputForm.detailInfos.forEach( (item,index) => {
  440. if (this.isNotEmpty(item.fileInfoLost)) {
  441. this.fileList3[index] = []
  442. item.fileInfoLost.forEach( (item,index2) => {
  443. this.fileList3[index].push(item)
  444. this.$set(this.showFileList2, index2, true);
  445. })
  446. }
  447. })
  448. }
  449. })
  450. }
  451. },
  452. buildTree(nodes, parentId = '0') {
  453. const tree = [];
  454. for (const node of nodes) {
  455. if (node.parentId === parentId) {
  456. const children = this.buildTree(nodes, node.id);
  457. if (children.length) {
  458. node.children = children;
  459. }
  460. tree.push(node);
  461. }
  462. }
  463. return tree;
  464. },
  465. formatDate(date) {
  466. const dateNew = new Date(date); // 将日期字符串转换为 Date 对象
  467. const year = dateNew.getFullYear();
  468. const month = (dateNew.getMonth() + 1).toString().padStart(2, '0');
  469. const day = dateNew.getDate().toString().padStart(2, '0');
  470. return `${year}-${month}-${day}`;
  471. },
  472. isEmpty(value) {
  473. let result = false;
  474. if (value == null || value == undefined) {
  475. result = true;
  476. }
  477. if (typeof value == 'string' && (value.replace(/\s+/g, "") == "" || value == "")) {
  478. result = true;
  479. }
  480. if (typeof value == "object" && value instanceof Array && value.length === 0) {
  481. result = true;
  482. }
  483. return result;
  484. },
  485. isNotEmpty (value) {
  486. return !this.isEmpty(value)
  487. },
  488. /**
  489. * 判断是否为空
  490. */
  491. isNull(val) {
  492. if (val instanceof Array) {
  493. if (val.length === 0) return true;
  494. } else if (val instanceof Object) {
  495. if (JSON.stringify(val) === "{}") return true;
  496. } else {
  497. if (
  498. val === "null" ||
  499. val == null ||
  500. val === "undefined" ||
  501. val === undefined ||
  502. val === ""
  503. )
  504. return true;
  505. return false;
  506. }
  507. return false;
  508. },
  509. addRow() {
  510. // 点击新增按钮时,向表格中添加一行空数据
  511. this.inputForm.detailInfos.push({ recipientAgent: this.userInfo.name,
  512. recipientAgentId: this.userInfo.id, recipientOffice: this.userInfo.officeDTO.name });
  513. let valueData = this.materialList;
  514. // 将扁平数据转换为树形结构
  515. const result = this.buildTree(valueData);
  516. this.listData = result
  517. },
  518. removeRow(index) {
  519. // 点击删除按钮时,从表格中移除指定行
  520. // this.tableData.splice(index, 1);
  521. this.inputForm.detailInfos.splice(index, 1);
  522. },
  523. formatDateNew(date) {
  524. const year = date.getFullYear();
  525. const month = (date.getMonth() + 1).toString().padStart(2, '0');
  526. const day = date.getDate().toString().padStart(2, '0');
  527. const hours = date.getHours().toString().padStart(2, '0');
  528. const minutes = date.getMinutes().toString().padStart(2, '0');
  529. const seconds = date.getSeconds().toString().padStart(2, '0');
  530. return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
  531. },
  532. // 领用人下拉弹窗
  533. openUserPullForm(index) {
  534. // 点击 "领用人" 输入框时打开userPullForm页面,传入index用于区分不同的行
  535. uni.navigateTo({
  536. url: '/pages/materialManagement/collect/UserPullForm?index=' + index // userPullForm页面的路径
  537. });
  538. },
  539. handleUploadSuccess (res, file, fileList, index, type) {
  540. console.log('fileListSuccess', fileList)
  541. // 将 fileList 转换为你期望的格式
  542. const formattedFiles = fileList.map(fileItem => {
  543. return {
  544. name: fileItem.name,
  545. size: fileItem.size,
  546. url: fileItem.response ? '/' + fileItem.response.url : fileItem.url,
  547. lsUrl: fileItem.response ? fileItem.response.lsUrl : fileItem.lsUrl, // 如果没有 lsUrl,可以根据需要设置为空字符串或其他默认值
  548. createBy: this.userInfo,
  549. by: this.userInfo.id,
  550. createTime: this.formatDateNew(new Date())
  551. };
  552. });
  553. if (type === 'detail') {
  554. // 将格式化后的数据设置到 detailInfos 的 fileInfoLost 属性中
  555. this.inputForm.detailInfos[index].fileInfoLost = formattedFiles;
  556. fileList.forEach((item, i) => {
  557. if (item === file) {
  558. this.$set(this.showFileList2, i, true);
  559. }
  560. });
  561. } else {
  562. this.inputForm.files = formattedFiles
  563. fileList.forEach((item, index) => {
  564. if (item === file) {
  565. this.$set(this.showFileList, index, true);
  566. }
  567. });
  568. }
  569. // 强制更新视图
  570. this.$forceUpdate();
  571. },
  572. handleRemove(file, fileList, index, type) {
  573. console.log('fileList', fileList)
  574. // 处理移除文件逻辑
  575. // file 是移除的文件
  576. // fileList 是当前文件列表
  577. const formattedFiles = fileList.map(fileItem => {
  578. return {
  579. name: fileItem.name,
  580. size: fileItem.size,
  581. url: '/' + fileItem.response.url,
  582. createBy: this.userInfo,
  583. by: this.userInfo.id,
  584. createTime: this.formatDateNew(new Date())
  585. };
  586. });
  587. if (type === 'detail') {
  588. this.inputForm.detailInfos[index].fileInfoLost = formattedFiles;
  589. } else {
  590. this.inputForm.files = formattedFiles
  591. }
  592. // 如果你想要更新文件列表,可以在这里更新 inputForm.fileInfoLost
  593. // this.inputForm.fileInfoLost = fileList;
  594. },
  595. saveForm(callback) {
  596. return new Promise((resolve, reject) => {
  597. // 表单规则验证
  598. // ...
  599. let errors = [];
  600. if (this.isNotEmpty(this.inputForm.collectDate)) {
  601. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  602. }
  603. if (this.isEmpty(this.inputForm.detailInfos)) {
  604. errors.push('至少填写一条领用详情信息');
  605. } else {
  606. let i = this.inputForm.detailInfos.length;
  607. for (let j = 0; j < i; j++) {
  608. let k = j + 1;
  609. if (this.isEmpty(this.inputForm.detailInfos[j].recipientAgent)) {
  610. errors.push('领用详情第' + k + '行请选择领用人');
  611. } else if (this.isEmpty(this.inputForm.detailInfos[j].collectType)) {
  612. errors.push('领用详情第' + k + '行请选择领用类型');
  613. } else if (this.isEmpty(this.inputForm.detailInfos[j].goodsName)) {
  614. errors.push('领用详情第' + k + '行请选择物品名称');
  615. } else if (this.isEmpty(this.inputForm.detailInfos[j].collectNumber)) {
  616. errors.push('领用详情第' + k + '行请输入领用数量');
  617. }
  618. }
  619. }
  620. if (errors.length > 0) {
  621. // 存在错误,显示提示信息
  622. errors.forEach(error => {
  623. uni.showToast({
  624. title: error,
  625. icon: 'none',
  626. duration: 2000
  627. });
  628. });
  629. reject('Form validation failed');
  630. } else {
  631. // 所有验证通过,执行保存操作
  632. this.$refs.inputForm.validate().then(() => {
  633. uni.showLoading();
  634. this.inputForm.status = '2';
  635. collectService.save(this.inputForm).then(data => {
  636. callback(data.businessTable, data.businessId);
  637. resolve('Form saved successfully');
  638. }).catch(error => {
  639. reject('Save operation failed');
  640. });
  641. }).catch(() => {
  642. reject('Form validation failed');
  643. });
  644. }
  645. });
  646. },
  647. // 修改状态
  648. async updateStatusById (type, callback) {
  649. if (type === 'reject' || type === 'reback') {
  650. collectService.findById(this.inputForm.id).then((data) => {
  651. if (data.status !== '2') { // status的值不等于“审核中”,就弹出提示
  652. this.loading = false
  653. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  654. throw new Error()
  655. } else {
  656. if (type === 'reject') {
  657. // 驳回
  658. this.inputForm.status = '4'
  659. }
  660. if (type === 'reback') {
  661. // 撤回
  662. this.inputForm.status = '3'
  663. }
  664. if (type === 'reject' || type === 'reback') {
  665. let param = {status: this.inputForm.status, id: this.inputForm.id}
  666. collectService.updateStatusById(param).then(() => {
  667. this.loading = false
  668. callback()
  669. })
  670. }
  671. }
  672. })
  673. } else if (type === 'hold') {
  674. collectService.findById(this.inputForm.id).then((data) => {
  675. if (data.status !== '4') { // status的值不等于“驳回”就弹出提示
  676. this.loading = false
  677. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  678. throw new Error()
  679. } else {
  680. // 终止
  681. let param = {status: '1', id: this.inputForm.id}
  682. collectService.updateStatusById(param).then(() => {
  683. this.loading = false
  684. callback()
  685. })
  686. }
  687. })
  688. }
  689. },
  690. reapplyForm (callback) {
  691. this.loading = true
  692. collectService.findById(this.inputForm.id).then((data) => {
  693. if (data.status !== '4') { // 审核状态不是“驳回”,就弹出提示
  694. this.loading = false
  695. this.$message.error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  696. throw new Error('任务数据已发生改变或不存在,请在待办任务中确认此任务是否存在')
  697. } else {
  698. this.startFormTrue(callback)
  699. }
  700. })
  701. },
  702. // 送审
  703. async startFormTrue (callback) {
  704. if (this.isNotEmpty(this.inputForm.collectDate)) {
  705. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  706. }
  707. this.$refs.inputForm.validate().then(res => {
  708. this.inputForm.status = '2'
  709. collectService.save(this.inputForm).then((data) => {
  710. this.inputForm.id = data.businessId
  711. callback(data.businessTable, data.businessId, this.inputForm)
  712. this.$refs.inputForm.resetFields()
  713. this.loading = false
  714. }).catch(() => {
  715. this.$refs.inputForm.resetFields()
  716. }).catch((e) => {
  717. })
  718. })
  719. },
  720. // 通过
  721. async agreeForm (callback) {
  722. if (this.isNotEmpty(this.inputForm.collectDate)) {
  723. this.inputForm.collectDate = this.formatDate(this.inputForm.collectDate);
  724. }
  725. console.log('this.inputForm', this.inputForm)
  726. this.$refs.inputForm.validate().then(res => {
  727. this.commonApi.getTaskNameByProcInsId(this.inputForm.procInsId).then((data) => {
  728. if (this.isNotEmpty(data)) {
  729. if (data === '仓库管理员审核') {
  730. this.inputForm.status = '5'
  731. }
  732. }
  733. collectService.save(this.inputForm).then((data) => {
  734. callback(data.businessTable, data.businessId, this.inputForm)
  735. this.$refs.inputForm.resetFields()
  736. this.loading = false
  737. }).catch(() => {
  738. this.loading = false
  739. this.$refs.inputForm.resetFields()
  740. })
  741. })
  742. })
  743. },
  744. shouldShowFile(file,index,type) {
  745. if (type === 'detail') {
  746. if (this.inputForm.detailInfos[index].fileInfoLost && this.inputForm.detailInfos[index].fileInfoLost.length > 0) {
  747. // 返回一个布尔值,确定是否显示上传成功后的文件
  748. return this.showFileList2[this.inputForm.detailInfos[index].fileInfoLost.indexOf(file)];
  749. }
  750. }else {
  751. if (this.inputForm.files && this.inputForm.files.length > 0) {
  752. // 返回一个布尔值,确定是否显示上传成功后的文件
  753. return this.showFileList[this.inputForm.files.indexOf(file)];
  754. }
  755. }
  756. return false; // 默认返回 false 或者其他适当的
  757. },
  758. async handleFileClick(file) {
  759. await this.ossService.getTemporaryUrl(file.url).then((data) => {
  760. file.lsUrl = data
  761. })
  762. console.log('file', file)
  763. if (this.isImage(file.name)) {
  764. // 如果是图片文件,则执行放大显示图片的逻辑
  765. this.handleImageClick(file);
  766. } else {
  767. // window.open(file.lsUrl, '_blank')
  768. window.location.href = file.lsUrl
  769. // 如果不是图片文件,则执行其他操作,比如下载文件等
  770. }
  771. },
  772. handleImageClick(file) {
  773. // 在点击图片时执行放大显示的逻辑
  774. this.$alert(`<img src="${file.lsUrl}" style="max-width: 100%; max-height: 100%;" />`, '图片详情', {
  775. dangerouslyUseHTMLString: true,
  776. customClass: 'custom-alert'
  777. });
  778. },
  779. // 判断文件是否是图片类型
  780. isImage(fileName) {
  781. const ext = fileName.toLowerCase().split('.').pop(); // 获取文件的后缀名
  782. return ['jpg', 'jpeg', 'png', 'gif', 'bmp'].includes(ext); // 判断后缀名是否是图片类型
  783. },
  784. handleDelete(file,lineIndex,type) {
  785. // 处理删除文件的逻辑
  786. if (type === 'detail') {
  787. const index = this.inputForm.detailInfos[lineIndex].fileInfoLost.indexOf(file);
  788. if (index !== -1) {
  789. this.inputForm.detailInfos[lineIndex].fileInfoLost.splice(index, 1);
  790. this.showFileList2.splice(index, 1); // 从showFileList中移除对应的元素
  791. }
  792. } else {
  793. // 从文件列表中移除文件
  794. const index = this.inputForm.files.indexOf(file);
  795. if (index !== -1) {
  796. this.inputForm.files.splice(index, 1);
  797. this.showFileList.splice(index, 1); // 从showFileList中移除对应的元素
  798. }
  799. }
  800. },
  801. }
  802. }
  803. </script>
  804. <style>
  805. .cu-form-group .title {
  806. min-width: calc(4em + 40px);
  807. }
  808. /* 样式示例,您可能需要根据实际情况调整 */
  809. .upload-demo {
  810. width: 40%;
  811. }
  812. </style>