file-edit.vue 8.3 KB

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