edit.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <el-dialog
  3. :title="refList.title"
  4. :visible.sync="dialogVisible"
  5. width="33%"
  6. :before-close="handleClose"
  7. v-loading.fullscreen.lock="fullscreenLoading"
  8. >
  9. <el-form :model="form" ref="form" :rules="rules" label-width="100px">
  10. <el-form-item label="分类名称:" prop="typeId">
  11. <el-select
  12. placeholder="请选择"
  13. v-model="form.typeId"
  14. @visible-change="visbleChange"
  15. @change="classifyChange"
  16. >
  17. <el-option
  18. v-for="(item,index) in classifyList"
  19. :key="index"
  20. :label="item.name"
  21. :value="item.typeId"
  22. >
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="文件名称:" prop="name">
  27. <el-input placeholder="请输入" v-model.trim="form.name"></el-input>
  28. </el-form-item>
  29. <el-form-item label="上传文件:" prop="docUrl">
  30. <div>
  31. <el-upload
  32. class="upload-demo"
  33. action
  34. :http-request="api_import"
  35. :on-success="handleSuccess"
  36. :on-remove="handleRemove"
  37. multiple
  38. :limit="1"
  39. :on-exceed="handleExceed"
  40. :file-list="fileList"
  41. :before-upload="beforeAvatarUpload"
  42. >
  43. <el-button size="small" type="primary">点击上传</el-button>
  44. <div slot="tip" class="el-upload__tip">仅支持pdf文件</div>
  45. </el-upload>
  46. </div>
  47. </el-form-item>
  48. <el-form-item required>
  49. <template slot="label" class="status"
  50. ><span>状&#8195;&emsp;态</span>:</template
  51. >
  52. <el-radio-group v-model="form.status">
  53. <el-radio :label="1">启用</el-radio>
  54. <el-radio :label="0">禁用</el-radio>
  55. </el-radio-group>
  56. </el-form-item>
  57. </el-form>
  58. <span slot="footer" class="dialog-footer">
  59. <el-button size="small" @click="handleClose">取 消</el-button>
  60. <el-button
  61. size="small"
  62. style="margin-left: 60px"
  63. type="primary"
  64. @click="addList('form')"
  65. >确 定</el-button
  66. >
  67. </span>
  68. </el-dialog>
  69. </template>
  70. <script>
  71. import * as api from '@/api/api'
  72. export default {
  73. data() {
  74. return {
  75. fullscreenLoading:false,
  76. dialogVisible: false,
  77. form: {
  78. docUrl: '',
  79. id: '',
  80. linkUrl: '',
  81. name: '',
  82. status: 0,
  83. typeId: ''
  84. },
  85. refList: {},
  86. fileList: [],
  87. classifyList: [],
  88. rules:{
  89. typeId:[{required:true,trigger:'change',message:'请选择分类名称'}],
  90. name:[{required:true,trigger:'blur',message:'请输入文件名称'}],
  91. docUrl:[{required:true,trigger:'click',message:'请上传文件'}]
  92. }
  93. }
  94. },
  95. methods: {
  96. /**
  97. * @method 关闭弹框
  98. * **/
  99. handleClose() {
  100. this.dialogVisible = false
  101. this.$parent.search()
  102. this.form = {
  103. docUrl: '',
  104. id: '',
  105. linkUrl: '',
  106. name: '',
  107. status: 0,
  108. typeId: '',
  109. fileSize: ''
  110. }
  111. this.fileList = []
  112. this.$refs['form'].resetFields()
  113. },
  114. /**
  115. * @method 打开文件弹框
  116. * **/
  117. openClose(val) {
  118. if (val) {
  119. this.refList = val
  120. if (val.id) {
  121. this.visbleChange(true)
  122. this.details()
  123. }
  124. }
  125. this.dialogVisible = true
  126. },
  127. /**
  128. * @method 详情
  129. * **/
  130. details() {
  131. api.GET('/doc/getDetail', { id: this.refList.id }).then(data => {
  132. if (data.code == 0) {
  133. this.form = data.data
  134. this.fileList = [{name:this.form.name,url:this.form.docUrl}]
  135. }
  136. })
  137. },
  138. /**
  139. * @method 分类下拉列表
  140. * **/
  141. visbleChange(val) {
  142. if (val) {
  143. api.POST('/doc/type/dropList').then(data => {
  144. if (data.code == 0) {
  145. this.classifyList = data.data
  146. }
  147. })
  148. }
  149. },
  150. /**
  151. * @method 分类选择
  152. * **/
  153. classifyChange(val) {
  154. this.classifyList.find(item => {
  155. if (item.typeId == val) {
  156. this.form.linkUrl = item.linkUrl
  157. }
  158. })
  159. },
  160. /**
  161. * @method 上传
  162. * **/
  163. api_import(file) {
  164. const files = {
  165. file: file.file
  166. }
  167. api.IMPORT('/api/file/local/upload', files).then(data => {
  168. if (data.code == 0) {
  169. data.data.name = data.data.fileName
  170. this.fileList = [data.data]
  171. this.form.docUrl = data.data.url
  172. this.form.fileSize = data.data.size
  173. this.$message.success('上传成功')
  174. }
  175. }).catch(()=>{
  176. this.fileList = []
  177. })
  178. },
  179. /**
  180. * @method 文件上传限制
  181. * **/
  182. handleExceed(files, fileList) {
  183. if (fileList.length == 1) {
  184. this.$message.warning('只能上传单个文件')
  185. }
  186. },
  187. /**
  188. * @method 上传成功
  189. * **/
  190. handleSuccess(file,fileList) {
  191. console.log(file,fileList)
  192. },
  193. /**
  194. * @method 文件删除
  195. * **/
  196. handleRemove(files, fileList) {
  197. this.fileList = fileList
  198. this.form.docUrl = ''
  199. this.form.fileSize = ''
  200. },
  201. /**
  202. * @method 上传限制
  203. * **/
  204. beforeAvatarUpload(file) {
  205. const ispaf = file.type === 'application/pdf'
  206. if (!ispaf) {
  207. this.$message.error('上传文件只能是 PDF 格式!')
  208. }
  209. return ispaf
  210. },
  211. /**
  212. * @method 提交确定
  213. * **/
  214. addList(formName) {
  215. this.$refs[formName].validate(valid => {
  216. if (valid) {
  217. this.fullscreenLoading = true
  218. let code = {
  219. docUrl: this.form.docUrl,
  220. linkUrl: this.form.linkUrl,
  221. name: this.form.name,
  222. status: this.form.status,
  223. typeId: this.form.typeId,
  224. fileSize: this.form.fileSize
  225. }
  226. this.refList.show ? this.addfile(code) : this.editfile(code)
  227. }
  228. })
  229. },
  230. /**
  231. * @method 新增文件
  232. * **/
  233. addfile(val) {
  234. api.POST('/doc/addDoc', val).then(data => {
  235. if (data.code == 0) {
  236. this.$message.success(data.message)
  237. this.handleClose()
  238. this.fullscreenLoading = false
  239. }
  240. }).catch(()=>{
  241. this.fullscreenLoading = false
  242. })
  243. },
  244. /**
  245. * @method 编辑文件
  246. * **/
  247. editfile(val) {
  248. val.id = this.form.id
  249. api.PUT('/doc/updateDoc',val).then(data => {
  250. if (data.code == 0) {
  251. this.$message.success(data.message)
  252. this.handleClose()
  253. this.fullscreenLoading = false
  254. }
  255. }).catch(()=>{
  256. this.fullscreenLoading = false
  257. })
  258. }
  259. }
  260. }
  261. </script>
  262. <style lang="less" scoped>
  263. </style>