<template>
    <div class="container">
        <header class="mb-20">
            <el-form :label-width="114">
                <el-row>
                    <el-col :span="6">
                        <el-form-item label="申请时间">
                            <date-time-range-picker-ext
                                v-model="query.applyDate"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="事发时间">
                            <date-time-range-picker-ext
                                v-model="query.happenTime"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="姓名">
                            <el-input
                                placeholder="请输入姓名"
                                v-model="query.applicantEmpName"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="6">
                        <el-form-item label="申请人单位">
                            <depart-tree-select v-model="query.departId" />
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
            <div class="flex between">
                <el-button type="primary" @click="handleShowAdd">
                    <template #icon>
                        <icon name="el-icon-Plus" />
                    </template>
                    申请抚慰</el-button
                >
                <div>
                    <el-button type="primary" @click="search">
                        <template #icon>
                            <icon name="el-icon-Search" />
                        </template>
                        查询</el-button
                    >
                    <el-button @click="reset">重置</el-button>
                </div>
            </div>
        </header>
        <el-tabs>
            <el-tab-pane label="我的待办">
                <div class="table-container">
                    <el-table :data="todos">
                        <el-table-column
                            label="抚慰编号"
                            prop="number"
                            show-overflow-tooltip
                        />
                        <el-table-column
                            label="申请时间"
                            prop="applyDate"
                            width="160"
                        />
                        <el-table-column
                            label="事发时间"
                            prop="happenTime"
                            width="160"
                        />
                        <el-table-column
                            label="申请人姓名"
                            prop="applicantEmpName"
                            width="100"
                        />
                        <el-table-column label="申请人单位" prop="departName" />
                        <el-table-column label="开户行">
                            <template #default="{ row }">
                                <span>{{ row.bankCard }}</span>
                                <span>{{ row.bankBranch }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="状态" width="100">
                            <template #default="{ row }">
                                <el-tag
                                    :type="
                                        row.rpcStatus !== 'returned'
                                            ? 'primary'
                                            : 'danger'
                                    "
                                    v-if="row.rpcStatus"
                                    >{{
                                        getDictLable(
                                            dict.comfortStatus,
                                            row.rpcStatus
                                        )
                                    }}</el-tag
                                >
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="200">
                            <template #default="{ row }">
                                <el-button
                                    link
                                    type="primary"
                                    @click="handleShow(row, false)"
                                    v-if="row.rpcStatus !== 'returned'"
                                    >立即处理</el-button
                                >
                                <template v-else>
                                    <el-button
                                        link
                                        type="primary"
                                        @click="handleShow(row, true)"
                                        >查看</el-button
                                    >
                                    <el-button
                                        link
                                        type="primary"
                                        @click="handleReSubmit(row)"
                                        >重新提交</el-button
                                    >
                                    <el-button
                                        link
                                        type="danger"
                                        v-if="row.rpcStatus === 'returned'"
                                        @click="handleDelete(row)"
                                        >删除</el-button
                                    >
                                </template>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div class="flex end mt-8">
                    <el-pagination
                        @size-change="getTodos"
                        @current-change="getTodos"
                        :page-sizes="[10, 20, 50]"
                        v-model:page-size="todoPage.size"
                        v-model:current-page="todoPage.current"
                        layout="total, sizes, prev, pager, next"
                        :total="todoPage.total"
                    >
                    </el-pagination>
                </div>
            </el-tab-pane>
            <el-tab-pane label="我的已办">
                <div class="table-container">
                    <el-table :data="dones">
                        <el-table-column
                            label="抚慰编号"
                            prop="number"
                            show-overflow-tooltip
                        />
                        <el-table-column
                            label="申请时间"
                            prop="applyDate"
                            width="160"
                        />
                        <el-table-column
                            label="事发时间"
                            prop="happenTime"
                            width="160"
                        />
                        <el-table-column
                            label="申请人姓名"
                            prop="applicantEmpName"
                            width="100"
                        />
                        <el-table-column label="申请人单位" prop="departName" />
                        <el-table-column label="当前审批人" prop="approver">
                        </el-table-column>
                        <el-table-column label="状态" width="100">
                            <template #default="{ row }">
                                <el-tag type="primary">{{
                                    getDictLable(
                                        dict.comfortStatus,
                                        row.rpcStatus
                                    )
                                }}</el-tag>
                            </template>
                        </el-table-column>
                        <el-table-column label="操作" width="200">
                            <template #default="{ row }">
                                <el-button
                                    link
                                    type="primary"
                                    @click="handleShow(row, true)"
                                    >查看</el-button
                                >
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <div class="flex end mt-8">
                    <el-pagination
                        @size-change="getDones"
                        @current-change="getDones"
                        :page-sizes="[10, 20, 50]"
                        v-model:page-size="donePage.size"
                        v-model:current-page="donePage.current"
                        layout="total, sizes, prev, pager, next"
                        :total="donePage.total"
                    >
                    </el-pagination>
                </div>
            </el-tab-pane>
        </el-tabs>
      说明：我的抚慰，用于展示当前需本人待办的抚慰申请；同时可在此界面申请提交抚慰。
    </div>

    <el-dialog
        title="申请抚慰"
        v-model="show"
        width="60vw"
        top="2vh"
        style="margin-bottom: 0"
    >
        <el-scrollbar height="calc(96vh - 130px)">
            <el-form
                :label-width="140"
                ref="formRef"
                :model="formData"
                v-if="step === 0"
            >
                <h5>办理信息</h5>
                <el-row>
                    <el-col :span="12">
                        <el-form-item
                            label="申请时间"
                            :rules="{
                                required: true,
                                trigger: ['blur'],
                            }"
                            prop=""
                        >
                            <el-date-picker
                                v-model="formData.applyDate"
                                type="date"
                                placeholder="请选择"
                                value-format="YYYY-MM-DD"
                                style="width: 300px"
                                :disabled-date="disabledDate"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="主办单位"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                            prop="handleDepartId"
                        >
                            <div style="width: 300px">
                                <el-tree-select
                                    v-model="formData.handleDepartId"
                                    :data="departs"
                                    :props="{ label: 'shortName', value: 'id' }"
                                    node-key="id"
                                    :default-expanded-keys="['12630']"
                                    clearable
                                    filterable
                                    @node-click="
                                        (node) =>
                                            (formData.handleDepartName =
                                                node.shortName)
                                    "
                                />
                            </div>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-divider />
                <el-row>
                    <el-col :span="12">
                        <el-form-item
                            label="是否为本人申请"
                            :rules="{
                                required: true,
                                trigger: ['blur'],
                            }"
                            prop=""
                        >
                            <el-radio-group
                                v-model="formData.isSelf"
                                @change="handleSelectIsSelf"
                            >
                                <el-radio value="1">是</el-radio>
                                <el-radio value="0">否</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="formData.isSelf === 0">
                        <el-form-item
                            label="关系"
                            :rules="{
                                required: true,
                                trigger: ['blur'],
                                message: '请选择',
                            }"
                            prop="relation"
                        >
                            <el-radio-group v-model="formData.relation">
                                <el-radio :value="1">同事</el-radio>
                                <el-radio :value="2">亲属</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12" v-if="formData.isSelf === '0'">
                        <el-form-item
                            label="代理人姓名"
                            :rules="{
                                required: true,
                                message: '请输入代理人姓名',
                            }"
                            prop="agentName"
                        >
                            <el-input
                                style="width: 300px"
                                v-model="formData.agentName"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <h5>申请人信息</h5>
                <el-row>
                    <el-col :span="12">
                        <el-form-item
                            label="申请人姓名"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                            prop="applicantEmpName"
                        >
                            <el-autocomplete
                                v-model="formData.applicantEmpName"
                                :fetch-suggestions="querySearch"
                                :trigger-on-focus="false"
                                value-key="name"
                                clearable
                                placeholder="请输入姓名搜索"
                                @select="handleSelect"
                                style="width: 300px"
                            >
                                <template #default="{ item }">
                                    <span class="mr-10">{{ item.name }}</span>
                                    <span class="text-primary">{{
                                        item.empNo
                                    }}</span>
                                    <span class="text-primary">
                                       &nbsp; {{item.parentDepartShortName}}  &nbsp; {{item.departShortName}}
                                    </span>
                                </template>
                            </el-autocomplete>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="性别"
                            :rules="{
                                required: true,
                                message: '请选择性别',
                            }"
                            prop="sex"
                        >
                            <el-radio-group v-model="formData.sex">
                                <el-radio :value="0">男</el-radio>
                                <el-radio :value="1">女</el-radio>
                            </el-radio-group>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="出生年月"
                            :rules="{
                                required: true,
                                message: '请选择出生年月',
                            }"
                            prop="birthday"
                        >
                            <el-date-picker
                                v-model="formData.birthday"
                                type="date"
                                placeholder="请选择"
                                value-format="YYYY-MM-DD"
                                style="width: 300px"
                            />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item
                            label="身份证号码"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                            prop="idCode"
                        >
                            <el-input
                                v-model="formData.idCode"
                                clearable
                                style="width: 300px"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item
                            label="单位"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                            prop="departId"
                        >
                            <div style="width: 300px">
                                <depart-tree-select
                                    v-model="formData.departId"
                                    :check-strictly="true"
                                    @node-click="
                                        (node) =>
                                            (formData.departName =
                                                node.shortName)
                                    "
                                />
                            </div>
                        </el-form-item>
                    </el-col>

                    <el-col :span="12">
                        <el-form-item
                            label="警号"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                            prop="empNo"
                        >
                            <el-input
                                v-model="formData.empNo"
                                style="width: 300px"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="职务" prop="job">
                            <el-input
                                v-model="formData.job"
                                style="width: 300px"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="警衔" prop="policeRank">
                            <el-input
                                v-model="formData.policeRank"
                                style="width: 300px"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="文化程度"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                            prop="levelEducation"
                        >
                            <el-select
                                clearable
                                style="width: 300px"
                                v-model="formData.levelEducation"
                            >
                                <el-option value="高中">高中</el-option>
                                <el-option value="大专">大专</el-option>
                                <el-option value="本科">本科</el-option>
                                <el-option value="研究生及以上"
                                    >研究生及以上</el-option
                                >
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="政治面貌"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                            prop="politicCountenance"
                        >
                            <el-select
                                clearable
                                style="width: 300px"
                                v-model="formData.politicCountenance"
                            >
                                <el-option value="群众">群众</el-option>
                                <el-option value="团员">团员</el-option>
                                <el-option value="预备党员">预备党员</el-option>
                                <el-option value="党员">党员</el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item-ext
                            label="联系电话"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                            prop="mobile"
                            content="银行预留电话"
                        >
                            <el-input
                                v-model="formData.mobile"
                                style="width: 300px"
                                placeholder="请输入银行预留电话"
                            />
                        </el-form-item-ext>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="开户行"
                            prop="bankCard"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                        >
                            <el-select
                                v-model="formData.bankCard"
                                clearable
                                style="width: 300px"
                            >
                                <el-option
                                    v-for="item in dict.bank"
                                    :key="item.id"
                                    :label="item.dictLabel"
                                    :value="item.dictValue"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="所属支行"
                            prop="bankBranch"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                        >
                            <el-input
                                v-model="formData.bankBranch"
                                style="width: 300px"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="银行账号"
                            prop="bankCardAccount"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                        >
                            <el-input
                                v-model="formData.bankCardAccount"
                                style="width: 300px"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-divider />
                <h5>案发情况</h5>
                <el-row>
                    <el-col :span="12">
                        <el-form-item
                            label="事发时间"
                            prop="happenTime"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                        >
                            <el-date-picker
                                v-model="formData.happenTime"
                                type="datetime"
                                placeholder="请选择"
                                value-format="YYYY-MM-DD HH:mm"
                                time-format="HH:mm"
                                style="width: 300px"
                                :disabled-date="disabledDate"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item
                            label="事实及理由"
                            prop="factReason"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                        >
                            <el-input
                                v-model="formData.factReason"
                                type="textarea"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="案发环节"
                            prop="incidentLink"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                        >
                            <el-select
                                v-model="formData.incidentLink"
                                style="width: 300px"
                                clearable
                                @change="
                                    (val) =>
                                        (formData.incidentLinkName =
                                            dict.incidentLink.find(
                                                (item) => item.dictValue === val
                                            )?.dictLabel)
                                "
                            >
                                <el-option
                                    v-for="item in dict.incidentLink"
                                    :key="item.id"
                                    :label="item.dictLabel"
                                    :value="item.dictValue"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="受伤程度"
                            prop="injurySeverity"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                        >
                            <el-select
                                v-model="formData.injurySeverity"
                                style="width: 300px"
                                clearable
                                @change="
                                    (val) =>
                                        (formData.injurySeverityName =
                                            dict.injurySeverity.find(
                                                (item) => item.dictValue === val
                                            )?.dictLabel)
                                "
                            >
                                <el-option
                                    v-for="item in dict.injurySeverity"
                                    :key="item.id"
                                    :label="item.dictLabel"
                                    :value="item.dictValue"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="侵权形式"
                            prop="formsOfTort"
                            :rules="{
                                required: true,
                                message: '请选择',
                            }"
                        >
                            <el-select
                                v-model="formData.formsOfTort"
                                style="width: 300px"
                                clearable
                                @change="
                                    (val) =>
                                        (formData.formsOfTortName =
                                            dict.formsOfTort.find(
                                                (item) => item.dictValue === val
                                            )?.dictLabel)
                                "
                            >
                                <el-option
                                    v-for="item in dict.formsOfTort"
                                    :key="item.id"
                                    :label="item.dictLabel"
                                    :value="item.dictValue"
                                />
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="侵权人姓名"
                            prop="infringerName"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                        >
                            <el-input
                                v-model="formData.infringerName"
                                style="width: 300px"
                                placeholder="请输入"
                            />
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item
                            label="处理方式"
                            prop="infringerHandle"
                            :rules="{
                                required: true,
                                message: '请输入',
                            }"
                        >
<!--                            <el-input-->
<!--                                v-model="formData.infringerHandle"-->
<!--                                style="width: 300px"-->
<!--                                placeholder="请输入"-->
<!--                            />-->
                            <el-select style="width: 300px"  v-model="formData.infringerHandle" clearable>
                              <el-option v-for="(item,index) in infringerHandleDict" :key="index" :value="item" :label="item"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                </el-row>
                <div style="margin-left: 100px;">备注：经济抚慰 精神伤害1000元、一般性损伤2000元、轻微伤3000元、轻伤5000元、重伤10000元填报，并出具伤情法医鉴定书及其它相关材料。</div>
                <el-divider />
                <h5>佐证材料</h5>
                <el-form-item label="附件" prop="documentFile">
                    <file-upload
                        v-model:files="formData.documentFile"
                    >
                        <template #tips>
                            <div>
                                <a class="link" :href="`${BASE_PATH}/templates/5、民警维权抚慰申请表.doc`" target="__blank">1、抚慰申请表</a>(盖章)
                                2、事情经过(盖章)。3、受伤照片。4、伤情鉴定。5、受立案登记表。6、其他</div>
                        </template>
                    </file-upload>
                </el-form-item>
                <el-divider />
                <h5>呈报审批</h5>
                <el-row>
                    <el-col :span="12">
                        <el-form-item
                            label="审批人"
                            :rules="{
                                required: true,
                                message:
                                    '未选择主办单位或当前主办单位的未配置维权专干(请联系系统管理员)',
                            }"
                            prop="approverEmpNo"
                        >
                            <el-input disabled v-model="formData.approver" />
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                  审批人为主办单位的维权专干，若无审批人员请联系市局专班新增。
                </el-row>
            </el-form>
            <div v-else style="height: 60vh" class="flex center">
                <el-result
                    icon="success"
                    title="申请成功"
                    sub-title="请在我的已办查看进度"
                >
                </el-result>
            </div>
        </el-scrollbar>
        <footer class="flex end" v-if="step === 0">
            <el-button @click="show = false" size="large">取消</el-button>
            <el-button
                type="primary"
                @click="submit"
                size="large"
                :disabled="btDisabled"
                >确定</el-button
            >
        </footer>
    </el-dialog>

    <comfort-dialog
        v-model:show="actionShow"
        :id="activeRpcId"
        :disabled="dialogDisabled"
        @update="search()"
    />
</template>
<script setup>
import { BASE_PATH } from "@/api/request";
import moment from "moment";
import {
    listComfortTodos,
    listDone,
    applyComfort,
    updateComfort,
    delComfort,
    getDetail,
} from "@/api/rightsComfort/comfort";
import { listPolice } from "@/api/system/police";
import { listRightPersonByDepartId } from "@/api/system/rightPerson";
import { secondList } from "@/api/system/depart";

import { getDictLable, getGenderFromIdCode,extractInfoFromID } from "@/utils/util";
import feedback from "@/utils/feedback";

import useCatchStore from "@/stores/modules/catch";
import useUserStore from "@/stores/modules/user";

const catchStore = useCatchStore();
const dict = catchStore.getDicts([
    "formsOfTort",
    "injurySeverity",
    "incidentLink",
    "comfortStatus",
    "bank",
]);
const infringerHandleDict = ref([
  "刑事追究","立案侦查","行政处罚","其他"
])
const query = ref({});

const todos = ref([]);
const todoPage = reactive({
    total: 0,
    current: 1,
    size: 10,
});

const dones = ref([]);
const donePage = reactive({
    total: 0,
    current: 1,
    size: 10,
});

function getTodos() {
    const queryParam = { ...query.value };
    queryParam.current = todoPage.current;
    queryParam.size = todoPage.size;
    listComfortTodos(queryParam).then((data) => {
        todos.value = data.records;
        todoPage.total = data.total;
    });
}

function getDones() {
    const queryParam = { ...query.value };
    queryParam.current = donePage.current;
    queryParam.size = donePage.size;
    listDone(queryParam).then((data) => {
        dones.value = data.records;
        donePage.total = data.total;
    });
}

function reset() {
    query.value = {
        current: 1,
        size: 10,
    };
    getTodos();
    getDones();
}
console.log('dict.bank',dict.bank)
function search() {
    getTodos();
    getDones();
}

const departs = ref([]);
onMounted(() => {
    getTodos();
    getDones();
    secondList().then((data) => {
        departs.value = data;
    });
});

const show = ref(false);
const formData = ref({
    bankCard:'长沙银行',
    applyDate: moment().format("YYYY-MM-DD"),
});
const formRef = ref(null);

const btDisabled = ref(false);
const step = ref(0);
async function submit() {
    try {
        await formRef.value.validate();
    } catch (e) {
        feedback.msgWarning("请检查输入项");
        return;
    }
    btDisabled.value = true;
    if (mode.value === "add") {
        await applyComfort(formData.value);
    } else {
        updateComfort(formData.value);
        getTodos();
    }
    step.value = 1;
    show.value = false;
    formData.value = {
        applyDate: moment().format("YYYY-MM-DD"),
    };
    getDones();
    btDisabled.value = false;
    formRef.value.resetFields();
}

const mode = ref("add");
function handleShowAdd() {
    step.value = 0;
    mode.value = "add";
    show.value = true;
}

async function handleReSubmit(row) {
    const data = await getDetail(row.rpcId);
    formData.value = {
        rpcId: data.apply.rpcId,
        applyDate: data.apply.applyDate,
        happenTime: data.apply.happenTime,
        applicantEmpName: data.apply.applicantEmpName,
        handleDepartId: data.apply.handleDepartId,
        handleDepartName: data.apply.handleDepartName,
        isSelf: data.apply.isSelf,
        relation: data.apply.relation,
        agentName: data.apply.agentName,
        departId: data.apply.departId,
        departName: data.apply.departName,
        happenTime: data.apply.happenTime,

        factReason: data.apply.factReason,
        incidentLink: data.apply.incidentLink,
        incidentLinkName: data.apply.incidentLinkName,

        formsOfTort: data.apply.formsOfTort,
        formsOfTortName: data.apply.formsOfTortName,
        infringerName: data.apply.infringerName,
        infringerHandle: data.apply.infringerHandle,
        documentFile: data.apply.documentFile
            ? JSON.parse(data.apply.documentFile)
            : [],

        sex: data.person.sex,
        birthday: data.person.birthday,
        idCode: data.person.idCode,
        empNo: data.person.empNo,
        job: data.person.job,
        policeRank: data.person.policeRank,
        politicCountenance: data.person.politicCountenance,
        mobile: data.person.mobile,
        bankCard: data.person.bankCard,
        bankBranch: data.person.bankBranch,
        bankCardAccount: data.person.bankCardAccount,
        levelEducation: data.person.levelEducation,
        injurySeverity: data.applyPerson.injurySeverity,
        injurySeverityName: data.applyPerson.injurySeverityName,
    };
    mode.value = "edit";
    show.value = true;
}

async function querySearch(queryString, cb) {
    if (!queryString) {
        cb([]);
    }
    const data = await listPolice({
        size: 20,
        current: 1,
        name: queryString,
    });
    cb(data.records);
}

function handleSelect(item) {
    formData.value.empNo = item.empNo;
    formData.value.idCode = item.idCode;
    formData.value.mobile = item.mobile;
    formData.value.departId=item.orgId;
    if(formData.value?.idCode){
      console.log('formData.value.idCode,',formData.value.idCode )
      let res=  extractInfoFromID('430902199509098737');
      console.log('res',res)
      // formData.value.sex=gender;
      // formData.value.birthday = birthDate;
    }
}

watch(
    () => formData.value.handleDepartId,
    (val) => {
        listRightPersonByDepartId(val).then((data) => {
            if (data.length) {
                formData.value.approverEmpNo = data.map((item) => item.empNo);
                formData.value.approver = data
                    .map((item) => item.empName)
                    .join("、");
            } else {
                delete formData.value.approverEmpNo;
                delete formData.value.approver;
            }
        });
    }
);

const actionShow = ref(false);
const activeRpcId = ref(false);
const dialogDisabled = ref(true);
function handleShow(row, disabled) {
    actionShow.value = true;
    activeRpcId.value = row.rpcId;
    dialogDisabled.value = disabled;
}

const handleDelete = async (row) => {
    await feedback.confirm(`确定要删除 ${row.number}？`);
    await delComfort(row.rpcId);
    feedback.msgSuccess("删除成功");
    getTodos();
};

const userStore = useUserStore();
function handleSelectIsSelf() {
    if (formData.value.isSelf === "1") {
        formData.value.applicantEmpName = userStore.user.nickName;
        formData.value.idCode = userStore.user.userName;
        formData.value.empNo = userStore.user.empNo;
        formData.value.mobile = userStore.user.mobile;
        formData.value.departId = userStore.user.departId;
        const sex = getGenderFromIdCode(formData.value.idCode);
        if (sex) {
            formData.value.sex = sex === "男" ? 0 : 1;
        }
        if (formData.value.idCode && formData.value.idCode.length === 18) {
            formData.value.birthday = moment(
                formData.value.idCode.substring(6, 14),
                "YYYYMMDD"
            ).format("YYYY-MM-DD");
        }
    }
}

const resultShow = ref(true);
</script>
<style lang="scss" scoped>
h5 {
    margin: 10px 0;
}
</style>
