Enterprise.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="cases">
  3. <el-button type="primary" @click="openDialog()">新增数据</el-button>
  4. <el-table border :data="tableData" v-loading="loading" style="width: 100%">
  5. <el-table-column prop="Id" label="序号" width="180"></el-table-column>
  6. <el-table-column prop="Img" label="企业Logo">
  7. <template slot-scope="scope">
  8. <img style="width:200px" :src="imgserver+scope.row.Img" alt />
  9. </template>
  10. </el-table-column>
  11. <el-table-column prop="Remark" label="企业名称" width="180"></el-table-column>
  12. <el-table-column label="操作">
  13. <template slot-scope="scope">
  14. <el-button
  15. type="primary"
  16. icon="el-icon-edit"
  17. @click="handleEdit(scope.$index, scope.row)"
  18. ></el-button>
  19. <el-button
  20. type="danger"
  21. icon="el-icon-delete"
  22. @click="handleDelete(scope.$index, scope.row)"
  23. ></el-button>
  24. </template>
  25. </el-table-column>
  26. </el-table>
  27. <el-dialog title="合作企业管理" :visible.sync="dialogFormVisible">
  28. <el-form :model="formData">
  29. <el-form-item label="企业Logo" :label-width="formLabelWidth">
  30. <el-upload
  31. class="avatar-uploader"
  32. action="http://shkjgw.shkjem.com/api/UpLoad/UploadImage"
  33. :headers="headers"
  34. :show-file-list="false"
  35. :on-success="handleSuccess"
  36. >
  37. <img v-if="formData.Img" :src="imgserver+formData.Img" class="avatar" />
  38. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  39. </el-upload>
  40. </el-form-item>
  41. <el-form-item label="企业名称" :label-width="formLabelWidth">
  42. <el-input v-model="formData.Remark" autocomplete="off"></el-input>
  43. </el-form-item>
  44. </el-form>
  45. <div slot="footer" class="dialog-footer">
  46. <el-button @click="dialogFormVisible = false">取 消</el-button>
  47. <el-button type="primary" @click="handleCreateOrModify()">确 定</el-button>
  48. </div>
  49. </el-dialog>
  50. </div>
  51. </template>
  52. <script>
  53. export default {
  54. data() {
  55. return {
  56. loading: true,
  57. dialogFormVisible: false,
  58. formLabelWidth: "120px",
  59. tableData: [],
  60. formData: {
  61. Id: 0,
  62. Img: "",
  63. Remark: "",
  64. CreateTime: new Date()
  65. },
  66. options: {},
  67. headers: {}
  68. };
  69. },
  70. mounted() {
  71. let token = "Browser " + sessionStorage.getItem("token");
  72. //window.console.log(token);
  73. this.options = {
  74. headers: {
  75. Authorization: token
  76. }
  77. };
  78. this.headers = {
  79. Authorization: token
  80. };
  81. this.loadData();
  82. },
  83. methods: {
  84. handleSuccess(response, file, fileList) {
  85. window.console.log(response, file, fileList);
  86. this.formData.Img = response;
  87. },
  88. loadData() {
  89. this.loading = true;
  90. this.$http
  91. .get("Enterprise/GetEnterpriseAll")
  92. .then(response => {
  93. window.console.log(response);
  94. this.tableData = response.data;
  95. this.loading = false;
  96. })
  97. .catch(e => {
  98. this.$message({
  99. message: "网络或程序异常!" + e,
  100. type: "error"
  101. });
  102. });
  103. },
  104. openDialog() {
  105. // 清除数据
  106. this.formData.Id = 0;
  107. this.formData.Img = "";
  108. this.formData.Remark = "";
  109. this.formData.CreateTime = new Date();
  110. this.dialogFormVisible = true;
  111. },
  112. // 新增
  113. handleCreateOrModify() {
  114. window.console.log(this.formData);
  115. //window.console.log(JSON.stringify(this.formData));
  116. if (!this.formData.Id) {
  117. // ID 无效时 视为新增
  118. this.loading = true;
  119. this.$http
  120. .post("Enterprise/CreateEnterprise", this.formData, this.options)
  121. .then(response => {
  122. this.loading = false;
  123. window.console.log(response);
  124. this.$message({
  125. message: "创建成功!",
  126. type: "success"
  127. });
  128. this.dialogFormVisible = false;
  129. this.loadData();
  130. })
  131. .catch(e => {
  132. this.$message({
  133. message: "网络或程序异常!" + e,
  134. type: "error"
  135. });
  136. });
  137. } else {
  138. this.loading = true;
  139. this.$http
  140. .post("Enterprise/ModifiedEnterprise", this.formData, this.options)
  141. .then(response => {
  142. this.loading = false;
  143. window.console.log(response);
  144. this.$message({
  145. message: "修改成功!",
  146. type: "success"
  147. });
  148. this.dialogFormVisible = false;
  149. this.loadData();
  150. })
  151. .catch(e => {
  152. this.$message({
  153. message: "网络或程序异常!" + e,
  154. type: "error"
  155. });
  156. });
  157. }
  158. },
  159. handleEdit(index, row) {
  160. window.console.log(index, row);
  161. this.formData = row;
  162. this.dialogFormVisible = true;
  163. },
  164. handleDelete(index, row) {
  165. window.console.log(index, row);
  166. this.$confirm("此操作将永久此条数据, 是否继续?", "提示", {
  167. confirmButtonText: "确定",
  168. cancelButtonText: "取消",
  169. type: "warning"
  170. })
  171. .then(() => {
  172. // 已确认删除
  173. // 调接口删除
  174. this.loading = true;
  175. this.$http
  176. .post(
  177. `Enterprise/DeleteEnterprise?id=${row.Id}`,
  178. null,
  179. this.options
  180. )
  181. .then(response => {
  182. this.loading = false;
  183. window.console.log(response);
  184. this.$message({
  185. message: "删除成功!",
  186. type: "success"
  187. });
  188. this.loadData();
  189. })
  190. .catch(e => {
  191. this.$message({
  192. message: "网络或程序异常!" + e,
  193. type: "error"
  194. });
  195. });
  196. })
  197. .catch(() => {
  198. this.$message({
  199. type: "info",
  200. message: "已取消删除"
  201. });
  202. });
  203. },
  204. //时间格式化
  205. dateFormat: function(row) {
  206. //row 表示一行数据, CreateTime 表示要格式化的字段名称
  207. let t = new Date(row.CreateTime);
  208. return t.getFullYear() + "-" + (t.getMonth() + 1) + "-" + t.getDate();
  209. }
  210. }
  211. };
  212. </script>
  213. <style scoped>
  214. .el-table {
  215. margin-top: 20px;
  216. }
  217. </style>