<template>
  <div class="app-container">
    <div style="background-color: #fff;padding: 20px;border-radius: 10px;">
      <p style="margin: 0; font-weight: 800;font-size: 16px;color: #343434;display: flex;align-items: center;margin-bottom: 20px;">
        <img src="../../../assets/images/icon_htgl_btzs.png" alt="" style="width: 16px;height: 20px;">
       <span style="margin-left: 10px;">来访管理</span>
      </p>
      <div style="background: #F3F3F3;padding: 20px 15px; padding-bottom: 0;margin-bottom: 20px;">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-row>
        <el-col :span="8">
          <el-form-item label="门牌号码" prop="houseAddress">
            <el-select v-model="queryParams.houseAddress" placeholder="请选择门牌号" >
              <el-option
               @click.native="itneg(dict)"
                v-for="dict in houseInfoLise"
                :key="dict.houseId"
                :label="dict.detailedAddress"
                :value="dict.houseId"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="访客姓名" prop="name">
            <el-input
            style="width: 238px;"
              v-model="queryParams.name"
              placeholder="请输入访客姓名"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="手机号码" prop="mobileNumber">
            <el-input
              v-model="queryParams.mobileNumber"
              placeholder="请输入手机号码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="是否驾车" prop="isCar">
            <el-select v-model="queryParams.isCar" placeholder="请选择是否驾车" clearable>
              <el-option
                v-for="dict in dict.type.sys_yes_no"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="车牌号码" prop="plateNumber">
            <el-input
            style="width: 238px;"
              v-model="queryParams.plateNumber"
              placeholder="请输入车牌号码"
              clearable
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="8">
          <el-form-item label="状态" prop="status">
            <el-select v-model="queryParams.status" placeholder="请选择状态" clearable>
              <el-option
                v-for="dict in dict.type.visitor_status"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"
              />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-form-item class="butt">
        <el-button type="primary"  size="mini" @click="handleQuery">搜索</el-button>
        <el-button  size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    </div>

     <div class="casr">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="handleAdd"
          v-hasPermi="['wuYe:visitorManage:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['wuYe:visitorManage:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['wuYe:visitorManage:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          size="mini"
          @click="handleExport"
          v-hasPermi="['wuYe:visitorManage:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :max-height="tableMaxHeight" v-loading="loading" :data="visitorManageList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="门牌号" align="center" prop="houseAddress" />
      <el-table-column label="访客姓名" align="center" prop="name" />
      <el-table-column label="来访人数" align="center" prop="num" />
      <el-table-column label="来访事由" align="center" prop="reason" width="100" show-overflow-tooltip/>
      <el-table-column label="手机号码" align="center" prop="mobileNumber" width="120" />
      <el-table-column label="是否驾车" align="center" prop="isCar">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_yes_no" :value="scope.row.isCar"/>
        </template>
      </el-table-column>
      <el-table-column label="车牌号码" align="center" prop="plateNumber" />
      <el-table-column label="来访时间" align="center" prop="visitorTime" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.visitorTime }}</span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="预约时间" align="center" prop="reserveTime" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.reserveTime}}</span>
        </template>
      </el-table-column> -->
      <el-table-column label="状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.visitor_status" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column width="120" fixed="right" label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            style="color: #28C529;"
            v-hasPermi="['wuYe:visitorManage:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            style="color: red;"
            @click="handleDelete(scope.row)"
            v-hasPermi="['wuYe:visitorManage:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    </div>

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

    <!-- 添加或修改来访管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="门牌号" prop="houseAddress">
               <el-select style="width: 100%;" v-model="form.houseAddress" placeholder="请选择门牌号" clearable>
                 <el-option
                  @click.native="itnegadd(dict)"
                   v-for="dict in houseInfoLise"
                   :key="dict.houseId"
                   :label="dict.detailedAddress"
                   :value="dict.houseId"
                 />
               </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="访客姓名" prop="name">
              <el-input v-model="form.name" placeholder="请输入访客姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="来访人数" prop="num">
              <el-input type="number" v-model="form.num" placeholder="请输入来访人数" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="mobileNumber">
              <el-input v-model="form.mobileNumber" placeholder="请输入手机号码" />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="是否驾车 " prop="isCar">
              <el-radio-group v-model="form.isCar">
                          <el-radio
                            v-for="dict in dict.type.sys_yes_no"
                            :key="dict.value"
                            :label="dict.value"
                          >{{dict.label}}</el-radio>
                        </el-radio-group>
            </el-form-item>
          </el-col>

          <el-col :span="12" v-if="form.isCar == 'Y'" class="ngeshimg">
            <el-form-item label="车牌号码" prop="plateNumber" style="position: relative;">
              <el-input v-model="form.plateNumber" placeholder="请输入车牌号码" />
              <image-uploadshib @uploadedSuccessfully="uploadedSuccessfully" :typeg = "2" :limit="1" v-model="form.photo"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="来访时间" prop="visitorTime">
              <el-date-picker clearable
              style="width:100%"
                v-model="form.visitorTime"
                type="date"
                value-format="yyyy-MM-dd"
                placeholder="请选择来访时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="来访事由" prop="reason">
              <el-input v-model="form.reason" type="textarea" placeholder="请输入内容" />
            </el-form-item>
          </el-col>
        </el-row>
      </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>
  </div>
</template>

<script>
import { listVisitorManage, getVisitorManage, delVisitorManage, addVisitorManage, updateVisitorManage } from "@/api/wuguan/visitorManage";
import { listHouseInfo,listNoPage, getHouseInfo, delHouseInfo, addHouseInfo, updateHouseInfo } from "@/api/wuguan/houseInfo";
export default {
  name: "VisitorManage",
  dicts: ['visitor_status', 'sys_yes_no'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 来访管理表格数据
      visitorManageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        portalId: null,
        houseAddress: null,
        name: null,
        num: null,
        reason: null,
        mobileNumber: null,
        isCar: null,
        plateNumber: null,
        reserveTime: null,
        visitorTime: null,
        status: null,
        photo: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {

        houseAddress: [
          { required: true, message: "详细门牌号不能为空", trigger: "blur" }
        ],
        mobileNumber: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
             trigger: "blur"
            }
        ],
        isCar: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
        name: [
          { required: true, message: "不能为空", trigger: "blur" }
        ],
      },
      houseInfoLise:[],
      systemTime:'',
      tableMaxHeight:'200',
    };
  },
  created() {
    this.getList();
    this.getListhouvr()
    this.gettime()
 window.onresize = () => {
 	      this.changeTableMaxHeight()
 	    }
 	    this.changeTableMaxHeight()
 },
 mounted() {
 	window.onresize = () => {
 	          this.changeTableMaxHeight()
 	        }
 	        this.changeTableMaxHeight()
 },
  methods: {
    /** 查询来访管理列表 */
    getList() {
      this.loading = true;
      listVisitorManage(this.queryParams).then(response => {
        this.visitorManageList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 获取当前时间
    gettime(){
      let nowDate = new Date()
      				  let date = {
      				    year: nowDate.getFullYear(),
      				    month: nowDate.getMonth() + 1,
      				    date: nowDate.getDate()
      				  }

      				   if (parseInt(date.date) < 10) {
      				      date.date = '0' + date.date
      				    }
      				  this.systemTime = date.year + '-' + date.month + '-' + date.date

    },
    getListhouvr() {
       listNoPage().then(response => {
         this.houseInfoLise  = response.rows;
       });
     },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        visitorManageId: null,
        portalId: null,
        houseAddress: null,
        name: null,
        num: null,
        reason: null,
        mobileNumber: null,
        isCar: 'Y',
        plateNumber: null,
        reserveTime: null,
        visitorTime: this.systemTime,
        status: null,
        photo: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: 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.visitorManageId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加来访管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const visitorManageId = row.visitorManageId || this.ids
      getVisitorManage(visitorManageId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改来访管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.visitorManageId != null) {
            updateVisitorManage(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addVisitorManage(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const visitorManageIds = row.visitorManageId || this.ids;
      this.$modal.confirm('是否确认删除来访管理编号为"' + visitorManageIds + '"的数据项？').then(function() {
        return delVisitorManage(visitorManageIds);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('wuYe/visitorManage/export', {
        ...this.queryParams
      }, `visitorManage_${new Date().getTime()}.xlsx`)
    },
    itneg(item){
      // this.queryParams.portalId = item.houseId
      this.queryParams.houseAddress = item.detailedAddress
    },
    itnegadd(item){
      this.form.portalId = item.houseId
      this.form.houseAddress = item.detailedAddress
      console.log(item)
    },
    // 获取屏幕高度
    showFilterForm () {
          this.filterActive = !this.filterActive
          this.changeTableMaxHeight()
        },

        changeTableMaxHeight () {
          let height = document.body.offsetHeight // 网页可视区域高度
          // if (this.filterActive) {
          //   this.tableMaxHeight = height - 320
          // } else {
            this.tableMaxHeight = height - 150
          // }
          console.log(height)
        }
  }
};
</script>
<style  lang="scss">
  .ngeshimg{
    .el-upload--picture-card{
      width: 36px;
      height: 36px;
      line-height: 36px;
      position: absolute;
      top:0;
      right: 0;
    }
    .el-upload--picture-card i{
      font-size: 20px;
    }
    .el-upload-list--picture-card .el-upload-list__item{
      width: 58px;
      height: 36px;
      position: absolute;
      top:0;
      right: -10px;
    }
  }
  .imagwew{
    .el-upload--picture-card{
      width: 80px;
      height: 80px;
      line-height: 80px;
    }
    .el-upload-list--picture-card .el-upload-list__item{
      width: 80px;
      height: 80px;
    }
  }
  .butt{
    .el-button--small{
      padding: 9px 23px !important;
      font-size: 14px;
    }
  }
  .casr{
    .el-tabs__item.is-active{
      color: #196CFF;
    }
    .el-tabs--card > .el-tabs__header .el-tabs__item{
      padding: 0  30px !important;
    }
  }
  .el-table .el-table__header-wrapper th{
    background-color:#F5F6F8;
    color:#343434;
  }
  .el-table{
    color:#343434;
  }
</style>
<style scoped lang="scss">
  .goe{
    p{
      margin: 0;
      font-weight: 800;
      font-size: 16px;
      color: #161616;
      margin-top: 10px;
      margin-bottom: 3px;
      padding: 0 10px;
      overflow: hidden;
      text-overflow: ellipsis;
      display:-webkit-box; //作为弹性伸缩盒子模型显示。
      -webkit-box-orient:vertical; //设置伸缩盒子的子元素排列方式--从上到下垂直排列
      -webkit-line-clamp:1; //显示的行
    }
    p:nth-child(2){
      // margin-bottom: 10px;
      margin-top: 0;
     font-weight: 400;
     font-size: 14px;
     color: #AAAAAA;
     display: flex;
     justify-content: space-between;
     align-items: center;
     padding-bottom: 10px;
     span:nth-child(2){
       padding: 3px 5px;
       background: #EDEDED;
       border-radius: 10px;
     }
    }
  }
  .ingwe{
    border: 2px solid #196CFF;
  }
  </style>
