file-edit.vue 10.0 KB

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