<template>
  <div>
    <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">
          <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.type" placeholder="请选择类别" size="medium">
          <el-radio border label="ICOME">收入</el-radio>
          <el-radio border label="COST">费用</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="状态" :label-width="formLabelWidth">
        <el-radio-group v-model="form.incomeStatus" placeholder="请选择状态值" size="medium">
          <el-radio border label="INVOICE">开票/应收</el-radio>
          <el-radio border label="ARRIVAL">到账</el-radio>
          <el-radio border label="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>
    <el-table :data="searchResult" style="width: 100%;margin-top:50px;">
      <el-table-column fixed prop="deptName" label="部门" ></el-table-column>
      <el-table-column prop="type" label="类型" ></el-table-column>
      <el-table-column prop="product.name" label="产品" ></el-table-column>
      <el-table-column prop="amount" label="金额" ></el-table-column>
      <el-table-column prop="incomeStatus" label="状态" :filters="[{ text: '开票/应收', value: 'INVOICE' }, { text: '到账', value: 'INVOICE' }, { text: '内部核算', value: 'INTERNAL' }]"></el-table-column>
      <el-table-column prop="project.name" label="发生人/部门/单位" ></el-table-column>
    </el-table>
  </div>
</template>
<script>
import {
  getTeamSelect,
  getProjectSelect,
  getProductSelect,
  getCostTeamSelect,
  getCostTypeSelect,
  addManage,
  getManageList,
  setManage
} from "@/api/manageApi";
export default {
  data() {
    return {
      type: "",
      dialogFormVisible: false,
      addFlag: false,
      id: "",
      searchResult: [],
      form: {
        type: "",
        productId: "",
        projectId: "",
        toDeptId: "",
        toProjectId: "",
        deptId: "",
        incomeStatus: "",
        status: "NORMAL",
        costTypeId: ""
      },
      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: {
    onSubmit() {
      this.$fetch("manageBase/manage", this.form).then(response => {
        console.log(response);
        this.searchResult = response.data;
      });
    },
    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>