<template>
  <el-dialog :visible.sync="dialog"
             title="批量调整"
             width="25%"
             :before-close="handleClose">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px">


      <el-form-item label="小库区编号" prop="smallArea">
        <el-select
          v-model="form.smallArea"
          clearable
          size="small"
          placeholder="小库区编号"
          class="filter-item"
          style="width: 250px"
        >
          <el-option
            v-for="item in dict.smallArea"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>

      <el-form-item label="存储类型">
        <el-select
          v-model="form.description"
          clearable
          size="small"
          placeholder="存储类型"
          class="filter-item"
          style="width: 250px"
        >
          <el-option
            v-for="item in dict.item_type"
            :key="item.id"
            :label="item.label"
            :value="item.value"
          />
        </el-select>
      </el-form-item>


      <el-form-item label="库区" prop="area">
        <el-select v-model="form.areaId" clearable @focus="getArea" value-key="id"  placeholder="请选择" style="width: 250px;">
          <el-option
            v-for="item in areas"
            :key="item.id"
            :label="item.name"
            :value="item.id"
            v-if="item.name=='1F存储区' || item.name=='2F存储区'  "
          />
        </el-select>
      </el-form-item>

      <el-form-item label="是否启用">
        <el-select
          v-model="form.enabled"
          clearable
          size="small"
          placeholder="是否启用"
          class="filter-item"
          style="width: 250px"
        >
          <el-option
            v-for="item in dict.base_staus"
            :key="item.id"
            :label="item.label"
            :value="item.value"

          />
        </el-select>
      </el-form-item>

    </el-form>

    <span slot="footer" class="dialog-footer">
    <el-button @click="cancelForm">取 消</el-button>
    <el-button type="primary" @click="MultiAdjustConfirm">确 定</el-button>
    </span>


  </el-dialog>
</template>

<script>
import crud from '@/mixins/crud'
import CRUD from '@crud/crud'
import {getAres} from '@/api/area'
import MultiAdjust from "@/views/base-data/point/multiAdjust.vue";
import crudPoint from '@/api/point'
export default {
  computed: {
    MultiAdjust() {
      return MultiAdjust
    }
  },
  mixins: [crud],
  dicts:["smallArea","item_type","base_staus"],
  data() {
    return {
      title: '批量调整',
      errorInfo: '',
      errorDialog: false,
      areas: [],
      form:{
        enabled:"true"
      },
      multiadjust: {
        smallArea: '',
        description: '',
        areaId:'',
        enabled:''

      },
      rules: {
        smallArea: [
          {required: true, message: '小库区必填', trigger: 'blur'}
        ]
      },
    }
  },
  methods: {
    //关闭
    handleClose(done) {
      done();
      this.$refs['form'].resetFields();
      this.form.description=''
      this.form.areaId=''
      this.form.enabled="true"
    },
    getArea() {
      getAres({size: 300}).then(res => {
        this.areas = res.content.map(function (obj) {
          if (obj.hasChildren) {
            obj.children = null
          }
          return obj

        })
      })
    },
    MultiAdjustConfirm() {
      this.$refs['form'].validate((valid) => {
        if (valid) {

          this.multiadjust.smallArea = this.form.smallArea
          this.multiadjust.description = this.form.description===null||this.form.description===undefined?"":this.form.description
          this.multiadjust.areaId=this.form.areaId===null||this.form.areaId===undefined?"0":this.form.areaId
          this.multiadjust.enabled=this.form.enabled

          crudPoint.multiAdjust(this.multiadjust).then(res => {
            if(res.status==200){
              this.dialog = false
              this.$parent.crud.notify(res.message, CRUD.NOTIFICATION_TYPE.SUCCESS);
              this.$parent.crud.toQuery();
              this.$refs['form'].resetFields();
              this.form.description=''
              this.form.areaId=''
            }else{
              this.$parent.crud.notify(res.message, CRUD.NOTIFICATION_TYPE.ERROR);
              this.$refs['form'].resetFields();
              this.form.description=''
              this.form.areaId=''
            }
          }).catch(() => {

          })
        } else {
          return false;
        }
      });
    },
    cancelForm() {
      this.dialog = false
      this.$refs['form'].resetFields();
      this.form.description=''
      this.form.areaId=''
      this.form.enabled="true"
    }
  }
}
</script>

<style scoped>
.java.hljs {
  color: #444;
  background: #ffffff !important;
}

::v-deep .el-dialog__body {
  padding: 0 20px 10px 20px !important;
}
</style>
