<style>
  .scheduMain {
    height: 100%;
    width: 100%;
    padding: 15px;
    background-color: #f2f4f7;
    overflow: hidden;
  }

  .scheduMain .schedu_left {
    width: 248px;
    flex: 0 0 auto;
    position: relative;
    background-image: url(../../assets/images/sched_bg.png);
    background-repeat: no-repeat;
    background-size: 100% auto;
    height: 100%;
  }

  .scheduMain .okr-menu-active {
    color: var(--q-color-primary);
    font-weight: bold;
    background: #ecf1ff;
  }

  .mySched {
    border-radius: 8px;
    overflow: hidden;
    height: 100%;
    background-color: #fff;
  }

  .schedu_ImgDiv {
    width: 68px;
    height: 68px;
    border-radius: 20px;
    overflow: hidden;
    margin: 75px auto 0;
  }

  .schedu_ImgDiv img {
    width: 100%;
    height: 100%;
  }

  .schedu_Name {
    color: #fff;
    font-size: 16px;
    margin-top: 26px;
    text-align: center;
  }

  .schedu_Status {
    font-size: 12px;
    color: #fff;
    text-align: center;
    margin-top: 15px;
  }

  .schedu_st {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-right: 5px;
    position: relative;
    top: 1px;
  }

  .zbz {
    background-color: #00DB4E;
  }

  .xxz {
    background-color: #DBDBDB;
  }

  .wdk {
    background-color: #FE4475;
  }

  .clockon_Duty {
    width: 120px;
    height: 34px;
    background: linear-gradient(90deg, #00BDD3, #00D761);
    border-radius: 10px;
    margin: 100px auto 24px;
    text-align: center;
    line-height: 31px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
  }

  .sche_daka {
    font-size: 18px;
    position: relative;
    left: 5px;
    top: 2px;
  }

  .schedu_jiaojie {
    width: 120px;
    height: 34px;
    line-height: 34px;
    text-align: center;
    border-radius: 10px;
    border: 1px solid #91AEFF;
    color: #C4D4FF;
    font-size: 14px;
    margin: auto;
    cursor: pointer;
  }

  .schScroll {
    background-color: #F6F8FA;
  }

  .sche_Topflex {
    display: flex;
    align-items: center;
  }

  .Sctop_Color {
    font-size: 15px;
    color: #000000;
    width: 19%;
    text-align: center;
    font-weight: 600;
    font-family: pingfang;
  }

  .Scotop_little {
    color: #AAAAAA;
    font-size: 12px;
    font-weight: 400;
    margin-right: 15px;
    display: inline-block;
    text-align: right;
    width: 60px;
  }

  .Scdu_benci::after {
    content: "";
    position: absolute;
    height: 29px;
    width: 2px;
    background: #EBEBEB;
    right: 0;
  }

  .sche_mid {
    display: flex;
    width: 100%;
    justify-content: space-between;
  }

  .sche_midList {
    width: 31.6%;
    height: 320px;
    background: #fff;
    border-radius: 16px;
    border: 1px solid #EBEBEB;
    box-shadow: 0px 1px 1px 0px #E4E7FB;
    overflow: hidden;
    font-family: 'MicrosoftYaHei';
    position: relative;
  }

  .Sche_Bottom {
    margin: 26px 40px 0 40px;
  }

  .scheList_TOP {
    width: 100%;
    height: 107px;
    border-radius: 16px;
    overflow: hidden;
    position: relative;
  }

  .scheList_TOP img {
    width: 100%;
    height: 100%;
  }

  .word_sche {
    color: #fff;
    font-size: 20px;
    position: absolute;
    top: 25px;
    left: 32px;
  }

  .word_scheNumber {
    display: inline-block;
    width: 36px;
    height: 36px;
    color: #fff;
    background-color: #FE4475;
    position: absolute;
    top: 30px;
    left: 130px;
    text-align: center;
    line-height: 36px;
    border-radius: 8px;
    font-size: 25px;
  }

  .scheList_Bottom {
    font-size: 14px;
    color: #000000;
    height: 46px;
    border-bottom: 1px solid #F3F3F3;
    display: flex;
    align-items: center;
  }

  .sche_Dian {
    display: inline-block;
    width: 6px;
    height: 6px;
    background-color: #6D97FF;
    border-radius: 50%;
    margin-right: 10px;
  }

  .schScroll::-webkit-scrollbar {
    display: none;
  }

</style>

<template>
  <div class="scheduMain">
    <div class="flex row mySched">
      <div class="schedu_left">
        <div class="schedu_ImgDiv">
          <img :src="dataList.DutyManIcon" alt="" />
        </div>
        <div class="schedu_Name">
          {{dataList.DutyManName}}
        </div>
        <div class="schedu_Status">
          <span class="schedu_st zbz"></span>{{dataList.StatusStr}}
        </div>
        <div class="clockon_Duty" @click="SetDutyCheck(1)" v-if="dataList.Status==0">
          值班打卡<i class="iconfont icon-jiejue1 sche_daka"></i>
        </div>
        <div class="clockon_Duty" @click="SetDutyCheck(2)" v-if="dataList.Status==1">
          值班交接<i class="iconfont icon-jiejue1 sche_daka"></i>
        </div>
      </div>
      <div class="col scroll schScroll">
        <div class="scheduMain">
          <div class="flex row mySched">
            <div class="col scroll schScroll">
              <template v-if="dataList.Status==1||dataList.Status==2">
                <schedulHead :dataList="dataList"></schedulHead>
                <div class="Sche_Bottom">
                  <template v-if="dataList.Status!=2">
                    <schedulOrder :save-obj="msg" ref="schOrder"></schedulOrder>
                    <schedulVisit :save-obj="msg"></schedulVisit>
                  </template>
                  <template v-else>
                    <schedulOrder :save-obj="msg" :authObj="workAuthObj"></schedulOrder>
                    <schedulVisit :save-obj="msg" :authObj="vitiorAuthObj"></schedulVisit>
                  </template>
                </div>
              </template>
              <template v-if="dataList.Status==0">
                <schedulRemind></schedulRemind>
              </template>
            </div>
          </div>
        </div>
      </div>
    </div>

    <q-dialog v-model="isShowTuFA" style="width:400px">
      <q-card>
        <q-card-section>
          <div class="text-h6">值班交接</div>
        </q-card-section>
        <q-card-section class="q-pt-none">
          <div class="q-gutter-sm" style="width:400px;" v-if="isShowOne">
            <span style="position:relative;top:6px;">突发事件：</span>
            <q-radio v-model="isHaveTufa" :val="2" label="有" />
            <q-radio v-model="isHaveTufa" :val="1" label="无" />
          </div>
          <div class="q-gutter-sm" style="width:400px;" v-if="isShowTwo">
            <span style="position:relative;top:6px;">交接工作：</span>
            <q-radio v-model="isHaveHand" :val="2" label="有" />
            <q-radio v-model="isHaveHand" :val="1" label="无" />
          </div>
          <div class="q-gutter-sm" style="width:400px;margin-top:10px;">
            <span>交接班次：</span>
            <q-select filled multiple option-value="Id" style="display:inline-block;width:300px;" option-label="Name"
              v-model="classCked" :options="classData" emit-value map-options
              label="交接班次">
            </q-select>
          </div>
        </q-card-section>
        <q-card-actions align="right">
          <q-btn flat label="关闭" color="primary" @click="isShowTuFA=false" />
          <q-btn flat label="确定" color="primary" @click="submitHand" />
        </q-card-actions>
      </q-card>
    </q-dialog>

  </div>
</template>
<script>
  import {
    OnDuty,
    OnDuty_V2,
    saveDutyCheck, //值班打卡
    GetHandoverShiftList
  } from '../../api/scheduling/schedu'

  import schedulOrder from '../../components/schedul/schedul-orderlist'
  import schedulVisit from '../../components/schedul/schedul-visit'
  import schedulHead from '../../components/schedul/schedul-head'
  import schedulRemind from '../../components/schedul/schedul-remind'

  export default {
    props: {},
    components: {
      schedulOrder,
      schedulVisit,
      schedulHead,
      schedulRemind
    },
    data() {
      return {
        msg: {
          Id: 0,
          Shift: 0,
          PlanDate: "" //日期
        },
        checkMsg: {
          Id: 0,
          Shift: 0,
          Status: 0, //Status(1-值班打卡，2-交接打卡)
          IsBurst: 0, //突发
          IsHandover: 0, //交接
          HandoverDlandetails:'' //交接班次
        },
        dataList: {},
        //是否显示访客操作按钮
        vitiorAuthObj: {
          isShowAdd: false, //是否显示新增按钮【默认不显示】
          isShowEdit: false, //是否显示编辑按钮【默认不显示】
        },
        //是否显示工作内容相关按钮
        workAuthObj: {
          isShowAdd: false, //是否显示新增按钮【默认不显示】
          isShowEditAndDelete: false, //是否显示编辑和删除按钮【默认不显示】
        },
        isShowTuFA: false,
        isHaveTufa: 1, //是否有突发
        isHaveHand: 1, //是否有交接
        isShowOne: false,
        isShowTwo: false,
        status: 0,
        classData:[], //交接班次选择\
        classCked:[],
      }
    },
    created() {
      if (this.$route.query.Id) {
        this.msg.Id = this.$route.query.Id;
        this.checkMsg.Id = this.$route.query.Id;
      }
      if (this.$route.query.Shift) {
        this.msg.Shift = this.$route.query.Shift;
        this.checkMsg.Shift = this.$route.query.Shift;
      }
      this.getList();
      this.GetHandoverList();
    },
    methods: {
      //请求数据
      getList() {
        OnDuty_V2(this.msg).then(res => {
          if (res.Code == 1) {
            this.dataList = res.Data;
            this.msg.PlanDate = res.Data.PlanDate;
          }
        })
      },
      //值班打卡或值班交接
      SetDutyCheck(status) {
        this.status = status;
        if (this.status == 2) {
          this.checkMsg.IsBurst = this.$refs.schOrder.getTufaHand().IsBurst;
          this.checkMsg.IsHandover = this.$refs.schOrder.getTufaHand().IsHandover;
          //突发事件
          if (this.$refs.schOrder.getTufaHand().IsBurst == 0) {
            this.isShowOne = true;
            this.isShowTuFA = true;
          }else{
            this.isShowOne = false;
          }
          //交接工作
          if (this.$refs.schOrder.getTufaHand().IsHandover == 0) {
            this.isShowTwo = true;
            this.isShowTuFA = true;
          }else{
            this.isShowTwo = false;
          }
          if (this.$refs.schOrder.getTufaHand().IsBurst > 0 && this.$refs.schOrder.getTufaHand().IsHandover > 0) {
            this.saveInfo()
          }
        } else {
          this.saveInfo();
        }
      },
      //保存
      saveInfo() {
        let diaMsg = '';
        if (this.status == 1) {
          diaMsg = '是否确定值班打卡?'
        }
        if (this.status == 2) {
          diaMsg = '是否确定值班交接?'
        }
        this.checkMsg.HandoverDlandetails = this.classCked.toString();
        this.$q.dialog({
          title: '消息提示',
          message: diaMsg,
          cancel: true,
          persistent: true,
          ok: "确定",
          cancel: "取消",
        }).onOk(() => {
          this.checkMsg.Status = this.status;
          saveDutyCheck(this.checkMsg).then(res => {
            if (res.Code == 1) {
              this.getList();
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: '数据保存成功！',
                position: 'top'
              })
              this.$refs.schOrder.getWorkList();
            } else {
              this.$q.notify({
                icon: 'iconfont icon-chenggong',
                color: 'accent',
                timeout: 2000,
                message: res.Message,
                position: 'top'
              })
            }
          })
        }).onCancel(() => {

        });
      },

      //确定是否有突发
      submitHand() {
        if (this.isHaveTufa == 2) {
          this.$q.notify({
            type: 'negative',
            position: "top",
            message: `请填写突发事件`
          })
          this.isShowTuFA = false;
          return
        }
        if (this.isHaveHand == 2) {
          this.$q.notify({
            type: 'negative',
            position: "top",
            message: `请填写交接`
          })
          this.isShowTuFA = false;
          return
        }
        if (this.isHaveTufa == 1&&this.isHaveHand == 1) {
          this.checkMsg.IsBurst = 1;
          this.checkMsg.IsHandover = 1;
          this.saveInfo();
        }
        this.isShowTuFA = false;
      },

      //刷新父页面
      refreshPage() {
        this.getList();
      },
      //获取交接班次下拉
      GetHandoverList(){
        GetHandoverShiftList().then(res => {
          if (res.Code == 1) {
            this.classData = res.Data;
          }
        })
      }
    },
  }

</script>
