<template>
  <div class="">
    <Card v-if="loading" class="loading-card">
      <Spin fix size="large" />
    </Card>
    <Card v-else>
      <span>是否允许用户延后提货：</span>
      <i-switch v-model="commodityAllocation" :disabled="disabled" @on-change="changeStatue" />
    </Card>
  </div>
</template>
<script>
export default {
  computed: {
    platform () {
      return this.$store.state.admin.type == 1 || this.$store.state.admin.type == 4
    }
  },
  data () {
    return {
      loading: false,
      disabled: false,
      commodityAllocation: false
    }
  },
  methods: {
    initData () {
      let apiName = this.platform ? 'goodsConfigurePlatDetail' : 'goodsConfigureMerchantDetail'
      this.api({
        apiName,
        success: (res) => {
          if (this.platform) {
            if (res.data == 1) {
              this.commodityAllocation = true
            } else {
              this.commodityAllocation = false
            }
          } else {
            if (res.data.platform == 0) {
              this.disabled = true
            }
            if (res.data.isDelivery == 1) {
              this.commodityAllocation = true
            } else {
              this.commodityAllocation = false
            }
          }
          console.log(res)
        }
      })
    },
    changeStatue () {
      console.log('commodityAllocation', this.commodityAllocation)
      let apiName = this.platform ? 'goodsConfigurePlatConfigure' : 'goodsConfigureMerchantConfigure'
      let delayDelivery = ''
      if (this.commodityAllocation == true) {
        delayDelivery = 1
      } else {
        delayDelivery = 0
      }
      this.api({
        apiName,
        postdata: { delayDelivery },
        success: (res) => {
          this.$Notice.success({ title: '设置成功！' })
          this.initData()
        },
        complete: () => {
        }
      })
    }
  },
  mounted () {
    this.initData()
  }
}
</script>
<style lang="less" scoped>
  .add-banner-con {
    height: 100%;
    .loading-card {
      height: 100%;
    }
    .head {
      color: #17233d;
      font-size: 18px;
      font-weight: bold;
      display: flex;
      align-items: center;
      margin-bottom: 15px;
      i {
        margin-right: 10px;
      }
    }
    .item {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
      .ivu-radio{
        width: 200px;
      }
    }
    .item .label {
      display: block;
      width: 150px;
      text-align: right;
    }
    .footer-con {
      display: flex;
      padding: 30px 120px;
      margin-left:90px;
    }
  }
</style>
