<style>
  @import "../../../assets/css/newTravelManager.css";
</style>
<template>
  <div>
    <div class="TC_Content">
      <div class="query-box">
        <ul>
          <li>
            <span>
              <em>所属线路</em>
              <el-select class='w150' v-model="queryMsg.LineId" filterable :placeholder="$t('pub.pleaseSel')" @change="getLineTeamList()">
                <el-option :label="$t('pub.unlimitedSel')" :value='queryCommonData.SelectDefaultValue'></el-option>
                <el-option v-for="item in queryCommonData.LineList" :label='item.LineName' :value='item.LineID' :key='item.LineID'>
                </el-option>
              </el-select>
            </span>
          </li>
          <li>
            <span>
              <em>团号</em>
              <el-input maxlength="50" v-model="queryMsg.TCNUM" class="permiss-input w150" @keyup.native.enter="getList"
                :placeholder="$t('pub.pleaseImport')"></el-input>
            </span>
          </li>
          <li>
            <span>
              <em>发团日期</em>
              <el-date-picker class="w150" type="date" v-model='queryMsg.StartGroupDate' :picker-options="pickerBeginDateBefore"
                value-format="yyyy-MM-dd" placeholder="">
              </el-date-picker>
              <el-date-picker class="w150" type="date" v-model='queryMsg.EndGroupDate' :picker-options="pickerBeginDateAfter"
                value-format="yyyy-MM-dd" placeholder="">
              </el-date-picker>
            </span>
          </li>
          <li>
            <button class="hollowFixedBtn" @click="getList(),resetPageIndex()">{{$t('pub.searchBtn')}}</button>
            <button class="hollowFixedBtn" @click="goToOpenTravel('BasicOpenGroup')">新增</button>
          </li>
        </ul>
      </div>
      <div class="TC_ListContent" v-loading='queryCommonData.loading'>
        <div class="TC_List clearfix" v-for="item in queryCommonData.dataList" :key="item.subCode">
          <div class="TC_TeamInfo clearfix" :data-id="item.ID">
            <div class="TC_leftInfo">
              <span class="TC_CompanyName">
                {{item.CompanyName}}
              </span>
              <div class="TC_PlatDiv clearfix">
                <span class="TC_neibu" v-if="item.TCState==3" :class="{'TCneibu':plat==3,'TCb2b':plat==1,'TCb2c':plat==2,'AppPlat':plat==4,'otherPlat':plat==5}"
                  v-for="plat in item.SalePlat" :key="plat.subCode">
                  {{$tripUtils.getPlatName(plat)}}
                </span>
              </div>
              <span class="TC_xiajia daiwanshan" v-if="item.TCState==1">待完善</span>
              <span class="TC_xiajia" v-if="item.TCState==3">已上架</span>
              <span class="TC_xiajia" v-if="item.TCState==2">已下架</span>
              <span class="TC_xiajia quxiao" v-if="item.TCState==4">已取消</span>
            </div>
            <div class="TC_rightInfo">
              <div class="TC_Ti">
                <i class="iconfont icon-lists"></i>
                <el-tooltip popper-class="max-w250" effect="dark" :content="item.LineName" placement="top-start">
                  <span>{{item.LineName}}</span>
                </el-tooltip>
              </div>
              <div class="TC_TCont">
                <el-tooltip popper-class="max-w250" effect="dark" :content="item.LtName" placement="top-start">
                  <span>{{item.LtName}}</span>
                </el-tooltip>
              </div>
               <div class="TC_TCont">
                <el-tooltip popper-class="max-w250" effect="dark" :content="item.Title" placement="top-start">
                  <span>{{item.Title}}</span>
                </el-tooltip>
              </div>
            </div>
          </div>
          <div class="TC_TeamInfo">
            <div class="TC_topTeam">
              <i class="iconfont icon-img-rili"></i>团期<span class="TC_teamCodeNum">(编号:{{item.ID}})</span>
            </div>
            <div class="TC_groupStage">
              <div class="TC_GroupList" :class="{'yv1':dataItem.bkColor==1,'yv2':dataItem.bkColor==2,'yv3':dataItem.bkColor==3,'yv4':dataItem.bkColor==4,'teamCked':item.checkIndex==index,'purpleStyle':dataItem.RemainNum<0,
                            'cancelGrop':dataItem.Status==3,'IssuedGrop':dataItem.Status==2}"
                v-for="(dataItem,index) in item.GroupList" :key="dataItem.subCode">
                <span title="点击查看报价" @click="item.checkIndex = index">{{dataItem.StartDate| formatStartDate(dataItem.StartDate)}}</span>
                <span title="点击查看名单" v-if="dataItem.RemainNum>=0" @click='goUrl("RegistrationList", dataItem.TCID)'>余{{dataItem.RemainNum}}</span>
                <span title="点击查看名单" v-if="dataItem.RemainNum<0" @click='goUrl("RegistrationList", dataItem.TCID)'>超{{-dataItem.RemainNum}}</span>
                <!-- <span class="TCckedSpan"></span> -->
              </div>
            </div>
          </div>
          <div class="TC_Price">
            <div class="TC_topTeam">
              <i class="iconfont icon-img_jiaqian"></i>价格
            </div>
            <div class="TC_P1 clearfix">
              <div class="TC_leftConTitle">
                <span class="TC_PriceLeft">标准</span>
              </div>
              <div class="TC_rightConList">
                <span class="TC_comPrice">同行会员<span class="TC_PriceList">{{item.GroupList[item.checkIndex].B2BMemberPrice}}</span></span>
                <span class="TC_comPrice">同行<span class="TC_PriceList">{{item.GroupList[item.checkIndex].B2BPrice}}</span></span>
                <span class="TC_comPrice">直客会员<span class="TC_PriceList">{{item.GroupList[item.checkIndex].B2CMemberPrice}}</span></span>
                <span class="TC_comPrice">直客<span class="TC_PriceList">{{item.GroupList[item.checkIndex].B2CPrice}}</span></span>
                <span class="TC_comPrice">婴儿<span class="TC_PriceList">{{item.GroupList[item.checkIndex].BabyPrice}}</span></span>
                <span class="TC_comPrice">单地接<span class="TC_PriceList">{{item.GroupList[item.checkIndex].SingleDMCPrice}}</span></span>
              </div>
            </div>
            <div class="TC_P1 clearfix">
              <div class="TC_leftConTitle">
                <span class="TC_PriceLeft">增收</span>
              </div>
              <div class="TC_rightConList">
                <span class="TC_comPrice">儿童占床<span class="TC_PriceList">{{item.GroupList[item.checkIndex].ChildNeedPrice}}</span></span>
                <span class="TC_comPrice">儿童附加费<span class="TC_PriceList">{{item.GroupList[item.checkIndex].BabyChargePrice}}</span></span>
                <span class="TC_comPrice">老人附加费<span class="TC_PriceList">{{item.GroupList[item.checkIndex].OldManChargePrice}}</span></span>
                <span class="TC_comPrice">签证费<span class="TC_PriceList">{{item.GroupList[item.checkIndex].VisaPrice}}</span></span>
                <span class="TC_comPrice">单房差<span class="TC_PriceList">{{item.GroupList[item.checkIndex].SingleRoomPrice}}</span></span>
                <span class="TC_comPrice">保险<span class="TC_PriceList">{{item.GroupList[item.checkIndex].SafeMoney}}</span></span>
                <span class="TC_comPrice">杂费<span class="TC_PriceList">{{item.GroupList[item.checkIndex].OtherPrice}}</span></span>

                <!-- <span class="TC_comPrice">婴儿<span class="TC_PriceList">{{item.GroupList[item.checkIndex].BabyPrice}}</span></span> -->
              </div>
            </div>
            <div class="TC_P1 clearfix">
              <div class="TC_leftConTitle">
                <span class="TC_PriceLeft">减免</span>
              </div>
              <div class="TC_rightConList">
                <span class="TC_comPrice">儿童不占床<span class="TC_PriceList">{{item.GroupList[item.checkIndex].ChildNoNeedPrice}}</span></span>
                <span class="TC_comPrice">退签证费<span class="TC_PriceList">{{item.GroupList[item.checkIndex].BackVisaPrice}}</span></span>
              </div>
              <!-- <span class="TC_comPrice">同行返佣<span class="TC_PriceList">{{item.GroupList[item.checkIndex].RebatePrice}}</span></span>
              <span class="TC_comPrice">早鸟优惠<span class="TC_PriceList">{{item.GroupList[item.checkIndex].DiscountPrice}}</span></span> -->
            </div>
          </div>
          <div class="TC_Common">
            <div class="TC_topTeam">座位</div>
            <div class="TC_flightSeat">经济舱<span class="TC_Seat">{{item.GroupList[item.checkIndex].YSeat}}</span></div>
            <div class="TC_flightSeat">商务舱<span class="TC_Seat">{{item.GroupList[item.checkIndex].CSeat}}</span></div>
            <div class="TC_flightSeat">头等舱<span class="TC_Seat">{{item.GroupList[item.checkIndex].FSeat}}</span></div>
          </div>
          <div class="TC_Common ComOP">
            <div class="TC_topTeam">OP</div>
            <div>
              <span class="TC_OPHeader">
                <img v-if="item.CreateUserPhoto" :src="item.CreateUserPhoto" alt="">
                <img v-else src="../../../assets/img/default_head_img.jpg" alt="">
              </span>
              <span class="TC_OPName">{{item.CreateUserName}}</span>
            </div>
            <div class="TC_uptime">
              <span>更新日期</span>
              <span>{{item.UpdateDate}}</span>
            </div>
          </div>
          <div class="TC_BtnList">
            <div class="TC_TeamConfig"><button  @click="goToOpenTravel('BasicOpenGroup',item.ID)" class="normalBtn teamConfig">团期配置</button></div>
            <div class="chooseOperation">
              <el-dropdown  @command="getMore" >
                <el-button type="primary">
                  {{item.comInfoList}}<i class="el-icon-arrow-down el-icon--right"></i>
                </el-button>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item v-for="subItem in item.moreOperationList" trigger="click" @click.native="getOperation(item,subItem.Id)"  v-if="subItem.IsShow" :key='subItem.Id'>{{subItem.label}}</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </div>
          </div>
        </div>
        <div class="noData" v-show="queryMsg.noData">
          {{$t('system.content_noData')}}
        </div>
        <el-pagination background @current-change="handleCurrentChange" :current-page.sync="queryMsg.currentPage" layout="total,prev, pager, next, jumper"
          :page-size='queryMsg.pageSize' :total='queryMsg.total'>
        </el-pagination>
        <div class="combottomDiv TC_divCon" v-if="queryCommonData.setPlatDialog">
            <div class="combottomTitle">{{queryCommonData.comPlatTitle}}</div>
            <span class="setPlatLeft">销售平台</span>
            <span>
              <el-checkbox v-model="queryCommonData.checkDialogAll" @change="checkAllDialog" style="margin-right:20px;">{{$t('system.table_chekAll')}}</el-checkbox>
              <el-checkbox-group v-model="queryCommonData.ckedplat"  @change="checkDialog">
                <el-checkbox v-for="sales in $tripUtils.TeamStatesList.salsPlat" :label="sales.Id" :key="sales.Name">{{sales.Name}}</el-checkbox>
              </el-checkbox-group>
            </span>
            <span>
                <button class="normalBtn" style="margin-left:50px;" @click="setPlatForm">确定</button>
                <button class="hollowFixedBtn" @click="queryCommonData.setPlatDialog=false">取消</button>
            </span>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      //查询数据列表
      queryCommonData: {
        //线路列表
        LineList: [],
        //下拉框默认值
        SelectDefaultValue: 0,
        //航空公司
        AirlineList: [],
        //员工列表
        EmployeeList: [],
        //显示销售平台
        showPlatForm: false,
        //团期全选
        checkGroupALL: false,
        //销售平台全选
        checkPlatForm: false,
        //团队状态全选
        checkTCStateAll: false,
        //是否显示弹出框
        setPlatDialog: false,
        //弹出框全选
        checkDialogAll: false,
        //选择上架平台
        ckedplat: [],
        //loading
        loading: false,
        //中间变量ID
        comID: "",
        //中间变量TCState
        comState: "",
        //标题
        comPlatTitle: "",
        //高级搜索
        showHigradeSearch: false,
        //数据列表
        dataList: []
      },
      //查询参数
      queryMsg: {
        pageIndex: 1,
        pageSize: 3,
        LineId: 0,
        LineIdList: [],
        LineteamId: 0,
        TCNUM: "",
        StartGroupDate: "",
        EndGroupDate: "",
        OutBranchId: -1,
        AirTicketId: 0,
        TeamMinNum: "",
        TeamMaxNum: "",
        CreateBy: 0,
        ApplyMinNum: "",
        ApplyMaxNum: "",
        DayNum: "",
        OnlyShowOverTeam: false,
        TCState: [],
        GroupState: [],
        SalePlat: [],
        total: 0,
        //是否有数据
        noData: false,
        currentPage: 1,
        IsBasic:true
      },
      pickerBeginDateBefore: {
        disabledDate: time => {
          let endTime = new Date(this.queryMsg.EndGroupDate);
          return endTime.getTime() < time.getTime();
        }
      },
      pickerBeginDateAfter: {
        disabledDate: time => {
          let startTime = new Date(this.queryMsg.StartGroupDate);
          return startTime.getTime() >= time.getTime();
        }
      }
    };
  },
  methods: {
    //翻页
    handleCurrentChange(val) {
      this.queryMsg.pageIndex = val;
      this.getList();
    },
    //重新查询
    resetPageIndex() {
      this.queryMsg.pageIndex = 1;
      this.queryMsg.currentPage = 1;
    },
    //获取线路列表
    getLineList() {
      this.apipost("line_post_GetList", {}, res => {
        if (res.data.resultCode == 1) {
          this.queryCommonData.LineList = res.data.data;
        }
      });
    },
    //获取航空公司
    getAirlineList() {
      this.apipost(
        "airline_post_GetList",
        {},
        res => {
          if (res.data.resultCode == 1) {
            this.queryCommonData.AirlineList = res.data.data;
          }
        },
        err => {}
      );
    },
    //根据当前员工所在部门获取该部门及子部门员工信息
    getEmployeeList() {
      let userInfo = this.getLocalStorage();
      let msg = {
        GroupId: userInfo.RB_Group_id,
        BranchId: "-1",
        DepartmentId: "-1",
        PostId: "-1",
        IsLeave: "0"
      };
      this.apipost(
        "admin_get_EmployeeGetList",
        {},
        res => {
          if (res.data.resultCode == 1) {
            this.queryCommonData.EmployeeList = res.data.data;
          }
        },
        err => {}
      );
    },

    //获取列表数据
    getList() {
      this.queryCommonData.loading = true;
      var msg = JSON.parse(JSON.stringify(this.queryMsg));
      msg.IsBasic = true;
      if (msg.TeamMinNum == "") {
        msg.TeamMinNum = -1;
      }
      if (msg.TeamMaxNum == "") {
        msg.TeamMaxNum = -1;
      }
      if (msg.ApplyMinNum == "") {
        msg.ApplyMinNum = -1;
      }
      if (msg.ApplyMaxNum == "") {
        msg.ApplyMaxNum = -1;
      }
      if (msg.DayNum == "") {
        msg.DayNum = -1;
      }
      this.apipost(
        "travel_get_GetTravelPageList",
        msg,
        res => {
          this.queryCommonData.loading = false;
          if (res.data.resultCode == 1) {
            var _thisData = res.data.data.pageData;
            _thisData.forEach(x => {
              x.GroupList.forEach(y => {
                var total =
                  parseInt(y.FSeat) + parseInt(y.CSeat) + parseInt(y.YSeat);
                let harfTotal = total / 2;
                var remain =total-(
                  parseInt(y.SurplusCSeat) +
                  parseInt(y.SurplusFSeat) +
                  parseInt(y.SurplusYSeat));
                if (remain >= harfTotal && remain != total) {
                  y.bkColor = 1; //红色
                } else if (remain < total && remain > harfTotal) {
                  y.bkColor = 2; //蓝色
                } else if (remain >= total) {
                  y.bkColor = 3; //绿色
                } else {
                  y.bkColor = 4; //天蓝色
                }
              });
              if (x.SalePlat) {
                x.SalePlat = x.SalePlat.split(",");
              }
              var obj = this.$tripUtils.moreOperationObj();
              //下架
              if (x.TCState == 3) {
                obj.ItemArray.forEach(moreItem => {
                  if (moreItem.Id == obj.Item.Soldout) {
                    moreItem.IsShow = true;
                  }
                  if (moreItem.Id == obj.Item.Sell) {
                    moreItem.IsShow = false;
                  }
                });
              }
              //上架
              else if (x.TCState == 2 || x.TCState == 1) {
                obj.ItemArray.forEach(moreItem => {
                  if (moreItem.Id == obj.Item.Sell) {
                    moreItem.IsShow = true;
                  }
                  if (moreItem.Id == obj.Item.Soldout) {
                    moreItem.IsShow = false;
                  }
                });
              }

              x.moreOperationList = obj.ItemArray;
              x.comInfoList = "更多操作";
              x.checkIndex = 0;
              x.OperationId = 0;
            });
            this.queryCommonData.dataList = _thisData;
            this.queryMsg.total = res.data.data.count;
            this.queryMsg.noData = !this.queryMsg.total > 0;
          }
        },
        err => {}
      );
    },
    //验证大小
    checkTeamNum(queryMsg) {
      var TeamMinNum = parseInt(queryMsg.TeamMinNum);
      var TeamMaxNum = parseInt(queryMsg.TeamMaxNum);
      var ApplyMinNum = parseInt(queryMsg.ApplyMinNum);
      var ApplyMaxNum = parseInt(queryMsg.ApplyMaxNum);
      if (TeamMaxNum < TeamMinNum) {
        queryMsg.TeamMaxNum = "";
      }
      if (ApplyMaxNum < ApplyMinNum) {
        queryMsg.ApplyMaxNum = "";
      }
    },
    //团期状态全选
    checkGroupAll(val) {
      this.queryMsg.GroupState = [];
      if (val) {
        this.$tripUtils.TeamStatesList.teamDateStates.forEach(x => {
          this.queryMsg.GroupState.push(x.Id);
        });
      }
    },
    checkGroup(value) {
      let checkedCount = value.length;
      this.queryCommonData.checkGroupALL =
        checkedCount === this.$tripUtils.TeamStatesList.teamDateStates.length;
    },
    //销售平台全选
    checkAllSales(val) {
      this.queryMsg.SalePlat = [];
      if (val) {
        this.$tripUtils.TeamStatesList.salsPlat.forEach(x => {
          this.queryMsg.SalePlat.push(x.Id);
        });
      }
    },
    checkSales(value) {
      let checkedCount = value.length;
      this.queryCommonData.checkPlatForm =
        checkedCount === this.$tripUtils.TeamStatesList.salsPlat.length;
    },
    //团队状态全选
    checkAllTeam(val) {
      this.queryMsg.TCState = [];
      if (val) {
        this.$tripUtils.TeamStatesList.TeamStates.forEach(x => {
          this.queryMsg.TCState.push(x.Id);
        });
      }
      if (
        this.queryMsg.TCState.indexOf(
          this.$tripUtils.TeamStatesList.TeamStates[2].Id
        ) > -1
      ) {
        this.queryCommonData.showPlatForm = true;
      } else {
        this.queryCommonData.showPlatForm = false;
      }
    },
    checkedTeamList(value) {
      if (value.indexOf(this.$tripUtils.TeamStatesList.TeamStates[2].Id) > -1) {
        this.queryCommonData.showPlatForm = true;
      } else {
        this.queryCommonData.showPlatForm = false;
      }
      let checkedCount = value.length;
      this.queryCommonData.checkTCStateAll =
        checkedCount === this.$tripUtils.TeamStatesList.TeamStates.length;
    },
    //全选弹出框
    checkAllDialog(val) {
      this.queryCommonData.ckedplat = [];
      if (val) {
        this.$tripUtils.TeamStatesList.salsPlat.forEach(x => {
          this.queryCommonData.ckedplat.push(x.Id);
        });
      }
    },
    checkDialog(value) {
      let checkedCount = value.length;
      this.queryCommonData.checkDialogAll =
        checkedCount === this.$tripUtils.TeamStatesList.salsPlat.length;
    },
    getMore() {},
    //切换下拉框
    getOperation(item, optionId) {
      item.moreOperationList.forEach(x => {
        if (x.Id == optionId) {
          item.comInfoList = x.label;
        }
      });
      var subItemId = optionId;
      this.queryCommonData.ckedplat = [];
      this.queryCommonData.comPlatTitle = "请选择上架平台";
      if (subItemId == 3) {
        this.queryCommonData.setPlatDialog = true;
        this.queryCommonData.comID = item.ID;
        this.queryCommonData.comState = subItemId;
      }
      switch (subItemId) {
        case 2:
          let msg = {
            ID: item.ID,
            TCState: this.$tripUtils.TeamStatesList.TeamStates[1].Id,
            SalePlat: ""
          };
          this.apipost("travel_post_SetTCState", msg, res => {
            if (res.data.resultCode == 1) {
              this.getList();
              this.Success(res.data.message);
            }
          });
          break;
        case 4:
          this.goUrl("DistributionTransport", item.ID);
          break;
      }
    },
    //设置上架平台
    setPlatForm() {
      let msg = {
        ID: this.queryCommonData.comID,
        TCState: this.$tripUtils.TeamStatesList.TeamStates[2].Id,
        SalePlat: this.queryCommonData.ckedplat.join(",")
      };
      if (msg.SalePlat == "") {
        this.Error("请选择上架平台");
        return;
      }
      this.apipost("travel_post_SetTCState", msg, res => {
        if (res.data.resultCode == 1) {
          this.getList();
          this.Success(res.data.message);
          this.queryCommonData.setPlatDialog = false;
          this.queryCommonData.checkDialogAll = false;
        }
      });
    },
    goUrl(path, id) {
      this.$router.push({ name: path, query: { id: id } });
    },
    //开团或修改
    goToOpenTravel(path, configId) {
      if (configId > 0) {
        this.$store.commit("pageConditionUpdate", this.queryMsg);
        this.$router.push({
          name: path,
          query: { configId: configId, openState: 1 }
        });
      } else {
        this.$router.push({ name: path });
      }
    }
  },
  filters: {
    formatStartDate(value) {
      let dataArr = value.split("-");
      return dataArr[1] + "-" + dataArr[2];
    }
  },
  mounted() {
    this.getLineList();
    this.getAirlineList();
    this.getEmployeeList();
  },
  created() {
    if (this.$route.query.hasOwnProperty("cache")) {
      if (this.$store.state.pageCondition != null) {
        this.queryMsg = this.$store.state.pageCondition;
      }
    }
    this.getList();
  }
};
</script>