file-edit.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. if (!this.form.directoryName) {
  224. this.$refs.uToast.show({
  225. type: "error",
  226. message: "请选择文档位置",
  227. })
  228. return
  229. }
  230. if (!this.form.businessCodeId) {
  231. this.$refs.uToast.show({
  232. type: "error",
  233. message: "请选择编码方案",
  234. })
  235. return
  236. }
  237. uni.showLoading({
  238. title: '加载中'
  239. })
  240. this.form.storagePath = await this.uploadFile(this.files)
  241. let params = {
  242. ...this.form
  243. }
  244. delete params.codeTypeName
  245. delete params.directoryName
  246. fileSaveAPI(this.form)
  247. .then((msg) => {
  248. uni.hideLoading()
  249. console.log(msg, 'msg')
  250. this.$emit('success', msg);
  251. this.cancel()
  252. })
  253. .catch((e) => {
  254. uni.hideLoading()
  255. this.cancel()
  256. });
  257. },
  258. cancel() {
  259. this.form = {
  260. ...this.defaultForm
  261. };
  262. this.files = []
  263. this.show = false;
  264. }
  265. }
  266. };
  267. </script>
  268. <style scoped lang="scss">
  269. .aaa {
  270. width: 100%;
  271. ::v-deep .upload-demo {
  272. width: 100%;
  273. .el-upload--text {
  274. width: 100%;
  275. button {
  276. width: 100%;
  277. background: #ffffff;
  278. border: 1px solid #dbdbdb;
  279. border-radius: 5px;
  280. }
  281. }
  282. .el-upload-list {
  283. transform: translate(10px, -39px);
  284. position: absolute;
  285. }
  286. }
  287. }
  288. .fileList {
  289. padding: 0;
  290. /deep/.upload-area {
  291. height: 90rpx;
  292. width: 140rpx;
  293. }
  294. /deep/.file-item {
  295. padding: 0;
  296. margin-bottom: 8rpx;
  297. }
  298. }
  299. .btn {
  300. margin-top: 16rpx;
  301. margin-bottom: 10rpx;
  302. display: flex;
  303. uni-bottom {
  304. width: 160rpx;
  305. }
  306. }
  307. // /deep/.u-form-item__body {
  308. // padding: 16rpx 0
  309. // }
  310. /deep/ .u-form {
  311. padding: 30rpx;
  312. }
  313. </style>