<template>
  <div class="wrapper editwrap">
    <el-dialog
      :visible.sync="dialogVisible"
      :title="title"
      :show-close="false"
      :close-on-click-modal="false"
    >
      <el-row>
        <el-col :span="24">
          <el-form class="el-form-class" ref="editForm" :model="editForm" :rules="rules" label-width="100px">
            <!-- <div v-if="title != '详情'">
            </div>
            <div v-else>>
            </div> --> 
			
			<div v-if="title == '提交日志'">
				<el-form-item label="实际值班人员" prop="realityDutyUser" v-model="editForm.realityDutyUser">
				  <el-tree
					:props="NumbersProps"
					:data="NumberArrAll"
					node-key="id"
					show-checkbox
					ref="zbyTree"
				  ></el-tree>
				</el-form-item>
			</div>
			<div v-else>
				<el-form-item label="实际值班员" prop="realityDutyUser">
					<el-input :readonly="true" type="textarea" v-model="editForm.realityDutyUser"></el-input>
				</el-form-item>
			</div>
			<el-form-item label="值班开始时间" prop="dutyDateStart">
			  <el-date-picker
				v-model="editForm.dutyDateStart"
				type="datetime"
				placeholder="选择日期时间"
				align="right"
				value-format="yyyy-MM-dd HH:mm:ss"
				@change="datePick"
				:readonly="true"
			  ></el-date-picker>
			</el-form-item>
			<el-form-item label="值班结束时间" prop="dutyDateEnd">
			  <el-date-picker
				v-model="editForm.dutyDateEnd"
				type="datetime"
				placeholder="选择日期时间"
				align="right"
				value-format="yyyy-MM-dd HH:mm:ss"
				@change="datePick"
				:readonly="true"
			  ></el-date-picker>
			</el-form-item>
			<el-form-item label="值班日志" prop="dutyLog">
				<el-input type="textarea" v-model="editForm.dutyLog"></el-input>
			</el-form-item>
			<el-form-item label="备注" prop="remarks">
			  <el-input type="textarea" v-model="editForm.remarks"></el-input>
			</el-form-item>
          </el-form>
        </el-col>
      </el-row>
     <span slot="footer" class="dialog-footer">
       <el-button type="primary" size="small" @click="confirmFun('editForm')" v-if="title != '详情'">提交</el-button>
       <el-button @click="$emit('dialogFun')" size="small">取消</el-button>
     </span>
    </el-dialog>
  </div>
</template>
<style lang="scss">
.w100 .el-dialog {
  width: 80%;
  .flcolum {
    > div {
      border-radius: 3px;
    }
  }
  .yatit {
    background: #4273bd;
    color: #ffffff;
    line-height: 2;
    height: 2em;
    text-align: center;
    margin-bottom: 10px;
    border-radius: 2px;
  }
  .el-transfer-panel {
    width: calc((100% - 116px) / 2);
  }
  .el-transfer__buttons {
    width: 56px;
  }
  .el-transfer__button {
    margin-left: 0;
    display: block;
  }
  
}
.el-row .el-form-class .el-form-item__label{
	width: 110px !important;
  }
  .el-form-class .el-form-item__content {
	margin-left: 110px !important;
  }
</style>
<script lang="ts">
import { Component, Vue, Provide, Prop } from "vue-property-decorator";
import { State, Getter, Mutation, Action } from "vuex-class";
import METHOD from "@/utils/methods";
@Component({
  components: {}
})
export default class BookPlanDownEdit extends Vue {
  // @Getter('signs') signsData: any;
  @Prop(Boolean) dialogVisible!: Boolean;
  @Provide() showRentPrise: Boolean = false;
  @Prop(String) title!: String;
  @Prop(String) id!: String;
  @Prop(String) dutyId!: String;
  @Prop(Object) editForm: any = {
	  id: "",
	  dutyId: "",
	  realityDutyUser: ""
   }; 

  @Provide() rules: any = {
    // dutyId: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
    realityDutyUser: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
	dutyDateStart: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
	dutyDateEnd: [{ required: true, trigger: "blur", message: "该项为必填项！" }],
	dutyLog: [{ required: true, trigger: "blur", message: "该项为必填项！" }]
    // handoverMan: [{ required: true, trigger: "blur", message: "该项为必填项！" }]
    // handoverContent: [{ required: true, trigger: "blur", message: "该项为必填项！" }]
  };

  @Provide() NumberArr: any = [];
  @Provide() NumberArrAll: any = [];
  @Provide() checkedArr: any = [];
  @Provide() NumbersProps: Object = {
    key: "uid",
    label: "userName"
  };
  //取消事件要在父级取消是所以用到 $emit
  confirmFun(formName: string) {
    let that = this;
	that.editForm.dutyId=this.dutyId;
    that.editForm.realityDutyUser = that.getTreeNode("zbyTree");
    // that.editForm.handoverMan = that.getTreeNode("qtrTree");
    console.log(that.editForm);
    (that as any).$refs[formName].validate((valid: boolean) => {
      if (valid) {
        (that as any).$axios
          // .post("/onDutyInfo/addOrEditOnDutyInfo", that.editForm)
		  .post("/onDutyLog/addOrEditOnDutyLog", that.editForm)
          .then(() => {
            (that as any).$message({
              message: "操作成功！",
              type: "success"
            });
            (that as any).$emit("dialogFun");
            that.$emit("refreshTableData"); //刷新表格
          });
      } else {
        return false;
      }
    });
  }
  //人员
  getNumberData() {
    let that = this;
    (that as any).$axios.get(`/user/getDutyContactsList`).then((res: any) => {
      that.NumberArr = res;
      that.NumberArrAll = [
        {
          uid: 0,
          userName: "选择值班人员",
          children: that.NumberArr
        }
      ];
	  
    });
  }
  getTreeNode(refName: string) {
    let that = this,
      strs: any = [],
      checkedNode;
    checkedNode = (that.$refs[refName] as any).getCheckedNodes();
    checkedNode.forEach((ele: any) => {
      if (ele.uid != 0)
        strs.push((ele.deptName || '-') + "|" + (ele.userName || '-') + "|" + (ele.mobliePhone || '-'));
    });
    return strs.join(",");
  }
  datePick(v: string) {
    let today: Date = new Date(v);
    let d = today.getDay(),
      chnNumChar = ["日", "一", "二", "三", "四", "五", "六"];
    this.editForm.dutyWeek = "星期" + chnNumChar[d];
  }
  created() {
    
    
  }
  mounted() {
	  this.getNumberData();
  }
}
</script>
