file-edit.vue 8.2 KB

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