CollectForm.vue 42 KB

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