<template>
  <div class="goods-order-cont">
    <!-- 标题 -->
    <div class="goods-order-header">
      <!-- 待发货 -->
      <div class="unDelivered" v-if="type == 'orderGoods'">
        <p class="order-status">待发货</p>
        <a-button id="goodsOrder-send" type="primary" size="small" @click="sendGoods">立即发货</a-button>
      </div>
      <!-- 已发货 -->
      <div class="delivered" v-if="type == 'express'">
        <p class="companyInfo">快递公司：<span>{{ orderData.expressName }}</span></p>
        <div class="orderNoInfo">
          <p class="orderNo">运单编号：<span>{{ orderData.expressNum }}</span></p>
          <a-button id="goodsOrder-copy" size="small" v-clipboard:copy="orderData.expressNum" v-clipboard:success="onCopy">复制</a-button>
        </div>
      </div>
    </div>
    <!-- 表格 -->
    <a-table
      v-if="dataSource.length>0"
      ref="table"
      size="default"
      :row-selection="type=='orderGoods' ? { selectedRowKeys: selectedRowKeys, onChange: onSelectChange } : null"
      :columns="columns"
      :rowKey="(record) => record.id"
      :data-source="dataSource"
      :pagination="false"
      bordered>
    </a-table>
  </div>
</template>

<script>
export default {
  name: 'GoodsOrder',
  props: {
    orderData: {
      type: Object,
      default: () => {
        return {}
      }
    },
    type: {
      type: String,
      default: ''
    }
  },
  computed: {
    dataSource: function () {
      console.log(this.orderData, '-----this.orderData')
      if (this.type == 'orderGoods') {
        return this.orderData
      } else if (this.type == 'express') {
        return this.orderData.orderGoodsList
      } else {
        return []
      }
    }
  },
  data () {
    return {
      selectedRowKeys: [], //  已选项
      columns: [
        { title: '商品名称', dataIndex: 'goodsName', width: 200, align: 'center' },
        { title: '商品价格', dataIndex: 'payGold', width: 200, align: 'center' },
        { title: '购买数量', dataIndex: 'buyQty', width: 200, align: 'center' }
      ]
    }
  },
  methods: {
    //  选择商品
    onSelectChange (selectedRowKeys) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      this.selectedRowKeys = selectedRowKeys
    },
    //  立即发货
    sendGoods () {
      if (this.selectedRowKeys.length < 1) {
        this.$message.warning('请勾选需要发货的商品')
        return
      }
      this.$emit('sendGoods', this.selectedRowKeys)
    },
    //  复制成功
    onCopy (e) {
      this.$message.success('复制成功')
    }
  }
}
</script>

<style lang="less" scoped>
  .goods-order-cont{
    p{
      margin: 0;
    }
    .goods-order-header{
      border-left: 5px solid #ff9900;
      padding-left: 10px;
      margin: 25px 0 20px;
      .unDelivered{
        .order-status{
          display: inline-block;
          margin-right: 65px;
        }
      }
      .delivered{
        .companyInfo{
          display: inline-block;
          margin-right: 65px;
        }
        .orderNoInfo{
          display: inline-block;
          .orderNo{
            display: inline-block;
            margin-right: 20px;
          }
        }
      }
    }
  }
</style>
