<template>
  <el-form :inline="true" :model="form" ref="form" class="marginTop">
    <el-form-item label="归属产品" prop="productId" :label-width="formLabelWidth">
      <el-select v-model="form.productId" placeholder="请选择产品">
        <el-option key label="无" value></el-option>
        <el-option
          v-for="item in productSelectData"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="归属项目" prop="projectId" :label-width="formLabelWidth">
      <el-select v-model="form.projectId" placeholder="请选择项目">
        <el-option key label="无" value></el-option>
        <el-option
          v-for="item in projectSelectData"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        ></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="来源部门" prop="toDeptId" :label-width="formLabelWidth">
      <el-select v-model="form.toDeptId" placeholder="请选择部门">
        <el-option key label="无" value></el-option>
        <el-option
          v-for="item in teamSelectData"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        ></el-option>
      </el-select>
    </el-form-item>
    <el-form-item label="来源项目" prop="toProjectId" :label-width="formLabelWidth">
      <el-select v-model="form.toProjectId" placeholder="请选择项目">
        <el-option key label="无" value></el-option>
        <el-option
          v-for="item in projectSelectData"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        ></el-option>
      </el-select>
    </el-form-item>

    <el-form-item label="归属部门" prop="deptId" :label-width="formLabelWidth">
      <el-select v-model="form.deptId" placeholder="请选择部门" ref="select" @change="getName">
        <el-option key label="无" value></el-option>
        <el-option
          v-for="item in teamSelectData"
          :key="item.id"
          :label="item.name"
          :value="item.id"
        ></el-option>
      </el-select>
    </el-form-item>
        <el-form-item
      label="类别"
      :label-width="formLabelWidth"
    >
      <el-radio-group v-model="form.incomeStatus" placeholder="请选择类别"  size="medium">
        <el-radio border  label="收入" name="ICOME"  value="ICOME"></el-radio>
        <el-radio border  label="费用" name="COST" value="COST"></el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item
      label="状态"
      prop="incomeStatus"
      :label-width="formLabelWidth"
    >
      <el-radio-group v-model="form.incomeStatus" placeholder="请选择状态值"  size="medium">
        <el-radio border  label="开票/应收" name="INVOICE"  value="INVOICE"></el-radio>
        <el-radio border  label="到账" name="ARRIVAL" value="ARRIVAL"></el-radio>
        <el-radio border  label="内部核算" name="INTERNAL" value="INTERNAL"></el-radio>
      </el-radio-group>
    </el-form-item>
      <el-form-item>
    <el-button type="primary" @click="onSubmit">查询</el-button>
  </el-form-item>
  </el-form>
</template>
<script>
import {
  getTeamSelect,
  getProjectSelect,
  getProductSelect,
  getCostTeamSelect,
  getCostTypeSelect,
  addManage,
  getManageList,
  setManage
} from "@/api/manageApi";
export default {
  data() {
    return {
      type: "",
      dialogFormVisible: false,
      addFlag: false,
      id: "",
      form: {
        deptId: "",
        projectId: "",
        costTypeId: "",
        companyId: "",
        companyType: "",
        happenTime: "",
        incomeStatus: "",
        productId: "",
        toProjectId: "",
        remark: "",
        amount: "",
        toDeptId: "",
        deptName: "",
        code: "",
        name: "",
        status: "NORMAL",
        sort: ""
      },
      formLabelWidth: "120px",
      teamSelectData: [],
      projectSelectData: [],
      productSelectData: [],
      costTeamSelectData: [],
      costTypeSelectData: [],
      manageData: [],
      companyData: []
    };
  },
  created() {
    // 获取部门下拉框
    getTeamSelect().then(res => {
      this.teamSelectData = res.data.data;
    });
    // 获取项目下拉框
    getProjectSelect().then(res => {
      this.projectSelectData = res.data.data;
    });
    //获取产品下拉框
    getProductSelect().then(res => {
      this.productSelectData = res.data.data;
    });
    //获取经营列表
    getManageList({
      type: "INCOME"
    }).then(res => {
      this.manageData = res.data.data;
      console.log(res.data.data);
    });
    //获取单位下拉
    getCostTeamSelect().then(res => {
      this.costTeamSelectData = res.data.data;
    });
    //获取成本类型下拉
    getCostTypeSelect().then(res => {
      this.costTypeSelectData = res.data.data;
    });
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (row.type === "COST") {
        return "cost-row";
      } else {
        return "income-row";
      }
      return "";
    },
    //获取部门名称
    getName(val) {
      let obj = {};
      obj = this.teamSelectData.find(item => {
        return item.id === val;
      });
      let getName = "";
      this.form.deptName = obj.name;
    },
    // 添加
    append(type) {
      this.type = type;
      this.dialogFormVisible = true;
      this.addFlag = true;
    },
    
  }
};
</script>

<style scope>
 .marginTop{
   margin-top: 20px;
 }
</style>