<style>
  @import "../../assets/css/newTravelManager.css";
.DT_rightList {
  float: left;
  font-size: 12px;
  width:100%;
  margin-top: 10px;
}
.DT_rightList ._Checked {
  padding: 5px 10px;
  border-radius: 3px;
  margin-left: 10px;
}
/*未选中的状态*/
.DT_rightList .NoChecked {
  cursor: pointer;
  background-color: #c0ebd1;
}

/*选中的状态*/
.DT_rightList .YesChecked {
  cursor: pointer;
  background-color: #E95252;
  color:#fff;
}

.DT_rightList .DT_Table {
  width: 1100px;
  border-collapse: collapse;
}

.DT_rightList .DT_Table tr td {
  border: 1px solid #e5e5e5;
}

.DT_rightList .TMTitle {
  margin-bottom: 20px;
}

.DT_rightList .singeRowTable tr:hover {
  background-color: #fff !important;
}
.DT_rightList .singeRowTable tr:nth-child(2n + 1) {
  background-color: #fff !important;
}
.DT_rightList .el-button.is-circle{
  padding: 3px;
}
.DT_ConbinBtn{
  margin:10px 0 0 0;
  padding:0 10px;
  height:25px;
}
.DT_saveBtn{
  margin:10px 0 0 165px;
}
.Distri_TeamDayList{
  display: inline-block;
}
</style>
<template>
  <div class="clearfix">
    <div class="DT_rightList">
      <div class="TMTitle"><i></i>联运设置</div>
      <!--保存-->
      <input type='button' class="normalBtn" @click="SaveUnion()" value="保存"></input>
      <table class="singeRowTable DT_Table" border="0" cellspacing="0" cellpadding="0" v-loading="loading">
        <thead>
          <tr>
            <th width="140">
              公司
            </th>
            <th width="100">
              城市
            </th>
            <th width="80">
              航段
            </th>
            <th width="110">
              出发日期
            </th>
            <th width="200">
              航空公司
            </th>
            <th width="200">
              航班
            </th>
            <th width="100">
              是否住宿
            </th>
            <th width="110">
              票务估价
            </th>
            <th width="110">
              配置数量
            </th>
          </tr>
        </thead>
        <template v-if="UnionList&&UnionList.length>0">
          <tbody v-for="(item,index) in UnionList" :key="item.subCode">
            <tr>
              <td rowspan="2">
                <el-select class="w120" filterable v-model="item.UnionBranchId" :disabled="true">
                  <el-option label='请选择' :value="defaultBranchId"></el-option>
                  <el-option v-for="subItem in CompanyList" :label='subItem.BName' :value='subItem.Id' :key="subItem.Id">
                  </el-option>
                </el-select>
              </td>
              <td rowspan="2">
                <el-select class="w80" filterable v-model="item.UnionCityId" :disabled="true">
                  <el-option label='请选择' :value="selectDefauleValue"></el-option>
                  <el-option v-for="subItem in cityList" :label='subItem.Name' :value='subItem.ID' :key="subItem.subCode">
                  </el-option>
                </el-select>
              </td>
              <td>
                去程
              </td>
              <td>
                <el-select class="w95" filterable v-model="item.DayNum" :disabled="true">
                  <el-option v-for="subItem in DayList" :label='subItem.Name' :value='subItem.ID' :key="subItem.subCode">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-select class="w180" filterable v-model="item.AirLineId" @change="airLineSelectChange(item,item.AirLineId,1)">
                  <el-option label='请选择' :value="selectDefauleValue"></el-option>
                  <el-option v-for="subItem in AirlineList" :label='subItem.AlName' :value='subItem.AirLineId' :key="subItem.subCode">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-select class="w200" filterable v-model="item.FlightId">
                  <el-option label='请选择' :value="selectDefauleValue"></el-option>
                  <el-option v-for="subItem in item.FlightList" :label='subItem.Flight_number' :value='subItem.ID' :key="subItem.subCode">
                  </el-option>
                </el-select>
              </td>
              <td rowspan="2">
                <el-checkbox v-model="item.IsStay" :checked="item.IsStay===CheckedVaule" :true-label="CheckedVaule"
                  :false-label="UnCheckedVaule" :disabled="true"></el-checkbox>
              </td>
              <td>
                <el-input class="w95" v-model="item.AddGoCostPrice" @keyup.native="checkPrice(item,'AddGoCostPrice',true)"></el-input>
              </td>
              <td rowspan="2">
                <el-input class="w95" v-model="item.ConfigNum" @keyup.native="checkInteger(item,'ConfigNum',true)"></el-input>
              </td>
            </tr>
            <tr>
              <td>返程</td>
              <td>
                <el-select class="w95" filterable v-model="item.BackDayNum" :disabled="true">
                  <el-option v-for="subItem in DayList" :label='subItem.Name' :value='subItem.ID' :key="subItem.subCode">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-select class="w180" filterable v-model="item.BackAirlineId" @change="airLineSelectChange(item,item.BackAirlineId,2)">
                  <el-option label='请选择' :value="selectDefauleValue"></el-option>
                  <el-option v-for="subItem in AirlineList" :label='subItem.AlName' :value='subItem.AirLineId' :key="subItem.subCode">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-select class="w200" filterable v-model="item.BackFlightId">
                  <el-option label='请选择' :value="selectDefauleValue"></el-option>
                  <el-option v-for="subItem in item.BackFlightList" :label='subItem.Flight_number' :value='subItem.ID'
                    :key="subItem.subCode">
                  </el-option>
                </el-select>
              </td>
              <td>
                <el-input class="w95" v-model="item.AddBackCostPrice" @keyup.native="checkPrice(item,'AddBackCostPrice',true)"></el-input>
              </td>
            </tr>
          </tbody>
        </template>
        <tbody v-else>
          <tr>
            <td colspan="9">
              暂无配置联运信息
            </td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        ArrList: [],
        cityList: [],
        CompanyList: [],
        TCID: 0,
        defaultBranchId: -1,
        //下拉框默认值
        selectDefauleValue: 0,
        CheckedVaule: 1,
        UnCheckedVaule: 0,
        //加载数据层
        loading: false,
        //联运信息
        UnionList: [],
        //航空公司列表
        AirlineList: [],
        //天数
        DayList: [{
            ID: -1,
            Name: "前一天"
          },
          {
            ID: -2,
            Name: "前两天"
          },
          {
            ID: 0,
            Name: "当天"
          },
          {
            ID: 1,
            Name: "后一天"
          },
          {
            ID: 2,
            Name: "后两天"
          }
        ]
      };
    },
    methods: {
      getCityList() {
        this.apipost(
          "Destination_get_GetCityListByCountryId", {
            Id: 2
          },
          res => {
            this.cityList = res.data.data;
          },
          err => {}
        );
      },
      getCompanyList() { //获取公司列表
        this.apipost('admin_get_BranchGetList', this.getCompanyMsg, res => {
          if (res.data.resultCode == 1) {
            this.CompanyList = res.data.data;
          }
        }, err => {})
      },

      //获取联运数据
      getList() {
        this.UnionList = [];
        this.loading = true;
        this.apipost(
          "AirTicket_get_GetUnionTicketListByTCID", {
            TCID: this.TCID
          },
          res => {
            if (res.data.resultCode == 1) {
              var array = res.data.data;
              if (array != null && array.length > 0) {
                array.forEach(item => {
                  this.airLineSelectChange(item, item.AirLineId, 1);
                  this.airLineSelectChange(item, item.BackAirlineId, 2);
                });
              }
              this.UnionList = array;
            }
            this.loading = false;
          }
        );

      },

      //初始化航空公司下拉
      initAirlines() {
        this.apipost(
          "airline_post_GetList", {},
          res => {
            if (res.data.resultCode == 1) {
              this.AirlineList = res.data.data;
            } else {
              this.Warning(res.data.message);
            }
          },
          err => {}
        );
      },
      //航空公司切换
      airLineSelectChange(item, AirLineId, type) {
        let qMsg = {
          AirlineID: AirLineId,
          Arrival_city: 0,
          Departure_city: 0
        };
        if (type == 1) {
          qMsg.Departure_city = item.UnionCityId;
        } else if (type == 2) {
          qMsg.Arrival_city = item.UnionCityId;
        }
        this.apipost(
          "flight_post_GetAirportNameList",
          qMsg,
          res => {
            if (res.data.resultCode == 1) {
              var tempArray = [];
              res.data.data.forEach(item => {
                var str =
                  item.Flight_number +
                  "【" +
                  item.dName +
                  "-" +
                  item.aName +
                  "】";
                tempArray.push({
                  ID: item.ID,
                  Flight_number: str
                });
              });
              if (type == 1) {
                item.FlightList = tempArray;
              } else {
                item.BackFlightList = tempArray;
              }

            } else {
              this.Warning(res.data.message);
            }
          },
          err => {}
        );
      },

      //保存联运信息数据
      SaveUnion() {
        this.UnionList.forEach(item => {
          item.FlightList = [];
          item.BackFlightList = [];
        });
        let msg = {
          SaveData: this.UnionList,
          TCID: this.TCID
        };
        this.apipost("AirTicket_get_SetUnionTicket", msg, res => {
          if (res.data.resultCode == 1) {
            this.Success("设置联运成功!");
            this.ArrList = [];
            this.getList();
          } else {
            this.Error(res.data.message);
          }
        });
      },
    },
    mounted() {
      this.initAirlines();
      this.TCID = this.$route.query.tcid;
      this.getList();
      this.getCompanyList();
      this.getCityList()
    }
  };

</script>
