file-edit.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  1. <template>
  2. <u-popup :show="show" @close="cancel" :closeable="false">
  3. <view style="width: 750rpx;">
  4. <u--form ref="uForm" labelPosition="left" :model="form" labelWidth="180" labelAlign="left" :rules="rules">
  5. <u-form-item label="文档位置" prop="directoryName">
  6. <u--input placeholder="请选择" border="surround" v-model="form.directoryName"
  7. @click.native="directoryIdOpen">
  8. </u--input>
  9. </u-form-item>
  10. <u-form-item label="编码分类" prop="codeTypeName">
  11. <u--input placeholder="请选择" border="surround" v-model="form.codeTypeName"
  12. @click.native="codeTypeOpen">
  13. </u--input>
  14. </u-form-item>
  15. <u-form-item label="编码方案" prop="businessCodeId">
  16. <zxz-uni-data-select :localdata="options" v-model="form.businessCodeId" dataValue='id'
  17. dataKey="name"></zxz-uni-data-select>
  18. </u-form-item>
  19. <!-- <u-cell title="编码方案">
  20. <uni-data-picker :map="{text:'name',value:'id'}" v-model="form.businessCodeId" slot="value"
  21. placeholder="请选择" :localdata="options">
  22. </uni-data-picker>
  23. </u-cell> -->
  24. <!-- <u-cell title="文档类型">
  25. <uni-data-picker v-model="form.type" slot="value" placeholder="请选择" :localdata="doc_type">
  26. </uni-data-picker>
  27. </u-cell> -->
  28. <u-form-item label="文档类型" prop="type">
  29. <zxz-uni-data-select :localdata="doc_type" v-model="form.type" dataValue='value'
  30. dataKey="text"></zxz-uni-data-select>
  31. </u-form-item>
  32. <!-- <u-form-item :label="文档类型" prop="form.type">
  33. <zxz-uni-data-select :localdata="doc_type" v-model="form.type" dataValue='value'
  34. dataKey="text"></zxz-uni-data-select>
  35. </u-form-item> -->
  36. <u-cell title="文档">
  37. <fileSelector class="fileList" slot="value" @filesChanged="onFilesChanged" />
  38. </u-cell>
  39. <view class="btn">
  40. <u-button type="primary" @click="cancel" text="返回"></u-button>
  41. <u-button @click="save" text="保存"></u-button>
  42. </view>
  43. </u--form>
  44. </view>
  45. <u-toast ref="uToast"></u-toast>
  46. <ba-tree-picker ref="directoryIdRef" :multiple="false" title="选择文档位置" :localdata="folderList" valueKey="id"
  47. textKey="name" childrenKey='sonDirectoryList' @select-row="directoryIdBack">
  48. <template #toolbar>
  49. <view class="toolbar">
  50. <u-subsection :list="currentList" :current="current" @change="sectionChange"></u-subsection>
  51. </view>
  52. </template>
  53. </ba-tree-picker>
  54. <ba-tree-picker ref="codeTypeRef" key="verify" :multiple="false" @select-row="codeTypeBack" title="选择编码分类"
  55. :localdata="list" valueKey="id" textKey="name" childrenKey='sonDirectoryList' />
  56. </u-popup>
  57. </template>
  58. <script>
  59. import {
  60. fileSaveAPI,
  61. selectTreeList,
  62. listParentId,
  63. getDocTreeListAPI,
  64. listCode
  65. } from './api/index';
  66. import {
  67. getByCode
  68. } from '@/api/pda/common.js'
  69. import baTreePicker from "@/components/ba-tree-picker/ba-tree-picker.vue"
  70. // 引入组件
  71. import fileSelector from '@/uni_modules/zhouquan-fileSelector/components/zhouquan-fileSelector/file-selector.vue';
  72. export default {
  73. components: {
  74. baTreePicker,
  75. fileSelector
  76. },
  77. data() {
  78. const defaultForm = {
  79. name: '', //名称
  80. type: '', //类型
  81. sizeUnit: '', //大小,
  82. unit: '', //单位
  83. remark: '', //备注
  84. status: '', //状态
  85. storagePathId: '',
  86. directoryId: '',
  87. businessCodeId: '',
  88. storagePath: [],
  89. id: '',
  90. lcyStatus: 1,
  91. fileType: 0,
  92. codeTypeName: '',
  93. directoryName: '',
  94. };
  95. return {
  96. currentList: ['文档工作区', '个人文档区'],
  97. current: 0,
  98. folderList: [],
  99. allFolderList: [],
  100. myFolderList: [],
  101. files: [],
  102. // 表单数据
  103. form: {
  104. ...defaultForm
  105. },
  106. list: [],
  107. options: [],
  108. show: false,
  109. doc_type: [],
  110. rules: {
  111. 'directoryName': {
  112. type: 'string',
  113. required: true,
  114. message: '请选择文档位置',
  115. trigger: ['blur', 'change']
  116. },
  117. 'businessCodeId': {
  118. type: 'string',
  119. required: true,
  120. message: '请选择编码方案',
  121. trigger: ['blur', 'change']
  122. },
  123. },
  124. nodeData: {}
  125. };
  126. },
  127. async created() {
  128. this.userInfo = uni.getStorageSync('userInfo')
  129. this.allFolderList = await getDocTreeListAPI({
  130. type: 0,
  131. currentUserId: this.userInfo.userId
  132. });
  133. this.myFolderList = await getDocTreeListAPI({
  134. type: 1,
  135. currentUserId: this.userInfo.userId
  136. });
  137. this.folderList = JSON.parse(JSON.stringify(this.allFolderList));
  138. const doc_type = await getByCode('doc_type');
  139. this.doc_type = doc_type.map(item => {
  140. const key = Object.keys(item)[0]
  141. return {
  142. value: key,
  143. text: item[key]
  144. }
  145. })
  146. },
  147. methods: {
  148. async open() {
  149. this.show = true;
  150. // this.current = 0
  151. this.list = await selectTreeList();
  152. this.options = await listCode();
  153. if (this.options.length > 0) {
  154. this.form.businessCodeId = this.options[0].id
  155. }
  156. this.setTree(this.list);
  157. },
  158. setTree(data) {
  159. data.forEach((item) => {
  160. item.sonDirectoryList = item.sonDirectoryList.filter(
  161. (item) => item.type == 1
  162. );
  163. if (item.sonDirectoryList.length > 0) {
  164. this.setTree(item.sonDirectoryList);
  165. }
  166. });
  167. },
  168. codeTypeOpen() {
  169. this.$refs.codeTypeRef._show()
  170. },
  171. async directoryIdBack(data) {
  172. console.log(data);
  173. this.form.directoryName = data.name
  174. this.form.directoryId = data.id
  175. if (this.current != 1) {
  176. this.nodeData.id = data?.id
  177. this.nodeData.parentId = data.parentId == -1 ? '' : data.parentId
  178. }
  179. this.options = this.nodeData.id ? await listCode(this.nodeData) : [];
  180. if (this.options.length > 0) {
  181. this.form.businessCodeId = this.options[0].id;
  182. this.form.codeType = this.options[0].parentId;
  183. } else {
  184. this.form.businessCodeId = '';
  185. }
  186. // this.form.directoryName = name
  187. // this.form.directoryId = data[0]
  188. },
  189. async codeTypeBack(data, name) {
  190. console.log(data);
  191. let list = await listParentId({
  192. pageNum: 1,
  193. size: 100,
  194. parentId: data.id,
  195. objId: this.nodeData?.id,
  196. objParentId: this.nodeData?.parentId
  197. });
  198. // this.form.codeTypeName = data.name
  199. // this.form.codeType = data
  200. this.options = list.list.filter((item) => item.type == 2);
  201. this.form.codeType = data.id;
  202. this.form.codeTypeName = data.name;
  203. this.form.businessCodeId = '';
  204. },
  205. uploadFile(list) {
  206. let PromiseAll = []
  207. const apiUrl = this.apiUrl
  208. const token = uni.getStorageSync("token"); //取存本地的token
  209. list.forEach(item => {
  210. PromiseAll.push(
  211. new Promise((resolve, reject) => {
  212. uni.uploadFile({
  213. url: apiUrl + '/main/file/uploadFile',
  214. filePath: item.path,
  215. name: 'multiPartFile',
  216. header: {
  217. authorization: token
  218. },
  219. success: (uploadFileRes) => {
  220. let data = JSON.parse(uploadFileRes.data)
  221. resolve(data.data)
  222. }
  223. });
  224. }),
  225. )
  226. })
  227. return Promise.all(PromiseAll)
  228. },
  229. directoryIdOpen() {
  230. this.$refs.directoryIdRef._show()
  231. },
  232. // 当文件发生变化时触发
  233. onFilesChanged(fileList) {
  234. console.log(fileList);
  235. this.files = fileList
  236. this.form.name = fileList[0].name.replace(/\.[^/.]+$/, '');
  237. // console.log('文件列表:', fileList)
  238. },
  239. sectionChange(index) {
  240. this.form.directoryId = '';
  241. this.form.businessCodeId = '';
  242. this.form.codeType = '';
  243. this.current = index;
  244. if (index == 1) {
  245. this.folderList = JSON.parse(JSON.stringify(this.myFolderList));
  246. } else {
  247. this.folderList = JSON.parse(JSON.stringify(this.allFolderList));
  248. }
  249. },
  250. /* 保存编辑 */
  251. async save() {
  252. if (!this.form.directoryName) {
  253. this.$refs.uToast.show({
  254. type: "error",
  255. message: "请选择文档位置",
  256. })
  257. return
  258. }
  259. if (!this.form.businessCodeId) {
  260. this.$refs.uToast.show({
  261. type: "error",
  262. message: "请选择编码方案",
  263. })
  264. return
  265. }
  266. uni.showLoading({
  267. title: '加载中'
  268. })
  269. this.form.storagePath = await this.uploadFile(this.files)
  270. // let params = {
  271. // ...this.form
  272. // }
  273. // delete params.codeTypeName
  274. // delete params.directoryName
  275. fileSaveAPI({
  276. ...this.form,
  277. fileType: this.current == 1 ? 1 : 0
  278. })
  279. .then((msg) => {
  280. uni.hideLoading()
  281. console.log(msg, 'msg')
  282. this.$emit('success', msg);
  283. this.cancel()
  284. })
  285. .catch((e) => {
  286. uni.hideLoading()
  287. this.cancel()
  288. });
  289. },
  290. cancel() {
  291. this.form = {
  292. ...this.defaultForm
  293. };
  294. this.files = []
  295. this.show = false;
  296. }
  297. }
  298. };
  299. </script>
  300. <style scoped lang="scss">
  301. .aaa {
  302. width: 100%;
  303. ::v-deep .upload-demo {
  304. width: 100%;
  305. .el-upload--text {
  306. width: 100%;
  307. button {
  308. width: 100%;
  309. background: #ffffff;
  310. border: 1px solid #dbdbdb;
  311. border-radius: 5px;
  312. }
  313. }
  314. .el-upload-list {
  315. transform: translate(10px, -39px);
  316. position: absolute;
  317. }
  318. }
  319. }
  320. .fileList {
  321. padding: 0;
  322. /deep/.upload-area {
  323. height: 90rpx;
  324. width: 140rpx;
  325. }
  326. /deep/.file-item {
  327. padding: 0;
  328. margin-bottom: 8rpx;
  329. }
  330. }
  331. .btn {
  332. margin-top: 16rpx;
  333. margin-bottom: 10rpx;
  334. display: flex;
  335. uni-bottom {
  336. width: 160rpx;
  337. }
  338. }
  339. // /deep/.u-form-item__body {
  340. // padding: 16rpx 0
  341. // }
  342. /deep/ .u-form {
  343. padding: 30rpx;
  344. }
  345. /deep/.u-subsection__item__text {
  346. font-size: 26rpx !important;
  347. }
  348. </style>