<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.communityName"></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 class="table-operator">
      <a-button @click="onCommunityAdd()" type="primary" icon="plus">新增</a-button>
      <!-- <a-button type="primary" icon="download" @click="handleExportXls('t_property_settled')">导出</a-button> -->
      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="onBatchDelele"><a-icon type="delete" />解绑</a-menu-item>
        </a-menu>
        <a-button style="margin-left: 8px">批量操作<a-icon type="down" /></a-button>
      </a-dropdown>
    </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:true}" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="ipagination" :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}" class="j-table-force-nowrap"
        @change="handleTableChange">
        <!-- <span slot="noticeTitle" slot-scope="text, record"
          style=" width: 200px;display: block;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">
          <a-tooltip placement="topLeft" :title="record.noticeTitle">{{record.noticeTitle}}</a-tooltip>
        </span>
        <span slot="employeeStatus" slot-scope="text, record">
          <span
            :style="{'color': record.employeeStatus === '1' ? 'green' : 'red'}">{{record.employeeStatus === '1' ? '在职' : '离职'}}</span>
        </span> -->
        <span slot="action" slot-scope="text, record">
          <a @click="onCommunityAdd(record.id)">详情</a>

          <a-divider type="vertical" />

          <a-popconfirm
            title="确认解绑此小区吗?"
            ok-text="是"
            cancel-text="否"
            @confirm="onHandleDelete(record.id)"
          >
            <a href="#">解绑</a>
          </a-popconfirm>
          
        </span>
      </a-table>

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

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

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import NoticeModal from './modules/NoticeModal'
import { deleteCommunityApi } from '@/api/api'

const columns = [
  {
    title: '小区名称',
    dataIndex: 'communityName',
    // scopedSlots: { customRender: 'communityName' },
    width: 100,
    ellipsis: true,
    key: 'communityName',
  },
  {
    title: '所属区域',
    dataIndex: 'communityArea',
    key: 'communityArea',
    align: 'center',
    // customRender: function (text) {
    //   return filterDictTextByStatic(URGENT_DEGREE, text)
    // },
  },
  {
    title: '占地面积（㎡）',
    dataIndex: 'coverArea',
    key: 'coverArea',
    align: 'center',
    // customRender: function (text) {
    //   return filterDictTextByStatic(SCHEDULED_RELEASE, text)
    // },
  },
  {
    title: '总栋数',
    dataIndex: 'buildingNum',
    key: 'buildingNum',
    align: 'center',
  },
  {
    title: '房屋数量',
    dataIndex: 'houseNum',
    key: 'houseNum',
    align: 'center',
  },
  // {
  //   title: '住户数量',
  //   dataIndex: 'noticeStatus',
  //   key: 'noticeStatus',
  //   align: 'center',
  //   customRender: function (text) {
  //     return filterDictTextByStatic(NOTICE_STATUS, text)
  //   },
  // },
  {
    title: '联系人',
    dataIndex: 'adminName',
    key: 'adminName',
    align: 'center'
  },
  {
    title: '联系方式',
    dataIndex: 'adminPhone',
    key: 'adminPhone',
    align: 'center'
  },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    key: 'createTime',
    align: 'center'
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    fixed: 'right',
    width: 150,
  },
]

export default {
  name: 'PermissionListAsync',
  mixins: [JeecgListMixin],
  components: { NoticeModal },
  data() {
    return {
      // 表头
      columns: columns,
      url: {
        list: '/property-company/community/companyCommunity/list?type=binded'
      },
    }
  },
  methods: {
    async onHandleDelete(ids) {
      let res = await deleteCommunityApi({
        action: 'delete',
        ids
      })
      this.$message.success('解绑成功')
      this.loadData()
    },
    onBatchDelele() {
      let _this = this
      this.$confirm({
        title: '提示',
        content: '确认要批量解绑选中的小区吗?',
        onOk() {
          _this.onHandleDelete(_this.selectedRowKeys.join(','))
        },
        onCancel() {
        },
      });
    },
    onCommunityAdd(id) {
      let path = id ? `/community/CommunityDetail?id=${id}` : '/community/CommunityDetail'
      this.$router.push({
        path
      });
    }
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>