| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228 |
- <template>
- <section>
- <!--工具条-->
- <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
- <el-form :inline="true">
- <el-form-item style="float:right;">
- <el-link type="primary" :underline="false" @click="handleAdd(-1)">新增项目</el-link>
- </el-form-item>
- </el-form>
- </el-col>
- <!--列表-->
- <el-table :data="list" highlight-current-row v-loading="listLoading" :height="tableHeight" style="width: 100%;">
- <el-table-column type="index" width="60"></el-table-column>
- <el-table-column prop="projectName" label="项目名称" sortable></el-table-column>
- <el-table-column label="操作" width="220">
- <template slot-scope="scope">
- <!-- <el-button size="small" type="primary" @click="detail(scope.$index)">详情</el-button> -->
- <el-button size="small" type="primary" @click="handleAdd(scope.$index)">编辑</el-button>
- <el-button size="small" type="danger" @click="deletePro(scope.$index)">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <!--工具条-->
- <el-col :span="24" class="toolbar">
- <el-pagination
- @size-change="handleSizeChange"
- @current-change="handleCurrentChange"
- :page-sizes="[20 , 50 , 80 , 100]"
- :page-size="20"
- layout="total, sizes, prev, pager, next"
- :total="total"
- style="float:right;"
- ></el-pagination>
- </el-col>
- <!--新增界面-->
- <el-dialog :title="title" v-if="addFormVisible" :visible.sync="addFormVisible" :close-on-click-modal="false" customClass="customWidth">
- <el-form ref="form1" :model="addForm" :rules="rules" label-width="100px">
- <el-form-item label="项目名称" prop="name">
- <el-input v-model="addForm.name" placeholder="请输入项目名称" clearable></el-input>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button @click.native="addFormVisible = false">取消</el-button>
- <el-button type="primary" @click="submitInsert" :loading="addLoading">提交</el-button>
- </div>
- </el-dialog>
- </section>
- </template>
- <script>
- import util from "../../common/js/util";
- export default {
- data() {
- return {
- user: JSON.parse(sessionStorage.getItem("user")),
- date: new Date(),
- tableHeight: 0,
- listLoading: false,
- total: 0,
- page: 1,
- size: 20,
- list: [],
- addFormVisible: false,
- addLoading: false,
- title: "",
- addForm: {
- name: '',
- },
- rules: {
- name: [{ required: true, message: "请输入项目名称", trigger: "blur" }],
- }
- };
- },
- methods: {
- //分页
- handleCurrentChange(val) {
- this.page = val;
- this.getList();
- },
- handleSizeChange(val) {
- this.size = val;
- this.getList();
- },
- //获取项目列表
- getList() {
- this.listLoading = true;
- this.http.post(this.port.project.listPage, {
- pageIndex: this.page,
- pageSize: this.size
- },
- res => {
- this.listLoading = false;
- if (res.code == "ok") {
- this.list = res.data.records;
- this.total = res.data.total;
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.listLoading = false;
- this.$message({
- message: error,
- type: "error"
- });
- });
- },
- //显示新增界面
- handleAdd(i) {
- if(i == -1) {
- this.title = "新增项目";
- this.addForm = {
- name: ''
- }
- } else {
- this.title = "修改项目";
- this.addForm = {
- id: this.list[i].id,
- name: this.list[i].projectName
- }
- }
- this.addFormVisible = true;
- },
- submitInsert() {
- this.$refs.form1.validate(valid => {
- if (valid) {
- this.addLoading = true;
- this.http.post(this.port.project.add,this.addForm,
- res => {
- this.addLoading = false;
- if (res.code == "ok") {
- this.$message({
- message: this.addForm.id!=null?'修改':'创建'+"成功",
- type: "success"
- });
- this.addFormVisible = false;
- this.getList();
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.addLoading = false;
- this.$message({
- message: error,
- type: "error"
- });
- });
- }
- });
- },
- // 删除
- deletePro(i) {
- this.$confirm("确定要项目" + this.list[i].projectName + "吗?","删除项目", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- })
- .then(() => {
- this.listLoading = true;
- this.http.post(this.port.project.delete,{
- id: this.list[i].id
- },
- res => {
- this.listLoading = false;
- if (res.code == "ok") {
- this.$message({
- message: "删除成功",
- type: "success"
- });
- this.getList();
- } else {
- this.$message({
- message: res.msg,
- type: "error"
- });
- }
- },
- error => {
- this.listLoading = false;
- this.$message({
- message: error,
- type: "error"
- });
- }
- );
- })
- .catch(() => {});
- },
- detail(i) {
- this.$router.push("/list/" + this.list[i].id + "/" + this.list[i].projectName);
- }
- },
- created() {
- let height = window.innerHeight;
- this.tableHeight = height - 195;
- const that = this;
- window.onresize = function temp() {
- that.tableHeight = window.innerHeight - 195;
- };
- },
- mounted() {
- this.getList();
- }
- };
- </script>
- <style lang="scss" scoped>
- </style>
|