<template>
  <div class="detail-container major-project">
    <head-form-new title="重点项目" :form-data="formData" :query-params="queryParams" :total="tableDataTotal" :isExcel="false"
      @handle-search="handleSearch" />
    <skeleton style="margin-left:16px;" v-if="isSkeleton"></skeleton>
    <tables v-else :tableLoading="tableLoading" :tableData="tableData" :forData="forData" :tableDataTotal="tableDataTotal" :queryParams="queryParams"
      @handle-current-change="handleCurrentChange" @sort-change="sortChange">
      <template slot="projectName" slot-scope="scope">
        <router-link :to="`/radar/Land/details/${scope.row.id}`" tag="a" class="a-link" v-if="scope.row.id&&scope.row.projectName "
          v-html="scope.row.projectName"></router-link>
        <div v-else v-html="scope.row.projectName  || '--'"></div>
      </template>
      <!-- 项目投资金额 -->
      <template slot="totalInvestment" slot-scope="scope">
        <div style="text-align:right;">
          {{scope.row.totalInvestment ? `${scope.row.totalInvestment}万元` : "--"}}
        </div>
      </template>
    </tables>

  </div>
</template>

<script>
import mixin from '../mixins/mixin';
import { getMajorProjectListApi } from '@/api/detail/party-a/opport';
import skeleton from '@/views/project/projectList/component/skeleton';
export default {
  name: 'majorProject',
  props: ['companyId'],
  mixins: [mixin],
  components: {
    skeleton
  },
  data() {
    return {
      isSkeleton: true,
      queryParams: {
        cid: this.companyId,
        pageNum: 1,
        pageSize: 20
      },
      forData: [
        { label: '项目名称', prop: 'projectName', minWidth: '450', slot: true },
        { label: '项目地区', prop: 'projectAddress', width: '127' },
        { label: '项目等级', prop: 'projectLevel', width: '90' },
        { label: '项目投资金额', prop: 'totalInvestment', width: '120', slot: true },
        { label: '项目类型', prop: 'projectType', width: '120' },
        { label: '项目年度', prop: 'year', width: '90' },
      ],
      formData: [
        { type: 1, fieldName: 'projectLevel', value: '', placeholder: '项目级别', options: [], uid: this.getUid() },
        { type: 4, fieldName: 'projectType', value: '', placeholder: '项目类型', options: [], uid: this.getUid() },
        { type: 3, fieldName: 'keys', value: '', placeholder: '输入项目名称关键词查询', options: [], width: 220, uid: this.getUid() }
      ],
      //列表
      tableLoading: false,
      tableData: [],
      tableDataTotal: 0
    };
  },
  computed: {
  },
  created() {
    this.setProjectLevelOptions();
    this.setProjectTypeOptions();
    this.handleQuery();
  },
  methods: {
    async setProjectLevelOptions() {
      try {
        const result = await this.getDicts("project_level");
        if (result.code == 200) {
          const levels = result.data.map(item => {
            return {
              name: item.dictLabel,
              value: item.dictValue,
              id: item.dictCode
            };
          });
          this.setFormData("projectLevel", levels);
        }
      } catch (error) {

      }
    },
    async setProjectTypeOptions() {
      try {
        const result = await this.getDicts("project_type_new");
        if (result.code == 200) {
          const types = result.data.map(item => {
            return {
              name: item.dictLabel,
              value: item.dictValue,
              id: item.dictCode
            };
          });
          this.setFormData("projectType", types);
        }
      } catch (error) {

      }
    },
    async handleQuery(params) {
      this.tableLoading = true;
      let param = params ? params : this.queryParams;
      let res = await getMajorProjectListApi(param);
      this.tableLoading = false;
      if (res.code == 200) {
        this.isSkeleton = false;
        this.tableData = res.rows;
        if (this.tableData.length > 0) {
          this.tableData.map(item => {
            item.transactionPrice == 0 && (item.transactionPrice = '--');
          });
        }
      }
      this.tableDataTotal = res.total;
    }
  }
}
</script>
<style lang="scss" scoped>
.detail-container {
  background: #ffffff;
  border-radius: 4px;
  padding: 16px;
}

.major-project {
  @import "@/assets/styles/search-common.scss";
}
</style>