<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="教练员性名" prop="name" label-width="90px">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入教练员性名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="驾校全国统一编号" prop="inscode" label-width="130px">
        <el-input
          v-model="queryParams.inscode"
          placeholder="请输入驾校全国统一编号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="mobile">
        <el-input
          v-model="queryParams.mobile"
          placeholder="请输入手机号码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</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"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['coach:info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['coach:info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['coach:info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['coach:info:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="教练员性名" align="center" prop="name" />
      <el-table-column label="教练员全国统一编号" align="center" prop="coachnum" />
      <el-table-column label="身份证明号码" align="center" prop="idcard" />
      <el-table-column label="岗位" align="center" prop="address" />
      <el-table-column label="手机号码" align="center" prop="mobile" />
      <el-table-column label="合同结束日期" align="center" prop="photo" />
      <el-table-column label="备注" align="center" prop="district" />
      <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-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['coach:info:edit']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['coach:info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['coach:info:remove']"
          >删除</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="open" width="1000px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :inline="true">
        <el-form-item label="教练员性名" prop="name">
          <el-input v-model="form.name" placeholder="请输入教练员性名" />
        </el-form-item>
        <el-form-item label="性别 ：1男  2女" prop="sex">
          <el-select v-model="form.sex" placeholder="请选择性别 ：1男  2女">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="驾校全国统一编号" prop="inscode">
          <el-input v-model="form.inscode" placeholder="请输入驾校全国统一编号" />
        </el-form-item>
        <el-form-item label="身份证明号码" prop="idcard">
          <el-input v-model="form.idcard" placeholder="请输入身份证明号码" />
        </el-form-item>
        <el-form-item label="手机号码" prop="mobile">
          <el-input v-model="form.mobile" placeholder="请输入手机号码" />
        </el-form-item>
        <el-form-item label="地址" prop="address">
          <el-input v-model="form.address" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="教练员头像ID" prop="photo">
          <el-input v-model="form.photo" placeholder="请输入教练员头像ID" />
        </el-form-item>
        <el-form-item label="准驾车型" prop="dripermitted">
          <el-input v-model="form.dripermitted" placeholder="请输入准驾车型" />
        </el-form-item>
        <el-form-item label="准教车型" prop="teachpermitted">
          <el-input v-model="form.teachpermitted" placeholder="请输入准教车型" />
        </el-form-item>
        <el-form-item label="地区编号" prop="district">
          <el-input v-model="form.district" placeholder="请输入地区编号" />
        </el-form-item>
        <el-form-item label="供职状态：0:在职 1离职
            1:离职
            供职状态：0:在职
            1:离职
            
            1:离职
            ">
          <el-radio-group v-model="form.employstatus">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="停训 1-停训 0-启用" prop="stopTrain">
          <el-input v-model="form.stopTrain" placeholder="请输入停训 1-停训 0-启用" />
        </el-form-item>
        <el-form-item label="微信号" prop="wechar">
          <el-input v-model="form.wechar" placeholder="请输入微信号" />
        </el-form-item>
        <el-form-item label="微信openid" prop="openid">
          <el-input v-model="form.openid" placeholder="请输入微信openid" />
        </el-form-item>
        <el-form-item label="点赞数" prop="fabulous">
          <el-input v-model="form.fabulous" placeholder="请输入点赞数" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listInfo, getInfo, delInfo, addInfo, updateInfo, exportInfo } from "@/api/coach/info";

export default {
  name: "Info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 教练表格数据
      infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        sex: null,
        inscode: null,
        idcard: null,
        mobile: null,
        address: null,
        photo: null,
        dripermitted: null,
        teachpermitted: null,
        district: null,
        employstatus: null,
        stopTrain: null,
        wechar: null,
        openid: null,
        fabulous: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询教练列表 */
    getList() {
      this.loading = true;
      listInfo(this.queryParams).then(response => {
        this.infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        coachnum: null,
        name: null,
        sex: null,
        inscode: null,
        idcard: null,
        mobile: null,
        address: null,
        photo: null,
        dripermitted: null,
        teachpermitted: null,
        district: null,
        employstatus: 0,
        stopTrain: null,
        wechar: null,
        openid: null,
        createTime: null,
        updateTime: null,
        fabulous: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.coachnum)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加教练";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const coachnum = row.coachnum || this.ids
      getInfo(coachnum).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改教练";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.coachnum != null) {
            updateInfo(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addInfo(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const coachnums = row.coachnum || this.ids;
      this.$confirm('是否确认删除教练编号为"' + coachnums + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delInfo(coachnums);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有教练数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportInfo(queryParams);
        }).then(response => {
          this.download(response.data);
        })
    }
  }
};
</script>
