<style scoped>
  .PQ_detail {
    width: 100%;
    border-collapse: collapse;
  }

  .PQ_detail tr th,
  .v-table-title-cell {
    background: #e6e6e6;
    height: 40px;
    font-size: 14px;
    border-right: 1px solid #e6e6e6;
    color: #333;
  }

  .PQ_detail tr {
    background: #fff;
    text-align: center;
    height: 40px;
  }

  .PQ_detail tr td {
    font-size: 12px;
    border: 1px solid #e5e5e5;
  }

</style>

<template>
  <div>
    <el-popover width="630" trigger="click">
      <table class="PQ_detail" v-loading="loading" v-if="OrderPrice&&OrderPrice.B2BMemberPrice">
        <tr>
          <td colspan="6" style="text-align: left; padding-left: 10px">
            {{ $t("salesModule.BasePrice") }}
          </td>
        </tr>
        <tr>
          <td colspan="6" style="text-align: left; padding-left: 10px">
            <div>
              总金额: {{Getdetail().datas}}={{Getdetail().Total}}
              <span style="color: red;margin-left: 10px; font-size: 11px;">注:如计算应收与订单应收不一致,请看订单日志可能存在其他修改。</span>
            </div>
          </td>
        </tr>
        <tr>
          <th>{{ $t("advmanager.v_type") }}</th>
          <th>{{ $t("salesModule.HYTHJ") }}</th>
          <th>{{ $t("salesModule.PTTHJ") }}</th>
          <th>{{ $t("salesModule.ZKHYJ") }}</th>
          <th colspan="2">{{ $t("salesModule.PTZKJ") }}</th>
        </tr>
        <tr>
          <td>{{ $t("salesModule.Adult") }}</td>
          <td>
            {{
            OrderPrice.B2BMemberPrice | priceFormat(OrderPrice.B2BMemberPrice)
          }}
          </td>
          <td>{{ OrderPrice.B2BPrice | priceFormat(OrderPrice.B2BPrice) }}</td>
          <td>
            {{
            OrderPrice.B2CMemberPrice | priceFormat(OrderPrice.B2CMemberPrice)
          }}
          </td>
          <td colspan="2">
            {{ OrderPrice.B2CPrice | priceFormat(OrderPrice.B2CPrice) }}
          </td>
        </tr>
        <tr>
          <td>{{ $t("salesModule.ChildBed") }}</td>
          <td>
            {{
            (OrderPrice.B2BMemberPrice + OrderPrice.ChildNeedPrice)
              | priceFormat(
                OrderPrice.B2BMemberPrice + OrderPrice.ChildNeedPrice
              )
          }}
          </td>
          <td>
            {{
            (OrderPrice.B2BPrice + OrderPrice.ChildNeedPrice)
              | priceFormat(OrderPrice.B2BPrice + OrderPrice.ChildNeedPrice)
          }}
          </td>
          <td>
            {{
            (OrderPrice.B2CMemberPrice + OrderPrice.ChildNeedPrice)
              | priceFormat(
                OrderPrice.B2CMemberPrice + OrderPrice.ChildNeedPrice
              )
          }}
          </td>
          <td colspan="2">
            {{
            (OrderPrice.B2CPrice + OrderPrice.ChildNeedPrice)
              | priceFormat(OrderPrice.B2CPrice + OrderPrice.ChildNeedPrice)
          }}
          </td>
        </tr>
        <tr>
          <td>{{ $t("salesModule.ChildNoBed") }}</td>
          <td>
            {{
            (OrderPrice.B2BMemberPrice - OrderPrice.ChildNoNeedPrice)
              | priceFormat(
                OrderPrice.B2BMemberPrice - OrderPrice.ChildNoNeedPrice
              )
          }}
          </td>
          <td>
            {{
            (OrderPrice.B2BPrice - OrderPrice.ChildNoNeedPrice)
              | priceFormat(OrderPrice.B2BPrice - OrderPrice.ChildNoNeedPrice)
          }}
          </td>
          <td>
            {{
            (OrderPrice.B2CMemberPrice - OrderPrice.ChildNoNeedPrice)
              | priceFormat(
                OrderPrice.B2CMemberPrice - OrderPrice.ChildNoNeedPrice
              )
          }}
          </td>
          <td colspan="2">
            {{
            (OrderPrice.B2CPrice - OrderPrice.ChildNoNeedPrice)
              | priceFormat(OrderPrice.B2CPrice - OrderPrice.ChildNoNeedPrice)
          }}
          </td>
        </tr>
        <tr>
          <td>{{ $t("salesModule.SingleJ") }}</td>
          <td colspan="5">
            {{
            OrderPrice.SingleDMCPrice | priceFormat(OrderPrice.SingleDMCPrice)
          }}
          </td>
        </tr>
        <tr>
          <td>{{ $t("Operation.Op_baby") }}</td>
          <td colspan="5">
            {{ OrderPrice.BabyPrice | priceFormat(OrderPrice.BabyPrice) }}
          </td>
        </tr>
        <tr>
          <td colspan="6" style="text-align: left; padding-left: 10px">
            {{ $t("salesModule.OtherPrice") }}
          </td>
        </tr>
        <tr>
          <th>{{ $t("Operation.Op_oldmanSurcharge") }}</th>
          <th>{{ $t("Operation.Op_childSurcharge") }}</th>
          <th>{{ $t("salesModule.VisaBack") }}</th>
          <th>{{ $t("Operation.Op_singleRoomcha") }}</th>
          <th>{{ $t("Operation.Op_zafei") }}</th>
          <th>{{ $t("fnc.xiaofei") }}</th>
        </tr>
        <tr>
          <td>
            {{
            OrderPrice.OldManChargePrice
              | priceFormat(OrderPrice.OldManChargePrice)
          }}
          </td>
          <td>
            {{
            OrderPrice.BabyChargePrice
              | priceFormat(OrderPrice.BabyChargePrice)
          }}
          </td>
          <td>
            {{ OrderPrice.VisaPrice | priceFormat2(OrderPrice.VisaPrice) }}(-{{
            OrderPrice.BackVisaPrice | priceFormat(OrderPrice.BackVisaPrice)
          }})
          </td>
          <td>
            {{
            OrderPrice.SingleRoomPrice
              | priceFormat(OrderPrice.SingleRoomPrice)
          }}
          </td>
          <td>
            {{ OrderPrice.OtherPrice | priceFormat(OrderPrice.OtherPrice) }}
          </td>
          <td>{{ OrderPrice.TipAmount ? OrderPrice.TipAmount : "0.00" }}</td>
        </tr>
      </table>
      <span slot="reference" class="price" @click="CalculationDetails">{{ PreferPrice }}</span>
    </el-popover>
  </div>

</template>
<script>
  export default {
    //订单信息
    props: [
      "OrderId", "PreferPrice"
    ],
    filters: {
      priceFormat(value) {
        if (value == null) {
          return 0.0;
        }
        let nStr = value.toFixed(2);
        let x = nStr.split(".");
        let x1 = x[0];
        let x2 = x.length > 1 ? "." + x[1] : "";
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
          x1 = x1.replace(rgx, "$1" + "," + "$2");
        }
        return x1 + x2;
      },
      priceFormat2(value) {
        if (value == null) {
          return "已包含";
        }
        let nStr = value.toFixed(2);
        nStr += "";
        let x = nStr.split(".");
        let x1 = x[0];
        let x2 = x.length > 1 ? "." + x[1] : "";
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1)) {
          x1 = x1.replace(rgx, "$1" + "," + "$2");
        }
        let result = x1 + x2;
        if (result === "0.00") {
          result = "已包含";
        }
        return result;
      },

    },
    data() {
      return {
        childItem: {},
        OrderPrice: null,
        loading: false
      };
    },
    methods: {
      Getdetail() {
        let childItem = this.childItem
        let OrderPrice = this.OrderPrice
        let String1 = '',
          Price1 = 0,
          String2 = '',
          Price2 = 0,
          String3 = '',
          Price3 = 0,
          String4 = '',
          Price4 = 0,
          String5 = '',
          Price5 = 0,
          String6 = '',
          Price6 = 0,
          String7 = '',
          Price7 = 0,
          String8 = '',
          Price8 = 0,
          String9 = '',
          Price9 = 0,
          String10 = '',
          Price10 = 0,
          String11 = '',
          Price11 = 0,
          String12 = '',
          Price12 = 0
        let datas = '',
          Total = 0
        var TotalPNum = childItem.ChirdNum + childItem.ManNum + childItem.OldPeopleNum
        if (childItem.ManNum > 0) {
          if (childItem.DiscountPrice > 0 && childItem.Unit_Price > 0) {
            String1 = `${childItem.Unit_Price}-${childItem.DiscountPrice}*${childItem.ManNum}`
          } else {
            String1 = `${childItem.Unit_Price}*${childItem.ManNum}`
          }
          Price1 = (childItem.Unit_Price - (childItem.DiscountPrice > 0 ? childItem.DiscountPrice : 0)) * childItem
            .ManNum
        }
        if (childItem.ChirdNum > 0 && childItem.Unit_Price > 0) {
          if (childItem.DiscountPrice > 0) {
            String2 =
              `+(${childItem.Unit_Price } + ${OrderPrice.BabyChargePrice} - ${childItem.DiscountPrice>0?childItem.DiscountPrice:0 }) * ${childItem.ChirdNum}`
          } else {
            String2 = `+(${childItem.Unit_Price } + ${OrderPrice.BabyChargePrice} ) * ${childItem.ChirdNum}`
          }

          Price2 = (childItem.Unit_Price + OrderPrice.BabyChargePrice - (childItem.DiscountPrice > 0 ? childItem
            .DiscountPrice : 0)) * childItem.ChirdNum
        }
        if (childItem.BabyNum > 0 && childItem.BabyPrice > 0) {
          String3 = `+(${childItem.BabyNum} * ${OrderPrice.BabyPrice})`
          Price3 = childItem.BabyNum * OrderPrice.BabyPrice
        }
        if (childItem.OldPeopleNum > 0 && childItem.Unit_Price > 0) {
          if (childItem.DiscountPrice > 0) {
            String4 =
              `+(${OrderPrice.Unit_Price} + ${OrderPrice.OldManChargePrice} - ${childItem.DiscountPrice}) * ${childItem.OldPeopleNum}`
          } else {
            String4 = `+(${OrderPrice.Unit_Price} + ${OrderPrice.OldManChargePrice} ) * ${childItem.OldPeopleNum}`
          }

          Price4 = (OrderPrice.Unit_Price + OrderPrice.OldManChargePrice - childItem.DiscountPrice) * childItem
            .OldPeopleNum
        }
        if (TotalPNum > 0 && OrderPrice.OtherPrice > 0) {
          String5 = `+(${OrderPrice.OtherPrice } * ${TotalPNum})`
          Price5 = OrderPrice.OtherPrice * TotalPNum
        }
        if (TotalPNum > 0 && OrderPrice.VisaPrice > 0) {
          String6 = `+(${OrderPrice.VisaPrice } * ${TotalPNum})`
          Price6 = OrderPrice.VisaPrice * TotalPNum
        }
        if (((TotalPNum + childItem.BabyNum) != childItem.VisaNum) && OrderPrice.BackVisaPrice != 0) {
          String7 = `+(${OrderPrice.BackVisaPrice } * (${TotalPNum} + ${childItem.BabyNum}  - ${childItem.VisaNum}))`
          Price7 = OrderPrice.BackVisaPrice * (TotalPNum + childItem.BabyNum - childItem.VisaNum)
        }
        if (childItem.SingleRoomNum > 0 && OrderPrice.SingleRoomPrice > 0) {
          String8 = `+(${childItem.SingleRoomNum} * ${OrderPrice.SingleRoomPrice})`
          Price8 = childItem.SingleRoomNum * OrderPrice.SingleRoomPrice
        }
        if (childItem.ChirdNeedBedNum > 0 && OrderPrice.ChildNeedPrice > 0) {
          String9 = `+(${childItem.ChirdNeedBedNum} * ${OrderPrice.ChildNeedPrice} )`
          Price9 = childItem.ChirdNeedBedNum * OrderPrice.ChildNeedPrice
        }

        if (childItem.ChirdNum > 0 && OrderPrice.ChildNoNeedPrice > 0) {
          if (childItem.ChirdNeedBedNum > 0) {
            String10 = `+((${childItem.ChirdNum } - ${childItem.ChirdNeedBedNum }) * ${OrderPrice.ChildNoNeedPrice})`
          } else {
            String10 = `+(${childItem.ChirdNum }  * ${OrderPrice.ChildNoNeedPrice})`
          }
          Price10 = (childItem.ChirdNum - childItem.ChirdNeedBedNum) * OrderPrice.ChildNoNeedPrice
        }
        if (OrderPrice.GoAddPrice > 0) {
          String11 += `+${OrderPrice.GoAddPrice}`
          Price11 += OrderPrice.GoAddPrice
        }
        if (OrderPrice.BackAddPrice > 0) {
          String11 += `+${OrderPrice.BackAddPrice}`
          Price11 += OrderPrice.BackAddPrice
        }
        if (childItem.AirticketNum > 0 && OrderPrice.SingleDMCPrice != 0) {
          String12 = `+(${OrderPrice.SingleDMCPrice } * ${childItem.AirticketNum })`
          Price12 = OrderPrice.SingleDMCPrice * childItem.AirticketNum
        }
        datas =
          `${String1}${String2}${String3}${String4}${String5}${String6}${String7}${String8}${String9}${String10}${String11}${String12}`
        Total = Price1 + Price2 + Price3 + Price4 + Price5 + Price6 + Price7 + Price8 + Price9 + Price10 + Price11 +
          Price12
        return {
          datas,
          Total
        }
      },
      CalculationDetails() {
        this.loading = true
        this.apipost(
          "order_post_GetOrderPrice", {
            OrderId: this.OrderId
          },
          (res) => {
            this.loading = false
            if (res.data.resultCode == 1) {
              let data = res.data.data.OrderPrice
              this.childItem = res.data.data.OrderModel
              this.OrderPrice = {
                AddCostPrice: data.AddCostPrice ? data.AddCostPrice : 0,
                AddSellPrice: data.AddSellPrice ? data.AddSellPrice : 0,
                AirticketMoney: data.AirticketMoney ? data.AirticketMoney : 0,
                B2BMemberPrice: data.B2BMemberPrice ? data.B2BMemberPrice : 0,
                B2BPrice: data.B2BPrice ? data.B2BPrice : 0,
                B2CMemberPrice: data.B2CMemberPrice ? data.B2CMemberPrice : 0,
                B2CPrice: data.B2CPrice ? data.B2CPrice : 0,
                BabyChargePrice: data.BabyChargePrice ? data.BabyChargePrice : 0,
                BabyPrice: data.BabyPrice ? data.BabyPrice : 0,
                BackAddPrice: data.BackAddPrice ? data.BackAddPrice : 0,
                BackVisaPrice: data.BackVisaPrice ? data.BackVisaPrice : 0,
                ChildNeedPrice: data.ChildNeedPrice ? data.ChildNeedPrice : 0,
                ChildNoNeedPrice: data.ChildNoNeedPrice ? data.ChildNoNeedPrice : 0,
                DiscountPrice: data.DiscountPrice ? data.DiscountPrice : 0,
                GoAddPrice: data.GoAddPrice ? data.GoAddPrice : 0,
                ID: data.ID,
                MinUnitPrice: data.MinUnitPrice ? data.MinUnitPrice : 0,
                OldManChargePrice: data.OldManChargePrice ? data.OldManChargePrice : 0,
                OrderId: data.OrderId,
                OtherPrice: data.OtherPrice ? data.OtherPrice : 0,
                RB_Branch_id: data.RB_Branch_id,
                RB_Group_id: data.RB_Group_id,
                RebatePrice: data.RebatePrice ? data.RebatePrice : 0,
                SafeMoney: data.SafeMoney ? data.SafeMoney : 0,
                SingleDMCPrice: data.SingleDMCPrice ? data.SingleDMCPrice : 0,
                SingleRoomPrice: data.SingleRoomPrice ? data.SingleRoomPrice : 0,
                TCID: data.TCID,
                VisaPrice: data.VisaPrice ? data.VisaPrice : 0,
              }
            } else {
              this.Error(res.data.message);
            }
          },
          (err) => {})

      }

    },
    mounted() {

    },
    watch: {
      PreferPrice: {
        handler(newVal) {

        },
        deep: true,
        immediate: true,
      },
      OrderId: {
        handler(newVal) {

        },
        deep: true,
        immediate: true,
      },
    },
  };

</script>