<style lang="scss" scoped>

</style>
<template>
    <div>
        <div
          class="rounded-borders bg-white q-py-md"
          style="width: 300px"
          :style="{
            width:
              $q.platform.is.mobile
                ? 'unset'
                : '300px',
            position: $q.platform.is.mobile ? 'unset' : 'sticky',
            top: $q.platform.is.mobile ? 'unset' : '50px',
          }"
        >
          <div class="text-grey-9">
            <div class="row q-mb-sm" v-if="chosenObj.ManNum > 0">
              <div class="col">成人佔床 x {{ chosenObj.ManNum }}</div>
              <div>CNY {{ moneyFormat(price.B2CMemberPrice, 2) }}</div>
            </div>
            <div class="row q-mb-sm" v-if="chosenObj.ChirdNeedBedNum > 0">
              <div class="col">兒童佔床 x {{ chosenObj.ChirdNeedBedNum }}</div>
              <div>
                CNY
                {{
                  moneyFormat(price.B2CMemberPrice + price.ChildNeedPrice, 2)
                }}
              </div>
            </div>
            <div class="row q-mb-sm" v-if="chosenObj.ChirdNum - chosenObj.ChirdNeedBedNum > 0">
              <div class="col">兒童不佔床 x {{ chosenObj.ChirdNum - chosenObj.ChirdNeedBedNum }}</div>
              <div>
                CNY
                {{
                  moneyFormat(
                    price.B2CMemberPrice - price.ChildNoNeedPrice,
                    2
                  )
                }}
              </div>
            </div>
            <div class="row q-mb-sm" v-if="chosenObj.BabyNum > 0">
              <div class="col">嬰兒不佔床 x {{ chosenObj.BabyNum }}</div>
              <div>CNY {{ moneyFormat(price.BabyPrice, 2) }}</div>
            </div>
            <div v-if="price.safeMoney > 0">
              <div class="row q-mb-sm" v-if="price.safeMoney > 0">
                <div class="col">保險費 x {{ price.safeMoney }}/人</div>
                <div>
                  CNY
                  {{
                    moneyFormat(
                      price.safeMoney *
                        (chosenObj.ManNum +
                          chosenObj.ChirdNum +
                          chosenObj.BabyNum),
                      2
                    )
                  }}
                </div>
              </div>
            </div>
            <div v-if="price.VisaPrice > 0 || price.OtherPrice > 0">
              <div class="row q-mb-sm" v-if="price.VisaPrice > 0">
                <div class="col">簽證費 x {{ price.VisaPrice }}/人</div>
                <div>
                  CNY
                  {{
                    moneyFormat(
                      price.VisaPrice *
                        (chosenObj.ManNum +
                          chosenObj.ChirdNum +
                          chosenObj.BabyNum),
                      2
                    )
                  }}
                </div>
              </div>
              <div class="row q-mb-sm" v-if="price.OtherPrice > 0">
                <div class="col">雜費 x {{ price.OtherPrice }}/人</div>
                <div>
                  CNY
                  {{
                    moneyFormat(
                      price.OtherPrice *
                        (chosenObj.ManNum +
                          chosenObj.ChirdNum +
                          chosenObj.BabyNum),
                      2
                    )
                  }}
                </div>
              </div>
            </div>
            <div class="row q-mb-sm" v-if="chosenObj.ChirdNum > 0">
              <div class="col">兒童附加費 x {{ chosenObj.ChirdNum }}</div>
              <div>CNY {{ moneyFormat(price.BabyChargePrice, 2) }}</div>
            </div>
            <div class="row q-mb-sm" v-if="chosenObj.SingleRoomNum > 0">
              <div class="col">單房差價 x {{ chosenObj.SingleRoomNum }}</div>
              <div>CNY {{ moneyFormat(price.SingleRoomPrice, 2) }}</div>
            </div>
            <div class="row q-mb-sm items-center">
              <div class="col">總金額</div>
              <div class="text-subtitle2 text-weight-bolder text-primary">
                CNY {{ moneyFormat(sumPrice, 2) }}
              </div>
            </div>
            <div class="row q-mb-sm items-center">
              <div class="col">優惠金額</div>
              <div
                class="text-subtitle2 text-weight-bolder text-teal"
                v-if="price.discountPrice > 0"
              >
                CNY - {{ moneyFormat(price.discountPrice, 2) }}
              </div>
              <div class="text-grey-5" v-else>暫無優惠</div>
            </div>
            <!-- <div class="row q-mb-sm items-center">
              <div class="col">支付金額</div>
              <div
                class="text-h6 text-weight-bolder text-primary product-price"
              >
                CNY {{ moneyFormat(sumPrice - price.discountPrice, 2) }}
              </div>
            </div> -->
          </div>
        </div>
    </div>
</template>
<script>
export default {
    props: {
        orderInfo: {
            type: Object,
            default: () => ({})
        }
    },
    data() {
      return {
        chosenObj: {},
        price: {},
        sumPrice: 0,
      }
    },
    mounted() {
        this.getOrder()
    },
    methods: {
    getOrder() {
        
        this.$q.loading.show();
      this.apipost(
        "sellorder_post_GetOrderEntity",
        { ID: this.orderInfo.ErpOrderId },
        (r) => {
          if (r.data.resultCode == 1) {
            this.chosenObj = r.data.data.model;
            this.price = r.data.data.modelPrice;
            this.calcMoney()
          } else {
            this.$q.notify({
              type: "negative",
              message: r.data.message,
              position: "top",
              timeout: 2000, // 以毫秒为单位; 0意味着没有超时
            });
          }
          this.$q.loading.hide();
        },
        null
      );
    
    },
    
    calcMoney() {
      let money = this.price.B2CMemberPrice * this.chosenObj.ManNum;
      console.log('money1', money, this.price.B2CMemberPrice * this.chosenObj.ManNum)
      money +=
        (this.price.B2CMemberPrice -
          this.price.ChildNoNeedPrice +
          this.price.BabyChargePrice) *(this.chosenObj.ChirdNum - this.chosenObj.ChirdNeedBedNum);
      console.log('money2', money, (this.price.B2CMemberPrice -
          this.price.ChildNoNeedPrice +
          this.price.BabyChargePrice) *(this.chosenObj.ChirdNum - this.chosenObj.ChirdNeedBedNum))
      money +=
        (this.price.B2CMemberPrice +
          this.price.ChildNeedPrice +
          this.price.BabyChargePrice) *(this.chosenObj.ChirdNum - this.chosenObj.ChirdNeedBedNum)
      console.log('money3', money, (this.price.B2CMemberPrice +
          this.price.ChildNeedPrice +
          this.price.BabyChargePrice) *(this.chosenObj.ChirdNum - this.chosenObj.ChirdNeedBedNum))
      money += this.price.BabyPrice * this.chosenObj.BabyNum;
      console.log('money4', money, this.price.BabyPrice * this.chosenObj.BabyNum)
      money += this.price.SingleRoomPrice * this.chosenObj.SingleRoomNum;
      console.log('money5', money, this.price.SingleRoomPrice * this.chosenObj.SingleRoomNum)

      let sumCount = this.chosenObj.ManNum + this.chosenObj.ChirdNum;
      money += (this.price.VisaPrice||0) * sumCount;
      console.log('money6', money, (this.price.VisaPrice||0) * sumCount)
      money += (this.price.safeMoney||0) * sumCount;
      console.log('money7', money, (this.price.safeMoney||0) * sumCount)
      money += (this.price.OtherPrice||0) * sumCount;
      console.log('money8', money, (this.price.OtherPrice||0) * sumCount)
      this.sumPrice = money;
    },
    }
}
</script>