file-edit.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <ele-modal
  4. width="500px"
  5. :visible.sync="showEditFlag"
  6. :close-on-click-modal="false"
  7. custom-class="ele-dialog-form"
  8. append-to-body
  9. @close="cancel"
  10. :title="title"
  11. ref="Emodal"
  12. :maxable="true"
  13. :resizable="true"
  14. >
  15. <el-tabs
  16. v-model="activeName"
  17. type="card"
  18. @tab-click="handleClick"
  19. style="margin-bottom: 10px"
  20. >
  21. <el-tab-pane label="文档工作区" name="1"></el-tab-pane>
  22. <el-tab-pane label="个人文档" name="2"></el-tab-pane>
  23. </el-tabs>
  24. <el-form ref="form" :model="form" :rules="rules" label-width="82px">
  25. <el-row :gutter="15">
  26. <el-col :span="24">
  27. <el-form-item label="文档位置" prop="directoryId">
  28. <el-cascader
  29. style="width: 100%"
  30. v-model="form.directoryId"
  31. :options="folderList"
  32. @change="initFileCode"
  33. ref="cascaderRef"
  34. :props="{
  35. value: 'id',
  36. label: 'name',
  37. children: 'sonDirectoryList',
  38. emitPath: false,
  39. checkStrictly: true
  40. }"
  41. ></el-cascader>
  42. </el-form-item>
  43. </el-col>
  44. <el-col :span="24">
  45. <el-form-item label="编码分类" prop="codeType">
  46. <ele-tree-select
  47. clearable
  48. :data="list"
  49. v-model="form.codeType"
  50. placeholder="请选择"
  51. default-expand-all
  52. labelKey="name"
  53. childrenKey="sonDirectoryList"
  54. valueKey="id"
  55. @change="typeChange"
  56. />
  57. </el-form-item>
  58. </el-col>
  59. <el-col :span="24">
  60. <el-form-item label="编码方案" prop="businessCodeId">
  61. <el-select
  62. v-model="form.businessCodeId"
  63. placeholder="请选择"
  64. style="width: 100%"
  65. >
  66. <el-option
  67. v-for="item in options"
  68. :key="item.id"
  69. :label="item.name"
  70. :value="item.id"
  71. >
  72. </el-option>
  73. </el-select>
  74. </el-form-item>
  75. </el-col>
  76. <el-col :span="24">
  77. <el-form-item label="文档类型" prop="type">
  78. <DictSelection
  79. dictName="文档类型"
  80. v-model="form.type"
  81. ></DictSelection>
  82. </el-form-item>
  83. </el-col>
  84. <el-col :span="24">
  85. <el-form-item label="文档" prop="storagePath">
  86. <div style="display: flex; align-items: center">
  87. <fileUpload
  88. v-model="form.storagePath"
  89. module="main"
  90. :limit="100"
  91. :multiple="true"
  92. @fileChange="fileChange"
  93. >
  94. </fileUpload>
  95. </div>
  96. </el-form-item>
  97. </el-col>
  98. <el-col :span="24">
  99. <el-form-item label="备注" prop="remark">
  100. <el-input
  101. v-model="form.remark"
  102. type="textarea"
  103. placeholder="请输入"
  104. ></el-input>
  105. </el-form-item>
  106. </el-col>
  107. </el-row>
  108. </el-form>
  109. <template v-slot:footer>
  110. <el-button @click="cancel">取消</el-button>
  111. <el-button type="primary" :loading="loading" @click="save">
  112. 确认
  113. </el-button>
  114. </template>
  115. </ele-modal>
  116. </template>
  117. <script>
  118. import {
  119. fileSaveAPI,
  120. selectTreeList,
  121. listParentId,
  122. getDocTreeListAPI,
  123. listCode
  124. } from './api/index';
  125. import FileUpload from './fileUpload.vue';
  126. import { setFolderList } from './util.js';
  127. import { mapGetters } from 'vuex';
  128. export default {
  129. components: { FileUpload },
  130. props: {
  131. isDefaultPersonal: {
  132. type: Boolean,
  133. default: false
  134. }
  135. },
  136. data() {
  137. const defaultForm = {
  138. name: '', //名称
  139. type: '1', //类型
  140. sizeUnit: '', //大小,
  141. unit: '', //单位
  142. remark: '', //备注
  143. status: '', //状态
  144. storagePathId: '',
  145. directoryId: '',
  146. businessCodeId: '',
  147. storagePath: [],
  148. id: '',
  149. lcyStatus: 1,
  150. fileType: 0
  151. };
  152. return {
  153. activeName: '1',
  154. rules: {
  155. businessCodeId: [
  156. { required: true, message: '请选择', trigger: 'blur' }
  157. ],
  158. // codeType: [{ required: true, message: '请选择', trigger: 'blur' }],
  159. directoryId: [{ required: true, message: '请选择', trigger: 'blur' }],
  160. storagePath: [{ required: true, message: '请选择', trigger: 'blur' }]
  161. },
  162. templateVisible: false,
  163. folderList: [],
  164. allFolderList: [],
  165. myFolderList: [],
  166. list: [],
  167. options: [],
  168. defaultForm,
  169. code: '',
  170. // 表单数据
  171. form: { ...defaultForm },
  172. // 提交状态
  173. loading: false,
  174. showEditFlag: false,
  175. title: '',
  176. type: '新建附件',
  177. nodeData: {}
  178. };
  179. },
  180. computed: {
  181. // 是否开启响应式布局
  182. styleResponsive() {
  183. return this.$store.state.theme.styleResponsive;
  184. },
  185. ...mapGetters(['user'])
  186. },
  187. async created() {
  188. this.allFolderList = await getDocTreeListAPI({
  189. type: 0,
  190. currentUserId: this.user.info.userId
  191. });
  192. this.myFolderList = await getDocTreeListAPI({
  193. type: 1,
  194. currentUserId: this.user.info.userId
  195. });
  196. this.activeName = this.isDefaultPersonal ? '2' : '1';
  197. console.log(this.activeName, 'this.activeName');
  198. this.folderList = this.activeName == '2' ? this.myFolderList : this.allFolderList;
  199. setFolderList(this.folderList); //权限过滤
  200. },
  201. methods: {
  202. handleClick() {
  203. this.form.directoryId = '';
  204. this.form.businessCodeId = '';
  205. this.form.codeType = '';
  206. if (this.activeName == 2) {
  207. this.folderList = this.myFolderList;
  208. } else {
  209. this.folderList = this.allFolderList;
  210. }
  211. if(this.isDefaultPersonal && this.activeName == '2') {
  212. this.form.directoryId = this.folderList[0]?.id || '';
  213. }
  214. },
  215. async getTreeCode() {
  216. let nodeData = {};
  217. await this.$nextTick(() => {
  218. // console.log(this.$refs,'this.$refs')
  219. nodeData =
  220. this.$refs.cascaderRef && this.$refs.cascaderRef.getCheckedNodes();
  221. });
  222. this.nodeData = {
  223. id: nodeData[0]?.data?.id,
  224. parentId:
  225. nodeData[0]?.data?.parentId != 0 ? nodeData[0]?.data?.parentId : ''
  226. };
  227. },
  228. async initFileCode() {
  229. console.log('getTreeCode~~~', this.nodeData);
  230. await this.getTreeCode();
  231. this.options = this.nodeData.id ? await listCode(this.nodeData) : [];
  232. if (this.options.length > 0) {
  233. this.form.businessCodeId = this.options[0].id;
  234. this.form.codeType = this.options[0].parentId;
  235. } else {
  236. this.form.businessCodeId = '';
  237. }
  238. },
  239. async open() {
  240. this.showEditFlag = true;
  241. this.$nextTick(async () => {
  242. this.list = await selectTreeList();
  243. if(this.isDefaultPersonal && this.activeName == '2') {
  244. this.form.directoryId = this.folderList[0]?.id || '';
  245. }
  246. await this.initFileCode();
  247. this.setTree(this.list);
  248. });
  249. },
  250. setTree(data) {
  251. data.forEach((item) => {
  252. item.sonDirectoryList = item.sonDirectoryList.filter(
  253. (item) => item.type == 1
  254. );
  255. if (item.sonDirectoryList.length > 0) {
  256. this.setTree(item.sonDirectoryList);
  257. }
  258. });
  259. },
  260. async typeChange(val) {
  261. let obj = {
  262. pageNum: 1,
  263. size: 100,
  264. parentId: val
  265. };
  266. if (this.activeName == 1) {
  267. obj['objId'] = this.nodeData?.id;
  268. obj['objParentId'] = this.nodeData?.parentId;
  269. }
  270. let data = await listParentId(obj);
  271. this.options = data.list.filter((item) => item.type == 2);
  272. this.form.businessCodeId = '';
  273. },
  274. fileChange(file) {
  275. this.form.name = file.name.replace(/\.[^/.]+$/, '');
  276. },
  277. /* 保存编辑 */
  278. save() {
  279. this.$refs.form.validate(async (valid) => {
  280. if (!valid) {
  281. return false;
  282. }
  283. let data = {
  284. ...this.form
  285. };
  286. if (this.activeName == 2) {
  287. data.fileType = 1;
  288. }
  289. this.loading = true;
  290. fileSaveAPI(data)
  291. .then((msg) => {
  292. this.loading = false;
  293. this.cancel();
  294. this.$emit('done', msg);
  295. })
  296. .catch((e) => {
  297. this.loading = false;
  298. });
  299. });
  300. },
  301. cancel() {
  302. this.form = { ...this.defaultForm, directoryId: this.form.directoryId };
  303. this.$refs.form.clearValidate();
  304. this.showEditFlag = false;
  305. }
  306. }
  307. };
  308. </script>
  309. <style scoped lang="scss">
  310. .aaa {
  311. width: 100%;
  312. ::v-deep .upload-demo {
  313. width: 100%;
  314. .el-upload--text {
  315. width: 100%;
  316. button {
  317. width: 100%;
  318. background: #ffffff;
  319. border: 1px solid #dbdbdb;
  320. border-radius: 5px;
  321. }
  322. }
  323. .el-upload-list {
  324. transform: translate(10px, -39px);
  325. position: absolute;
  326. }
  327. }
  328. }
  329. </style>