file-edit.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. nodeData: {}
  111. };
  112. },
  113. computed: {
  114. rules() {
  115. return {
  116. 'directoryName': {
  117. type: 'string',
  118. required: true,
  119. message: '请选择文档位置',
  120. trigger: ['blur', 'change']
  121. },
  122. 'businessCodeId': {
  123. type: 'string',
  124. required: true,
  125. message: '请选择编码方案',
  126. trigger: ['blur', 'change']
  127. },
  128. 'codeTypeName': {
  129. type: 'string',
  130. required: this.current == 1 ? true : false,
  131. message: '请选择编码分类',
  132. trigger: ['blur', 'change']
  133. },
  134. }
  135. }
  136. },
  137. async created() {
  138. this.userInfo = uni.getStorageSync('userInfo')
  139. this.allFolderList = await getDocTreeListAPI({
  140. type: 0,
  141. currentUserId: this.userInfo.userId
  142. });
  143. this.myFolderList = await getDocTreeListAPI({
  144. type: 1,
  145. currentUserId: this.userInfo.userId
  146. });
  147. this.folderList = JSON.parse(JSON.stringify(this.allFolderList));
  148. const doc_type = await getByCode('doc_type');
  149. this.doc_type = doc_type.map(item => {
  150. const key = Object.keys(item)[0]
  151. return {
  152. value: key,
  153. text: item[key]
  154. }
  155. })
  156. },
  157. methods: {
  158. async open() {
  159. this.show = true;
  160. // this.current = 0
  161. this.list = await selectTreeList();
  162. this.options = await listCode();
  163. if (this.options.length > 0) {
  164. this.form.businessCodeId = this.options[0].id
  165. }
  166. this.setTree(this.list);
  167. },
  168. setTree(data) {
  169. data.forEach((item) => {
  170. item.sonDirectoryList = item.sonDirectoryList.filter(
  171. (item) => item.type == 1
  172. );
  173. if (item.sonDirectoryList.length > 0) {
  174. this.setTree(item.sonDirectoryList);
  175. }
  176. });
  177. },
  178. codeTypeOpen() {
  179. this.$refs.codeTypeRef._show()
  180. },
  181. async directoryIdBack(data) {
  182. console.log(data);
  183. this.form.directoryName = data.name
  184. this.form.directoryId = data.id
  185. if (this.current != 1) {
  186. this.nodeData.id = data?.id
  187. this.nodeData.parentId = data.parentId == -1 ? '' : data.parentId
  188. }
  189. this.options = this.nodeData.id ? await listCode(this.nodeData) : [];
  190. if (this.options.length > 0) {
  191. this.form.businessCodeId = this.options[0].id;
  192. this.form.codeType = this.options[0].parentId;
  193. } else {
  194. this.form.businessCodeId = '';
  195. }
  196. // this.form.directoryName = name
  197. // this.form.directoryId = data[0]
  198. },
  199. async codeTypeBack(data, name) {
  200. console.log(data);
  201. let list = await listParentId({
  202. pageNum: 1,
  203. size: 100,
  204. parentId: data.id,
  205. objId: this.nodeData?.id,
  206. objParentId: this.nodeData?.parentId
  207. });
  208. // this.form.codeTypeName = data.name
  209. // this.form.codeType = data
  210. this.options = list.list.filter((item) => item.type == 2);
  211. this.form.codeType = data.id;
  212. this.form.codeTypeName = data.name;
  213. this.form.businessCodeId = '';
  214. },
  215. uploadFile(list) {
  216. let PromiseAll = []
  217. const apiUrl = this.apiUrl
  218. const token = uni.getStorageSync("token"); //取存本地的token
  219. list.forEach(item => {
  220. PromiseAll.push(
  221. new Promise((resolve, reject) => {
  222. uni.uploadFile({
  223. url: apiUrl + '/main/file/uploadFile',
  224. filePath: item.path,
  225. name: 'multiPartFile',
  226. header: {
  227. authorization: token
  228. },
  229. success: (uploadFileRes) => {
  230. let data = JSON.parse(uploadFileRes.data)
  231. resolve(data.data)
  232. }
  233. });
  234. }),
  235. )
  236. })
  237. return Promise.all(PromiseAll)
  238. },
  239. directoryIdOpen() {
  240. this.$refs.directoryIdRef._show()
  241. },
  242. // 当文件发生变化时触发
  243. onFilesChanged(fileList) {
  244. console.log(fileList);
  245. this.files = fileList
  246. this.form.name = fileList[0].name.replace(/\.[^/.]+$/, '');
  247. // console.log('文件列表:', fileList)
  248. },
  249. sectionChange(index) {
  250. this.form.directoryId = '';
  251. this.form.businessCodeId = '';
  252. this.form.codeType = '';
  253. this.current = index;
  254. if (index == 1) {
  255. this.folderList = JSON.parse(JSON.stringify(this.myFolderList));
  256. } else {
  257. this.folderList = JSON.parse(JSON.stringify(this.allFolderList));
  258. }
  259. },
  260. /* 保存编辑 */
  261. async save() {
  262. if (!this.form.directoryName) {
  263. this.$refs.uToast.show({
  264. type: "error",
  265. message: "请选择文档位置",
  266. })
  267. return
  268. }
  269. if (!this.form.businessCodeId) {
  270. this.$refs.uToast.show({
  271. type: "error",
  272. message: "请选择编码方案",
  273. })
  274. return
  275. }
  276. uni.showLoading({
  277. title: '加载中'
  278. })
  279. this.form.storagePath = await this.uploadFile(this.files)
  280. // let params = {
  281. // ...this.form
  282. // }
  283. // delete params.codeTypeName
  284. // delete params.directoryName
  285. fileSaveAPI({
  286. ...this.form,
  287. fileType: this.current == 1 ? 1 : 0
  288. })
  289. .then((msg) => {
  290. uni.hideLoading()
  291. console.log(msg, 'msg')
  292. this.$emit('success', msg);
  293. this.cancel()
  294. })
  295. .catch((e) => {
  296. uni.hideLoading()
  297. this.cancel()
  298. });
  299. },
  300. cancel() {
  301. this.form = {
  302. ...this.defaultForm
  303. };
  304. this.files = []
  305. this.show = false;
  306. }
  307. }
  308. };
  309. </script>
  310. <style scoped lang="scss">
  311. .aaa {
  312. width: 100%;
  313. ::v-deep .upload-demo {
  314. width: 100%;
  315. .el-upload--text {
  316. width: 100%;
  317. button {
  318. width: 100%;
  319. background: #ffffff;
  320. border: 1px solid #dbdbdb;
  321. border-radius: 5px;
  322. }
  323. }
  324. .el-upload-list {
  325. transform: translate(10px, -39px);
  326. position: absolute;
  327. }
  328. }
  329. }
  330. .fileList {
  331. padding: 0;
  332. /deep/.upload-area {
  333. height: 90rpx;
  334. width: 140rpx;
  335. }
  336. /deep/.file-item {
  337. padding: 0;
  338. margin-bottom: 8rpx;
  339. }
  340. }
  341. .btn {
  342. margin-top: 16rpx;
  343. margin-bottom: 10rpx;
  344. display: flex;
  345. uni-bottom {
  346. width: 160rpx;
  347. }
  348. }
  349. // /deep/.u-form-item__body {
  350. // padding: 16rpx 0
  351. // }
  352. /deep/ .u-form {
  353. padding: 30rpx;
  354. }
  355. /deep/.u-subsection__item__text {
  356. font-size: 26rpx !important;
  357. }
  358. </style>