<template>
  <a-modal
    centered
    class="chooseProducts-modal"
    :footer="null"
    :maskClosable="false"
    :title="type==1?'批量设置良品数量':'批量设置返库数量'"
    v-model="isShow"
    @cancel="isShow=false"
    width="450px">
    <div class="products-con">
      <div v-if="type == 1">
        <div>良品数量：</div>
        <a-radio-group v-model="value"><a-radio :style="radioStyle" :value="1">等于仓库实收数量</a-radio><a-radio :style="radioStyle" :value="0">等于0</a-radio></a-radio-group>
      </div>
      <div v-if="type == 2">
        <div>返库数量：</div>
        <a-radio-group v-model="value"><a-radio :style="radioStyle" :value="1">等于良品数量</a-radio><a-radio :style="radioStyle" :value="0">等于0</a-radio></a-radio-group>
      </div>
    </div>
    <div class="btn-con">
      <a-button size="large" @click="isShow=false" style="padding: 0 40px;margin:0 15px;" type="default">取消</a-button>
      <a-button
        size="large"
        style="padding: 0 40px;margin:0 15px;"
        type="primary"
        class="button-primary"
        @click="handleSubmit()"
      >确定</a-button>
    </div>
  </a-modal>
</template>

<script>
export default {
  name: 'ChooseTypeModal',
  props: {
    openModal: { //  弹框显示状态
      type: Boolean,
      default: false
    },
    type: {
      type: [Number, String],
      default: '1'
    }
  },
  data () {
    return {
      value: 1,
      spinning: false,
      isShow: this.openModal, //  是否打开弹框
      radioStyle: {
        display: 'block',
        height: '40px',
        lineHeight: '40px'
      }
    }
  },
  methods: {
    handleSubmit () {
      this.$emit('confirm', this.value)
    }
  },
  watch: {
    //  父页面传过来的弹框状态
    openModal (newValue, oldValue) {
      this.isShow = newValue
    },
    //  重定义的弹框状态
    isShow (newValue, oldValue) {
      if (!newValue) {
        this.$emit('close')
        this.value = 1
      }
    }
  }
}
</script>

<style lang="less" scoped>
  .chooseProducts-modal{
    .products-con{
      padding-top:20px;
      > div{
        padding: 0 30px;
        display: flex;
        > div:first-child{
          padding-top: 10px;
        }
      }
    }
    .btn-con{
      text-align: center;
      margin: 30px 0 20px;
    }
  }
</style>
