<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性别" prop="gender">
        <el-input
          v-model="queryParams.gender"
          placeholder="请输入性别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证号" prop="sfzid">
        <el-input
          v-model="queryParams.sfzid"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话1" prop="telOne">
        <el-input
          v-model="queryParams.telOne"
          placeholder="请输入电话1"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话2" prop="telTwo">
        <el-input
          v-model="queryParams.telTwo"
          placeholder="请输入电话2"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="电话3" prop="telThree">
        <el-input
          v-model="queryParams.telThree"
          placeholder="请输入电话3"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="出生年月" prop="birthday">
        <el-input
          v-model="queryParams.birthday"
          placeholder="请输入出生年月"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="年龄" prop="age">
        <el-input
          v-model="queryParams.age"
          placeholder="请输入年龄"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="民族" prop="national">
        <el-input
          v-model="queryParams.national"
          placeholder="请输入民族"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="当地户口" prop="local">
        <el-input
          v-model="queryParams.local"
          placeholder="请输入当地户口"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="家庭地址" prop="familyAddress">
        <el-input
          v-model="queryParams.familyAddress"
          placeholder="请输入家庭地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="详细地址" prop="detailAddress">
        <el-input
          v-model="queryParams.detailAddress"
          placeholder="请输入详细地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户籍地址" prop="houseAddress">
        <el-input
          v-model="queryParams.houseAddress"
          placeholder="请输入户籍地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="户籍详细地址" prop="houseDetailAddress">
        <el-input
          v-model="queryParams.houseDetailAddress"
          placeholder="请输入户籍详细地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属服务机构" prop="serviceid">
        <el-input
          v-model="queryParams.serviceid"
          placeholder="请输入所属服务机构"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="失能月数" prop="loseMonth">
        <el-input
          v-model="queryParams.loseMonth"
          placeholder="请输入失能月数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="治疗月数" prop="treatMonth">
        <el-input
          v-model="queryParams.treatMonth"
          placeholder="请输入治疗月数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="是否通过康复治疗" prop="isTreat">
        <el-input
          v-model="queryParams.isTreat"
          placeholder="请输入是否通过康复治疗"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="医疗保障" prop="treateSure">
        <el-input
          v-model="queryParams.treateSure"
          placeholder="请输入医疗保障"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经济来源" prop="moneyCome">
        <el-input
          v-model="queryParams.moneyCome"
          placeholder="请输入经济来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="月收入" prop="moneyMonth">
        <el-input
          v-model="queryParams.moneyMonth"
          placeholder="请输入月收入"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="社保卡号" prop="cardCode">
        <el-input
          v-model="queryParams.cardCode"
          placeholder="请输入社保卡号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="慢性疾病" prop="slowIllness">
        <el-input
          v-model="queryParams.slowIllness"
          placeholder="请输入慢性疾病"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="残疾登记" prop="disablityEntry">
        <el-input
          v-model="queryParams.disablityEntry"
          placeholder="请输入残疾登记"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="文化程度" prop="educaLevel">
        <el-input
          v-model="queryParams.educaLevel"
          placeholder="请输入文化程度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="专业" prop="special">
        <el-input
          v-model="queryParams.special"
          placeholder="请输入专业"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="职称" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入职称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原单位" prop="unity">
        <el-input
          v-model="queryParams.unity"
          placeholder="请输入原单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="性格心理" prop="natureHeart">
        <el-input
          v-model="queryParams.natureHeart"
          placeholder="请输入性格心理"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="饮食特点" prop="eatPoint">
        <el-input
          v-model="queryParams.eatPoint"
          placeholder="请输入饮食特点"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="特长" prop="speciality">
        <el-input
          v-model="queryParams.speciality"
          placeholder="请输入特长"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="爱好" prop="hobby">
        <el-input
          v-model="queryParams.hobby"
          placeholder="请输入爱好"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="照片" prop="photo">
        <el-input
          v-model="queryParams.photo"
          placeholder="请输入照片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="其他照片" prop="otherPhoto">
        <el-input
          v-model="queryParams.otherPhoto"
          placeholder="请输入其他照片"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remarks">
        <el-input
          v-model="queryParams.remarks"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:profile:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:profile:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:profile:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['system:user:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:profile:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="profileList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="性别" align="center" prop="gender">
      </el-table-column>
      <el-table-column label="身份证号" align="center" prop="sfzid" />
      <el-table-column label="电话1" align="center" prop="telOne" />
      <el-table-column label="电话2" align="center" prop="telTwo" />
      <el-table-column label="电话3" align="center" prop="telThree" />
      <el-table-column label="出生年月" align="center" prop="birthday" />
      <el-table-column label="年龄" align="center" prop="age" />
      <el-table-column label="结婚状态" align="center" prop="marrStatus" />
      <el-table-column label="民族" align="center" prop="national" />
      <el-table-column label="当地户口" align="center" prop="local" />
      <el-table-column label="客户类别" align="center" prop="clientType" />
      <el-table-column label="居住情况" align="center" prop="liveStatus" />
      <el-table-column label="家庭地址" align="center" prop="familyAddress" />
      <el-table-column label="详细地址" align="center" prop="detailAddress" />
      <el-table-column label="户籍地址" align="center" prop="houseAddress" />
      <el-table-column label="户籍详细地址" align="center" prop="houseDetailAddress" />
      <el-table-column label="所属服务机构" align="center" prop="serviceid" />
      <el-table-column label="老人身体特征和状态" align="center" prop="oldmenStatus" />
      <el-table-column label="主要改造内容字段" align="center" prop="changeContent" />
      <el-table-column label="失能月数" align="center" prop="loseMonth" />
      <el-table-column label="治疗月数" align="center" prop="treatMonth" />
      <el-table-column label="是否通过康复治疗" align="center" prop="isTreat" />
      <el-table-column label="服务状态" align="center" prop="serviceType" />
      <el-table-column label="医疗保障" align="center" prop="treateSure" />
      <el-table-column label="经济来源" align="center" prop="moneyCome" />
      <el-table-column label="月收入" align="center" prop="moneyMonth" />
      <el-table-column label="社保卡号" align="center" prop="cardCode" />
      <el-table-column label="慢性疾病" align="center" prop="slowIllness" />
      <el-table-column label="血型" align="center" prop="bloodType" />
      <el-table-column label="失能状态" align="center" prop="shiStatus" />
      <el-table-column label="残疾情况" align="center" prop="disablityStatus" />
      <el-table-column label="残疾登记" align="center" prop="disablityEntry" />
      <el-table-column label="文化程度" align="center" prop="educaLevel" />
      <el-table-column label="专业" align="center" prop="special" />
      <el-table-column label="职称" align="center" prop="title" />
      <el-table-column label="原单位" align="center" prop="unity" />
      <el-table-column label="性格心理" align="center" prop="natureHeart" />
      <el-table-column label="饮食特点" align="center" prop="eatPoint" />
      <el-table-column label="特长" align="center" prop="speciality" />
      <el-table-column label="爱好" align="center" prop="hobby" />
      <el-table-column label="照片" align="center" prop="photo" />
      <el-table-column label="其他照片" align="center" prop="otherPhoto" />
      <el-table-column label="备注" align="center" prop="remarks" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:profile:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:profile:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改用户档案对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="姓名" prop="name">
          <el-input v-model="form.name" placeholder="请输入姓名" />
        </el-form-item>
        <el-form-item label="性别" prop="gender">
          <el-input v-model="form.gender" placeholder="请输入性别" />
        </el-form-item>
        <el-form-item label="身份证号" prop="sfzid">
          <el-input v-model="form.sfzid" placeholder="请输入身份证号" />
        </el-form-item>
        <el-form-item label="电话1" prop="telOne">
          <el-input v-model="form.telOne" placeholder="请输入电话1" />
        </el-form-item>
        <el-form-item label="电话2" prop="telTwo">
          <el-input v-model="form.telTwo" placeholder="请输入电话2" />
        </el-form-item>
        <el-form-item label="电话3" prop="telThree">
          <el-input v-model="form.telThree" placeholder="请输入电话3" />
        </el-form-item>
        <el-form-item label="出生年月" prop="birthday">
          <el-input v-model="form.birthday" placeholder="请输入出生年月" />
        </el-form-item>
        <el-form-item label="年龄" prop="age">
          <el-input v-model="form.age" placeholder="请输入年龄" />
        </el-form-item>
        <el-form-item label="民族" prop="national">
          <el-input v-model="form.national" placeholder="请输入民族" />
        </el-form-item>
        <el-form-item label="当地户口" prop="local">
          <el-input v-model="form.local" placeholder="请输入当地户口" />
        </el-form-item>
        <el-form-item label="家庭地址" prop="familyAddress">
          <el-input v-model="form.familyAddress" placeholder="请输入家庭地址" />
        </el-form-item>
        <el-form-item label="详细地址" prop="detailAddress">
          <el-input v-model="form.detailAddress" placeholder="请输入详细地址" />
        </el-form-item>
        <el-form-item label="户籍地址" prop="houseAddress">
          <el-input v-model="form.houseAddress" placeholder="请输入户籍地址" />
        </el-form-item>
        <el-form-item label="户籍详细地址" prop="houseDetailAddress">
          <el-input v-model="form.houseDetailAddress" placeholder="请输入户籍详细地址" />
        </el-form-item>
        <el-form-item label="所属服务机构" prop="serviceid">
          <el-input v-model="form.serviceid" placeholder="请输入所属服务机构" />
        </el-form-item>
        <el-form-item label="主要改造内容字段">
          <editor v-model="form.changeContent" :min-height="192"/>
        </el-form-item>
        <el-form-item label="失能月数" prop="loseMonth">
          <el-input v-model="form.loseMonth" placeholder="请输入失能月数" />
        </el-form-item>
        <el-form-item label="治疗月数" prop="treatMonth">
          <el-input v-model="form.treatMonth" placeholder="请输入治疗月数" />
        </el-form-item>
        <el-form-item label="是否通过康复治疗" prop="isTreat">
          <el-input v-model="form.isTreat" placeholder="请输入是否通过康复治疗" />
        </el-form-item>
        <el-form-item label="医疗保障" prop="treateSure">
          <el-input v-model="form.treateSure" placeholder="请输入医疗保障" />
        </el-form-item>
        <el-form-item label="经济来源" prop="moneyCome">
          <el-input v-model="form.moneyCome" placeholder="请输入经济来源" />
        </el-form-item>
        <el-form-item label="月收入" prop="moneyMonth">
          <el-input v-model="form.moneyMonth" placeholder="请输入月收入" />
        </el-form-item>
        <el-form-item label="社保卡号" prop="cardCode">
          <el-input v-model="form.cardCode" placeholder="请输入社保卡号" />
        </el-form-item>
        <el-form-item label="慢性疾病" prop="slowIllness">
          <el-input v-model="form.slowIllness" placeholder="请输入慢性疾病" />
        </el-form-item>
        <el-form-item label="残疾登记" prop="disablityEntry">
          <el-input v-model="form.disablityEntry" placeholder="请输入残疾登记" />
        </el-form-item>
        <el-form-item label="文化程度" prop="educaLevel">
          <el-input v-model="form.educaLevel" placeholder="请输入文化程度" />
        </el-form-item>
        <el-form-item label="专业" prop="special">
          <el-input v-model="form.special" placeholder="请输入专业" />
        </el-form-item>
        <el-form-item label="职称" prop="title">
          <el-input v-model="form.title" placeholder="请输入职称" />
        </el-form-item>
        <el-form-item label="原单位" prop="unity">
          <el-input v-model="form.unity" placeholder="请输入原单位" />
        </el-form-item>
        <el-form-item label="性格心理" prop="natureHeart">
          <el-input v-model="form.natureHeart" placeholder="请输入性格心理" />
        </el-form-item>
        <el-form-item label="饮食特点" prop="eatPoint">
          <el-input v-model="form.eatPoint" placeholder="请输入饮食特点" />
        </el-form-item>
        <el-form-item label="特长" prop="speciality">
          <el-input v-model="form.speciality" placeholder="请输入特长" />
        </el-form-item>
        <el-form-item label="爱好" prop="hobby">
          <el-input v-model="form.hobby" placeholder="请输入爱好" />
        </el-form-item>
        <el-form-item label="照片" prop="photo">
          <el-input v-model="form.photo" placeholder="请输入照片" />
        </el-form-item>
        <el-form-item label="其他照片" prop="otherPhoto">
          <el-input v-model="form.otherPhoto" placeholder="请输入其他照片" />
        </el-form-item>
        <el-form-item label="备注" prop="remarks">
          <el-input v-model="form.remarks" placeholder="请输入备注" />
        </el-form-item>
        <el-divider content-position="center">紧急联系人信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddTEmergentPeople">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteTEmergentPeople">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="tEmergentPeopleList" :row-class-name="rowTEmergentPeopleIndex" @selection-change="handleTEmergentPeopleSelectionChange" ref="tEmergentPeople">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="联系人姓名" prop="name" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.name" placeholder="请输入联系人姓名" />
            </template>
          </el-table-column>
          <el-table-column label="电话" prop="telno" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.telno" placeholder="请输入电话" />
            </template>
          </el-table-column>
          <el-table-column label="关系" prop="relation" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.relation" placeholder="请输入关系" />
            </template>
          </el-table-column>
          <el-table-column label="是否接收消息" prop="isConn" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.isConn" placeholder="请输入是否接收消息" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listProfile, getProfile, delProfile, addProfile, updateProfile } from "@/api/system/profile";
import {getToken} from "@/utils/auth";

export default {
  name: "Profile",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedTEmergentPeople: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户档案表格数据
      profileList: [],
      // 紧急联系人表格数据
      tEmergentPeopleList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 用户导入参数
      upload: {
        // 是否显示弹出层（用户导入）
        open: false,
        // 弹出层标题（用户导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/profile/importData"
      },
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        gender: null,
        sfzid: null,
        telOne: null,
        telTwo: null,
        telThree: null,
        birthday: null,
        age: null,
        marrStatus: null,
        national: null,
        local: null,
        clientType: null,
        liveStatus: null,
        familyAddress: null,
        detailAddress: null,
        houseAddress: null,
        houseDetailAddress: null,
        serviceid: null,
        oldmenStatus: null,
        changeContent: null,
        loseMonth: null,
        treatMonth: null,
        isTreat: null,
        serviceType: null,
        treateSure: null,
        moneyCome: null,
        moneyMonth: null,
        cardCode: null,
        slowIllness: null,
        bloodType: null,
        shiStatus: null,
        disablityStatus: null,
        disablityEntry: null,
        educaLevel: null,
        special: null,
        title: null,
        unity: null,
        natureHeart: null,
        eatPoint: null,
        speciality: null,
        hobby: null,
        photo: null,
        otherPhoto: null,
        remarks: null,
        createTime: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询用户档案列表 */
    getList() {
      this.loading = true;
      listProfile(this.queryParams).then(response => {
        this.profileList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        gender: null,
        sfzid: null,
        telOne: null,
        telTwo: null,
        telThree: null,
        birthday: null,
        age: null,
        marrStatus: null,
        national: null,
        local: null,
        clientType: null,
        liveStatus: null,
        familyAddress: null,
        detailAddress: null,
        houseAddress: null,
        houseDetailAddress: null,
        serviceid: null,
        oldmenStatus: null,
        changeContent: null,
        loseMonth: null,
        treatMonth: null,
        isTreat: null,
        serviceType: null,
        treateSure: null,
        moneyCome: null,
        moneyMonth: null,
        cardCode: null,
        slowIllness: null,
        bloodType: null,
        shiStatus: null,
        disablityStatus: null,
        disablityEntry: null,
        educaLevel: null,
        special: null,
        title: null,
        unity: null,
        natureHeart: null,
        eatPoint: null,
        speciality: null,
        hobby: null,
        photo: null,
        otherPhoto: null,
        remarks: null,
        createTime: null
      };
      this.tEmergentPeopleList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加用户档案";
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('system/profile/importTemplate', {
      }, `user_template_${new Date().getTime()}.xlsx`)
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProfile(id).then(response => {
        this.form = response.data;
        this.tEmergentPeopleList = response.data.tEmergentPeopleList;
        this.open = true;
        this.title = "修改用户档案";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.tEmergentPeopleList = this.tEmergentPeopleList;
          if (this.form.id != null) {
            updateProfile(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProfile(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除用户档案编号为"' + ids + '"的数据项？').then(function() {
        return delProfile(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 紧急联系人序号 */
    rowTEmergentPeopleIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 紧急联系人添加按钮操作 */
    handleAddTEmergentPeople() {
      let obj = {};
      obj.name = "";
      obj.telno = "";
      obj.relation = "";
      obj.isConn = "";
      this.tEmergentPeopleList.push(obj);
    },
    /** 紧急联系人删除按钮操作 */
    handleDeleteTEmergentPeople() {
      if (this.checkedTEmergentPeople.length == 0) {
        this.$modal.msgError("请先选择要删除的紧急联系人数据");
      } else {
        const tEmergentPeopleList = this.tEmergentPeopleList;
        const checkedTEmergentPeople = this.checkedTEmergentPeople;
        this.tEmergentPeopleList = tEmergentPeopleList.filter(function(item) {
          return checkedTEmergentPeople.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleTEmergentPeopleSelectionChange(selection) {
      this.checkedTEmergentPeople = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/profile/export', {
        ...this.queryParams
      }, `profile_${new Date().getTime()}.xlsx`)
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    }
  }
};
</script>
