<template>
  <div class="mod-axis__caRental}">
    <el-card>
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item label="所属网格" prop="gridId">
          <el-cascader
            :options="caLouDongOptions"
            :props="{ checkStrictly: true }"
            clearable
            @change="handlePartyChange">
          </el-cascader>
        </el-form-item>
        <el-form-item label="房屋编号" prop="houseName">
          <el-input
            v-model="dataForm.houseName"
            placeholder="房屋编号"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="房主姓名" prop="residentName">
          <el-input
            v-model="dataForm.residentName"
            placeholder="房主姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item label="承租人姓名" prop="renterName">
          <el-input
            v-model="dataForm.renterName"
            placeholder="承租人姓名"
            clearable
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="getDataList()">{{ $t("query") }}</el-button>
        </el-form-item>
        <!-- <el-form-item>
            <el-button v-if="$hasPermission('axis:caResident:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
          </el-form-item>
          <el-form-item>
            <el-button v-if="$hasPermission('axis:caResident:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
          </el-form-item> -->
      </el-form>
    </el-card>
    <el-card shadow="never" class="aui-card--fill">
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%"
      >
        <el-table-column
          type="selection"
          header-align="center"
          align="center"
          width="50"
        ></el-table-column>
        <el-table-column
          prop="comName"
          label="社区"
          header-align="center"
          align="center"
          :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column
          prop="streetName"
          label="街道"
          header-align="center"
          align="center"
          :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column
          prop="gridName"
          label="网格"
          header-align="center"
          align="center"
          :show-overflow-tooltip="true">
        </el-table-column>
        <el-table-column
          prop="houseName"
          label="房屋编号"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="houseAddress"
          label="房屋地址"
          header-align="center"
          align="center"
          :show-overflow-tooltip="true"
        ></el-table-column>
        <el-table-column
          prop="houseArea"
          label="建筑面积（平方米）"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="residentName"
          label="房主姓名"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="telephone"
          label="房主联系方式"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="rentUse"
          label="出租用途"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="renterName"
          label="承租人姓名"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="renterPhone"
          label="承租人联系方式"
          header-align="center"
          align="center"
        ></el-table-column>
        <el-table-column :label="$t('handle')" fixed="right" align="center" width="100">
          <template slot-scope="scope">
            <el-button
              type="text"
              class="div-table-button--detail"
              size="small"
              @click="addOrUpdateHandle(scope.row.rentalId)"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        :current-page="page"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="limit"
        :total="total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="pageSizeChangeHandle"
        @current-change="pageCurrentChangeHandle"
      >
      </el-pagination>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update
        v-if="addOrUpdateVisible"
        ref="addOrUpdate"
        @refreshDataList="getDataList"
      ></add-or-update>
    </el-card>
  </div>
</template>

<script>
import mixinViewModule from "@/mixins/view-post";
import AddOrUpdate from "./carental-add-or-update";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/opendata/caRental/getPage",
        getDataListIsPage: true,
        deleteURL: "",
        deleteIsBatch: true,
      },
      dataForm: {
        houseName: "",
        residentName: "",
        renterName: "",
        gridId:""
      },
      caLouDongOptions:[]
    };
  },
  methods:{
    getloudongOptions(){
      this.$http.post(`/opendata/cabmGrid/getCascadeMenu`).then(resp => {
        if(resp.data.code === 0){
          this.caLouDongOptions = this.removeEmptySubOrgList(resp.data.data)
        }
      }).catch(error => {
        this.$message.error(error)
      })     
  },
  removeEmptySubOrgList (orgArray) {
      orgArray.forEach((orgInfo) => {
        if (orgInfo && orgInfo.children) {
          if (orgInfo.children.length === 0) {
              orgInfo.children = undefined
          } else {
              this.removeEmptySubOrgList(orgInfo.children)
          }
        }
      })
      return orgArray;
    },
  handlePartyChange(val) {
      console.log('val------pp', val)
      this.dataForm.gridId = val[val.length - 1]
    },
  },
created(){
    this.getloudongOptions()
  },
  components: {
    AddOrUpdate,
  },
};
</script>
