file-edit.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <u-popup :show="show" @close="cancel" :closeable="true">
  3. <view style="width: 750rpx;">
  4. <u-cell-group>
  5. <u-cell title="编码分类">
  6. <u--input slot="value" placeholder="请选择" border="surround" v-model="form.codeTypeName"
  7. @click.native="codeTypeOpen"></u--input>
  8. </u-cell>
  9. <u-cell title="编码方案">
  10. <uni-data-picker :map="{text:'name',value:'id'}" v-model="form.businessCodeId" slot="value"
  11. placeholder="请选择" :localdata="options">
  12. </uni-data-picker>
  13. </u-cell>
  14. <u-cell title="文档类型">
  15. <uni-data-picker v-model="form.type" slot="value" placeholder="请选择" :localdata="doc_type">
  16. </uni-data-picker>
  17. </u-cell>
  18. <u-cell title="文档">
  19. <fileSelector class="fileList" slot="value"
  20. @filesChanged="onFilesChanged" />
  21. </u-cell>
  22. <u-cell title="文档位置">
  23. <u--input slot="value" placeholder="请选择" border="surround" v-model="form.directoryName"
  24. @click.native="directoryIdOpen">
  25. </u--input>
  26. </u-cell>
  27. </u-cell-group>
  28. <view class="btn">
  29. <u-button type="primary" @click="cancel" text="返回"></u-button>
  30. <u-button @click="save" text="保存"></u-button>
  31. </view>
  32. </view>
  33. <ba-tree-picker ref="codeTypeRef" key="verify" :multiple="false" @select-change="codeTypeBack" title="选择编码分类"
  34. :localdata="list" valueKey="id" textKey="name" childrenKey='sonDirectoryList' />
  35. <ba-tree-picker ref="directoryIdRef" :multiple="false" @select-change="directoryIdBack" title="选择文档位置"
  36. :localdata="folderList" valueKey="id" textKey="name" childrenKey='sonDirectoryList' />
  37. </u-popup>
  38. </template>
  39. <script>
  40. import {
  41. fileSaveAPI,
  42. selectTreeList,
  43. listParentId,
  44. getDocTreeListAPI,
  45. listCode
  46. } from './api/index';
  47. import {
  48. getByCode
  49. } from '@/api/pda/common.js'
  50. import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue"
  51. // 引入组件
  52. import fileSelector from '@/uni_modules/zhouquan-fileSelector/components/zhouquan-fileSelector/file-selector.vue';
  53. export default {
  54. components: {
  55. baTreePicker,
  56. fileSelector
  57. },
  58. data() {
  59. const defaultForm = {
  60. name: '', //名称
  61. type: '', //类型
  62. sizeUnit: '', //大小,
  63. unit: '', //单位
  64. remark: '', //备注
  65. status: '', //状态
  66. storagePathId: '',
  67. directoryId: '',
  68. businessCodeId: '',
  69. storagePath: [],
  70. id: '',
  71. lcyStatus: 1,
  72. fileType: 0,
  73. codeTypeName: '',
  74. directoryName: '',
  75. };
  76. return {
  77. folderList: [],
  78. files: [],
  79. // 表单数据
  80. form: {
  81. ...defaultForm
  82. },
  83. list: [],
  84. options: [],
  85. show: false,
  86. doc_type: []
  87. };
  88. },
  89. async created() {
  90. this.userInfo = uni.getStorageSync('userInfo')
  91. let query = {
  92. type: 0,
  93. currentUserId: this.userInfo.userId
  94. };
  95. this.folderList = await getDocTreeListAPI(query);
  96. const doc_type = await getByCode('doc_type');
  97. this.doc_type = doc_type.map(item => {
  98. const key = Object.keys(item)[0]
  99. return {
  100. value: key,
  101. text: item[key]
  102. }
  103. })
  104. },
  105. methods: {
  106. async open() {
  107. this.show = true;
  108. this.list = await selectTreeList();
  109. this.options = await listCode();
  110. if (this.options.length > 0) {
  111. this.form.businessCodeId = this.options[0].id
  112. }
  113. this.setTree(this.list);
  114. },
  115. setTree(data) {
  116. data.forEach((item) => {
  117. item.sonDirectoryList = item.sonDirectoryList.filter(
  118. (item) => item.type == 1
  119. );
  120. if (item.sonDirectoryList.length > 0) {
  121. this.setTree(item.sonDirectoryList);
  122. }
  123. });
  124. },
  125. codeTypeOpen() {
  126. this.$refs.codeTypeRef._show()
  127. },
  128. async codeTypeBack(data, name) {
  129. let list = await listParentId({
  130. pageNum: 1,
  131. size: 100,
  132. parentId: data[0]
  133. });
  134. this.form.codeTypeName = name
  135. this.form.codeType = data[0]
  136. this.options = list.list.filter((item) => item.type == 2);
  137. this.form.businessCodeId = '';
  138. },
  139. uploadFile(list) {
  140. let PromiseAll = []
  141. const apiUrl = this.apiUrl
  142. const token = uni.getStorageSync("token"); //取存本地的token
  143. list.forEach(item => {
  144. PromiseAll.push(
  145. new Promise((resolve, reject) => {
  146. uni.uploadFile({
  147. url: apiUrl + '/main/file/uploadFile',
  148. filePath: item.path,
  149. name: 'multiPartFile',
  150. header: {
  151. authorization: token
  152. },
  153. success: (uploadFileRes) => {
  154. let data = JSON.parse(uploadFileRes.data)
  155. resolve(data.data)
  156. }
  157. });
  158. }),
  159. )
  160. })
  161. return Promise.all(PromiseAll)
  162. },
  163. directoryIdOpen() {
  164. this.$refs.directoryIdRef._show()
  165. },
  166. directoryIdBack(data, name) {
  167. this.form.directoryName = name
  168. this.form.directoryId = data[0]
  169. },
  170. // 当文件发生变化时触发
  171. onFilesChanged(fileList) {
  172. this.files = fileList
  173. // console.log('文件列表:', fileList)
  174. },
  175. /* 保存编辑 */
  176. async save() {
  177. uni.showLoading({
  178. title: '加载中'
  179. })
  180. this.form.storagePath = await this.uploadFile(this.files)
  181. fileSaveAPI(this.form)
  182. .then((msg) => {
  183. uni.hideLoading()
  184. console.log(msg,'msg')
  185. this.$emit('success', msg);
  186. this.cancel()
  187. })
  188. .catch((e) => {
  189. uni.hideLoading()
  190. this.cancel()
  191. });
  192. },
  193. cancel() {
  194. this.form = {
  195. ...this.defaultForm
  196. };
  197. this.files = []
  198. this.show = false;
  199. }
  200. }
  201. };
  202. </script>
  203. <style scoped lang="scss">
  204. .aaa {
  205. width: 100%;
  206. ::v-deep .upload-demo {
  207. width: 100%;
  208. .el-upload--text {
  209. width: 100%;
  210. button {
  211. width: 100%;
  212. background: #ffffff;
  213. border: 1px solid #dbdbdb;
  214. border-radius: 5px;
  215. }
  216. }
  217. .el-upload-list {
  218. transform: translate(10px, -39px);
  219. position: absolute;
  220. }
  221. }
  222. }
  223. .fileList {
  224. padding: 0;
  225. /deep/.upload-area {
  226. height: 90rpx;
  227. width: 140rpx;
  228. }
  229. /deep/.file-item {
  230. padding: 0;
  231. margin-bottom: 8rpx;
  232. }
  233. }
  234. .btn{
  235. margin-top: 16rpx;
  236. margin-bottom: 10rpx;
  237. display: flex;
  238. uni-bottom{
  239. width: 160rpx;
  240. }
  241. }
  242. </style>