<template>
  <div>
    <el-button size="mini" type="primary" @click="dialogFormVisible = true">新 增</el-button>
    <el-dialog title="新 增" :visible.sync="dialogFormVisible" width="50%">
      <div slot="title" style="font-size: 15px">
        新增账户类型
      </div>
      <el-row :gutter="20">
        <el-form :model="form" :rules="rules" ref="form" label-width="120px" label-position="left" size="mini">
          <el-col :span="24">
            <el-form-item label="项目类型" prop="itemids">
              <el-select v-model="form.itemids" placeholder="请选择项目类型" multiple size="small">
                <el-option
                  v-for="(item,index) in productList()"
                  :key="item.itemid"
                  :label="item.itemname"
                  :value="item.itemid">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
      <div class="dialog-footer">
        <el-button size="small" @click="dialogFormVisible = false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="warning" @click="onSubmit" class="normal-btn-width btn-warning">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: "add",
  inject:['productList'],
  components:{},
  data(){
    return {
      dialogFormVisible:false,
      projectAddress:[],
      form:{
        "sa_projectid": "",
        "itemids": []
      },
      rules:{
        itemids:[
          { required: true, message: '请选择商品', trigger: 'blur'},
        ]
      }
    }
  },
  methods:{
    onSubmit(){
      this.$refs['form'].validate(async (valid) => {
        if (!valid) return false
        this.form.sa_projectid = this.$route.query.id
        const res = await this.$api.requested({
          "id": "20221021145502",
          "version":1,
          "content": this.form
        })
        this.tool.showMessage(res,()=>{
          this.$emit('onSuccess')
          this.$refs['form'].resetFields();
          this.dialogFormVisible = false
        })
      })
    },
  }
}
</script>

<style scoped>
/deep/.el-select {
  height: 28px !important;
  width: 100%;
}
/deep/.el-input__inner {
  height: 28px !important;
}
</style>