<template>
  <section class="psList">
    <ai-list>
      <ai-title slot="title" title="党员积分" isShowBottomBorder/>
      <template #content>
        <ai-table :tableData="tableData" :total="page.total" :current.sync="page.current" :size.sync="page.size"
                  @getList="getTableData" :col-configs="colConfigs" :dict="dict">
          <el-table-column slot="options" label="操作" fixed="right" align="center">
            <template slot-scope="{row}">
              <el-button type="text" @click="getFamilyByPartyId(row.idNumber)">家庭成员</el-button>
              <el-button type="text" @click="showDetail(row.id)">详情</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-list>
    <ai-dialog :visible.sync="dialog" title="家庭成员" :customFooter="true" width="780px" @close="familyList=[]">
      <ai-table :tableData="familyList" :isShowPagination="false" :col-configs="familyCols" :dict="dict"/>
      <div class="dialog-footer" slot="footer">
        <el-button @click="dialog=false">关 闭</el-button>
      </div>
    </ai-dialog>
  </section>
</template>

<script>
import {mapState} from "vuex";

export default {
  name: "psList",
  props: {
    instance: Function,
    dict: Object,
  },
  computed: {
    ...mapState(['user']),
    colConfigs() {
      return [
        {label: "姓名", prop: "name"},
        {label: "个人积分", prop: "integral", align: "center"},
        {label: "家庭积分", prop: "familySurplusIntegral", align: "center"},
        {label: "学习强国", prop: "learningIntegral", align: "center"},
        {slot: "options"}
      ]
    },
    familyCols() {
      return [
        {
          label: '与户主关系', prop: 'householdRelation', align: 'center', width: 165,
          render: (h, {row}) => h('p', this.dict.getLabel('householdRelation', row.householdRelation || "户主"))
        },
        {label: '类型', prop: 'residentType', align: 'center', dict: "residentType"},
        {label: '姓名', prop: 'name', align: 'center'},
        {label: '身份证号', render: (h, {row}) => h('p', this.idCardNoUtil.hideId(row.idNumber)), width: 165},
        {label: '联系电话', prop: 'phone', align: 'center', width: 120}
      ]
    }
  },
  data() {
    return {
      search: {},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
      dialog: false,
      familyList: [],
    }
  },
  methods: {
    back() {
      this.$router.push({})
    },
    getTableData() {
      this.instance.post("/app/appparty/listByPartyIntegral", null, {
        params: {...this.page, ...this.search}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data?.records
          this.page.total = res.data.total
        }
      })
    },
    showDetail(id) {
      this.$router.push({query: {id}})
    },
    getFamilyByPartyId(idNumber) {
      this.instance.post("/app/appresident/queryHomeMember", null, {
        params: {idNumber}
      }).then(res => {
        if (res?.data) {
          this.familyList = res.data?.family || []
          this.dialog = true
        }
      })
    }
  },
  created() {
    this.getTableData()
  }
}
</script>

<style lang="scss" scoped>
.psList {
  height: 100%;
}
</style>
