<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="业主姓名">
              <j-input placeholder="请输入业主姓名" v-model="queryParam.ownerName"></j-input>
            </a-form-item>
          </a-col>

          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>

    <div style="display:flex">
      <div style="flex: none;width:200px">
        <a-tree :load-data="onLoadData" :tree-data="treeData" @select="onClickTree" />
      </div>

      <div style="flex:auto;width:80%;">
        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button type="primary" icon="download">设置业委会</a-button>
        </div>

        <!-- table区域-begin -->
        <div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
            <i class="anticon anticon-info-circle ant-alert-icon"></i>已选择&nbsp;<a style="font-weight: 600">{{
            selectedRowKeys.length }}</a>项&nbsp;&nbsp;
            <a style="margin-left: 24px" v-if="selectedRowKeys.length > 0" @click="onClearSelected">清空</a>
          </div>

          <a-table ref="table" size="middle" :scroll="{ x: 1500}" bordered rowKey="id" :columns="columns"
            :dataSource="dataSource" :pagination="ipagination" :loading="loading" :rowSelection="{
              selectedRowKeys: selectedRowKeys,
              onChange: onSelectChange,
              getCheckboxProps: onCheckboxProps
            }" class="j-table-force-nowrap" @change="handleTableChange">
            <span slot="ownerId" slot-scope="text, record">
              <span>{{record.ownerName}}，{{record.ownerPhone}}</span>
            </span>
            <span slot="residentPhone" slot-scope="text, record">
              <span>{{record.residentName}}，{{record.residentPhone}}</span>
            </span>
            <span slot="roomId" slot-scope="text, record">
              <span>{{record.buildingName}}{{record.unitName}}{{record.roomName}}</span>
            </span>
            <span slot="action" slot-scope="text, record">
              <a @click="onDetail(record.id)">查看</a>
              <template v-if="record.paymentStatus === 'unPaid'">
                <a-divider type="vertical" />
                <a @click="handleDelete(record.id)">删除</a>
              </template>
            </span>
          </a-table>

        </div>
        <!-- table区域-end -->
      </div>
    </div>

    <notice-modal ref="modalForm" @ok="modalFormOk"></notice-modal>
  </a-card>
</template>

<script>
import { getBuildingListApi, getUnitListApi, getRoomListApi, callPayMentApi, getTotalMoneyApi } from '@/api/api'
import { downFile } from '@/api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import NoticeModal from './modules/NoticeModal'
import { filterDictTextByStatic } from '@/assets/static.js'

const columns = [
  {
    title: '业主',
    dataIndex: 'ownerId',
    key: 'ownerId',
    width: 160,
    scopedSlots: { customRender: 'ownerId' },
    align: 'center',
  },
  {
    title: '与业主关系',
    dataIndex: 'relationShip',
    key: 'relationShip',
    width: 120,
    align: 'center'
  },
  {
    title: '住户',
    dataIndex: 'residentPhone',
    key: 'residentPhone',
    width: 160,
    scopedSlots: { customRender: 'residentPhone' },
    align: 'center',
  },
  {
    title: '房屋编号',
    dataIndex: 'roomId',
    scopedSlots: { customRender: 'roomId' },
    key: 'roomId',
    width: 140,
    align: 'center',
  },
  {
    title: '金额（元）',
    dataIndex: 'totalAmount',
    key: 'totalAmount',
    width: 120,
    align: 'center',
  },
  {
    title: '本期读表时间',
    dataIndex: 'meterReadingTime',
    key: 'meterReadingTime',
    width: 150,
    align: 'center',
  },
  {
    title: '缴费状态',
    dataIndex: 'paymentStatus',
    key: 'paymentStatus',
    width: 120,
    align: 'center'
  },
  {
    title: '缴费单号',
    dataIndex: 'paymentNum',
    key: 'paymentNum',
    width: 120,
    align: 'center',
  },
  {
    title: '缴费日期',
    dataIndex: 'paymentTime',
    key: 'paymentTime',
    width: 150,
    align: 'center',
  },
  {
    title: '创建日期',
    dataIndex: 'createTime',
    key: 'createTime',
    width: 150,
    align: 'center',
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    width: 150,
    fixed: 'right',
  },
]

export default {
  name: 'PermissionListAsync',
  mixins: [JeecgListMixin],
  components: { NoticeModal },
  data() {
    return {
      // 表头
      columns: columns,
      url: {
        list: '/property-community/payment/communityPayment/propertyFeeList',
        deleteBatch: '/property-community/payment/communityPayment/deleteBatch',
      },
      treeData: [],
      statistical: {},
    }
  },
  created() {
    this.onLoadData()
  },
  methods: {
    onCheckboxProps(record) {
      let props = {
        disabled: record.paymentStatus === 'paid',
        name: record.chargeTypeName,
      }
      return props
    },
    onLoadData(treeNode) {
      
    },
    onClickTree(value, option) {
      console.log(value, option)
      let level = option.node.pos.split('-').length
      if (level === 2) {
        this.queryParam['buildingId'] = value[0]
        this.queryParam['unitId'] = undefined
        this.queryParam['roomId'] = undefined
      }
      if (level === 3) {
        this.queryParam['buildingId'] = undefined
        this.queryParam['unitId'] = value[0]
        this.queryParam['roomId'] = undefined
      }
      if (level === 4) {
        this.queryParam['buildingId'] = undefined
        this.queryParam['unitId'] = undefined
        this.queryParam['roomId'] = value[0]
      }
      this.searchQuery()
    },
    onBatchCallpay() {
      // console.log(this.selectionRows)
      let chooseIds = this.selectedRowKeys.join(',')
    },
    onDetail(id) {
      this.$router.push({
        path: '/property/propertyfee-detail?id=' + id,
      })
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>