<template>
  <!-- <div>多喝水抠脚大汉时间跨度花洒金卡等哈手机卡等哈</div> -->
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      label-width="100px"
    >
      <el-form-item label="业务类型">
        <el-input
          v-model="queryParams.ywlx"
          placeholder="请输入业务类型"
          clearable
          @keyup.enter.native="getList"
        />
      </el-form-item>
      <el-form-item label="业务类型名称">
        <el-input
          v-model="queryParams.ywlxmc"
          placeholder="请输入业务类型名称"
          clearable
          @keyup.enter.native="getList"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getList"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          @click="addYwlx"
          size="mini"
          >新增</el-button
        >
      </el-col></el-row
    >
    <el-table
      v-loading="loading"
      :data="ydlxList"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="业务类型" align="center">
        <template slot-scope="scope">
          <span style="color: #337ab7;cursor: pointer;" @click="goYzpz(scope.row)"> {{ scope.row.ywlx }}</span>
        </template>
      </el-table-column>
      <el-table-column label="业务类型名称" align="center" prop="ywlxmc" />
      <el-table-column label="排序" align="center" prop="sort" />
      <el-table-column label="数据源" align="center" prop="sjy" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            >查看</el-button
          > -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleEdit(scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      :title="title"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="110px">
        <el-form-item label="业务类型" prop="ywlx">
          <el-input v-model="form.ywlx"></el-input>
        </el-form-item>
        <el-form-item label="业务类型名称" prop="ywlxmc">
          <el-input v-model="form.ywlxmc"></el-input>
        </el-form-item>
        <el-form-item label="排序" prop="sort">
          <!-- <el-input v-model="form.sort"></el-input> -->
          <el-input-number
            v-model="form.sort"
            @change="handleChange"
            :min="1"
            label="最小值为1"
          ></el-input-number>
        </el-form-item>
        <el-form-item label="数据源" prop="sjy">
          <el-input v-model="form.sjy"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="submitForm('form')">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getYwlxList,
  addYwlx,
  updateYwlx,
  delYwlx,
} from "@/api/supervise/pcsj";
import { reset } from "ol/transform";
export default {
  data() {
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        ywlx: "", //业务类型
        ywlxmc: "", //业务类型名称
      },
      total: 0,
      loading: false,
      ydlxList: [],
      dialogVisible: false,
      title: "新增",
      form: {
        ywlx: "",
        ywlxmc: "",
        sort: 1,
        sjy: "",
      },
      rules: {
        // { min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }
        ywlx: [{ required: true, message: "请输入业务类型", trigger: "blur" }],
        ywlxmc: [
          { required: true, message: "请输入业务类型名称", trigger: "blur" },
        ],
        sort: [{ required: true, message: "请输入排序", trigger: "blur" }],
        sjy: [{ required: true, message: "请输入数据源", trigger: "blur" }],
      },
    };
  },
  methods: {
    /** 查询监管批次数据列表 */
    getList() {
      this.loading = true;
      getYwlxList(this.queryParams).then((response) => {
        this.ydlxList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    goYzpz(row){
      this.$router.push({ path: "/remote/mbyz", query: { id: row.ywlx } });
    },
    handleQuery() {},
    //重置
    resetQuery() {
      this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        ywlx: "", //业务类型
        ywlxmc: "", //业务类型名称
      };
      this.getList()
    },
    handleSelectionChange() {},
    // handleView(row) {},
    handleEdit(row) {
      this.title = "修改";
      this.form = JSON.parse(JSON.stringify(row));
      this.dialogVisible = true;
    },
    handleDelete(row) {
      this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          delYwlx(row.ywlx).then((res) => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: "删除成功!",
              });
              this.getList();
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    //新增业务类型数据
    addYwlx() {
      this.dialogVisible = true;
      this.title = "新增"
      this.reset();
    },
    handleClose() {
      this.dialogVisible = false;
    },
    //排序改变的方法
    handleChange(value) {
      console.log(value);
    },
    submitForm(form) {
      this.$refs[form].validate((valid) => {
        if (valid) {
          if (this.title == "新增") {
            addYwlx(this.form).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: "添加成功!",
                  type: "success",
                });
                this.dialogVisible = false;
                this.getList();
              }
            });
          } else {
            updateYwlx(this.form).then((res) => {
              if (res.code == 200) {
                this.$message({
                  message: "修改成功!",
                  type: "success",
                });
                this.dialogVisible = false;
                this.getList();
              }
            });
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    reset() {
      this.$refs.form.resetFields();
      this.form = {
        ywlx: "",
        ywlxmc: "",
        sort: 1,
        sjy: "",
      };
    },
  },
  mounted() {
    this.getList();
  },
  watch: {
    // dialogVisible(newVal, oldVal) {
    //   this.$refs.form.resetFields();
    // },
  },
};
</script>

<style lang="scss" scoped>
</style>