<style>
</style>
<template>
  <div class="clearfix">
    <el-table :data="orderUnionList" stripe style="width:550px;">
      <el-table-column prop="GuestNameInfo" :label="$t('salesModule.TravelInfo')" width="120px">
      </el-table-column>
      <el-table-column prop="FlightName" :label="$t('Airticket.Air_go')" width="160px">
        <template slot-scope="scope">
          <template v-if="scope.row.FlightName">
            {{scope.row.FlightName.GoDate}}
            <br />
            {{scope.row.FlightName.Flight_number}}
            {{scope.row.FlightName.Departure_time}}-{{scope.row.FlightName.Arrival_time}}
            <br />
            {{scope.row.FlightName.DepartureCityName}}({{scope.row.FlightName.DIATA}})
            -{{scope.row.FlightName.ArrivalCityName}}({{scope.row.FlightName.AIATA}})
          </template>
          <template v-else>
            <span style="color:red;">{{$t('objFill.v101.traveltrip.weipeizhi')}}</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column prop="BackFlightName" :label="$t('Airticket.Air_returnTrip')" width="160px">
        <template slot-scope="scope">
          <template v-if="scope.row.BackFlightName">
            {{scope.row.BackFlightName.BackDate}}
            <br />
            {{scope.row.BackFlightName.Flight_number}}
            {{scope.row.BackFlightName.Departure_time}}-{{scope.row.BackFlightName.Arrival_time}}
            <br />
            {{scope.row.BackFlightName.DepartureCityName}}({{scope.row.BackFlightName.DIATA}})
            -{{scope.row.BackFlightName.ArrivalCityName}}({{scope.row.BackFlightName.AIATA}})
          </template>
          <template v-else>
            <span style="color:red;">{{$t('objFill.v101.traveltrip.weipeizhi')}}</span>
          </template>
        </template>
      </el-table-column>
      <el-table-column>
        <template slot-scope="scope">
          <template v-if="scope.row.TicketUnionId>0">
            <a style="color:blue;cursor:pointer" @click="editOrderUnion(scope.row)">{{$t('pub.updateMsg')}}</a>
            <a style="color:blue;cursor:pointer" @click="deleteOrderUnion(scope.row)">{{$t('system.table_delete')}}</a>
          </template>
        </template>
      </el-table-column>
    </el-table>
    <br />


    
    <el-form label-width="100px">
      <template v-if="postMsg.GuestList&&postMsg.GuestList.length>0">
      <el-row :gutter="20">
        <el-col :span="20">
          <el-form-item :label="$t('objFill.v101.traveltrip.quxiaohanbxs')">
            <template v-if="PiceOrderUnionFlightList&&PiceOrderUnionFlightList.length>0">
  <el-select v-model="SelectList" multiple :placeholder="$t('objFill.qingxuanzhe')" style="width:100%">
    <el-option
      v-for="item in PiceOrderUnionFlightList"
      :key="item.ID"
      :label="item.Flight_number"
      :value="item.ID">
      <span style="float: left">{{ item.Flight_number }} {{ item.FlightSubType==1?$t('objFill.v101.traveltrip.qicheng'):$t('Airticket.Air_returnTrip') }}</span>
      <span style="float: right; color: #8492a6; font-size: 13px">{{ item.AlName }}{{ item.FlightDateStr}} {{item.Departure_time}}{{item.DepartureName}}({{item.DIATA}})-
        {{ item.FlightDateStr}} {{item.Arrival_time}}{{item.ArrivalCityName}}({{item.AIATA}})
      </span>
    </el-option>
  </el-select>
  </template>
          </el-form-item>
        </el-col>
      </el-row>
    </template>
      <el-row :gutter="20">
        <el-col :span="10">
          <el-form-item :label="$t('fnc.ddbianhao')">
            {{orderInfo.OrderId}}
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item :label="$t('op.TQBH')">
            {{orderInfo.TCID}}
          </el-form-item>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="20">
          <el-form-item :label="$t('objFill.fangshi')">
            <el-radio v-model="postMsg.OperateType" :label="1">{{$t('Airticket.Air_orderImport')}}</el-radio>
            <el-radio v-model="postMsg.OperateType" :label="2">{{$t('objFill.shoudongtx')}}</el-radio>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="10">
          <el-form-item :label="$t('objFill.shiyonglvke')">
            <el-select v-model="postMsg.GuestList" :placeholder="$t('pub.pleaseSel')" multiple>
              <el-option v-for="(item,index) in orderGuestList" :key="index" :label="item.Name" :value="item.Id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item :label="$t('admin.admin_status')">
            <el-select filterable v-model='postMsg.IsSure' class="">
              <el-option :label="$t('visa.v_zanding')" :value='0' :key='0'></el-option>
              <el-option :label="$t('pub.sureBtn')" :value='1' :key='1'></el-option>
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <!--命令模式-->
      <el-row v-if="postMsg.OperateType==1">
        <el-col :span="20">
          <el-form-item :label="$t('objFill.jipiaoml')">
            <el-input type="textarea" v-model="postMsg.TicketOrder" :autosize="{ minRows: 2, maxRows: 4}"
              placeholder="SS CA8210 Y  09Aug  PEKWUH  2"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <!--手动模式-->
      <el-row v-if="postMsg.OperateType==2">
        <el-col :span="10">
          <el-form-item :label="$t('objFill.quchengriqi')">
            <el-date-picker v-model="postMsg.GoDate" style="width:150px" value-format="yyyy-MM-dd" type="date"
              :placeholder="$t('objFill.quchengriqi')">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item :label="$t('objFill.v101.BasicDocuments.quchenghb')">
            <el-input v-model="postMsg.GoFlightNum" type="text" maxlength="20" :placeholder="$t('objFill.v101.BasicDocuments.quchenghb')">
            </el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row v-if="postMsg.OperateType==2">
        <el-col :span="10">
          <el-form-item :label="$t('objFill.huichengriqi')">
            <el-date-picker v-model="postMsg.BackDate" style="width:150px" value-format="yyyy-MM-dd" type="date"
              :placeholder="$t('objFill.huichengriqi')">
            </el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item :label="$t('objFill.huichenghb')">
            <el-input v-model="postMsg.BackFlightNum" type="text" maxlength="20" :placeholder="$t('objFill.huichenghb')"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="20">
          <el-form-item :label="$t('pub.pubRemark')">
            <el-input type="textarea" v-model="postMsg.Notes"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="20">
          <el-form-item>
            <input type="button" class="normalBtn Rs_leaderSearch" @click="saveTicketUnion" :value="$t('pub.sureBtn')" />
            <input type="button" class="normalBtn Rs_leaderSearch" @click="closeDialog()" :value="$t('pub.closeSel')" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </div>
</template>
<script>
  export default {
    props: ["orderInfo"],
    data() {
      return {
        postMsg: {
          TCID: 0, //团期编号
          OrderId: 0, //订单编号
          TicketOrder: "", //机票导入命令
          TicketUnionId: 0, //判断新增还是修改
          IsSure: 0, //0-暂定,1-确定
          selectFlight: 1, //查询航班
          GuestList: [], //选择的旅客
          OperateType: 1, //1-SS命令模式,2-手动填写模式
          GoDate: "", //去程日期
          BackDate: "", //回程日期
          GoFlightNum: "", //去程航班
          BackFlightNum: "", //回程航班
          Notes: "", //备注
          NotShowFlightIds:"",//不需要的航班ids
        },
        orderUnionList: [], //订单联运信息
        orderGuestList: [], //订单旅客信息
        PiceOrderUnionFlightList:[],//团航班信息
        SelectList:[],//已选航班信息
      }
    },
    mounted() {

    },
    methods: {
      //修改联运
      editOrderUnion(item) {
        this.SelectList=[];
        this.SelectList=item.NotShowFlightList;
        this.PiceOrderUnionFlightList=[];
        this.PiceOrderUnionFlightList=item.PiceOrderUnionFlightList;
        if (item.TicketUnionId) {
          this.postMsg.TicketUnionId = item.TicketUnionId;
        }
        if (item.GuestList && item.GuestList.length > 0) {
          this.postMsg.GuestList = item.GuestList;
        }
        if (item.IsSure) {
          this.postMsg.IsSure = item.IsSure;
        }
        if (item.GoDate) {
          this.postMsg.GoDate = item.GoDate;
        }
        if (item.GoFlightNum) {
          this.postMsg.GoFlightNum = item.GoFlightNum;
        }
        if (item.BackDate) {
          this.postMsg.BackDate = item.BackDate;
        }
        if (item.BackFlightNum) {
          this.postMsg.BackFlightNum = item.BackFlightNum;
        }
          this.postMsg.OperateType = 2;
        
      },
      //删除联运
      deleteOrderUnion(item) {
        var that = this;
        that.Confirm(that.$t('objFill.shifouysccdddlyxx'), function () {
          var msg = {
            TicketUnionId: item.TicketUnionId
          };
          that.apipost("AirTicket_post_DeleteUnionOrderFlight", msg,
            res => {
              if (res.data.resultCode == 1) {
                that.Success(this.$t('objFill.shangchulycg'));
                that.getOrderUnionList();
              } else {
                that.Error(res.data.data);
              }
            }, null);
        });
      },
      //获取订单设置联运信息
      getOrderUnionList() {
        this.apipost("AirTicket_get_GetUnionTicketListByTCIDNew", this.postMsg,
          (res) => {
            if (res.data.resultCode == 1) {
              this.orderUnionList = res.data.data;
              if (this.postMsg.TicketUnionId==0&&this.orderUnionList&&this.orderUnionList.length>0) {
                this.PiceOrderUnionFlightList=this.orderUnionList[0].PiceOrderUnionFlightList;
              }
            }
          }
        );
      },
      //设置联运
      saveTicketUnion() {
        if(this.SelectList&&this.SelectList.length>0){
          this.postMsg.NotShowFlightIds=this.SelectList.map(item => item).join(', ');
        }
        this.apipost("AirTicket_post_ImportUnionOrderFlight", this.postMsg,
          (res) => {
            if (res.data.resultCode == 1) {
              this.clearMsg();
              this.Success(res.data.message);
              this.closeDialog();
              //调用父页面刷新方法
              this.$emit("success");
            } else {
              this.Error(res.data.message);
            }
          }
        );
      },
      //清空表单
      clearMsg() {
        this.postMsg.TCID = this.orderInfo.TCID;
        this.postMsg.OrderId = this.orderInfo.OrderId;
        this.postMsg.TicketOrder = "";
        this.postMsg.TicketUnionId = 0;
        this.postMsg.IsSure = 0;
        this.postMsg.GuestList = [];
      },
      //关闭弹窗
      closeDialog() {
        this.$emit("success");
        this.$emit("close");
      },
      //获取订单旅客信息
      getOrderGuestList() {
        var guestMsg = {
          OrderId: this.postMsg.OrderId
        }
        this.apipost("sellorder_get_GetTravelGuestList", guestMsg, res => {
          if (res.data.resultCode == 1) {
            this.orderGuestList = res.data.data.list;
          }
        })
      },
    },
    watch: {
      //监听订单属性编号
      orderInfo: {
        handler(newVal, oldVal) {
          this.orderGuestList = [];
          this.orderUnionList = [];
          this.postMsg.TCID = this.orderInfo.TCID;
          this.postMsg.OrderId = this.orderInfo.OrderId;
          this.getOrderUnionList();
          this.getOrderGuestList();
        },
        deep: true,
        immediate: true,
      },
    },
  };

</script>