<template>
  <div class="container">
    <!-- <h1>payCostTag-缴费标签管理</h1> -->
    <el-form
      :model="listQuery"
      ref="listQuery"
      label-width="100px"
      class="demo-list"
    >
      <div class="line">
        <el-form-item label="缴费标签" prop="costTag">
          <el-col :span="20">
            <el-input v-model="listQuery.costTag"></el-input>
          </el-col>
        </el-form-item>
      </div>

      <el-form-item>
        <el-button type="primary" @click="handlePayCostTagAdd">添加</el-button>
        <el-button @click="resetForm('listQuery')">重置</el-button>
      </el-form-item>
    </el-form>

    <div class="table-container">
      <el-table
        ref="productTable"
        :data="list"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        v-loading="listLoading"
        border
        @sort-change="changeTableSort"
      >
        <!-- <el-table-column
          type="selection"
          width="60"
          align="center"
        ></el-table-column> -->
        <el-table-column label="缴费标签" align="center">
          <template slot-scope="scope">{{ scope.row.costTag }}</template>
        </el-table-column>

        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <!-- <el-button @click="confirm(scope.row.costTag)" type="mini" -->
            <el-button
              @click="edit(scope.row.costTag, scope.row.id)"
              type="mini"
              >编辑</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div class="pagination-container">
      <el-pagination
        background
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        layout="total,sizes,prev, pager, next,jumper"
        :page-size="pageSize"
        :page-sizes="[5, 10, 15]"
        :current-page.sync="pageNum"
        :total="total"
      >
      </el-pagination>
    </div>

    <el-dialog title="编辑缴费标签" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item
          label="缴费标签"
          prop="costTag"
          :label-width="formLabelWidth"
        >
          <el-input v-model="form.costTag" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  payCostTagAll,
  payCostTagAdd,
  payCostTagUpdate,
  updateOutlineState
} from "@/api/cso";
// import { newAllocate } from "@/api/cso";

const defaultListQuery = {
  pageNum: 1,
  pageSize: 10,
  outlineState: null
};

export default {
  name: "payCostTag",
  data() {
    return {
      // list: {
      //   outlineState: null
      // },
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      pageSize: null,
      pageNum: null,
      total: null,
      listLoading: true,
      multipleSelection: [],
      formLabelWidth: "120px",
      dialogFormVisible: false,
      form: {
        costTag: "",
        di: ""
      }
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          addCurrentTermCourse(this.goOnForm).then(response => {
            this.$message({
              type: "success",
              message: "提交成功",
              duration: 1000
            });

            this.getCourseList();
            this.$forceUpdate();
          });
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
      this.listQuery = Object.assign({}, defaultListQuery);
      this.getData();
    },
    getData() {
      payCostTagAll(this.listQuery).then(res => {
        this.listLoading = false;
        this.list = res.data.list;
        this.pageNum = res.data.pageNum;
        this.pageSize = res.data.pageSize;
        this.total = res.data.total;
        console.log(this.list, "this.list,getpayCostTagAll");
      });
    },
    handleCurrentChange(val) {
      // 翻页
      this.listQuery.pageNum = val;
      this.getData();
    },
    handleSizeChange(val) {
      //切换展示条数
      this.listQuery.pageSize = val;
      this.getData();
    },

    handleStuDetail(id) {
      this.$router.push({
        path: "/pms/stuDetail",
        query: {
          id: id
        }
      });
      // console.log(123);
    },
    changeTableSort(column) {
      console.log("prop", column.prop);
      console.log("order", column.order);
      // console.log("column", column);
      if (column.prop == "addTime") {
        this.listQuery.secondSort = null;
        if (column.order == "ascending") {
          this.listQuery.firstSort = 0;
        } else if (column.order == "descending") {
          this.listQuery.firstSort = 1;
        }
      }
      if (column.prop == "allocateTime") {
        this.listQuery.firstSort = null;
        if (column.order == "ascending") {
          this.listQuery.secondSort = 0;
        } else if (column.order == "descending") {
          this.listQuery.secondSort = 1;
        }
      }
      if (column.order == null) {
        this.listQuery.secondSort = this.listQuery.firstSort = null;
      }
      this.getData();
      console.log("changeTableSort");
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    edit(costTag, id) {
      this.form.costTag = costTag;
      this.form.id = id;
      this.dialogFormVisible = true;
    },
    confirm() {
      //   console.log(costTag, "confirm");

      this.$confirm("确认修改?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(res => {
        payCostTagUpdate({
          costTag: this.form.costTag,
          id: this.form.id
        }).then(res => {
          this.$message({
            type: "success",
            message: "修改成功!"
          });
          this.dialogFormVisible = false;
          this.getData();
          this.$forceUpdate();
        });
      });
    },
    handlePayCostTagAdd() {
      this.$confirm("确认添加?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(res => {
        payCostTagAdd({
          costTag: this.listQuery.costTag
        }).then(res => {
          this.$message({
            type: "success",
            message: "添加成功!"
          });
          this.getData();
          this.$forceUpdate();
        });
      });
    }
  },
  mounted() {
    this.getData();
  }
};
</script>

<style lang="scss" scoped>
.container {
  padding: 20px;
}
.line {
  display: flex;
}
</style>
