<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="communityCode">
        <el-input
          v-model="queryParams.communityCode"
          placeholder="请输入居住小区编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="所属区域编码" prop="areaCode">
        <el-input
          v-model="queryParams.areaCode"
          placeholder="请输入所属区域编码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户编号" prop="patientCode">
        <el-input
          v-model="queryParams.patientCode"
          placeholder="请输入用户编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
       <el-form-item label="所属区域" prop="areaCode">
        <el-select
          v-model="value"
          clearable
          placeholder="请选择省"
        
        >
          <el-option
            v-for="item in arealist"
            :key="item.id"
            :label="item.areaName"
            :value="item.id"
            @click.native="province(item)"
          >
          </el-option>
        </el-select>
        <el-select
            v-model="value1"
            clearable
            placeholder="请选择市"
            style="margin-left: 10px"
          
          >
            <el-option
              v-for="item in citylist"
              :key="item.areaCode"
              :label="item.areaName"
              :value="item.areaCode"
              @click.native="clickcity(item)"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="value2"
            clearable
            placeholder="请选择区"
           style="margin-left: 10px"
           
          >
            <el-option
              v-for="item in arealists"
              :key="item.areaCode"
              :label="item.areaName"
              :value="item.areaCode"
              @click.native="clickarea(item)"
            >
            </el-option>
          </el-select>
          <el-select
            v-model="value3"
            clearable
            placeholder="请选择街道"
            style="margin-left: 10px"
           
          >
            <el-option
              v-for="item in streetlist"
              :key="item.areaCode"
              :label="item.areaName"
              :value="item.areaCode"
              @click.native="clickstreet(item)"
            >
            </el-option>
          </el-select>
        
      </el-form-item>
      
      <!-- <el-form-item label="身份证号" prop="cardNo">
        <el-input
          v-model="queryParams.cardNo"
          placeholder="请输入身份证号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="sys_user表id" prop="userId">
        <el-input
          v-model="queryParams.userId"
          placeholder="请输入sys_user表id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户微信unionid" prop="unionid">
        <el-input
          v-model="queryParams.unionid"
          placeholder="请输入用户微信unionid"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户微信openid" prop="openid">
        <el-input
          v-model="queryParams.openid"
          placeholder="请输入用户微信openid"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="手机号码" prop="phone">
        <el-input
          v-model="queryParams.phone"
          placeholder="请输入手机号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="居住小区" prop="communityAliasName">
        <el-input
          v-model="queryParams.communityAliasName"
          placeholder="请输入居住小区"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="姓名" prop="patientName">
        <el-input
          v-model="queryParams.patientName"
          placeholder="请输入姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="紧急联系人名称" prop="urgentContactName">
        <el-input
          v-model="queryParams.urgentContactName"
          placeholder="请输入紧急联系人名称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="紧急联系人电话" prop="urgentContactPhone">
        <el-input
          v-model="queryParams.urgentContactPhone"
          placeholder="请输入紧急联系人电话"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="住址经度" prop="homeLongitude">
        <el-input
          v-model="queryParams.homeLongitude"
          placeholder="请输入住址经度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="住址纬度" prop="homeLatitude">
        <el-input
          v-model="queryParams.homeLatitude"
          placeholder="请输入住址纬度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="个人头像地址" prop="headPictureUrl">
        <el-input
          v-model="queryParams.headPictureUrl"
          placeholder="请输入个人头像地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </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:patientArchives: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:patientArchives: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:patientArchives:remove']"
        >删除</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:patientArchives:export']"
        >导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="patientArchivesList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="姓名" align="center" prop="patientName" />
      <el-table-column label="所属区域" align="center" prop="areaName" />
        <el-table-column label="居住小区" align="center" prop="communityAliasName" />
         <el-table-column label="身份证号" align="center" prop="cardNo" />
          <el-table-column label="联系电话" align="center" prop="phone" />
          <el-table-column label="居住地址" align="center" prop="address" />
            <el-table-column label="创建人" align="center" prop="createBy" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
communityAliasName
      <!-- <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="居住小区编码" align="center" prop="communityCode" />
      <el-table-column label="所属区域编码" align="center" prop="areaCode" />
      <el-table-column label="用户编号" align="center" prop="patientCode" />
      <el-table-column label="用户姓名" align="center" prop="patientName" />
     
      <el-table-column label="sys_user表id" align="center" prop="userId" />
      <el-table-column label="用户微信unionid" align="center" prop="unionid" />
      <el-table-column label="用户微信openid" align="center" prop="openid" />
      <el-table-column label="手机号码" align="center" prop="phone" />
    
      <el-table-column label="紧急联系人名称" align="center" prop="urgentContactName" />
      <el-table-column label="紧急联系人电话" align="center" prop="urgentContactPhone" />
      <el-table-column label="住址经度" align="center" prop="homeLongitude" />
      <el-table-column label="住址纬度" align="center" prop="homeLatitude" />
      <el-table-column label="个人头像地址" align="center" prop="headPictureUrl" /> -->
      <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:patientArchives:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:patientArchives: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="1018px" append-to-body >
      <el-form ref="form" :model="form" :rules="rules" label-width="110px" :inline="true">
         <el-form-item label="姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入姓名"  :disabled="true"/>
        </el-form-item>
         <el-form-item label="所属区域" prop="areaName">
          <el-input v-model="form.areaName" placeholder="请输入所属区域" :disabled="true"/>
        </el-form-item>
         <el-form-item label="居住小区" prop="communityAliasName">
          <el-input v-model="form.communityAliasName" placeholder="请输入居住小区" maxlength="100"/>
        </el-form-item>
         <el-form-item label="客户编号" prop="patientCode">
          <el-input v-model="form.patientCode" placeholder="请输入客户编号" />
        </el-form-item>
         <el-form-item label="客户姓名" prop="patientName">
          <el-input v-model="form.patientName" placeholder="请输入客户姓名" maxlength="20"/>
        </el-form-item>
         <el-form-item label="身份证号" prop="cardNo">
          <el-input v-model="form.cardNo" placeholder="请输入身份证号" maxlength="18"/>
        </el-form-item>
         <el-form-item label="联系电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" maxlength="11"/>
        </el-form-item>
         <el-form-item label="居住地址" prop="address">
          <el-input v-model="form.address" placeholder="请输入居住地址" maxlength="100"/>
        </el-form-item>
         <el-form-item label="紧急联系人" prop="urgentContactName">
          <el-input v-model="form.urgentContactName" placeholder="请输入紧急联系人名称" maxlength="20"/>
        </el-form-item>
        <el-form-item label="紧急联系电话" prop="urgentContactPhone" label-width="80">
          <el-input v-model="form.urgentContactPhone" placeholder="请输入紧急联系人电话" maxlength="11"/>
        </el-form-item>
        <el-form-item label="居住住址经度" prop="homeLongitude">
          <el-input v-model="form.homeLongitude" placeholder="请输入住址经度" maxlength="20"/>
        </el-form-item>
        <el-form-item label="居住住址纬度" prop="homeLatitude">
          <el-input v-model="form.homeLatitude" placeholder="请输入住址纬度" maxlength="11"/>
        </el-form-item>
        <el-form-item label="头像" prop="headPictureUrl">
          <!-- <img src="/profile/avatar/2022/09/08/1662624067718_20220908160250A001.jpg" alt=""> -->
          <img :src="baseUrl + form.headPictureUrl" style="width: 500px;height: 400px">
          <img slot="reference" :src="baseUrl + form.headPictureUrl" style="width: 200px;height: 150px">

          <!-- <el-input v-model="form.headPictureUrl" placeholder="请输入个人头像地址" /> -->
        </el-form-item> 
      </el-form>
        <!-- <el-form-item label="居住小区编码" prop="communityCode">
          <el-input v-model="form.communityCode" placeholder="请输入居住小区编码" />
        </el-form-item>
        <el-form-item label="所属区域编码" prop="areaCode">
          <el-input v-model="form.areaCode" placeholder="请输入所属区域编码" />
        </el-form-item>
        <el-form-item label="用户编号" prop="patientCode">
          <el-input v-model="form.patientCode" placeholder="请输入用户编号" />
        </el-form-item>
       
       
        <el-form-item label="sys_user表id" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入sys_user表id" />
        </el-form-item>
        <el-form-item label="用户微信unionid" prop="unionid">
          <el-input v-model="form.unionid" placeholder="请输入用户微信unionid" />
        </el-form-item>
        <el-form-item label="用户微信openid" prop="openid">
          <el-input v-model="form.openid" placeholder="请输入用户微信openid" />
        </el-form-item>
        <el-form-item label="手机号码" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入手机号码" />
        </el-form-item>
       
        <el-form-item label="紧急联系人名称" prop="urgentContactName">
          <el-input v-model="form.urgentContactName" placeholder="请输入紧急联系人名称" />
        </el-form-item>
        <el-form-item label="紧急联系人电话" prop="urgentContactPhone">
          <el-input v-model="form.urgentContactPhone" placeholder="请输入紧急联系人电话" />
        </el-form-item>-->
    
      <div slot="footer" class="dialog-footer" style="margin-right:40%">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listPatientArchives, getPatientArchives, delPatientArchives, addPatientArchives, updatePatientArchives,FirstLevel,SecondaryLevelInfo} from "@/api/system/patientArchives";

export default {
  name: "PatientArchives",
  data() {
    return {
      baseUrl:"http://192.168.16.85:8080",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      total2:0,
      total3:0,
      value3: "",
      value2: "",
      value1: "",
      value: "",
      // 被护理人基本信息表格数据
      patientArchivesList: [],
      // 所属区域
      arealist:[],
      // 查询市
      SecondaryLevelInfolist:[],

      citylist: [],
      arealists:[],
      streetlist:[],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        communityCode: null,
        areaCode: null,
        patientCode: null,
        patientName: null,
        cardNo: null,
        userId: null,
        unionid: null,
        openid: null,
        phone: null,
        address: null,
        urgentContactName: null,
        urgentContactPhone: null,
        homeLongitude: null,
        homeLatitude: null,
        headPictureUrl: null,
      },
      getProvincequeryParams: {
        pageNum: 1,
        pageSize: 10,
      },
       SecondaryLevelInfoqueryParams: {
        pageNum: 1,
        pageSize: 10,
        id:null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        patientName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        areaName: [
          { required: true, message: "所属区域不能为空", trigger: "blur" }
        ],
         communityAliasName: [
          { required: true, message: "居住不能为空", trigger: "blur" }
        ],
         patientCode: [
          { required: true, message: "客户编号不能为空", trigger: "blur" }
        ],
         urgentContactName: [
          { required: true, message: "客户姓名不能为空", trigger: "blur" }
        ],
         cardNo: [
          { required: true, message: "身份证号不能为空", trigger: "blur" }
        ],
        phone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" }
        ],
          address: [
          { required: true, message: "居住地址不能为空", trigger: "blur" }
        ],
         urgentContactName: [
          { required: true, message: "紧急联系人不能为空", trigger: "blur" }
        ],
         urgentContactPhone: [
          { required: true, message: "紧急联系电话不能为空", trigger: "blur" }
        ],
         homeLongitude: [
          { required: true, message: "居住地址经度不能为空", trigger: "blur" }
        ],
        homeLatitude: [
          { required: true, message: "居住地址维度不能为空", trigger: "blur" }
        ],
        headPictureUrl: [
          { required: true, message: "头像不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
    this.Provincelist();
    // this.areas();
  },
  methods: {
    // 查询省事件
    province(item){
      console.log(item)
      this.value1 = "";
       this.value2 = "";
      this.value3 = "";
      SecondaryLevelInfo(item.id).then((res) => {
        console.log(res);
        this.SecondaryLevelInfolist = res.data;
        // console.log(this.SecondaryLevelInfolist);
        this.citylist = res.data;
      });
    },
    // 点击市
     clickcity(item) {
      this.value2 = "";
      this.value3 = "";
      console.log(item);
      SecondaryLevelInfo(item.id).then((res) => {
        console.log(res);
        this.arealists = res.data;
      });
    },
 //点击区县城
    clickarea(item) {
      this.value3 = "";
      console.log(item);
      SecondaryLevelInfo(item.id).then((res) => {
        console.log(res);
        this.streetlist = res.data;
      });
    },
     //点击街道
    clickstreet(item) {
      this.form.areaCode = item.areaCode;
      console.log(this.form);
    },
    // 所属省下拉框
        loadMore() {
      console.log("1");
      var a = Math.ceil(this.total2 / 10);
      console.log(this.arealist.length);
      if (this.arealist.length + 1 >= this.total2) {
      } else {
        if (this.getProvincequeryParams.pageNum >= a) {
        } else {
          this.getProvincequeryParams.pageNum++;
          FirstLevel(this.getProvincequeryParams).then((res) => {
            console.log(res);
            res.rows.forEach((e) => {
              this.arealist.push(e);
              console.log(this.arealist)
            });
          });
        }
      }
    },
      Provincelist() {
      FirstLevel(this.getProvincequeryParams).then((res) => {
        console.log(res);
        this.arealist = res.data;
        this.total2 = res.total;
        console.log(this.arealist);
      });
    },
    /** 查询被护理人基本信息列表 */
    getList() {
      this.loading = true;
      listPatientArchives(this.queryParams).then(response => {
        this.patientArchivesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        communityCode: null,
        areaCode: null,
        patientCode: null,
        patientName: null,
        cardNo: null,
        userId: null,
        unionid: null,
        openid: null,
        phone: null,
        address: null,
        urgentContactName: null,
        urgentContactPhone: null,
        homeLongitude: null,
        homeLatitude: null,
        headPictureUrl: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    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 = "添加被护理人基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPatientArchives(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改被护理人基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updatePatientArchives(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPatientArchives(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 delPatientArchives(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/patientArchives/export', {
        ...this.queryParams
      }, `patientArchives_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
