<template>
  <div style="padding: 0.5% 0.5%">
    <el-row>
      <el-col :span="24">
        <span style="font-weight: ; font-size: 14px">筛选:</span>
        <el-input
          v-model="seach"
          placeholder="请输入内容"
          style="width: 20%"
        ></el-input>
        <el-button type="primary" size="small" @click="add">新增</el-button>
      </el-col>
      <el-col :span="24" style="margin-top: 0.2%">
        <el-table
          stripe
          :data="tableData"
          border
          :height="height"
          style="width: 100%"
        >
          <el-table-column
            align="center"
            prop="tcm"
            label="套餐名"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="tcll"
            label="套餐流量(MB)"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="xgr"
            label="修改人"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="xgsj"
            label="修改时间"
          ></el-table-column>
          <el-table-column
            align="center"
            prop="lx"
            label="类型"
          ></el-table-column>
          <el-table-column label="操作" align="center" width="180">
            <template slot-scope="scope">
              <el-button
                @click="handleClick(scope.row)"
                type="primary"
                size="mini"
                >修改</el-button
              >
              <el-button
                type="primary"
                size="mini"
                @click="deleteData(scope.row)"
                >删除</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageData.pageNum"
          :page-sizes="[23, 30, 50, 100]"
          :page-size="pageData.pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="pageData.total"
        >
        </el-pagination>
      </el-col>
    </el-row>
    <el-dialog
      :close-on-click-modal="false"
      :title="title + '套餐'"
      :visible.sync="dialogVisible"
      width="20%"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="formData" label-width="100px">
        <el-form-item label="套餐名称:">
          <el-input v-model="formData.name" style="width: 83%"></el-input>
        </el-form-item>
        <el-form-item label="套餐流量:">
          <el-select v-model="formData.flow" placeholder="请选择套餐流量">
            <el-option
              v-for="item in tcoptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="套餐类型:">
          <el-select v-model="formData.tctype" placeholder="请选择套餐类型">
            <el-option
              v-for="item in tclxoptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="二级类型:">
          <el-select v-model="formData.type" placeholder="请选择二级类型">
            <el-option
              v-for="item in erjitcoptions"
              :key="item.id"
              :label="item.name"
              :value="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitData">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import { tableheight } from "@/assets/commjs/common";
import pagination from "@/views/components/pagination/index";
export default {
  components: {
    pagination,
  },
  data() {
    return {
      dialogVisible: false,
      seach: "",
      height: "",
      pageData: {
        pageNum: 1,
        pageSize: 23,
        total: 100,
      },
      formData: {
        name: "",
        flow: "",
        tctype: 1,
        type: 1,
      },
      tcoptions: [],
      tclxoptions: [
        { id: 1, name: "通用" },
        { id: 2, name: "普通" },
      ],
      erjitcoptions: [
        { id: 1, name: "通用" },
        { id: 2, name: "普通" },
      ],
      tableData: [
        {
          id: "1",
          tcm: "基础套餐",
          tcll: 1024,
          xgr: "管理员",
          xgsj: "2022-06-12 12:22:12",
          lx: "默认套餐",
        },
        {
          id: "2",
          tcm: "基础套餐2",
          tcll: 1024,
          xgr: "管理员2",
          xgsj: "2022-06-12 12:22:12",
          lx: "默认套餐1",
        },
      ],
      title: "",
    };
  },
  created() {},
  mounted() {
    this.height = tableheight() + "px";
  },
  methods: {
    //改变页触发方法
    handleCurrentChange(val) {
     // console.log(`当前页: ${val}`);
    },
    //改变条数触发方法
    handleSizeChange(val) {
     // console.log(`每页 ${val} 条`);
    },
    //修改方法
    handleClick(row) {
      this.form = {
        name: "",
        flow: "",
        tctype: "",
        type: "",
      };
      this.dialogVisible = true;
      this.title = "修改";
    },
    //删除方法
    deleteData(row) {
      this.$confirm("此操作将永久删除该条记录, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //关闭弹窗
    handleClose() {
      this.dialogVisible = false;
    },
    //新增
    add() {
      this.form = {
        name: "",
        flow: "",
        tctype: "",
        type: "",
      };
      this.dialogVisible = true;
      this.title = "新增";
    },
    //提交
    submitData() {
      this.dialogVisible = false;
    },
  },
};
</script>
