list.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. <template>
  2. <section>
  3. <!--工具条-->
  4. <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
  5. <el-form :inline="true">
  6. <el-form-item style="float:right;">
  7. <el-link type="primary" :underline="false" @click="handleAdd(-1)">新增项目</el-link>
  8. </el-form-item>
  9. </el-form>
  10. </el-col>
  11. <!--列表-->
  12. <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
  13. <el-table-column type="index" width="60"></el-table-column>
  14. <el-table-column prop="projectName" label="项目名称" sortable></el-table-column>
  15. <el-table-column label="操作" width="220">
  16. <template slot-scope="scope">
  17. <!-- <el-button size="small" type="primary" @click="detail(scope.$index)">详情</el-button> -->
  18. <el-button size="small" type="primary" @click="handleAdd(scope.$index)">编辑</el-button>
  19. <el-button size="small" type="danger" @click="deletePro(scope.$index)">删除</el-button>
  20. </template>
  21. </el-table-column>
  22. </el-table>
  23. <!--工具条-->
  24. <el-col :span="24" class="toolbar">
  25. <el-pagination
  26. @size-change="handleSizeChange"
  27. @current-change="handleCurrentChange"
  28. :page-sizes="[20 , 50 , 80 , 100]"
  29. :page-size="20"
  30. layout="total, sizes, prev, pager, next"
  31. :total="total"
  32. style="float:right;"
  33. ></el-pagination>
  34. </el-col>
  35. <!--新增界面-->
  36. <el-dialog :title="title" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth">
  37. <el-form ref="form1" :model="addForm" :rules="rules" label-width="100px">
  38. <el-form-item label="项目名称" prop="name">
  39. <el-input v-model="addForm.name" placeholder="请输入项目名称" clearable></el-input>
  40. </el-form-item>
  41. </el-form>
  42. <div slot="footer" class="dialog-footer">
  43. <el-button @click.native="addFormVisible = false">取消</el-button>
  44. <el-button type="primary" @click="submitInsert" :loading="addLoading">提交</el-button>
  45. </div>
  46. </el-dialog>
  47. </section>
  48. </template>
  49. <script>
  50. import util from "../../common/js/util";
  51. export default {
  52. data() {
  53. return {
  54. user: JSON.parse(sessionStorage.getItem("user")),
  55. date: new Date(),
  56. tableHeight: 0,
  57. listLoading: false,
  58. total: 0,
  59. page: 1,
  60. size: 20,
  61. list: [],
  62. addFormVisible: false,
  63. addLoading: false,
  64. title: "",
  65. addForm: {
  66. name: '',
  67. },
  68. rules: {
  69. name: [{ required: true, message: "请输入项目名称", trigger: "blur" }],
  70. }
  71. };
  72. },
  73. methods: {
  74. //分页
  75. handleCurrentChange(val) {
  76. this.page = val;
  77. this.getList();
  78. },
  79. handleSizeChange(val) {
  80. this.size = val;
  81. this.getList();
  82. },
  83. //获取项目列表
  84. getList() {
  85. this.listLoading = true;
  86. this.http.post(this.port.project.listPage, {
  87. pageIndex: this.page,
  88. pageSize: this.size
  89. },
  90. res => {
  91. this.listLoading = false;
  92. if (res.code == "ok") {
  93. this.list = res.data.records;
  94. this.total = res.data.total;
  95. } else {
  96. this.$message({
  97. message: res.msg,
  98. type: "error"
  99. });
  100. }
  101. },
  102. error => {
  103. this.listLoading = false;
  104. this.$message({
  105. message: error,
  106. type: "error"
  107. });
  108. });
  109. },
  110. //显示新增界面
  111. handleAdd(i) {
  112. if(i == -1) {
  113. this.title = "新增项目";
  114. this.addForm = {
  115. name: ''
  116. }
  117. } else {
  118. this.title = "修改项目";
  119. this.addForm = {
  120. id: this.list[i].id,
  121. name: this.list[i].projectName
  122. }
  123. }
  124. this.addFormVisible = true;
  125. },
  126. submitInsert() {
  127. this.$refs.form1.validate(valid => {
  128. if (valid) {
  129. this.addLoading = true;
  130. this.http.post(this.port.project.add,this.addForm,
  131. res => {
  132. this.addLoading = false;
  133. if (res.code == "ok") {
  134. this.$message({
  135. message: this.addForm.id!=null?'修改':'创建'+"成功",
  136. type: "success"
  137. });
  138. this.addFormVisible = false;
  139. this.getList();
  140. } else {
  141. this.$message({
  142. message: res.msg,
  143. type: "error"
  144. });
  145. }
  146. },
  147. error => {
  148. this.addLoading = false;
  149. this.$message({
  150. message: error,
  151. type: "error"
  152. });
  153. });
  154. }
  155. });
  156. },
  157. // 删除
  158. deletePro(i) {
  159. this.$confirm("确定要项目" + this.list[i].projectName + "吗?","删除项目", {
  160. confirmButtonText: "确定",
  161. cancelButtonText: "取消",
  162. type: "warning"
  163. })
  164. .then(() => {
  165. this.listLoading = true;
  166. this.http.post(this.port.project.delete,{
  167. id: this.list[i].id
  168. },
  169. res => {
  170. this.listLoading = false;
  171. if (res.code == "ok") {
  172. this.$message({
  173. message: "删除成功",
  174. type: "success"
  175. });
  176. this.getList();
  177. } else {
  178. this.$message({
  179. message: res.msg,
  180. type: "error"
  181. });
  182. }
  183. },
  184. error => {
  185. this.listLoading = false;
  186. this.$message({
  187. message: error,
  188. type: "error"
  189. });
  190. }
  191. );
  192. })
  193. .catch(() => {});
  194. },
  195. detail(i) {
  196. this.$router.push("/list/" + this.list[i].id + "/" + this.list[i].projectName);
  197. }
  198. },
  199. created() {
  200. let height = window.innerHeight;
  201. this.tableHeight = height - 195;
  202. const that = this;
  203. window.onresize = function temp() {
  204. that.tableHeight = window.innerHeight - 195;
  205. };
  206. },
  207. mounted() {
  208. this.getList();
  209. }
  210. };
  211. </script>
  212. <style lang="scss" scoped>
  213. </style>