<template>
  <div>
    <el-button type="primary" size="small" :disabled="disabled" @click="addBtn">添 加</el-button>
    <el-dialog title="添加年度" append-to-body :visible.sync="visible" width="500px">
      <el-form :model="form" :rules="rules" ref="form" label-width="55px" label-position="right" size="mini">
        <el-form-item label="年度:" prop="year">
          <el-date-picker
            style="width: 100%"
            v-model="form.year"
            type="year"
            value-format="yyyy"
            placeholder="选择年">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="领域:" prop="year">
          <el-select v-model="form.tradefield" placeholder="请选择领域" style="width: 100%">
            <el-option
                v-for="item in fieldList"
                :key="item.rowindex"
                :label="item.tradefield"
                :value="item.tradefield">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="dialog-footer">
        <el-button size="small" @click="visible=false" class="normal-btn-width">取 消</el-button>
        <el-button size="small" type="primary" @click="submit" class="normal-btn-width">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
export default {
  props:['data','disabled'],
  name: '',
  data() {
    return {
      visible:false,
      form: {
        year: '2022',
        tradefield:''
      },
      rules:{
        year:[
          { required: true, message: '请选择年度', trigger: 'change'},
        ],
      },
      fieldList:[]
    };
  },
  computed:{
  },
  watch:{
  },
  methods: {
    addBtn () {
      this.visible=true
      this.form.year = this.$parent.year
      this.queryField()
      
    },
    async submit () {
      let res = await this.$api.requested({
        "id": 20221229104202,
        "content": {
            "year": this.form.year,
            "sa_salestargetbillid": 0, //新建年度是为0，添加人员时为具体的数据id
            "sys_enterpriseid": this.data.sys_enterpriseid,
            "sa_contractid":this.$route.query.id,
            "tradefield":this.form.tradefield
        },
      })
      this.tool.showMessage(res,() => {
        this.visible = false
        this.$emit('onSuccess',this.form.year)
      })
    },
    /*领域信息*/
    async queryField(){
      const res = await this.$api.requested({
        "id": 20221223141802,
        "content": {
          "sys_enterpriseid": this.data.sys_enterpriseid,//可不传，默认取当前账号的
          "pageNumber": 1,
          "pageSize": 99,
          "where": {
            "condition": ""
          }
        }
      })
      console.log(res,"领域信息")
      this.fieldList = res.data
    }
  },
};
</script>

<style scoped>

</style>
