<template>
  <a-modal
    :visible="value"
    title="新增广告位"
    @ok="handleOk"
    width="60%"
    @cancel="handleCancel"
  >
    <a-form :form="form">
      <a-form-item
        v-bind="formItemLayout"
        label="名称"
      >
        <a-input
          v-decorator="[
            'name',
            {
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        v-bind="formItemLayout"
        label="类型"
      >
        微信
      </a-form-item>
      <a-form-item
        v-bind="formItemLayout"
        label="描述"
      >
        <a-input
          v-decorator="[
            'description',
            {
              rules: [{ required: true, message: '请输入' }]
            }
          ]"
        ></a-input>
      </a-form-item>
      <a-form-item
        v-bind="formItemLayout"
        label="广告"
      >
        <a-select
          mode="multiple"
          placeholder="请选择"
          v-decorator="[
            'advs',
            {
              rules: [{ required: true, message: '请选择' }]
            }
          ]"
        >
          <a-select-option
            v-for="(item, index) in advList"
            :key="index"
            :value="item.id"
          >
            {{ item.name }}
          </a-select-option>
        </a-select>
      </a-form-item>
    </a-form>
  </a-modal>
</template>

<script>
import { addAdvPosition } from '@/api/adv'
import advMixins from './advPosMixins'
export default {
  mixins: [advMixins],
  methods: {
    handleOk (e) {
      e.preventDefault()
      this.form.validateFieldsAndScroll((err, values) => {
        if (!err) {
          console.log(values)
          values.type = 'WX'
          values.schedule = {
            type: 'SEQUENCE',
            advs: values.advs
          }
          addAdvPosition(values).then(res => {
            this.$message.success('添加成功')
            this.$emit('update')
            this.handleCancel()
          })
        }
      })
    }
  }
}
</script>

<style scoped>
.ant-form-item{
  width: 50%; display: inline-block;
}
.color-block {
  display: flex;
}
.color-label {
  margin-left: 15px;
  font-size: 16px;
  font-weight: bold;
}
.time-block {
  display: flex;
  align-items: center;
}
.input-ctrl {
  width: 200px; height: 200px;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>
