<template>
  <div class="groupdialog">
    <el-form label-width="120px">
      <el-form-item :label="$t('objFill.biaoti')">
        <el-input type="text" v-model="plugData.Title"></el-input>
      </el-form-item>
      <el-form-item :label="$t('objFill.v101.xuanzhexingc')">
        <el-button type="primary" size="small" @click="isShowTripDailog=true">{{$t('objFill.v101.xuanzhexingc')}}</el-button>
      </el-form-item>
      <el-row>
        <el-col :span="24">
          <el-table :data="plugData.GroupSelfItems" style="width: 100%">
            <el-table-column prop="StartDate" :label="$t('objFill.v101.chufari')" width="150">
            </el-table-column>
            <el-table-column :label="$t('visa.v_tuanhao')" width="210">
              <template slot-scope="scope">
                {{scope.row.TCNUM}}({{scope.row.TCID}})
              </template>
            </el-table-column>
            <el-table-column :label="$t('Operation.Op_TeamName')" width="210">
              <template slot-scope="scope">
                {{scope.row.Title}}
              </template>
            </el-table-column>
            <el-table-column prop="DayNum" :label="$t('ground.tianshu')">
            </el-table-column>
            <el-table-column prop="Price" :label="$t('objFill.jiage')">
            </el-table-column>
            <el-table-column prop="Seat" :label="$t('objFill.v101.tuanweizku')">
            </el-table-column>
            <el-table-column :label="$t('system.table_operation')">
              <template slot-scope="scope">
                <el-tooltip class="item" effect="dark" :content="$t('system.table_delete')" placement="top-start">
                  <el-button type="danger" style="padding:6px;" icon="el-icon-delete" circle
                    @click="deleteData(scope.$index)"></el-button>
                </el-tooltip>
              </template>
            </el-table-column>
          </el-table>
        </el-col>
      </el-row>
    </el-form>

    <el-dialog :title="$t('objFill.v101.xuanzhexingc')" :visible.sync="isShowTripDailog" width="1000px" append-to-body>
      <!-- 行程选中 -->
      <chooseTrip ref="chooseTrip" :IsMultiple="true"></chooseTrip>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShowTripDailog = false" size="small">{{$t('pub.cancelBtn')}}</el-button>
        <el-button type="danger" size="small" @click="getChooseTripData()">{{$t('pub.sureBtn')}}</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  import chooseTrip from "../plug-in/choose_trip.vue"
  export default {
    props: ["plugData"],
    data() {
      return {
        isShowTripDailog: false,
      };
    },
    components: {
      chooseTrip,
    },
    created() {},
    methods: {
      //获取选择行程数据
      getChooseTripData() {
        var tempArray = this.$refs.chooseTrip.getChooseData();
        this.isShowTripDailog = false;
        if (tempArray && tempArray.length > 0) {
          tempArray.forEach(item => {
            var totalSeat = 0;
            if (item.FSeat) {
              totalSeat += item.FSeat;
            }
            if (item.CSeat) {
              totalSeat += item.CSeat;
            }
            if (item.YSeat) {
              totalSeat += item.YSeat;
            }
            if (item.SurplusFSeat) {
              totalSeat -= item.SurplusFSeat;
            }
            if (item.SurplusCSeat) {
              totalSeat -= item.SurplusCSeat;
            }

            if (item.SurplusYSeat) {
              totalSeat -= item.SurplusYSeat;
            }
            var flightStatus = false;
            if (item.flightList && item.flightList.length > 0) {
              flightStatus = item.flightList[0].FlightState == 1;
            }
            var LinkUrl = this.$tripUtils.GetB2BUrl(this.getLocalStorage().B2BDomain, item.ConfigId, item.TCID);
            var obj = {
              StartDate: item.StartDate,
              TCNUM: item.TCNUM,
              TCID: item.TCID,
              Title: item.Title,
              DayNum: item.DayNum,
              Price: item.B2CPrice,
              Seat: totalSeat,
              LinkUrl: LinkUrl,
              Substitute: item.IsSubstitution > 0,
              FlightStatus: flightStatus,
            };
            this.plugData.GroupSelfItems.push(obj);
          });
        }
      },
      //删除行程
      deleteData(index) {
        var that = this;
        that.Confirm(that.$t('tips.shifoushanchu'), function () {
          that.plugData.GroupSelfItems.splice(index, 1);
        });
      }
    },
    mounted() {

    },
  };

</script>