<template>
  <div class="transfer-list-item-con" @click="toDetail">
    <div class="sku-con flex-default">
      <img class="thumb" :src="itemData.thumb" />
      <div class="right-con">
        <div class="top">
          <div class="name">{{ itemData.goodsName }}</div>
          <div class="coin">{{ itemData.coin }}</div>
        </div>
        <div class="price-con">
          <span class="total-label">{{ transferTypeLabel }}</span>
          <m-price :amt="itemData.price" />
        </div>
      </div>
    </div>
    <div class="info-con">
      <div class="info-item flex-default">
        <div class="label">规格</div>
        <div class="val">{{ skuLabel }}</div>
      </div>
      <div class="info-item flex-default">
        <div class="label">总数</div>
        <div class="val">{{ itemData.number }}</div>
      </div>
      <div class="info-item flex-default">
        <div class="label">已转让</div>
        <div class="val">{{ itemData.transferOrderTotal }}</div>
      </div>
    </div>
    <div class="opt-con flex-default" v-if="showOpt">
      <van-button @click.stop="handleCancel" color="#AEAEAE" round plain>
        撤销
      </van-button>
      <van-button @click.stop="handleModifyPrice" color="#AEAEAE" round plain>
        修改价格
      </van-button>
    </div>
  </div>
</template>
<script>
export default {
  props: {
    itemData: {
      type: Object,
      default: function () {
        return {};
      },
    },
    tab: {
      type: Object,
    },
    deleteItem: {
      type: Function
    }
  },
  computed: {
    transferTypeLabel() {
      return this.itemData.type == 1 ? "单价" : "打包价";
    },
    skuLabel() {
      if (this.itemData.propValList) {
        return this.itemData.propValList.join(" ");
      }
      return "";
    },
    showOpt() {
      return +this.itemData.transferOrderTotal == 0;
    },
  },
  data() {
    return {};
  },
  methods: {
    toDetail() {
      let query = { id: this.itemData.tranId };
      this.$router.push({ name: "assets-transfer-detail", query });
    },
    handleCancel() {
      this.$confirm({
        content: "您确定取消该转让信息？",
        confirm: this.confirmCancel,
      });
    },
    confirmCancel() {
      this.$showLoading();
      this.$api({
        apiName: "cancelTransfer",
        postData: this.itemData.tranId,
        success: () => {
          this.deleteItem && this.deleteItem()
          this.$toast("已撤销~");
        },
        complete: this.$hideLoading,
      });
    },
    handleModifyPrice() {
      this.$emit("modifyPrice", this.itemData);
    },
  },
};
</script>
<style lang="less">
.transfer-list-item-con {
  padding: 14px 10px;
  background: #ffffff;
  box-shadow: 0px 1px 9px 1px rgba(0, 0, 0, 0.07);
  border-radius: 6px;
  margin-bottom: 10px;

  > .sku-con {
    margin-bottom: 12px;
    .thumb {
      width: 80px;
      height: 80px;
      border-radius: 6px;
      object-fit: contain;
      margin-right: 14px;
    }
    .right-con {
      height: 70px;
      flex: 1;
      display: flex;
      flex-direction: column;
    }
    .right-con .top {
      flex: 1;
      .name,
      .coin {
        font-size: 14px;
        font-weight: bold;
      }
      .name {
        margin-bottom: 3px;
      }
    }
    .right-con > .price-con {
      display: flex;
      align-items: flex-end;
      .total-label {
        color: @mall-primary-color;
        font-size: 12px;
        margin-right: 5px;
      }
    }
  }

  > .info-con {
    background: #f9faf9;
    border-radius: 2px;
    padding: 7px 14px;
    display: flex;
    flex-wrap: wrap;
    .info-item {
      width: 50%;
      line-height: 1.8;
    }
    .info-item .label {
      color: #999999;
      font-size: 12px;
      font-weight: bold;
      margin-right: 10px;
    }
    .info-item .val {
      font-weight: bold;
    }
  }

  > .opt-con {
    justify-content: flex-end;
    margin-top: 16px;
    button {
      width: 80px;
      font-size: 12px;
      height: 28px;
      margin-left: 10px;
    }
  }
}
</style>