<template>
  <a-modal
    centered
    :footer="null"
    :maskClosable="false"
    title="选择合并方式"
    v-model="isShow"
    @cancel="isShow=false"
    width="500px">
    <a-spin :spinning="spinning" tip="Loading...">
      <div style="padding:15px;">
        <a-icon :style="{ fontSize: '16px', color: '#666', marginRight:'6px' }" type="check-square" /> 相同客户名称
      </div>
      <div style="padding:5px 0 25px 40px;" v-if="sameCustomeName">
        <a-checkbox id="meargeOptions-sameRules1" v-model="sameRules1" @change="sameRules2=undefined">相同促销活动</a-checkbox>
        <a-checkbox id="meargeOptions-sameRules2" v-model="sameRules2" @change="sameRules1=undefined">相同活动规则（同一促销活动）</a-checkbox>
      </div>
      <div class="btn-cont" style="padding:20px 20px 0;text-align: center;">
        <a-button type="info" @click="isShow=false" id="meargeOptions-cancel-btn">取消</a-button>
        <a-button type="primary" style="margin-left: 10px" @click="submit" id="meargeOptions-ok-btn">确定</a-button>
      </div>
    </a-spin>
  </a-modal>
</template>

<script>
import {
  commonMixin
} from '@/utils/mixin'
export default {
  name: 'ViewSelectModal',
  mixins: [commonMixin],
  props: {
    openModal: {
      type: Boolean, // 弹框显示
      default: false
    }
  },
  data () {
    return {
      spinning: false,
      isShow: this.openModal,
      sameCustomeName: true, // 是否勾选相同客户名称
      sameRules1: undefined, // 相同促销活动
      sameRules2: undefined, // 相同活动规则（同一促销活动）
      groupType: 'CUSTOMER'
    }
  },
  methods: {
    // 确定提交
    submit () {
      if (!this.sameRules1 && !this.sameRules2) {
        this.groupType = 'CUSTOMER' // 相同客户名称
      } else {
        if (this.sameRules1) {
          this.groupType = 'CUSTOMER_PROMO' // 相同促销活动
        } else if (this.sameRules2) {
          this.groupType = 'CUSTOMER_PROMO_RULE' // 相同活动规则（同一促销活动）
        }
      }
      this.$emit('meargeOk', this.groupType)
      this.isShow = false
    }
  },
  watch: {
    openModal (nVal, oVal) {
      this.isShow = nVal
    },
    isShow (nVal, oVal) {
      if (!nVal) {
        this.$emit('close')
      } else {
        this.sameRules1 = undefined
        this.sameRules2 = undefined
        this.groupType = 'CUSTOMER'
      }
    }
  }
}
</script>

<style>
</style>
