<template>
  <section class="hbnAuditList mar-t16">
    <ai-card hideTitle>
      <template #content>
        <ai-search-bar class="mar-t8">
          <template #left>
            <el-date-picker v-model="search.createTime" type="date" placeholder="日期" size="small" clearable
                            @change="page.current=1,getTableData()"/>
          </template>
          <template #right>
            <el-input size="small" placeholder="搜索党员/四邻信息" v-model="search.name" clearable
                      @change="page.current=1,getTableData()"/>
          </template>
        </ai-search-bar>
        <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 v-if="row.status==0" type="text" @click="handleAudit(row)">审批</el-button>
            </template>
          </el-table-column>
        </ai-table>
      </template>
    </ai-card>
    <ai-dialog title="联动记录审核" :visible.sync="dialog" @closed="form={}" @onConfirm="submit" width="600px">
      <el-form :model="form" size="small" ref="DialogForm" :rules="rules" label-width="120px">
        <el-form-item label="是否通过审核" prop="status">
          <ai-select v-model="form.status" placeholder="请选择党员" :selectList="dict.getDict('yesOrNo')"/>
        </el-form-item>
        <el-form-item label="审批意见" prop="remark" v-if="form.status==0">
          <el-input type="textarea" v-model="form.remark" placeholder="请输入审批意见" maxlength="200" show-word-limit
                    rows="5"/>
        </el-form-item>
      </el-form>
    </ai-dialog>
  </section>
</template>

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

export default {
  name: "hbnAuditList",
  props: {
    instance: Function,
    dict: Object,
    permissions: Function
  },
  computed: {
    ...mapState(['user']),
    colConfigs() {
      return [
        {label: "党员", prop: "partyName"},
        {label: "四邻信息", prop: "residentName"},
        {label: "描述", prop: "description"},
        {label: "日期", prop: "linksageDate"},
        {label: "状态", prop: "status", dict: "partyFourLinkageStatus"},
        {slot: "options"}
      ]
    }
  },
  data() {
    return {
      search: {name: ""},
      page: {current: 1, size: 10, total: 0},
      tableData: [],
      dialog: false,
      form: {},
      rules: {
        status: {required: true, message: "请选择是否通过审核"},
        remark: {required: true, message: "请输入审批意见"},
      }
    }
  },
  methods: {
    getTableData() {
      this.instance.post("/app/apppartyfourlinkage/list", null, {
        params: {...this.page, ...this.search, status: 0}
      }).then(res => {
        if (res?.data) {
          this.tableData = res.data?.records
          this.page.total = res.data.total
        }
      })
    },
    submit() {
      this.$refs.DialogForm.validate(v => {
        if (v) {
          let {id, status, remark} = this.form
          this.instance.post("/app/apppartyfourlinkage/auditById", null, {
            params: {id, status, remark}
          }).then(res => {
            if (res?.code == 0) {
              this.$message.success("提交成功!")
              this.dialog = false
              this.getTableData()
            }
          })
        }
      })
    },
    handleAudit(row) {
      this.form = JSON.parse(JSON.stringify({...row, status: null}))
      this.dialog = true
    }
  },
  created() {
    this.getTableData()
  }
}
</script>

<style lang="scss" scoped>
.hbnAuditList {
  height: fit-content;
}
</style>
