<template>
  <div class="goods-sku-addr-con">
    <div class="item-con flex-default" @click="$emit('addr')" v-if="goodsTypeMap.TRANSFER">
      <div class="title">转让</div>
      <div class="content flex-default">
        <img class="avatar" :src="transferData.uheadUrl"/>
        <div class="text">{{transferData.unickName}}</div>
      </div>
    </div>
    <div class="item-con flex-default" @click="handleSku">
      <div class="title">已选</div>
      <div class="content flex-default">
        <div class="text">{{ skuLabel }}</div>
        <m-icon icon="icon-more" :size="10" className="more" />
      </div>
    </div>
    <div class="item-con flex-default" @click="$emit('addr')">
      <div class="title">送至</div>
      <div class="content flex-default">
        <div class="text">{{ addrLabel }}</div>
        <m-icon icon="icon-more" :size="10" className="more" />
      </div>
    </div>
  </div>
</template>

<script>
import {TransferType} from "@/enums"
export default {
  props: {
    sku: {
      type: Object,
      default: null,
    },
    addr: {
      type: Object,
      default: null,
    },
    skuList: {
      type: Array,
      default: () => [],
    },
    addrList: {
      type: Array,
      default: () => [],
    },
    goodsTypeMap: Object,
    transferData: Object
  },
  computed: {
    skuLabel() {
      if (!this.sku) {
        return (
          "请选择  " + this.skuList.map((item) => item.propKey).join(" / ")
        );
      } else {
        let { propObj, weight, num } = this.sku;
        return `${Object.keys(propObj)
          .map((key) => propObj[key])
          .join("， ")}， ${weight}kg，${num}件`;
      }
    },
    addrLabel() {
      if (!this.addr) {
        return "请选择";
      }
      let {province, city, county, street, detailAddr, name, phone} = this.addr
      return `${province}${city}${county || ''}${street || ''} ${detailAddr}\n ${name} ${phone}`;
    },
  },
  methods: {
    handleSku(){
      if(this.goodsTypeMap.TRANSFER && this.transferData.type == TransferType.PACKAGE){
        return
      }
      this.$emit("sku")
    }
  },
};
</script>

<style lang="less">
.goods-sku-addr-con {
  padding: 14px 0 14px 16px;
  background: #ffffff;
  border-radius: 10px;
  margin-bottom: 10px;
  > .item-con{
    align-items: flex-start;
  }
  > .item-con > .title {
    padding-top: 17px;
    font-size: 12px;
    color: #140603;
    font-weight: bold;
    line-height: 17px;
    margin-right: 15px;
  }
  > .item-con > .content {
    flex: 1;
    padding: 16px 16px 16px;
    border-top: 1px solid #f1f1f1;
    .text {
      font-size: 12px;
      color: #2b2b3a;
      line-height: 17px;
      flex: 1;
      margin-right: 20px;
      white-space: pre-line;
    }
    .more {
    }
    .avatar{
      object-fit: contain;
      width: 20px;
      height: 20px;
      margin-right: 8px;
      border-radius: 50%;
    }
  }
  > .item-con:first-of-type {
    > .title {
      padding-top: 0;
    }
    > .content {
      padding-top: 0;
      padding-bottom: 16px;
      border-top: none;
    }
  }
  > .item-con:last-of-type{
    > .content{
      padding-bottom: 0;
    }
  }
}
</style>