qualifications.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="app-container">
  3. <el-button size="small" type="primary" @click="openDialog(false, null)" :loading="loading">添加</el-button>
  4. <el-table :data="cooperations" style="width: 100%">
  5. <el-table-column type="index" width="50"></el-table-column>
  6. <el-table-column label="图片" width="200">
  7. <template slot-scope="scope">
  8. <el-image :src="scope.row.imgUrl"></el-image>
  9. <!-- style="width: 200px; height: 200px" -->
  10. </template>
  11. </el-table-column>
  12. <el-table-column prop="title" label="名称" width="150"></el-table-column>
  13. <el-table-column prop="content" label="描述"></el-table-column>
  14. <el-table-column label="操作" width="300">
  15. <template slot-scope="scope">
  16. <el-button size="small" @click="openDialog(true, scope.$index)" :loading="loading">编辑</el-button>
  17. <el-button size="small" type="danger" @click="deleteCooperation(scope.row.id)" :loading="loading">删除</el-button>
  18. </template>
  19. </el-table-column>
  20. </el-table>
  21. <!-- 添加和编辑的dialog -->
  22. <el-dialog title="荣誉资质" :visible.sync="addDialogVisible" width="500px">
  23. <el-form ref="form" :model="cooperationsForm" :rules="rules" label-width="80px">
  24. <el-form-item label="名称" prop="name">
  25. <el-input v-model="cooperationsForm.name" placeholder="请输入名称" clearable></el-input>
  26. </el-form-item>
  27. <el-form-item label="描述" prop="description">
  28. <el-input v-model="cooperationsForm.description" placeholder="请输入描述" clearable></el-input>
  29. </el-form-item>
  30. <el-form-item>
  31. <el-upload ref="upload" action="customize" :http-request="uploadDiscardFile" :limit="1" :before-remove="beforeRemove">
  32. <el-button size="small" type="primary" :loading="loading">上传一张图片</el-button>
  33. </el-upload>
  34. </el-form-item>
  35. </el-form>
  36. <span slot="footer" class="dialog-footer">
  37. <el-button @click="addDialogVisible = false">取消</el-button>
  38. <el-button type="primary" @click="addCooperation()" :loading="loading">提交</el-button>
  39. </span>
  40. </el-dialog>
  41. </div>
  42. </template>
  43. <script>
  44. import request from "@/utils/request";
  45. export default {
  46. data() {
  47. return {
  48. editing: false,
  49. loading: false,
  50. addDialogVisible: false,
  51. cooperations: [],
  52. cooperationsForm: {
  53. id: null,
  54. name: null,
  55. description: null,
  56. image: null
  57. },
  58. };
  59. },
  60. methods: {
  61. //打开对话框
  62. openDialog(isEdit, index) {
  63. this.editing = isEdit;
  64. if (this.editing) {
  65. this.cooperationsForm.id = this.cooperations[index].id;
  66. this.cooperationsForm.name = this.cooperations[index].title;
  67. this.cooperationsForm.description = this.cooperations[index].content;
  68. this.cooperationsForm.image = null;
  69. } else {
  70. this.cooperationsForm.id = null;
  71. this.cooperationsForm.name = "";
  72. this.cooperationsForm.description = "";
  73. this.cooperationsForm.image = null;
  74. }
  75. this.addDialogVisible = true;
  76. },
  77. //获取合作信息
  78. getCooperations() {
  79. this.loading = true;
  80. request({
  81. url: "/qualification/list",
  82. method: "post"
  83. })
  84. .then(response => {
  85. this.cooperations = response.data;
  86. this.loading = false;
  87. })
  88. .catch(error => {
  89. this.$message({
  90. message: error,
  91. type: "error"
  92. });
  93. this.loading = false;
  94. });
  95. },
  96. //删除合作信息
  97. deleteCooperation(id) {
  98. request({
  99. url: "/qualification/delete",
  100. method: "post",
  101. params: { id: id }
  102. })
  103. .then(response => {
  104. this.$message({
  105. message: "删除成功",
  106. type: "success"
  107. });
  108. this.getCooperations();
  109. this.addDialogVisible = false;
  110. this.loading = false;
  111. })
  112. .catch(error => {
  113. this.$message({
  114. message: error,
  115. type: "error"
  116. });
  117. this.loading = false;
  118. });
  119. },
  120. //添加/编辑合作信息
  121. addCooperation() {
  122. this.$refs.form.validate(valid => {
  123. if (valid) {
  124. this.loading = true;
  125. var form = new FormData();
  126. form.append("title", this.cooperationsForm.name);
  127. form.append("content", this.cooperationsForm.description);
  128. //新增记录 并且 没有图片时
  129. if (this.cooperationsForm.image == null && this.editing == false) {
  130. //如果没上传文件的话
  131. this.loading =false;
  132. this.$message({
  133. message: "尚未上传图片",
  134. type: "error"
  135. });
  136. return;
  137. //有图片时
  138. } else if (this.cooperationsForm.image != null) {
  139. form.append("multipartFile", this.cooperationsForm.image);
  140. }
  141. if (this.cooperationsForm.id != null) {
  142. form.append("id", this.cooperationsForm.id);
  143. }
  144. request({
  145. url: "/qualification/insertOrUpdate",
  146. method: "post",
  147. data: form
  148. })
  149. .then(response => {
  150. this.$refs.upload.clearFiles();
  151. this.getCooperations();
  152. this.addDialogVisible = false;
  153. this.loading = false;
  154. this.$message({
  155. message: "添加成功",
  156. type: "success"
  157. });
  158. })
  159. .catch(error => {
  160. this.$message({
  161. message: error,
  162. type: "error"
  163. });
  164. this.loading = false;
  165. });
  166. }
  167. });
  168. },
  169. //文件上传的部分操作
  170. uploadDiscardFile(params) {
  171. this.cooperationsForm.image = params.file;
  172. return false;
  173. },
  174. //文件上传的移除操作
  175. beforeRemove(params) {
  176. this.cooperationsForm.image = null;
  177. }
  178. },
  179. mounted() {
  180. this.getCooperations();
  181. }
  182. };
  183. </script>
  184. <style scoped>
  185. </style>