CollectForm.vue 42 KB

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