<template>
  <a-modal
    :title="modalTitle"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    class="ant-modal2"
    @cancel="handleCancel"
  >
    <a-form :form="form">
      <row-list :col="2">
        <row-item>

          <a-form-item
            label="状态"
            :labelCol="BaseTool.Constant.labelCol"
            :wrapperCol="BaseTool.Constant.wrapperCol"
          >
            <a-select
              @change="statusChange"
              v-decorator="['status', {initialValue: parseInt(DictCache.VALUE.SB_OIL_STATUS.AGREE),rules: [{required: true, message: '状态不能为空'}]}]"
              placeholder="请选择">
              <a-select-option
                :key="2"
                label="同意"
                :value="parseInt(DictCache.VALUE.SB_OIL_STATUS.AGREE)">同意
              </a-select-option>
              <a-select-option
                :key="4"
                label="不同意"
                :value="parseInt(DictCache.VALUE.SB_OIL_STATUS.NOT_AGREE)">不同意
              </a-select-option>
            </a-select>
          </a-form-item>
        </row-item>
      </row-list>
      <row-list :col="1">
        <row-item>
          <a-form-item
            label="说明"
            :labelCol="BaseTool.Constant.labelCol2"
            :wrapperCol="BaseTool.Constant.wrapperCol2"
          >
            <a-textarea
              :rows="4"
              v-decorator="['remark']"/>
          </a-form-item>
        </row-item>
      </row-list>
    </a-form>
    <template slot="footer">
      <a-button :loading="confirmLoading" type="primary" @click="save()">保存</a-button>
    </template>
  </a-modal>
</template>

<script>
import { updateAuditSbOilList } from '@/api/sb/oil'

export default {
  name: 'BaseSbOil',
  components: {
  },
  data () {
    return {
      confirmLoading: false,
      modalTitle: null,
      form: this.$form.createForm(this),
      status: 2,
      ids: [],
      model: {},
      visible: false,
      // 下拉框map
      statusMap: {}
    }
  },
  props: {},
  created () {
    // 下拉框map
    this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_OIL_STATUS)
  },
  methods: {
    base (ids) {
      this.visible = true
      // 如果是空标识添加
      this.modalTitle = '批量审批'
      this.ids = ids
    },
    statusChange (val) {
      console.log(val)
      this.status = val
    },
    save () {
      const { form: { validateFieldsAndScroll } } = this
      this.confirmLoading = true
      validateFieldsAndScroll((errors, values) => {
        if (errors) {
          this.confirmLoading = false
          return
        }
        values.ids = this.ids
        updateAuditSbOilList(values)
          .then(() => {
            this.handleCancel(values)
          }).catch(() => {
            this.confirmLoading = false
          })
      })
    },
    handleCancel (values) {
      this.visible = false
      this.confirmLoading = false
      this.form.resetFields()
      if (this.BaseTool.Object.isNotBlank(values)) {
        this.$emit('ok', values)
      }
    }

  }
}
</script>
