<style>
  @import "../../../assets/css/newTravelManager.css";
  .singlePrice .el-form-item__content,.el-form-item__label{line-height: 30px;}
  .CP_halfWi{width:45%;}
</style>

<template>
  <div>
    <div class="singlePrice clearfix CP_Div">
      <div class="CP_title">
        {{lineName}}{{lineTeamName}}
      </div>
      <el-form>
        <table class="CP_comTable">
          <tr>
            <td class="CP_comBack" width="170">币种</td>
            <td v-for='(item,index) in OfferCostPriceObj.CostCurrencyList'>
              {{item.CurrencyName}}
              <span>
                <i class="iconfont icon-quxiao" @click="DeleteCurrency(index)"></i>
              </span>
            </td>
            <td>
              <el-form-item class="w100">
                <el-select v-model='currencyType' @change="getRate(currencyType),addCurrency()">
                  <el-option v-for="item in currencyTypeArr" :label='item.Name' :value='item.ID' :key='item.ID'>
                  </el-option>
                </el-select>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td class="CP_comBack">汇率</td>
            <td v-for='item in OfferCostPriceObj.CostCurrencyList'>
              <el-input class="w80" v-model='item.ExchangeRate'
                        @keyup.native="checkRate(item,'ExchangeRate')"></el-input>
            </td>
            <td>
              <el-input class="w100" v-model='queryMsg.RateInput'
                        @keyup.native="checkRate(queryMsg,'RateInput')"></el-input>
            </td>
          </tr>
        </table>
        <table class="CP_comTable">
          <tr>
            <td class="CP_comBack" width="170">人数</td>
            <td v-for="(item,index) in OfferCostPriceObj.CostNumberList" :key='item.subCode'>
              <el-input class="w80" v-model='item.PeopleNumber'
                        @keyup.native="checkInteger(item,'PeopleNumber')"></el-input>
              <span>
                <i class="iconfont icon-quxiao" @click="DeletePNumber(index)"></i>
              </span>
            </td>
            <td width="150">
              <el-form-item>
                <el-input class="w80" v-model='queryMsg.PeopleNumber'
                          @keyup.native="checkInteger(queryMsg,'PeopleNumber')"></el-input>
              </el-form-item>
              <div class="AS_addPeoNumer">
                <i class="iconfont icon-img_haha" @click="addPeoNunber"></i>
              </div>
            </td>
          </tr>
          <tr v-for="item in OfferCostPriceObj.CostCurrencyList">
            <td class="CP_comBack">地接报价({{item.CurrencyName}})</td>
            <td v-if="checkExists(item.CurrencyId)" v-for="childItem in getCurrencyNumberList(item.CurrencyId)">
              <el-form-item>
                <el-input class="w80" v-model='childItem.Money'
                          @keyup.native="checkPrice(childItem,'Money',true),ReCalc()"></el-input>
              </el-form-item>
            </td>
            <td>

            </td>
          </tr>
        </table>
        <el-form-item label="地接项目">
          <el-checkbox-group v-model="checkedPei">
            <el-checkbox v-for="checkItem in checkList" :label="checkItem.Id" :key="checkItem.Id">
              {{checkItem.Name}}
            </el-checkbox>
          </el-checkbox-group>
        </el-form-item>
        <table class="CostPriceTable">
          <tr>
            <th rowspan="2" width='100'>Day</th>
            <th rowspan="2" width="200">币种</th>
            <th rowspan="2" width='220'>酒店</th>
            <th rowspan="2" width='200'>车</th>
            <th rowspan="2" width='220'>门票</th>
            <th colspan="3" width='200'>餐</th>
          </tr>
          <tr>
            <th width="90">早</th>
            <th width="90">中</th>
            <th width="90">晚</th>
          </tr>
          <tr v-for="subItem in OfferCostPriceObj.CostLocalList" :key="subItem.subCode">
            <td align="center">{{subItem.DayNum}}</td>
            <td>
              <el-form-item>
                <el-select v-model='subItem.CurrencyId'>
                  <el-option :label="$t('pub.unlimitedSel')" :value='defaultSelect'></el-option>
                  <el-option v-for="items in OfferCostPriceObj.CostCurrencyList" :label='items.CurrencyName'
                             :value='items.CurrencyId'
                             :key='items.CurrencyId'>
                  </el-option>
                </el-select>
              </el-form-item>
            </td>
            <td>
              <el-select v-model='subItem.HotelId' class="CP_halfWi">
                  <el-option :label="$t('pub.unlimitedSel')" :value='defaultSelect'></el-option>
                  <el-option v-for="items in subItem.HotelArr" :label='items.HotelName'
                             :value='items.HotelId'
                             :key='items.HotelId'>
                  </el-option>
              </el-select>
              <el-input v-if="!showHotel" type='text' class="CP_halfWi" v-model="subItem.HotelMoney"
                        @keyup.native="checkPrice(subItem,'HotelMoney')"
                        ></el-input>
            </td>
            <td>
              <span v-if="showCar">{{subItem.CarName}}</span>
              <el-input type='text' v-model="subItem.CarMoney"
                        @keyup.native="checkPrice(subItem,'CarMoney')"
                        v-if="!showCar"></el-input>
            </td>
            <td>
              <span v-if="showTicket" class="QD_DetailName">{{subItem.TicketName}}</span>
              <el-input type='text' v-model="subItem.TicketMoney"
                        @keyup.native="checkPrice(subItem,'TicketMoney')"
                        v-if="!showTicket"></el-input>
            </td>
            <td>
              <el-input type="text" :disabled='disabMoney' v-model='subItem.FoodItem[0].money'
                        @keyup.native="checkPrice(subItem.FoodItem[0],'money')"></el-input>
            </td>
            <td>
              <el-input type="text" :disabled='disabMoney' v-model='subItem.FoodItem[1].money'
                        @keyup.native="checkPrice(subItem.FoodItem[1],'money')"></el-input>
            </td>
            <td>
              <el-input type="text" :disabled='disabMoney' v-model='subItem.FoodItem[2].money'
                        @keyup.native="checkPrice(subItem.FoodItem[2],'money')"></el-input>
            </td>
          </tr>
        </table>
        <div class="CP_ComTitle">内陆段交通部分</div>
        <table class="CostPriceTable">
          <tr>
            <td width='50'>1</td>
            <td width='200'>内陆段机位(每人)</td>
            <td width='200'>
              <el-form-item>
                <el-select v-model='OfferCostPriceObj.InlandAirTicketCurrency'>
                  <el-option :label="$t('pub.unlimitedSel')" :value='defaultSelect'></el-option>
                  <el-option v-for="items in OfferCostPriceObj.CostCurrencyList" :label='items.CurrencyName'
                             :value='items.CurrencyId'
                             :key='items.CurrencyId'>
                  </el-option>
                </el-select>
              </el-form-item>
            </td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.InlandAirTicketMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'InlandAirTicketMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>2</td>
            <td>内陆段船票(每人</td>
            <td>
              <el-form-item>
                <el-select v-model='OfferCostPriceObj.InlandShipTicketCurrency'>
                  <el-option :label="$t('pub.unlimitedSel')" :value='defaultSelect'></el-option>
                  <el-option v-for="items in OfferCostPriceObj.CostCurrencyList" :label='items.CurrencyName'
                             :value='items.CurrencyId'
                             :key='items.CurrencyId'>
                  </el-option>
                </el-select>
              </el-form-item>
            </td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.InlandShipTicketMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'InlandShipTicketMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>3</td>
            <td>内陆段火车票(每人)</td>
            <td>
              <el-form-item>
                <el-select v-model='OfferCostPriceObj.InlandTrainTicketCurrency'>
                  <el-option :label="$t('pub.unlimitedSel')" :value='defaultSelect'></el-option>
                  <el-option v-for="items in OfferCostPriceObj.CostCurrencyList" :label='items.CurrencyName'
                             :value='items.CurrencyId'
                             :key='items.CurrencyId'>
                  </el-option>
                </el-select>
              </el-form-item>
            </td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.InlandTrainTicketMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'InlandTrainTicketMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
        </table>
        <div class="CP_ComTitle">杂支部分</div>
        <table class="CostPriceTable">
          <tr>
            <td width='50'>1</td>
            <td width='200'>签证费(每人)</td>
            <td colspan='3'>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.VisaMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'VisaMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>2</td>
            <td>保险费(每人)</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.SafeMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'SafeMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>3</td>
            <td>领队小费</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.LeaderTripMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'LeaderTripMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>4</td>
            <td>司机、导游小费</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.DriverGuideMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'DriverGuideMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
        </table>
        <div class="CP_ComTitle">其他支出</div>
        <table class="CostPriceTable">
          <tr>
            <td width='50'>1</td>
            <td width='200'>销售提成1%</td>
            <td colspan='3'>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.SalesCommissionMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'SalesCommissionMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>2</td>
            <td>作业处提成</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.OfficeCommissionMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'OfficeCommissionMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
        </table>
        <div class="CP_ComTitle">机票</div>
        <table class="CostPriceTable">
          <tr>
            <td width='50'>机票</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.AirTicketMoeny"
                          @keyup.native="checkPrice(OfferCostPriceObj,'AirTicketMoeny')"></el-input>
              </el-form-item>
            </td>
          </tr>
        </table>
        <div class="CP_ComTitle">收入</div>
        <table class="CostPriceTable">
          <tr>
            <td width='50'>1</td>
            <td width='200'>客人小费收入</td>
            <td colspan='3'>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.TripMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'TripMoney',true)"></el-input>
              </el-form-item>
            </td>
          </tr>
          <tr>
            <td>2</td>
            <td>导游人头费</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.GuidePeopleMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'GuidePeopleMoney')"></el-input>
              </el-form-item>
            </td>
          </tr>
        </table>
        <div class="CP_ComTitle">团负费</div>
        <table class="CostPriceTable">
          <tr>
            <td width='50'>KB</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.KBMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'KBMoney',true)"></el-input>
              </el-form-item>
            </td>
          </tr>
        </table>
        <div class="CP_ComTitle">领队分摊部分</div>
        <table class="CP_comTable">
          <tr>
            <td width='200'>人数</td>
            <td width="200"></td>
            <td width="150" v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode">
              {{item.PeopleNumber}}+1
            </td>
          </tr>
          <tr>
            <td>机票</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.AirTicketShareMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'AirTicketShareMoney')"></el-input>
              </el-form-item>
            </td>
            <td v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode">
              {{item.AirTicketMoney}}
            </td>
          </tr>
          <tr>
            <td>门票</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.TicketShareMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'TicketShareMoney')"></el-input>
              </el-form-item>
            </td>
            <td v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode">
              {{item.TicketMoney}}
            </td>
          </tr>
          <tr>
            <td>单房差</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.SingleRoomShareMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'SingleRoomShareMoney')"></el-input>
              </el-form-item>
            </td>
            <td v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode">
              {{item.SingleRoomMoney}}
            </td>
          </tr>
          <tr>
            <td>内陆段交通</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.InlandTrafficShareMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'InlandTrafficShareMoney')"></el-input>
              </el-form-item>
            </td>
            <td v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode">
              {{item.InlandTrafficMoney}}
            </td>
          </tr>
          <tr>
            <td>杂费</td>
            <td>
              <el-form-item>
                <el-input type='text' class="w120" v-model="OfferCostPriceObj.OtherShareMoney"
                          @keyup.native="checkPrice(OfferCostPriceObj,'OtherShareMoney')"></el-input>
              </el-form-item>
            </td>
            <td v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode">
              {{item.OtherMoney}}
            </td>
          </tr>
          <tr>
            <td>小计</td>
            <td></td>
            <td v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode">
              {{item.SubtotalMoney}}
            </td>
          </tr>
        </table>
        <div class="Cost_Line"></div>
        <div class="CP_ComTitle Cost_Title">成本统计</div>
        <table class="CostPriceTable">
          <tr>
            <td width='250' rowspan="2" class="CP_comBack">
              人数统计
            </td>
            <td v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode" class="CP_comBack">
              {{item.PeopleNumber}}+1
            </td>
          </tr>
          <tr>
            <td v-for="item in OfferCostPriceObj.CostNumberList" :key="item.subCode">
              {{item.TotalMoney}}
            </td>
          </tr>
        </table>
      </el-form>
    </div>
  </div>
</template>
<script>
  export default {
    props: ["OfferCostPrice", "lineName", "lineTeamName"],
    data() {
      return {
        checkedPei: [],
        //中间值
        OfferCostPriceObj: "",
        //默认下拉
        defaultSelect: 0,
        queryMsg: {
          //汇率输入
          RateInput: "",
          //人数
          PeopleNumber: ""
        },
        //币种下拉
        currencyType: "",
        checkList: [
          {
            Id: 1,
            Name: "酒店"
          },
          {
            Id: 2,
            Name: "车辆"
          },
          {
            Id: 3,
            Name: "门票"
          },
          {
            Id: 4,
            Name: "餐厅"
          }
        ],
        //各种显示隐藏
        showHotel: false,
        showCar: false,
        showTicket: false,
        showFood: false,
        disabMoney: false,
        //币种汇率数据
        currencyArr: [],
        //币种下拉
        currencyTypeArr: []
      };
    },
    methods: {
      ReCalc() {
        this.OfferCostPriceObj = JSON.parse(
          JSON.stringify(this.OfferCostPriceObj)
        );
        this.$emit("headCallBack", this.OfferCostPriceObj);
      },
      //添加币种
      addCurrency() {
        var currencyId = this.currencyType;
        var ckedName;
        var ckedRate = this.queryMsg.RateInput;
        if (currencyId == "") {
          this.Info("请选择币种");
          return;
        }
        if (ckedRate == "") {
          this.Info("请输入汇率");
          return;
        }
        this.currencyTypeArr.forEach(x => {
          if (currencyId == x.ID) {
            ckedName = x.Name;
          }
        });
        if (
          this.$tripUtils.isInObjArr(
            this.OfferCostPriceObj.CostCurrencyList,
            "CurrencyId",
            currencyId
          )
        ) {
          this.Info("币种已经存在");
          return;
        }
        var CurObj = this.$tripUtils.CostCurrency();
        CurObj.CurrencyName = ckedName;
        CurObj.ExchangeRate = ckedRate;
        CurObj.CurrencyId = currencyId;
        this.OfferCostPriceObj.CostCurrencyList.push(CurObj);
        this.currencyType = "";
        this.queryMsg.RateInput = "";
        let currencyNumberItem = {
          Key: currencyId,
          currencyNumberList: []
        };
        if (this.OfferCostPriceObj.CurrencyNumberListExt.length > 0) {
          if (
            this.OfferCostPriceObj.CurrencyNumberListExt[0].currencyNumberList
              .length > 0
          ) {
            this.OfferCostPriceObj.CurrencyNumberListExt[0].currencyNumberList.forEach(
              x => {
                let tempData = JSON.parse(JSON.stringify(x));
                tempData.CurrencyId = currencyId;
                tempData.Money = 0.0;
                currencyNumberItem.currencyNumberList.push(tempData);
              }
            );
          }
        }
        this.OfferCostPriceObj.CurrencyNumberListExt.push(currencyNumberItem);
      },
      //添加人数费用
      addPeoNunber() {
        var PeopleNumber = this.queryMsg.PeopleNumber;
        if (PeopleNumber == "") {
          this.Info("请输入人数");
          return;
        }
        if (
          this.$tripUtils.isInObjArr(
            this.OfferCostPriceObj.CostNumberList,
            "PeopleNumber",
            PeopleNumber
          )
        ) {
          this.Info("人数已经存在");
          return;
        }
        var CostNumberObj = this.$tripUtils.CostNumber();
        CostNumberObj.PeopleNumber = PeopleNumber;
        this.OfferCostPriceObj.CostNumberList.push(CostNumberObj);
        this.OfferCostPriceObj.CurrencyNumberListExt.forEach(x => {
          var CurrencyNumberObj = this.$tripUtils.CurrencyNumber();
          CurrencyNumberObj.CurrencyId = x.Key;
          CurrencyNumberObj.PeopleNumber = PeopleNumber;
          x.currencyNumberList.push(CurrencyNumberObj);
        });
        this.queryMsg.PeopleNumber = "";
        this.queryMsg.Money = "";
        this.shortPeopleNumber();
      },
      //删除币种
      DeleteCurrency(index) {
        let currencyId = this.OfferCostPriceObj.CostCurrencyList[index]
          .CurrencyId;
        this.OfferCostPriceObj.CostCurrencyList.splice(index, 1);
        if (currencyId > 0) {
          let tempCurrencyNumberListExt = [];
          this.OfferCostPriceObj.CurrencyNumberListExt.forEach(x => {
            if (x.Key != currencyId) {
              tempCurrencyNumberListExt.push(x);
            }
          });
          this.OfferCostPriceObj.CurrencyNumberListExt = tempCurrencyNumberListExt;
        }
        if (this.OfferCostPriceObj.CostCurrencyList.length === 0) {
          this.OfferCostPriceObj.CurrencyNumberListExt = [];
        }
      },
      //删除人数
      DeletePNumber(index) {
        var item = this.OfferCostPriceObj.CostNumberList[index];
        this.OfferCostPriceObj.CurrencyNumberListExt.forEach(itemExt => {
          var array = [];
          itemExt.currencyNumberList.forEach(childItem => {
            if (childItem.PeopleNumber != item.PeopleNumber) {
              array.push(childItem);
            }
          });
          itemExt.currencyNumberList = array;
        });
        this.OfferCostPriceObj.CostNumberList.splice(index, 1);
      },
      //获取所有币种
      getAllCurrency() {
        this.apipost(
          "financeinfo_post_GetList",
          {},
          res => {
            if (res.data.resultCode == 1) {
              this.currencyTypeArr = res.data.data;
            }
          },
          err => {
          }
        );
      },
      //币种下拉获取汇率
      getRate(ID) {
        this.currencyTypeArr.forEach(x => {
          if (x.ID == ID) {
            this.queryMsg.RateInput = x.Rate;
          }
        });
      },
      //计算总价
      getSubtotalMoney() {
        let that = this;
        this.OfferCostPriceObj.CostNumberList.forEach(x => {
          x.SubtotalMoney = (
            this.getConvertMoney(x.AirTicketMoney) +
            this.getConvertMoney(x.TicketMoney) +
            this.getConvertMoney(x.SingleRoomMoney) +
            this.getConvertMoney(x.InlandTrafficMoney) +
            this.getConvertMoney(x.OtherMoney)
          ).toFixed(2);

          x.TotalMoney = (
            that.getLocalTotalMoney() +
            that.getCostTotalMoney() +
            this.getConvertMoney(x.SubtotalMoney) +
            this.getCurrencyNumberTotalMoney(x.PeopleNumber)
          ).toFixed(2);
        });
      },
      //获取地接项目报价
      getLocalTotalMoney() {
        let totalMoney = 0.0;
        this.OfferCostPriceObj.CostLocalList.forEach(x => {
          let subTotalMoney = 0.0;
          subTotalMoney =
            (this.getConvertMoney(x.CarMoney) +
              this.getConvertMoney(x.HotelMoney) +
              this.getConvertMoney(x.TicketMoney) +
              this.getConvertMoney(x.FoodItem[0].money) +
              this.getConvertMoney(x.FoodItem[1].money) +
              this.getConvertMoney(x.FoodItem[2].money)) *
            this.getCurrencyMoney(x.CurrencyId);
          totalMoney += subTotalMoney;
        });
        return totalMoney;
      },
      //获取汇率
      getCurrencyMoney(currencyId) {
        let currency = 0.0;
        this.OfferCostPriceObj.CostCurrencyList.forEach(x => {
          if (x.CurrencyId == currencyId) {
            currency = x.ExchangeRate;
          }
        });
        return currency;
      },
      //获取主成本价
      getCostTotalMoney() {
        let totalMoney =
          this.getConvertMoney(this.OfferCostPriceObj.InlandAirTicketMoney) *
          this.getCurrencyMoney(
            this.OfferCostPriceObj.InlandAirTicketCurrency
          ) +
          this.getConvertMoney(this.OfferCostPriceObj.InlandShipTicketMoney) *
          this.getCurrencyMoney(
            this.OfferCostPriceObj.InlandShipTicketCurrency
          ) +
          this.getConvertMoney(this.OfferCostPriceObj.InlandTrainTicketMoney) *
          this.getCurrencyMoney(
            this.OfferCostPriceObj.InlandTrainTicketCurrency
          ) +
          this.getConvertMoney(this.OfferCostPriceObj.DriverGuideMoney) +
          this.getConvertMoney(this.OfferCostPriceObj.LeaderTripMoney) +
          this.getConvertMoney(this.OfferCostPriceObj.OfficeCommissionMoney) +
          this.getConvertMoney(this.OfferCostPriceObj.SafeMoney) +
          this.getConvertMoney(this.OfferCostPriceObj.SalesCommissionMoney) +
          this.getConvertMoney(this.OfferCostPriceObj.TripMoney) +
          this.getConvertMoney(this.OfferCostPriceObj.GuidePeopleMoney) +
          this.getConvertMoney(this.OfferCostPriceObj.AirTicketMoeny) +
          this.getConvertMoney(this.OfferCostPriceObj.KBMoney) +
          this.getConvertMoney(this.OfferCostPriceObj.VisaMoney);
        return totalMoney;
      },
      //获取不同人数组合价
      getCurrencyNumberTotalMoney(peopleNumber) {
        let totalMoney = 0.0;
        this.OfferCostPriceObj.CurrencyNumberListExt.forEach(x => {
          x.currencyNumberList.forEach(y => {
            if (peopleNumber === y.PeopleNumber) {
              totalMoney +=
                this.getConvertMoney(y.Money) *
                this.getCurrencyMoney(y.CurrencyId);
            }
          });
        });
        return totalMoney;
      },
      //价格转换器
      getConvertMoney(value) {
        if (value === "" || value === undefined || value === null) {
          value = 0.0;
        }
        return parseFloat(value);
      },
      //人数排序
      shortPeopleNumber() {
        this.OfferCostPriceObj.CurrencyNumberListExt.forEach(x => {
          x.currencyNumberList.sort(
            this.$commonUtils.createComprisonFunction("PeopleNumber")
          );
        });
        this.OfferCostPriceObj.CostNumberList.sort(
          this.$commonUtils.createComprisonFunction("PeopleNumber")
        );
      },
      //判断币种是否相等
      checkExists(CurrencyId) {
        var flag = false;
        this.OfferCostPriceObj.CurrencyNumberListExt.forEach(item => {
          if (!flag && item.Key == CurrencyId) {
            flag = true;
          }
        });
        return flag;
      },
      //获取币种对应 的人数报价
      getCurrencyNumberList(CurrencyId) {
        let currencyNumberList = [];
        let flag = false;
        this.OfferCostPriceObj.CurrencyNumberListExt.forEach(item => {
          if (!flag && item.Key == CurrencyId) {
            flag = true;
            currencyNumberList = item.currencyNumberList;
          }
        });
        return currencyNumberList;
      },
      initOfferCostPrice(offerCostPrice) {
        this.getAllCurrency();
        this.OfferCostPriceObj = offerCostPrice;
        if (
          this.OfferCostPriceObj.CurrencyNumberListExt == undefined ||
          this.OfferCostPriceObj.CurrencyNumberListExt == null ||
          !(this.OfferCostPriceObj.CurrencyNumberListExt.length > 0)
        ) {
          this.OfferCostPriceObj.CurrencyNumberListExt = [];
        }
        var dataArr = this.OfferCostPriceObj.LocalProject.split(',');
        this.checkedPei = dataArr.map(function (data) {
          return +data;
        });
        this.shortPeopleNumber();
        this.getSubtotalMoney();
      },
      //计算领队分摊
      getLeaderShare() {
        let that = this;
        var AirTicketShareMoney = this.OfferCostPriceObj.AirTicketShareMoney;
        var TicketShareMoney = this.OfferCostPriceObj.TicketShareMoney;
        var SingleRoomShareMoney = this.OfferCostPriceObj.SingleRoomShareMoney;
        var InlandTrafficShareMoney = this.OfferCostPriceObj.InlandTrafficShareMoney;
        var OtherShareMoney = this.OfferCostPriceObj.OtherShareMoney;
        this.OfferCostPriceObj.CostNumberList.forEach(x => {
          x.AirTicketMoney = (AirTicketShareMoney / x.PeopleNumber).toFixed(2);
          x.TicketMoney = (TicketShareMoney / x.PeopleNumber).toFixed(2);
          x.SingleRoomMoney = (SingleRoomShareMoney / x.PeopleNumber).toFixed(2);
          x.InlandTrafficMoney = (InlandTrafficShareMoney / x.PeopleNumber).toFixed(2);
          x.OtherMoney = (OtherShareMoney / x.PeopleNumber).toFixed(2);
        });
      },
      //报价单发生改变从新初始化数据
      onChangeInitOfferCostPrice(offerCostPrice) {
        this.initOfferCostPrice(offerCostPrice);
      },
    },
    mounted() {
      this.getAllCurrency();
      this.initOfferCostPrice(this.OfferCostPrice);
    },
    watch: {
      OfferCostPriceObj: {
        handler: function (val, oldVal) {
          this.getLeaderShare();
          this.getSubtotalMoney();
          this.$emit("headCallBack", this.OfferCostPriceObj);
        },
        deep: true
      },
      checkedPei: {
        handler: function (val, oldVal) {
          if (val.indexOf(1) > -1) {
            this.showHotel = true;
            this.OfferCostPriceObj.CostLocalList.forEach(x => {
              x.HotelMoney = 0;
            });
          } else {
            this.showHotel = false;
          }
          if (val.indexOf(2) > -1) {
            this.showCar = true;
            this.OfferCostPriceObj.CostLocalList.forEach(x => {
              x.CarMoney = 0;
            });
          } else {
            this.showCar = false;
          }
          if (val.indexOf(3) > -1) {
            this.showTicket = true;
            this.OfferCostPriceObj.CostLocalList.forEach(x => {
              x.TicketMoney = 0;
            });
          } else {
            this.showTicket = false;
          }
          if (val.indexOf(4) > -1) {
            this.showFood = true;
            this.disabMoney = true;
            this.OfferCostPriceObj.CostLocalList.forEach(x => {
              x.FoodItem.forEach(y => {
                y.money = 0;
              });
            });
          } else {
            this.showFood = false;
            this.disabMoney = false;
          }
          this.OfferCostPriceObj.LocalProject = val.join(',')
        },
        deep: true

      }
    }
  };
</script>