<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      v-show="showSearch"
      ref="queryForm"
      :model="queryParams"
      size="small"
      label-width="88px"
    >
      <SearchBar :show-more="false" :show-span="6">
        <template #header>
          <el-col :span="5">
            <el-form-item label="任岗时间" prop="appointmentPostsTime">
              <el-date-picker
                v-model="queryParams.appointmentPostsTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="主要任岗" prop="mainPostFlag">
              <!-- <el-input
                v-model="queryParams.mainPostFlag"
                placeholder="请输入是否主要任岗"
                clearable
                @keyup.enter.native="handleQuery"
              /> -->
              <DictSelect
                v-model="queryParams.mainPostFlag"
                placeholder="请选择是否主要任岗"
                dict-type="YES_NO"
              />
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="任免状态" prop="isDisabled">
              <el-select
                v-model="queryParams.isDisabled"
                placeholder="请选择任免状态"
                clearable
                size="small"
              >
                <el-option
                  v-for="dict in getDictDatas(
                    DICT_TYPE.MES_POST_APPOINTMENT_REMOVAL
                  )"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="5">
            <el-form-item label="创建时间" prop="createTime">
              <el-date-picker
                v-model="queryParams.createTime"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
        </template>
        <template #buttons>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </template>
      </SearchBar>
    </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
          v-hasPermi="['mes:employee-appoint-remove-post-detail:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          >导出</el-button
        >
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" border>
      <el-table-column
        label="任岗单号"
        align="center"
        prop="eBillNo"
        width="140"
        fixed="left"
      />
      <el-table-column
        label="任岗开始时间"
        align="center"
        prop="appointmentPostsTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.appointmentPostsTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="是否主要任岗" align="center" prop="mainPostFlag">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.YES_NO" :value="scope.row.mainPostFlag" />
        </template>
      </el-table-column>
      <el-table-column label="任免状态" align="center" prop="eBillStatus">
        <template slot-scope="scope">
          <dict-tag
            :type="DICT_TYPE.MES_POST_APPOINTMENT_REMOVAL"
            :value="scope.row.eBillStatus"
          />
        </template>
      </el-table-column>
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="180"
      >
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['mes:employee-appoint-remove-post-master:update']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            v-hasPermi="['mes:employee-appoint-remove-post-master:delete']"
            size="mini"
            type="text"
            class="text-danger"
            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.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  createEmployeeAppointRemovePostDetail,
  updateEmployeeAppointRemovePostDetail,
  deleteEmployeeAppointRemovePostMaster,
  getEmployeeAppointRemovePostMasterPage,
  exportEmployeeAppointRemovePostDetailExcel,
} from "@/api/mes/employeeMaster/employeeAppointRemove";

export default {
  name: "EmployeeAppointRemove",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // MES 岗位任免单明细列表
      list: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        mesEmployeeMasterId: null,
        systemPostId: null,
        appointmentPostsTime: [],
        mainPostFlag: null,
        isDisabled: null,
        createTime: [],
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      // 执行查询
      getEmployeeAppointRemovePostMasterPage(this.queryParams)
        .then((response) => {
          this.list = response.data.list;
          // this.list = this.list.map(item => {
          //   item.eBillStatus = item.eBillStatus + ''
          //   return item
          // })
          this.total = response.data.total;
        })
        .finally(() => {
          this.loading = false;
        });
    },
    /** 取消按钮 */
    cancel() {
      this.open = false;
      this.reset();
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        mesEmployeeMasterId: undefined,
        systemPostId: undefined,
        appointmentPostsTime: undefined,
        mainPostFlag: undefined,
        isDisabled: undefined,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.$router.push({ path: "/personal-manage/employeeAppoint-detail" });
      // // this.open = true
      // // this.title = '添加MES 岗位任免单明细'
      // this.$refs.employeeAppointDetail.viewOpen = true
      // this.$refs.employeeAppointDetail.title = '新增岗位任免单'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const { id, eBillNo } = row;
      this.$router.push({
        path: "/personal-manage/employeeAppoint-detail",
        query: { id, eBillNo },
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (!valid) {
          return;
        }
        // 修改的提交
        // const { appointmentPostsTime, isDisabled, mainPostFlag, mesEmployeeMasterId, systemPostId } = this.form
        // const params = {
        //   appointmentPostsTime,
        //   isDisabled,
        //   mainPostFlag,
        //   mesEmployeeMasterId,
        //   systemPostId
        // }
        if (this.form.id != null) {
          updateEmployeeAppointRemovePostDetail(this.form).then((response) => {
            this.$modal.msgSuccess("修改成功");
            this.open = false;
            this.getList();
          });
          return;
        }
        // 添加的提交
        createEmployeeAppointRemovePostDetail(this.form).then((response) => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
        });
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const id = row.id;
      this.$modal
        .confirm('是否确认删除MES 岗位任免单编号为"' + id + '"的数据项?')
        .then(function () {
          return deleteEmployeeAppointRemovePostMaster(id);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      // 处理查询参数
      const params = { ...this.queryParams };
      params.pageNo = undefined;
      params.pageSize = undefined;
      this.$modal
        .confirm("是否确认导出所有MES 岗位任免单明细数据项?")
        .then(() => {
          this.exportLoading = true;
          return exportEmployeeAppointRemovePostDetailExcel(params);
        })
        .then((response) => {
          this.$download.excel(response, "MES 岗位任免单明细.xls");
          this.exportLoading = false;
        })
        .catch(() => {});
    },
  },
};
</script>
