<template>
  <a-modal
    v-model="opened"
    :title="title"
    centered
    :maskClosable="false"
    :confirmLoading="confirmLoading"
    width="450px"
    :footer="null"
    @cancel="cancel"
  >
    <a-spin :spinning="spinning" tip="Loading...">
      <div style="padding: 0 30px;">
        <aRadioGroup v-model="upActiveVal">
          <aRadio :style="radioStyle" value="0">
            不参加促销
          </aRadio>
          <div v-for="(item,idx) in activeList" :key="idx">
            <div>
              <strong>{{ item.title }}</strong> 
              <!-- <a-popover title="活动详情">
                <div slot="content">
                  <ul class="active-li">
                    <li><strong>促销类型：</strong> 买产品送产品</li>
                    <li><strong>促销门槛：</strong> 购买1000元门槛产品，可使用200元配额，采购正价产品</li>
                    <li><strong>促销规则：</strong> 购买满10个正价产品，送10个促销产品</li>
                    <li><strong>限制正价产品款数</strong> 40</li>
                    <li><strong>订单起订金额：</strong> 20000</li>
                    <li><strong>活动经费上线：</strong> 5000</li>
                  </ul>
                </div>
                <a-button type="link">详情</a-button>
              </a-popover> -->
            </div>
            <aRadio :style="radioStyle" v-for="(sitem,sindex) in item.promotionRuleList" :key="sindex" :value="item.promotionSn+'-'+sitem.promotionRuleSn+'-'+sitem.promotionProductType">
              {{sindex+1}}、{{ sitem.description }}
            </aRadio>
          </div>
        </aRadioGroup>
      </div>
        <div style="padding: 30px 0 0;text-align: center;">
          <a-button @click="cancel" style="margin-right: 15px" id="chooseCustom-btn-back">取消</a-button>
          <a-button type="primary" :loading="confirmLoading" @click="handleSubmit" id="chooseCustom-btn-submit">确定</a-button>
        </div>
    </a-spin>
  </a-modal>
</template>

<script>
import { commonMixin } from '@/utils/mixin'
import { salesPromoMatchProduct } from '@/api/salesNew'
export default {
  name: 'SetWarehouse',
  mixins: [commonMixin],
  props: {
    show: [Boolean]
  },
  data () {
    return {
      opened: this.show,
      spinning: false,
      title: '确定换促销活动?',
      confirmLoading: false,
      upActiveVal: null,
      radioStyle:"display:block;height: '30px';lineHeight: '30px';padding:5px 0;",
      activeList: null,
      editRow: null
    }
  },
  methods: {
    getActiveList(data, record){
      this.editRow = record
      this.spinning = true
      salesPromoMatchProduct(data).then(res => {
        this.activeList = res.data
        this.spinning = false
      })
    },
    //  保存
    handleSubmit (e) {
      e.preventDefault()
      const _this = this
      if(_this.upActiveVal){
        _this.$emit('ok', _this.upActiveVal, _this.editRow)
      }else{
        _this.$message.info("请选择活动规则!")
      }
    },
    cancel () {
      this.opened = false
      this.upActiveVal = null
      this.$emit('cancel')
    }
  },
  watch: {
    show (newValue, oldValue) {
      this.opened = newValue
      if (!newValue) {
        this.upActiveVal = null
      }
    }
  }
}
</script>
