<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="专家姓名" prop="fName">
        <el-input
          v-model="queryParams.fName"
          placeholder="请输入专家姓名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="人员编码" prop="fCode">
        <el-input
          v-model="queryParams.fCode"
          placeholder="请输入人员编码"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="fIdNo">
        <el-input
          v-model="queryParams.fIdNo"
          placeholder="请输入身份证号"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="fPhone">
        <el-input
          v-model="queryParams.fPhone"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否省级专家" prop="fThisProvinceFlag">
        <el-select v-model="queryParams.fThisProvinceFlag" placeholder="请选择是否省级专家" clearable size="small">
          <el-option
            v-for="dict in fThisProvinceFlagOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="是否有效" prop="fValidType">
        <el-select v-model="queryParams.fValidType" placeholder="请选择是否有效" clearable size="small">
          <el-option
            v-for="dict in fValidTypeOptions"
            :key="dict.dictValue"
            :label="dict.dictLabel"
            :value="dict.dictValue"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" 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"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
		      :loading="exportLoading"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          plain
          size="mini"
          type="info"
          @click="getGovermentTaskInfo"
        >从省平台获取数据</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="browseList">
      <!--<el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="专家姓名" align="center" prop="fName" />
      <el-table-column label="人员编码" align="center" prop="fCode" :show-overflow-tooltip="true"/>
      <el-table-column label="身份证号" align="center" prop="fIdNo" :show-overflow-tooltip="true"/>
      <el-table-column label="性别" align="center" prop="fSex" :formatter="fSexFormat"/>
      <el-table-column label="出生日期" align="center" prop="fBirthday"/>
      <el-table-column label="联系电话" align="center" prop="fPhone" width="120"/>
      <el-table-column label="燃气种类" align="center" prop="fGasType" :formatter="fGasTypeFormat" :show-overflow-tooltip="true"/>
      <el-table-column label="所在地区" align="center" prop="fArea" :show-overflow-tooltip="true"/>
      <el-table-column label="照片" align="center" prop="fPicture" >
        <template slot-scope="scope">
          <el-image
            :src="scope.row.fPicture"
            :preview-src-list="[scope.row.fPicture]"
            v-if="scope.row.fPicture != '' && scope.row.fPicture != null"
            :z-index=5000 style="width: auto;height: auto;"
          ></el-image>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <el-table-column label="最后修改时间" align="center" prop="fUpdateTime" width="150"/>
      <el-table-column label="是否省级专家" align="center" prop="fThisProvinceFlag" :formatter="fThisProvinceFlagFormat" />
      <el-table-column label="是否有效" align="center" prop="fValidType" :formatter="fValidTypeFormat" />
      <el-table-column label="聘用批次" align="center" prop="fEmployBatch">
        <template slot-scope="scope">
          <span v-if="scope.row.fEmployBatch">{{ scope.row.fEmployBatch }}</span>
          <span v-else>-</span>
        </template>
      </el-table-column>
      <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)"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>-->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-document"
            @click="handleDetail(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="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="人员编码" prop="fCode">
          <el-input v-model="form.fCode" placeholder="请输入人员编码" />
        </el-form-item>
        <el-form-item label="专家姓名" prop="fName">
          <el-input v-model="form.fName" placeholder="请输入专家姓名" />
        </el-form-item>
        <el-form-item label="身份证号" prop="fIdNo">
          <el-input v-model="form.fIdNo" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="性别：1-男性，2-女性" prop="fSex">
          <el-select v-model="form.fSex" placeholder="请选择性别：1-男性，2-女性">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="出生日期" prop="fBirthday">
          <el-input v-model="form.fBirthday" placeholder="请输入出生日期" />
        </el-form-item>
        <el-form-item label="邮箱" prop="fEmail">
          <el-input v-model="form.fEmail" placeholder="请输入邮箱" />
        </el-form-item>
        <el-form-item label="联系电话" prop="fPhone">
          <el-input v-model="form.fPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="文化程度" prop="fEducation">
          <el-input v-model="form.fEducation" placeholder="请输入文化程度" />
        </el-form-item>
        <el-form-item label="毕业院校" prop="fGraduationSchool">
          <el-input v-model="form.fGraduationSchool" placeholder="请输入毕业院校" />
        </el-form-item>
        <el-form-item label="所属专业" prop="fMajor">
          <el-input v-model="form.fMajor" placeholder="请输入所属专业" />
        </el-form-item>
        <el-form-item label="毕业时间" prop="fGraduationTime">
          <el-input v-model="form.fGraduationTime" placeholder="请输入毕业时间" />
        </el-form-item>
        <el-form-item label="工作单位编码" prop="fEntUuid">
          <el-input v-model="form.fEntUuid" placeholder="请输入工作单位编码" />
        </el-form-item>
        <el-form-item label="工作单位名称" prop="fWorkUnit">
          <el-input v-model="form.fWorkUnit" placeholder="请输入工作单位名称" />
        </el-form-item>
        <el-form-item label="参加工作时间" prop="fWorkTime">
          <el-input v-model="form.fWorkTime" placeholder="请输入参加工作时间" />
        </el-form-item>
        <el-form-item label="所在部门" prop="fDepartment">
          <el-input v-model="form.fDepartment" placeholder="请输入所在部门" />
        </el-form-item>
        <el-form-item label="职务" prop="fDuties">
          <el-input v-model="form.fDuties" placeholder="请输入职务" />
        </el-form-item>
        <el-form-item label="专业技术职称" prop="fMajorTitle">
          <el-input v-model="form.fMajorTitle" placeholder="请输入专业技术职称" />
        </el-form-item>
        <el-form-item label="现从事专业" prop="fMajorNow">
          <el-input v-model="form.fMajorNow" placeholder="请输入现从事专业" />
        </el-form-item>
        <el-form-item label="从事专业工作年限" prop="fMajorLife">
          <el-input v-model="form.fMajorLife" placeholder="请输入从事专业工作年限" />
        </el-form-item>
        <el-form-item label="从事行业燃气种类

            03-0100-0101：管道燃气

            03-0100-0102：液化天然气" prop="fGasType">
          <el-select v-model="form.fGasType" placeholder="请选择从事行业燃气种类

            03-0100-0101：管道燃气

            03-0100-0102：液化天然气">
            <el-option label="请选择字典生成" value="" />
          </el-select>
        </el-form-item>
        <el-form-item label="擅长工作领域" prop="fGoodArea">
          <el-input v-model="form.fGoodArea" placeholder="请输入擅长工作领域" />
        </el-form-item>
        <el-form-item label="相关学习工作经历及工作业绩" prop="fLearningWorkExperience">
          <el-input v-model="form.fLearningWorkExperience" placeholder="请输入相关学习工作经历及工作业绩" />
        </el-form-item>
        <el-form-item label="所在地区" prop="fArea">
          <el-input v-model="form.fArea" placeholder="请输入所在地区" />
        </el-form-item>
        <el-form-item label="删除标记，0-可用，1-已删除" prop="fDeleteFlag">
          <el-input v-model="form.fDeleteFlag" placeholder="请输入删除标记，0-可用，1-已删除" />
        </el-form-item>
        <el-form-item label="市局燃气主管部门意见" prop="fCRecord">
          <el-input v-model="form.fCRecord" placeholder="请输入市局燃气主管部门意见" />
        </el-form-item>
        <el-form-item label="省级燃气主管部门意见" prop="fPRecord">
          <el-input v-model="form.fPRecord" placeholder="请输入省级燃气主管部门意见" />
        </el-form-item>
        <el-form-item label="照片" prop="fPicture">
          <el-input v-model="form.fPicture" placeholder="请输入照片" />
        </el-form-item>
        <el-form-item label="最后修改时间" prop="fUpdateTime">
          <el-input v-model="form.fUpdateTime" placeholder="请输入最后修改时间" />
        </el-form-item>
        <el-form-item label="是否省级专家 1 是，0 不是" prop="fThisProvinceFlag">
          <el-select v-model="form.fThisProvinceFlag" placeholder="请选择是否省级专家 1 是，0 不是">
            <el-option
              v-for="dict in fThisProvinceFlagOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否有效：0 有效，1 无效" prop="fValidType">
          <el-select v-model="form.fValidType" placeholder="请选择是否有效：0 有效，1 无效">
            <el-option
              v-for="dict in fValidTypeOptions"
              :key="dict.dictValue"
              :label="dict.dictLabel"
              :value="parseInt(dict.dictValue)"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="聘用批次" prop="fEmployBatch">
          <el-input v-model="form.fEmployBatch" 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>

    <!-- 详情 -->
    <DetailInfo ref="detail"/>
  </div>
</template>

<script>
import { listBrowse, getBrowse, delBrowse, addBrowse, updateBrowse, exportBrowse, getExpertDeclarationTask } from "@/api/specialist/browse";
import DetailInfo from "./components/DetailInfo";
import moment from "moment";
export default {
  name: "Browse",
  components: {
    DetailInfo
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 行业专家库-专家库浏览表格数据
      browseList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      fSexOptions: [],
      fGasTypeOptions: [],
      // 是否省级专家 1 是，0 不是字典
      fThisProvinceFlagOptions: [],
      // 是否有效：0 有效，1 无效字典
      fValidTypeOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        fCode: null,
        fName: null,
        fIdNo: null,
        fPhone: null,
        fThisProvinceFlag: null,
        fValidType: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        fCode: [
          { required: true, message: "人员编码不能为空", trigger: "blur" }
        ],
        fName: [
          { required: true, message: "专家姓名不能为空", trigger: "blur" }
        ],
        fIdNo: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
        fPhone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
        fMajor: [
          { required: true, message: "所属专业不能为空", trigger: "blur" }
        ],
        fMajorTitle: [
          { required: true, message: "专业技术职称不能为空", trigger: "blur" }
        ],
        fMajorNow: [
          { required: true, message: "现从事专业不能为空", trigger: "blur" }
        ],
        fMajorLife: [
          { required: true, message: "从事专业工作年限不能为空", trigger: "blur" }
        ],
        fGasType: [
          { required: true, message: "业燃气种类", trigger: "change" }
        ],
        fGoodArea: [
          { required: true, message: "擅长工作领域不能为空", trigger: "blur" }
        ],
        fArea: [
          { required: true, message: "所在地区不能为空", trigger: "blur" }
        ],
        fDeleteFlag: [
          { required: true, message: "删除标记，0-可用，1-已删除不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.getDicts("t_sex").then(response => {
        this.fSexOptions = response.data;
    });
    this.getDicts("t_gas_type").then(response => {
        this.fGasTypeOptions = response.data;
    });
    this.getDicts("t_province_mark").then(response => {
      this.fThisProvinceFlagOptions = response.data;
    });
    this.getDicts("t_valid_type").then(response => {
      this.fValidTypeOptions = response.data;
    });
  },
  methods: {
    /** 查询行业专家库-专家库浏览列表 */
    getList() {
      this.loading = true;
      listBrowse(this.queryParams).then(response => {
        this.browseList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 性别：1-男性，2-女性字典翻译
    fSexFormat(row, column) {
      return this.selectDictLabel(this.fSexOptions, row.fSex);
    },
    // 从事行业燃气种类
    fGasTypeFormat(row, column) {
      return this.selectDictLabels(this.fGasTypeOptions, row.fGasType);
    },
    // 是否省级专家 1 是，0 不是字典翻译
    fThisProvinceFlagFormat(row, column) {
      return this.selectDictLabel(this.fThisProvinceFlagOptions, row.fThisProvinceFlag);
    },
    // 是否有效：0 有效，1 无效字典翻译
    fValidTypeFormat(row, column) {
      return this.selectDictLabel(this.fValidTypeOptions, row.fValidType);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        fProAppInforId: null,
        fCode: null,
        fName: null,
        fIdNo: null,
        fSex: null,
        fBirthday: null,
        fEmail: null,
        fPhone: null,
        fEducation: null,
        fGraduationSchool: null,
        fMajor: null,
        fGraduationTime: null,
        fEntUuid: null,
        fWorkUnit: null,
        fWorkTime: null,
        fDepartment: null,
        fDuties: null,
        fMajorTitle: null,
        fMajorNow: null,
        fMajorLife: null,
        fGasType: null,
        fGoodArea: null,
        fLearningWorkExperience: null,
        fArea: null,
        fDeleteFlag: null,
        fCRecord: null,
        fPRecord: null,
        fPicture: null,
        fUpdateTime: null,
        fThisProvinceFlag: null,
        fValidType: null,
        fEmployBatch: 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.fProAppInforId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加行业专家库-专家库浏览";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const fProAppInforId = row.fProAppInforId || this.ids
      getBrowse(fProAppInforId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改行业专家库-专家库浏览";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.fProAppInforId != null) {
            updateBrowse(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addBrowse(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const fProAppInforIds = row.fProAppInforId || this.ids;
      this.$confirm('是否确认删除行业专家库-专家库浏览编号为"' + fProAppInforIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delBrowse(fProAppInforIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有行业专家库-专家库浏览数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportBrowse(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    },
    //获取数据
    getGovermentTaskInfo(){
      this.$confirm('是否确认从省平台获取数据?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(function() {
        return getExpertDeclarationTask({updateTime:moment().format('YYYY-MM-DD HH:mm:ss'),pageIndex: 1,pageSize: 1000});
      }).then(() => {
        this.getList();
        this.msgSuccess("从省平台获取数据成功");
      }).catch(() => {});
    },
    //详情
    handleDetail(row){
      this.$refs.detail.getDetailInfo(row.fProAppInforId);
    },
  }
};
</script>
