<template>
  <div class="max-big-box">
    <div class="big-max-box" v-if="!newModifyPageType&&detailsType==0">
      <!--返回按钮-->
      <div class="out-page-button cursor_pointer" @click="outButton">
        <img src="~@/assets/images/icon_25.png">
        <p>返回</p>
      </div>
      <!--操作按钮-->
      <div class="top-box">
        <div class="input-box">
          <input class="search-input" type="text" v-model="inputData" placeholder="请输入任务名称/任务执行地点关键字进行查询">
          <div class="dropdown-box" v-for="(item,index) in downList" :key="index">
            <p class="dropdown-left-title">{{item.name}}：</p>
            <div class="dropdown-right-box cursor_pointer"
                 @mouseenter="dropdownClickOpen(index,'1')" @mouseleave="dropdownClickOpen(index,'2')">
              <p class="dropdown-text">{{downList[index].downText}}</p>
              <div class="dropdown-for-max" v-if="downList[index].downType">
                <p v-for="(item,indexTwo) in downList[index].list" :key="indexTwo"
                   :class="{'color-A':downList[index].mouseColor == item}"
                   @mouseenter="colorTypeEnter(index,item)" @mouseleave="colorTypeLeave(index)"
                   @click="dropdownClick(index,item)">{{item}}</p>
              </div>
            </div>
          </div>
          <div class="time-box">
            <p>创建时间：</p>
            <p class="cursor_pointer" @click="openTimeBox('1')">{{playTime}}</p>
            <p>-</p>
            <p class="cursor_pointer" @click="openTimeBox('2')">{{endTime}}</p>
          </div>
          <div class="button-box cursor_pointer" @click="clickQuery">
            <img src="~@/assets/images/icon_27.png">
            <p class="cursor_pointer">查询</p>
          </div>
        </div>
      </div>
      <!--表格-->
      <div class="table-box">
        <el-table
          ref="multipleTable"
          :row-key="getRowKey"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%">
          <el-table-column
            type="index"
            :index="indexMethod"
            label="序号"
            width="87">
          </el-table-column>
          <el-table-column
            prop="planName"
            label="预案名称"
            width="305">
          </el-table-column>
          <el-table-column
            prop="planType"
            label="类型"
            width="160">
            <template slot-scope="scope">
              {{scope.row.planType==1?"战备拉动":(scope.row.planType==2?"应急支援":(scope.row.planType==3?"训练考核任务":""))}}
            </template>
          </el-table-column>
          <el-table-column
            prop="isEmergency"
            label="是否是应急预案"
            width="122">
            <template slot-scope="scope">
              <p :class="{'colorA':scope.row.isEmergency==1,'colorB':scope.row.isEmergency==0}">{{scope.row.isEmergency==1?"是":"否"}}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="planContent"
            label="预案内容"
            width="370">
          </el-table-column>
          <el-table-column
            prop="organizationName"
            label="单位名称"
            width="154">
          </el-table-column>
          <el-table-column
            prop="medicalName"
            label="医疗队名称"
            width="193">
          </el-table-column>
          <el-table-column
            prop="carryingEquipment"
            label="携运行物资装备(对应基数单位及数量)"
            width="289">
          </el-table-column>
          <el-table-column
            prop="createUser"
            label="创建人员"
            width="135">
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="创建时间"
            width="219">
          </el-table-column>
          <el-table-column
            label="操作"
            width="240">
            <template slot-scope="scope">
              <div class="table-min-button">
                <div class="cursor_pointer" @click="handleInfo(scope.$index, scope.row)">
                  <img src="~@/assets/images/icon_36.png">
                  <p>详情</p>
                </div>
                <div class="cursor_pointer" @click="handleDelete(scope.$index, scope.row)">
                  <img src="~@/assets/images/icon_60.png">
                  <p>直接选择</p>
                </div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        background
        @current-change="handleCurrentChange"
        layout="prev, pager, next"
        :current-page="currentPage"
        :page-size="pagesize"
        :total="total">
      </el-pagination>
      <!--时间日历-->
      <div class="time-max-big-box" v-if="timeType!=0">
        <div class="time-big-box">
          <el-calendar class="time-min-box" v-model="timeValue">
          </el-calendar>
          <div class="button-box">
            <p class="cursor_pointer" @click="openTimeBox('0')">返回</p>
            <p class="cursor_pointer" @click="clearTimeData">清除</p>
            <p class="cursor_pointer" @click="setTimeData">确定</p>
          </div>
        </div>
      </div>
    </div>
    <details-page
      v-if="detailsType==1"
      :dataInfo="dataInfo">
    </details-page>
    <new-modify
      v-if="newModifyPageType"
      @newModifyLeftClick="newModifyLeftClick"
      @newModifyRightClick="newModifyRightClick"
      :newModifyData="newModifyData">
    </new-modify>
    <interactive-window
      v-if="windowType"
      :windowData="windowData"
      @windowLeftClick="windowLeftClick"
      @windowRightClick="windowRightClick"
    ></interactive-window>
  </div>
</template>

<script>
  import { planFormulationList,medicalCorpsListData,taskInfoAdd,baseUnitDownList } from '@/api/userApi'
  export default {
    name: "choosePlan",//选择预案
    components:{
      detailsPage: resolve => {require(['@/components/detailsPage'], resolve)},//详情组件
      newModify: resolve => {require(['@/components/newModify'], resolve)},//新建/编辑
      interactiveWindow: resolve => {require(['@/components/interactiveWindow'], resolve)},//提示弹窗
    },
    data () {
      return {
        inputData:"",
        //传输用数据
        transmissionData:{},
        //下拉框
        downList:[
          {
            name:"类型",
            downType:false,
            downText:"全部",
            mouseColor:"",
            list:["全部","应急支援","战备拉动","训练考核任务"],
            idType:["","1","2","3"]
          },
          {
            name:"是否是应急预案",
            downType:false,
            downText:"全部",
            mouseColor:"",
            list:["全部","是","否",],
            idType:["","1","0"]
          },
          {
            name:"医疗队名称",
            downType:false,
            downText:"全部",
            mouseColor:"",
            list:[],
            idType:[]
          },
        ],
        //表格限制
        pagesize: 7,
        currentPage:1,
        //列表总数
        total:0,
        /*数据*/
        tableData:[],
        //搜索时间
        playTime:"请选择时间",
        endTime:"请选择时间",
        //日历时间
        timeValue: new Date(),
        timeType:0,
        // 详情页状态
        detailsType:0,
        //给组件传参数据
        dataInfo:[],
        // 弹窗状态
        windowType:false,
        //弹窗组件数据
        windowData:{},
        // 新增-修改页面状态
        newModifyPageType:false,
        //新增-修改页面数据
        newModifyData:{},
        //基数列表
        baseUnitList:[],
      }
    },

    created(){

    },
    mounted() {
      this.medicalCorpsListData();
      this.baseUnitDownList();
    },
    methods: {
      //基数下拉菜单
      async baseUnitDownList () {
        const { data } = await baseUnitDownList();
        if(data.code==200){
          this.baseUnitList = data.data;
        }
      },
      //点击查询
      clickQuery(){
        this.currentPage = 1;
        this.getListData();
      },
      //数据列表
      async getListData () {
        let self = this;
        let obj={
          searchValue:self.inputData,
          pageSize:self.pagesize,
          pageNum:self.currentPage,
          "params[beginTime]":self.playTime=="请选择时间"?"":self.playTime,
          "params[endTime]":self.endTime=="请选择时间"?"":self.endTime,
        };
        for(let i=0;i<self.downList[0].list.length;i++){
          if(self.downList[0].downText==self.downList[0].list[i]){
            obj.planType = self.downList[0].idType[i];
          }
        }
        for(let i=0;i<self.downList[1].list.length;i++){
          if(self.downList[1].downText==self.downList[1].list[i]){
            obj.isEmergency = self.downList[1].idType[i];
          }
        }
        for(let i=0;i<self.downList[2].list.length;i++){
          if(self.downList[2].downText==self.downList[2].list[i]){
            obj.medicalId = self.downList[2].idType[i];
          }
        }
        const { data } = await planFormulationList(obj);
        if(data.code==200){
          this.tableData = data.rows;
          this.total = data.total;
          this.$forceUpdate();
        }
      },
      //获取医疗队下拉菜单
      async medicalCorpsListData () {
        let self = this;
        const { data } = await medicalCorpsListData();
        if(data.code==200){
          let list = [];
          let idType = [];
          list.push("全部");
          idType.push("");
          for(let i=0;i<data.data.length;i++){
            list.push(data.data[i].medical_corps);
            idType.push(data.data[i].id);
          }
          self.downList[2].list = list;
          self.downList[2].idType = idType;
          this.getListData();
        }
      },
      //时间选择事件
      openTimeBox(type){
        this.timeType=type
      },
      setTimeData(){
        let year = this.timeValue.getFullYear();
        let month = this.timeValue.getMonth()+1;
        let day = this.timeValue.getDate();
        if(this.timeType==1){
          this.playTime = year+'-'+month+'-'+day;
        }else if(this.timeType==2){
          this.endTime = year+'-'+month+'-'+day;
        }
        this.timeType = 0;
      },
      clearTimeData(){
        if(this.timeType==1){
          this.playTime = "请选择时间";
        }else if(this.timeType==2){
          this.endTime = "请选择时间";
        }
        this.timeType = 0;
      },
      //下拉菜单进入悬浮状态
      colorTypeEnter(type,item){
        this.downList[type].mouseColor=item;
      },
      //下拉菜单离开悬浮状态
      colorTypeLeave(type){
        this.downList[type].mouseColor = "";
      },
      // 下拉菜单选项悬浮事件
      dropdownClickOpen(type,state){
        if(state==1){
          this.downList[type].downType = true
        }else if(state==2){
          this.downList[type].downType = false
        }
      },
      // 下拉菜单点击事件
      dropdownClick(type,item){
        this.downList[type].downText = item;
        this.downList[type].downType = false;
      },
      //表格绑定ID
      getRowKey (row) {
        return row.id
      },
      indexMethod(index) {
        return (this.currentPage-1)*this.pagesize+index+1;
      },
      //翻页
      handleCurrentChange(val) {
        console.log(`当前页: `,val);
        this.currentPage = val;
        this.getListData();
      },
      //详情
      handleInfo(index, row){
        this.dataInfo =[
          {
            name:"预案名称",
            value:row.planName,
          },
          {
            name:"类型",
          },
          {
            name:"是否是应急预案",
          },
          {
            name:"预案内容",
            value:row.planContent,
          },
          {
            name:"单位名称",
            value:row.organizationName,
          },
          {
            name:"医疗队名称",
            value:row.medicalName,
          },
          {
            name:"携运行物资装备",
            value:row.carryingEquipment,
          },
          {
            name:"创建人",
            value:row.createUser,
          },
          {
            name:"创建时间",
            value:row.createTime,
          },
        ];
        if(row.planType==1){
          this.dataInfo[1].value = "战备拉动";
        }else if(row.planType==2){
          this.dataInfo[1].value = "应急支援";
        }else if(row.planType==3){
          this.dataInfo[1].value = "训练考核任务";
        }
        if(row.isEmergency==1){
          this.dataInfo[2].value = "是";
        }else if(row.isEmergency==0){
          this.dataInfo[2].value = "否";
        }
        this.detailsType = 1;
      },
      // 直接选择
      handleDelete(index, row) {
        let newData = {
          title:"请录入对应信息",
          id:row.id,
          medicalId:row.medicalId,
          medicalName:row.medicalName,
          organizationId:row.organizationId,
          organizationName:row.organizationName,
          list:[
            {
              name:"预案名称",
              value:row.planName,
              textType:true,
            },
            {
              name:"类型",
              textType:true,
            },
            {
              name:"是否是应急预案",
              textType:true,
            },
            {
              name:"预案内容",
              value:row.planContent,
              textType:true,
            },
            {
              name:"单位名称",
              value:row.organizationName,
              textType:true,
            },
            {
              name:"医疗队名称",
              value:row.medicalName,
              textType:true,
            },
            {
              name:"携运行物资装备",
              value:row.carryingEquipment,
              textType:true,
              newList:[]
            },
            {
              name:"创建人",
              value:row.createUser,
              textType:true,
            },
            {
              name:"创建时间",
              value:row.createTime,
              textType:true,
            },
            {
              name:"执行任务时间",
              valueOne:"请选择",
              valueTwo:"请选择",
              doubleTimeType:true,
            },
            {
              name:"执行任务地点",
              value:"",
            },
            {
              name:"备注",
              value:"",
              textArea:true,
            },
          ]
        };
        if(row.planType==1){
          newData.list[1].value = "战备拉动";
        }else if(row.planType==2){
          newData.list[1].value = "应急支援";
        }else if(row.planType==3){
          newData.list[1].value = "训练考核任务";
        }
        if(row.isEmergency==1){
          newData.list[2].value = "是";
        }else if(row.isEmergency==0){
          newData.list[2].value = "否";
        }
        for(let i=0;i<row.planUnitList.length;i++){
          let obj = {
            value:row.planUnitList[i].unitName,
            num:row.planUnitList[i].unitNumber,
          };
          newData.list[6].newList.push(obj)
        }
        this.newModifyData = {...newData};
        this.newModifyPageType = !this.newModifyPageType;
      },
      //弹窗组件左侧按钮方法-对应取消方法
      windowLeftClick(){
        this.windowType = !this.windowType;
      },
      //弹窗组件右侧按钮方法
      windowRightClick(){
        this.windowType = false;
        console.log("点击确定")
        let self = this;
        setTimeout(function(){
          self.windowText();
        },500);
      },
      //成功提示
      windowText(){
        this.windowData = {
          type:"2",
          title:"提示",
          text:"删除成功",
        };
        this.windowType = true;
      },
      //新增-修改组件内左侧按钮事件
      newModifyLeftClick(){
        this.newModifyPageType = !this.newModifyPageType;
      },
      //新增-修改组件内左侧按钮事件
      newModifyRightClick(data){
        console.log(data)
        if(data.list[9].valueOne =="请选择"){
          this.windowData = {
            type:"3",
            title:"提示",
            text:"请选择开始时间",
          };
          this.windowType = !this.windowType;
          return
        }
        if(data.list[9].valueTwo=="请选择"){
          this.windowData = {
            type:"3",
            title:"提示",
            text:"请选择结束时间",
          };
          this.windowType = !this.windowType;
          return
        }
        if(!data.list[10].value){
          this.windowData = {
            type:"3",
            title:"提示",
            text:"请输入执行任务地点",
          };
          this.windowType = !this.windowType;
          return
        }
        if(!data.list[11].value){
          this.windowData = {
            type:"3",
            title:"提示",
            text:"请输备注信息",
          };
          this.windowType = !this.windowType;
          return
        }
        this.taskInfoAdd(data);
        console.log("data",data)
        // this.newModifyPageType = !this.newModifyPageType;
        // console.log("右键传值",data);
        // this.windowData = {
        //   type:"2",
        //   title:"提示",
        //   text:"操作成功",
        //   leftButton:"取消",
        //   rightButton:"确定",
        // };
        // this.windowType = !this.windowType;
      },
      //新建
      async taskInfoAdd (item) {
        let self = this;
        let obj={
          planId:item.id,
          pushType:"2",
          taskName:item.list[0].value,
          planType:"",
          taskContent:item.list[3].value,
          startTime:item.list[9].valueOne=="请选择时间"?"":item.list[9].valueOne,
          endTime:item.list[9].valueTwo=="请选择时间"?"":item.list[9].valueTwo,
          taskPlace:item.list[10].value,
          carryingEquipment:item.list[6].value,
          remark:item.list[11].value,
          medicalId:item.medicalId,
          organizationId:item.organizationId,
          organizationName:item.organizationName,
          medicalName:item.medicalName,
        };
        //类型
        for(let i=0;i<self.downList[0].list.length;i++){
          if(item.list[1].value==self.downList[0].list[i]){
            obj.planType = self.downList[0].idType[i];
          }
        }
        // for(let i=0;i<item.list[6].newList.length;i++){
        //   for(let k=0;k<self.baseUnitList.length;k++){
        //     if(item.list[6].newList[i].value == self.baseUnitList[k].unitName){
        //       let newObj = {
        //         unitId:self.baseUnitList[k].id,
        //         carryingEquipment:self.baseUnitList[k].unitName,
        //         unitNumber:item.list[6].newList[i].num,
        //       };
        //       obj.taskInfoUnitList.push(newObj)
        //     }
        //   }
        // }
        const { data } = await taskInfoAdd(obj);
        if(data.code==200){
          this.newModifyPageType = !this.newModifyPageType;
          this.outButtonOne();
        }
      },
      //供子组件调用方法
      outPage(){
        this.detailsType = 0;
      },
      // 调用父组件方法退出当前页面
      outButton(){
        this.$parent.outPage();
      },
      outButtonOne(){
        this.$parent.outPageOne();
      }
    }
  }
</script>

<style scoped lang="stylus">
  .max-big-box
    display flex
    flex-direction column
    flex:1;
    .big-max-box
      display flex
      flex-direction column
      flex:1;
      //返回按钮
      .out-page-button
        height:30px;
        width:93px;
        margin:0 0 20px 106px;
        background:url("~@/assets/images/button_02.png");
        background-size 100% 100%
        display flex
        img
          display block
          height:12px;
          width:7px;
          margin:9px 10px 0 22px;
        p
          line-height:30px;
          font-size:$font_12;
          color:$color_ff;
          text-align left
      //搜索与操作按钮
      .top-box
        height:30px;
        .input-box
          width:1670px;
          height:30px;
          display flex
          margin-left:105px;
          .search-input
            height:28px;
            width:290px;
            border:1px solid $theme;
            padding-left:10px;
          .dropdown-box
            display flex
            color:$color_ff;
            z-index:1;
            margin-left:30px;
            .dropdown-left-title
              line-height:30px;
              font-size:$font_14;
            .dropdown-right-box
              font-size:$font_12;
              .dropdown-text
                width:160px;
                height:30px;
                line-height:30px;
                background:url("~@/assets/images/button_15.png");
                background-size:100% 100%;
              .dropdown-for-max
                background:$backColor1;
                border-bottom-right-radius 4px
                border-bottom-left-radius 4px
                p
                  width:160px;
                  height:30px;
                  line-height:30px;
                .color-A
                  /*
                  background:$backColor2 !important;
                  color:$color_ff !important;
                  */
                  color:$theme !important;
                  border-bottom-right-radius 4px
                  border-bottom-left-radius 4px
          .time-box
            width:380px;
            display flex
            margin-left:20px;
            p
              color:$color_ff;
            p:nth-child(1)
              width:100px;
              line-height:30px;
              font-size:$font_14;
            p:nth-child(2)
              width:120px;
              height:30px;
              background url("~@/assets/images/button_08.png")
              background-size 100% 100%
              font-size:$font_12;
              line-height:30px;
            p:nth-child(3)
              width:27px;
              line-height:30px;
            p:nth-child(4)
              width:120px;
              height:30px;
              background url("~@/assets/images/button_08.png")
              background-size 100% 100%
              line-height:30px;
              font-size:$font_12;
          .button-box
            margin-left:32px;
            display flex
            height:30px;
            width:80px;
            background:url("~@/assets/images/button_03.png");
            background-size:100% 100%;
            img
              display block
              height:20px;
              width:20px;
              margin:5px 6px 0 13px;
            p
              line-height:30px;
              font-size:$font_12;
              color:$color_ff;
      //表格
      .table-box
        width:1710px !important;
        margin:20px 105px;
        text-align center !important
        //状态监控
        .type-box
          display flex
          p:nth-child(1)
            width:100px;
          p:nth-child(2)
            margin-left:20px;
            height:26px;
            line-height:26px;
            width:70px;
            background url("~@/assets/images/button_14.png")
            background-size 100% 100%
            color:#333;
            font-size:12px;
        /*点击详情*/
        .table-info-p-one
          display inline-block
        .table-info-p-two
          display inline-block
          width:60px;
          height:20px;
          color:$color_33;
          font-size:$font_12;
          background url("~@/assets/images/button_14.png")
          background-size 100% 100%
          border-radius:4px;
        .colorA
          color:$theme3;
        .color2
          color:#4fd1f3;
        .color3
          color:#72c9d0;
        .color4
          color:#68a4a5;
        .color5
          color:#e9ffce;
        .color6
          color:#f4db87;
        .color7
          color:#ec9e4b;
        .color8
          color:#7ce030;
        .table-min-button
          width:175px;
          margin:0 auto;
          display flex
          div:nth-child(1)
            height:20px;
            width:60px;
            font-size:$font_14;
            color:$theme;
            display flex
            margin-right:11px;
            img
              display block
              height:20px;
              width:20px;
              margin-right:4px;
          div:nth-child(2)
            height:20px;
            width:90px;
            font-size:$font_14;
            color:$theme2;
            display flex
            margin-right:11px;
            img
              display block
              height:20px;
              width:20px;
              margin-right:4px;
      //时间日历
      .time-max-big-box
        z-index 6
        height:100%;
        width:100%;
        position: absolute
        top:0;
        left:0;
        background:rgba(0,0,0,0.3);
        .time-big-box
          z-index 6
          height:750px;
          width:660px;
          position: absolute
          top:50%;
          left:50%;
          transform :translate3d(-50%,-50%,0)
          margin:auto;
          background $color_ff
          border-radius:8px;
          border:4px solid $theme;
          .button-box
            display flex
            color:$color_ff;
            width:390px;
            margin:20px auto;
            p:nth-child(1)
              height:30px;
              line-height:30px;
              width:120px;
              background:url("~@/assets/images/button_10.png");
              background-size 100% 100%
            p:nth-child(2)
              margin-left:20px;
              height:30px;
              line-height:30px;
              width:120px;
              background:url("~@/assets/images/button_05.png");
              background-size 100% 100%
            p:nth-child(3)
              margin-left:20px;
              height:30px;
              line-height:30px;
              width:120px;
              background:url("~@/assets/images/button_02.png");
              background-size 100% 100%
    //修改日期选择样式
    /*
    .el-calendar
      background $color_ff
    */
    //修改table表格样式
    .el-table
      background rgba(6,177,240,0.2)
    .el-table /deep/ .el-table__empty-text
      width: 100%;
      text-align left
      margin-left:825px;
    .el-table /deep/ .el-table__body-wrapper::-webkit-scrollbar
      width: 4px;     /*高宽分别对应横竖滚动条的尺寸*/
      height: 4px;
    .el-table /deep/ .el-table__body-wrapper::-webkit-scrollbar-thumb
      border-radius: 5px;
      -webkit-box-shadow: inset 0 0 5px $theme;
      background: $theme;
    .el-table /deep/ .el-table__body-wrapper::-webkit-scrollbar-track
      -webkit-box-shadow: inset 0 0 5px rgba(255,255,255,0);
      border-radius: 0;
      background: rgba(255,255,255,0);
    .el-table /deep/ tr
    .el-table /deep/ th
      background rgba(6,177,240,0)
    .el-table::before
      height:0;
    .el-table /deep/ .cell
      max-height:46px;
      display: -webkit-box;
      -webkit-box-orient: vertical;
      -webkit-line-clamp: 2;
      overflow: hidden;
    .el-table /deep/ td
    .el-table /deep/ th.is-leaf
      border-bottom:0!important;
    .el-table /deep/ .el-checkbox__inner
      //background rgba(6,177,240,0.2)
      border 1px solid #216f93 !important
    .el-table /deep/ thead
      color:$color_ff;
    .el-table
      color:$color_a1
    .el-table /deep/ th
      text-align-last: center;
    .el-table /deep/ td
      text-align-last: center;
    .el-table /deep/ tbody tr:hover > td
      background rgba(6,177,240,0.2)
      color:$theme;
    .el-table /deep/ .el-checkbox
      width:14px;
      margin:0 auto;
      display block
    //修改动作条样式
    .el-pagination.is-background /deep/ .btn-next
    .el-pagination.is-background /deep/ .btn-prev
    .el-pagination.is-background /deep/ .el-pager li
      background:url("~@/assets/images/button_13.png");
      color:$color_ff;
    .el-pagination.is-background /deep/ .el-pager li:not(.disabled).active
      background:url("~@/assets/images/button_14.png");
      color:$color_ff;
    .colorA
      color :$theme;
    ::-webkit-input-placeholder
      color: $border_1;
    ::-moz-placeholder
      color: $border_1;
    ::-ms-input-placeholder
      color: $border_1;

</style>
