<template>
  <div class="storeInfo container">
    <div class="form-group">
      <div class="storeIns">
        <div class="sign">选择商家：</div>
        <div class="storeInList" v-for="storeIn in store">
          <div class="choose" :class="{'storeIn-active' : storeIn.isSelected, 'storeIn' : !storeIn.isSelected}" @click="addStore(storeIn)">
            <a class="storeLogo">
              <img :src="storeIn.logoUrl || '/images/component/default.png'" :alt="storeIn.storeName" :title="storeIn.storeName">
            </a>
          </div>
        </div>
        <div class="storeInList" style="font-size: 14px" v-if="!store || store.length == 0">
          暂无商家信息
        </div>
      </div>
    </div>
    <div class="form-group" style="margin-bottom: 40px;">
      <div>
        <div style="font-size: 14px">
          <span>产品匹配：</span>
          <span v-if="store && store.length > 0">
            <input type="checkbox" v-if="storeExist && UmallExist">
            <span v-if="UmallExist">&nbsp;库存寄售</span>
            <input type="checkbox" v-if="storeExist && UmallExist">
            <span v-if="storeExist">&nbsp;店铺自营</span>
          </span>
          <span v-if="!store || store.length == 0">暂无可匹配的信息 </span>
        </div>
      </div>
    </div>
    <div class="goodsList">
      <div class="goods-item">按商家列表</div>
      <table class="table">
        <thead>
          <tr class="height54">
            <th class="text-center" width="100">制造商型号</th>
            <th class="text-center" width="120">生产日期</th>
            <th class="text-center" width="80">包装方式</th>
            <th class="text-center" width="150">库存</th>
            <th class="text-center" width="80">数量</th>
            <th class="text-center" width="100">香港交货<span style="font-size: 12px;">($)</span></th>
            <th class="text-center" width="130">大陆交货<span style="font-size: 12px;">(￥)</span></th>
            <th class="text-center" width="120">交期</span></th>
            <th class="text-center" width="140">操作</th>
          </tr>
        </thead>
        <tbody class="text-center">
          <tr style="cursor: pointer;" v-for="list in storeList.content">
            <td><a :href="'/store/' + list.storeid + '/' + list.batchCode">{{list.code}}</a></td>
            <td><a :href="'/store/' + list.storeid + '/' + list.batchCode">{{list.produceDate}}</a></td>
            <td><a :href="'/store/' + list.storeid + '/' + list.batchCode">{{list.packaging || '暂无包装方式'}}</a></td>
            <td style="text-align: left;padding-left: 25px;">
              <a :href="'/store/' + list.storeid + '/' + list.batchCode">
                <div>
                  <span>库存：</span>
                  <span>{{list.reserve}}</span>
                </div>
                <div>
                  <span>起拍：</span>
                  <span>{{list.minBuyQty}}</span>
                </div>
                <div>
                  <span>倍数：</span>
                  <span>{{list.minPackQty}}</span>
                </div>
              </a>
            </td>
            <td>
              <a :href="'/store/' + list.storeid + '/' + list.batchCode">
                <div v-for="price in list.prices">
                  <span>{{price.start}}</span>+
                </div>
              </a>
            </td>
            <td>
              <a :href="'/store/' + list.storeid + '/' + list.batchCode">
                <div v-show="list.currencyName.indexOf('USD')==-1 || !list.prices">
                  <span>—</span>
                </div>
                <div v-for="price in list.prices">
                  <span>{{price.uSDPrice | currency}}</span>
                </div>
              </a>
            </td>
            <td>
              <a :href="'/store/' + list.storeid + '/' + list.batchCode">
                <div v-show="list.currencyName.indexOf('RMB')==-1 || !list.prices">
                  <span>—</span>
                </div>
                <div v-for="price in list.prices">
                  <span>{{price.rMBPrice | currency}}</span>
                </div>
              </a>
            </td>
            <td>
              <a :href="'/store/' + list.storeid + '/' + list.batchCode">
                <div v-show="list.b2cMinDelivery">
                  <span>交期：</span>
                  <span>{{list.b2cMinDelivery}}</span>-<span>{{list.b2cMaxDelivery}}</span>
                </div>
              </a>
            </td>
            <td>
              <buy :item="list"></buy>
            </td>
          </tr>
          <tr v-if="!storeList.content || storeList.content.length == 0">
            <td colspan="10" class="text-center" style="line-height: 40px; font-size: 14px;"><i class="fa fa-smile-o fa-lg"></i> 暂无现货</td>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>
<script>
  import Buy from '~components/common/buyOrCar/BuyComponent.vue'
  export default {
    name: 'StoreInfo',
    data () {
      return {
        storeIds: [],
        UmallExist: false,
        storeExist: false
      }
    },
    components: {
      Buy
    },
    filters: {
      currency: function (num) {
        if (typeof num === 'number') {
          if (num.toString().indexOf('.') === -1) {
            num += '.00'
          }
        }
        return num
      }
    },
    computed: {
      stores () {
        return this.$store.state.componentStore.store
      },
      store () {
        return this.stores.data
      },
      storeList () {
        let storeList = this.$store.state.componentInformation.information.data
        if (storeList.storeid && storeList.storeid !== '') {
          this.storeIds = storeList.storeid
        }
        this.storeId
        if (this.storeIds.length > 0) {
          if (this.storeIds.indexOf(this.storeId) === -1) {
            this.storeExist = true
          } else {
            this.storeIds.splice(this.storeIds.indexOf(this.storeId), 1)
            if (this.storeIds.length > 0) {
              this.storeExist = true
            }
            this.UmallExist = true
          }
        }
        return storeList
      },
      storeId () {
        let UmallStoreId = this.$store.state.componentUmallStoreId.storeId.data
        return UmallStoreId
      }
    },
    methods: {
      addStore (storeIn) {
        if (this.storeIds.indexOf(storeIn.uuid) !== -1) {
          this.storeIds.splice(this.storeIds.indexOf(storeIn.uuid), 1)
          storeIn.isSelected = false
        } else {
          this.storeIds.push(storeIn.uuid)
          storeIn.isSelected = true
        }
      }
    }
  }
</script>
<style scoped>
  .storeInfo .storeIns{
    margin-top: 20px;
    width: 1190px;
    height: 48px;
    line-height: 48px;
  }
  .storeInfo .storeIns .sign {
    display: table-cell;
    vertical-align: middle;
    font-size: 14px;
  }
  .storeInfo .storeIns .storeInList {
    display: table-cell;
  }
  .storeInfo .choose {
    border: 1px solid #ccc;
  }
  .storeInfo .storeIn {
    width: 98px;
    height: 49px;
    line-height: 30px;
    float: left;
    border: 1px solid #ccc;
    text-align: center;
    vertical-align: middle;
    margin-right: 15px;
    cursor: pointer;
  }
  .storeInfo .storeIn-active {
    width: 98px;
    float: left;
    border: 1px solid #5078cb;
    text-align: center;
    vertical-align: middle;
    margin-right: 15px;
    cursor: pointer;
  }
  .storeInfo .storeIn a,.componentDetail .storeIn-active a {
    display: table-cell;
    height: 46px;
    width: 98px;
    text-align: center;
    vertical-align: middle;
  }
  a.storeLogo>img,.storeIn-active a.storeLogo>img {
    max-width: 95px;
    max-height: 46px;
  }
  .storeInfo .goodsList {
    clear: both;
    font-size: 14px;
  }
  .storeInfo .goodsList .goods-item {
    height: 30px;
    width: 120px;
    background-color: #5078cb;
    color: #fff;
    text-align: center;
    vertical-align: middle;
    line-height: 30px;
  }
  .storeInfo .goodsList thead {
    background-color: #F7F7F7;
  }
  .storeInfo .goodsList tbody tr td{
    vertical-align: middle;
    text-align: center;
  }
  .storeInfo .goodsList tbody tr td:hover a{
    color: #474443;
  }
  /*.storeInfo .goodsList .btn{*/
    /*border-radius: 4px;*/
    /*width: 80px;*/
    /*height: 30px;*/
    /*color: #214797;*/
    /*font-size: 14px;*/
    /*line-height: 14px;*/
    /*text-align: center;*/
    /*margin: 5px 0;*/
    /*padding: 0;*/
    /*user-select: none;*/
    /*background-image: none;*/
    /*border: 1px solid transparent;*/
    /*font-weight: 400;*/
  /*}*/
  /*.storeInfo .goodsList .btn-buyNow {*/
    /*color: #fff;*/
    /*background-color: #5078cb;*/
  /*}*/
  /*.storeInfo .goodsList .btn-default{*/
    /*background-color: #fff;*/
    /*border-color: #ccc;*/
  /*}*/
  .storeInfo .form-group input{
    vertical-align: sub;
  }
  .storeInfo .height54{
    height: 54px;
    background: none;
    color: #333;
  }
  .storeInfo .height54 th{
    line-height: 54px;
    border-bottom: none;
    padding: 0;
  }
  .storeInfo .table tbody td{
    border-bottom: #ddd 1px solid;
    border-top: none;
  }
  .storeInfo .table tbody{
    border-left: #ddd 1px solid;
    border-right: #ddd 1px solid;
  }
  .storeInfo .table tbody td div{
    text-align: center;
    margin-left: 10%;
  }
  .storeInfo .table tbody tr:hover{
    background: #f5f5f5;
  }
  .storeInfo .table tbody tr:hover{
    background: #f5f5f5;
  }
</style>
