<template>
  <div class="detail-container">
    <head-form
      title="土地交易"
      :form-data="formData"
      :query-params="queryParams"
      :total="tableDataTotal"
      :isExcel="true"
      @handle-search="handleSearch"
    />

    <tables
      :indexFixed="true"
      :defaultSort="defaultSort"
      :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>
    </tables>

  </div>
</template>

<script>
import mixin from '../mixins/mixin'
import {landUse, landTransactionPage} from '@/api/detail/party-a/opport'
export default {
  name: 'Landtransaction',
  props: ['companyId'],
  mixins: [mixin],
  components: {
  },
  data() {
    return {
      queryParams: {
        cid: this.companyId,
        sort: 3,
        pageNum: 1,
        pageSize: 20
      },
      defaultSort: {prop: 'contractSignTime', order: 'descending'},
      forData: [
        {label: '项目名称', prop: 'projectName', minWidth: '300', slot: true},
        {label: '土地用途', prop: 'landUse', width: '130'},
        {label: '行业分类', prop: 'industry', width: '100'},
        {label: '供地方式', prop: 'supplyLandWay', width: '100'},
        {label: '土地坐落', prop: 'landAddr', minWidth: '130'},
        {label: '成交金额（万元）', prop: 'transactionPrice', sortable: 'custom', descending: '1', ascending: '2', width: '140'},
        {label: '总面积（㎡）', prop: 'acreage', sortable: 'custom', descending: '11', ascending: '12', width: '130'},
        {label: '批准单位', prop: 'authority', width: '130'},
        {label: '签订日期', prop: 'contractSignTime', sortable: 'custom', descending: '3', ascending: '4', width: '130'}
      ],
      formData: [
        { type: 4, fieldName: 'landUse', value: '', placeholder: '土地用途', options: []},
        { type: 3, fieldName: 'keys', value: '', placeholder: '输入项目名称关键词查询', options: [], width: 220}
      ],
      //列表
      tableLoading:false,
      tableData:[],
      tableDataTotal:0
    }
  },
  computed: {
  },
  created() {
    this.handleOption()
    this.handleQuery()
  },
  methods: {
    async handleOption(){
      let res = await landUse({cid: this.companyId})
      if(res.code==200){
        let use = res.data.map(item => {
          let it = {name:item.landUse+'('+item.count+')',value:item.landUse}
          return it
        })
        this.setFormData('landUse', use)
      }
    },
    async handleQuery(params) {
      this.tableLoading = true
      let param = params?params:this.queryParams
      let res = await landTransactionPage(param)
      this.tableLoading = false
      if(res.code==200){
        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;
}
</style>
