<template>
  <div class="camerasMg">
    <el-row class="topBar">
      <el-col>
        <el-form :inline="true" :model="searchData">
          <el-form-item label>
            <el-input v-model="searchData.dutyMan" placeholder="请输人员名称"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="searchFun()">
              <i class="el-icon-search"></i> 搜索
            </el-button>
            <el-button type="primary" @click="resetFun()">
              <i class="el-icon-refresh"></i> 重置
            </el-button>
          </el-form-item>
          <el-form-item class="fr">
            <el-button plain type="primary" @click="addFun()">
              <i class="el-icon-plus"></i> 添加值班计划
            </el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
    <el-table :data="tableData.pageData" stripe border style="width:100%;" :loading="false">
      <el-table-column width="50" type="index" label="序号"></el-table-column>
      <el-table-column prop="dutyMan" label="值班人员"></el-table-column>
      <el-table-column prop="dutyDateStart" label="值班开始时间"></el-table-column>
      <el-table-column prop="dutyDateEnd" label="值班结束时间"></el-table-column>
      <el-table-column prop="dutyWeek" label="值班星期" width="150" ></el-table-column>
      <el-table-column prop="createTime" label="创建时间"></el-table-column>
      <el-table-column prop="isCommit" label="日志是否提交">
        <template slot-scope="scope">
            <font>{{scope.row.isCommit == 0 ? '未提交' : '已提交'}}</font>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="300" align="center">
        <template slot-scope="scope">
          <el-button @click="editFunEdit(scope.row)" size="small" :disabled="scope.row.isCommit == 1?true:false">
              <i class="el-icon-edit"></i> 提交日志
          </el-button>
          <el-button @click="editFun(scope.row)" size="small">
            <i class="el-icon-edit-outline"></i> 详情
          </el-button>
          <el-button type="danger" @click="delFun(scope.row)" size="small">
            <i class="el-icon-delete"></i> 删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="total,sizes, prev, pager, next, jumper"
      :total="tableData.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="PAGE.page"
      :page-size="PAGE.size"
    ></el-pagination>
    <BookPlanEdit
      v-if="dialogVisible"
      :dialogVisible="dialogVisible"
      :editForm="formData"
      :title="dialogTit"
      @dialogFun="closeDialog"
      @refreshTableData="getTableData"
      :key="zjKey"
    ></BookPlanEdit>
	
	<BookPlanDownEdit
	  v-if="dialogVisible2"
	  :dialogVisible="dialogVisible2"
	  :dutyId="formData.id"
	  :editForm="formData"
	  :title="dialogTit"
	  @dialogFun="closeDialog"
	  @refreshTableData="getTableData"
	  :key="rzKey"
	></BookPlanDownEdit>
  </div>
</template>


<script lang="ts">
import { Component, Vue, Provide } from "vue-property-decorator";
import BookPlanEdit from "./BookPlanEdit.vue";
import BookPlanDownEdit from "./BookPlanDownEdit.vue";
import METHOD from "@/utils/methods";
@Component({
  components: { BookPlanEdit, BookPlanDownEdit}
})
export default class CamerasMg extends Vue {
  @Provide() signId: String = "";
  @Provide() id: String = "";
  @Provide() tableData: Object = { pageData: [], total: 0 };
  @Provide() PAGE: any = { page: 1, size: 10 };
  @Provide() searchData: any = { dutyMan:'' };
  @Provide() loading: Boolean = false;
  //编辑组件
  @Provide() dialogVisible: Boolean = false;
  @Provide() dialogVisible2: Boolean = false;
  @Provide() dialogTit: String = "新增预案";
  @Provide() formData: Object = {};
  @Provide() zjKey: any = 0;
  
  //日志组件
  // @Provide() dialogVisible: Boolean = false;
  // @Provide() dialogTit: String = "提交日志";
  // @Provide() logData: Object = {};
  @Provide() rzKey: any = 0;
  
  getTableData() {
    let that = this,
      params = Object.assign(that.PAGE, that.searchData);
    (that as any).$axios
      .post("/onDutyInfo/getOnDutyInfoList", params)
      .then((res: any) => {
        if( res ) that.tableData = res;
      });
  }
  searchFun() {
    this.PAGE = { page: 1, size: 10 };
    this.getTableData();
  }
  resetFun() {
    this.PAGE = { page: 1, size: 10 };
    this.searchData = {};
    this.getTableData();
  }
  addFun() {
    this.zjKey++;
    this.dialogVisible = true;
    this.dialogTit = "新增";
  }
  editFun(row: any) {
    this.dialogTit = "详情";
    this.formData = Object.assign({}, row);
    this.zjKey++;
    this.dialogVisible = true;
  }
  editFunEdit(row: any) {
    this.dialogTit = "提交日志";
    this.formData = Object.assign({}, row);
	this.rzKey++;
    this.dialogVisible2 = true;
  }
  delFun(row: any) {
    let that = this as any;
    METHOD.deleteFun(that, `/onDutyInfo/delOnDutyInfoById/${row.id}`, function() {
      that.getTableData();
    });
  }
  handleSizeChange(val: any) {
    this.PAGE.size = val;
    this.getTableData();
  }
  handleCurrentChange(val: any) {
    this.PAGE.page = val;
    this.getTableData();
  }
  closeDialog() {
    //关闭窗口
    this.dialogVisible = false;
	this.dialogVisible2 = false;
    this.formData = {};
  }
  created() {
    this.getTableData();
  }
}
</script>
