<template>
  <div class="ResidentMainBox p-2 w-full h-full">
    <PageHeader></PageHeader>
    <div class="ResidentMainBody">
      <el-row :span="24" :gutter="20">
        <el-col :span="24">
          <!-- 车位信息 -->
          <div class="mb-10">
            <el-card>
              <template #header>
                <div class="card-header">
                  <span>车位信息</span>
                </div>
              </template>
              <div class="w-full h-full CarInfoBox gridBox">
                <div class="carInfo_item">
                  <div class="label">区域：</div>
                  <div class="main">{{ parkingReviewInfo.parking.areaName }}</div>
                </div>
                <div class="carInfo_item">
                  <div class="label">车位编号：</div>
                  <div class="main">{{ parkingReviewInfo.parking.parkingCode }}</div>
                </div>
                <div class="carInfo_item">
                  <div class="label">车位面积：</div>
                  <div class="main">{{ parkingReviewInfo.parking.parkingArea }} ㎡</div>
                </div>
                <div class="carInfo_item">
                  <div class="label">楼层：</div>
                  <div class="main">{{ parkingReviewInfo.parking.parkingFloor }} 层</div>
                </div>
                <div class="carInfo_item">
                  <div class="label">车位类型：</div>
                  <div class="main">
                    <dict-tag :options="com_parking_type" :value="parkingReviewInfo.parking.type" />
                  </div>
                </div>
                <div class="carInfo_item">
                  <div class="label">车位状态：</div>
                  <div class="main">
                    <DictTag :options="com_parking_status" :value="parkingReviewInfo.parking.parkingStatus"></DictTag>
                  </div>
                </div>
                <div class="carInfo_item">
                  <div class="label">持有人：</div>
                  <div class="main">
                    <span>
                      {{ parkingReviewInfo.parking.residentName }}
                    </span>
                    <el-button
                      v-if="parkingReviewInfo.parking.residentId"
                      @click="getUserInfo"
                      type="primary"
                      link
                      style="font-size: smaller; margin-left: 15px"
                      >详情</el-button
                    >
                  </div>
                </div>
                <div class="carInfo_item">
                  <div class="label">添加时间：</div>
                  <div class="main">{{ parkingReviewInfo.parking.createTime }}</div>
                </div>
              </div>
              <div class="CarInfoBox" style="margin-top: 20px">
                <div class="carInfo_item" v-if="parkingReviewInfo.parking.contactName">
                  <div class="label">非业主联系人：</div>
                  <div class="main">{{ parkingReviewInfo.parking.contactName }}</div>
                </div>
                <div class="carInfo_item" style="margin-top: 20px" v-if="parkingReviewInfo.parking.contactPhone">
                  <div class="label">联系电话：</div>
                  <div class="main">{{ parkingReviewInfo.parking.contactPhone }}</div>
                </div>
                <div class="carInfo_item" style="margin-top: 20px">
                  <div class="label">备注：</div>
                  <div class="main">{{ parkingReviewInfo.parking.remark }}</div>
                </div>
              </div>
            </el-card>
          </div>
          <!-- 车辆信息 -->
          <div class="mb-10">
            <el-card>
              <template #header>
                <div class="card-header">
                  <span>车辆信息</span>
                </div>
              </template>
              <div class="w-full h-full CarInfoBox" v-if="parkingReviewInfo.car">
                <el-row>
                  <el-col :span="8">
                    <div class="carInfo_item">
                      <div class="label">车牌号：</div>
                      <div class="main">{{ parkingReviewInfo.car.carNum }}</div>
                    </div>
                  </el-col>
                  <el-col :span="8">
                    <div class="carInfo_item">
                      <div class="label">车辆品牌：</div>
                      <div class="main">{{ parkingReviewInfo.car.carBrand }}</div>
                    </div>
                  </el-col>
                  <el-col :span="8">
                    <div class="carInfo_item">
                      <div class="label">车辆型号</div>
                      <div class="main">{{ parkingReviewInfo.car.carModel }}</div>
                    </div>
                  </el-col>
                </el-row>
                <el-row class="mt-30px mb-30px">
                  <el-col :span="8">
                    <div class="carInfo_item">
                      <div class="label">车身颜色：</div>
                      <div class="main">{{ parkingReviewInfo.car.carColor }}</div>
                    </div>
                  </el-col>
                  <el-col :span="8">
                    <div class="carInfo_item">
                      <div class="label">备注：</div>
                      <div class="main">{{ parkingReviewInfo.car.remark }}</div>
                    </div>
                  </el-col>
                  <el-col :span="8"> </el-col>
                </el-row>
                <el-row>
                  <el-col :span="24">
                    <div class="carInfo_item flex-items-start">
                      <div class="label">车辆照片：</div>
                      <div class="main">
                        <el-image
                          v-for="(item, index) in parkingReviewInfo.car.carImageUrlList"
                          :key="index"
                          class="carInfoImage"
                          :src="item"
                          :initial-index="index"
                          :preview-src-list="parkingReviewInfo.car.carImageUrlList"
                          preview-teleported
                        ></el-image>
                      </div>
                    </div>
                  </el-col>
                </el-row>
              </div>
              <div class="w-full h-full CarInfoBox flex flex-center min-h-17rem" v-else>
                <span style="color: #999; font-weight: 500; font-size: larger; letter-spacing: 10px">暂无信息</span>
              </div>
            </el-card>
          </div>
        </el-col>
      </el-row>
    </div>

    <el-dialog width="500" @close="handleClose" v-model="MainForm.visible" title="车位持有人详情">
      <div class="item">
        <div class="label">姓名</div>
        <div class="value">{{ MainFormInfo.name }}</div>
      </div>
      <div class="item">
        <div class="label">类型</div>
        <div class="value">
          <DictTag :value="MainFormInfo.type" :options="com_resident_relationship"></DictTag>
        </div>
      </div>
      <div class="item">
        <div class="label">状态</div>
        <div class="value">
          <DictTag :value="MainFormInfo.status" :options="com_review"></DictTag>
        </div>
      </div>
      <div class="item">
        <div class="label">证件号码</div>
        <div class="value">{{ MainFormInfo.idCard }}</div>
      </div>
      <div class="item">
        <div class="label">手机号码</div>
        <div class="value">{{ MainFormInfo.phone }}</div>
      </div>
      <div class="item">
        <div class="label">房间</div>
        <div class="value">{{ MainFormInfo.houseName }}</div>
      </div>
      <template #footer>
        <div class="dialog-footer">
          <el-button @click="handleClose">关闭</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>
<script setup lang="ts">
import { ref } from 'vue';
import PageHeader from '@/components/Pageheader/index.vue';
import { getParkingReviewInfo, getParkingResidentInfo } from '@/api/system/parking';
import DictTag from '@/components/DictTag/index.vue';

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
const { com_parking_status, com_parking_type, com_review, com_resident_relationship } = toRefs<any>(
  proxy?.useDict('com_parking_status', 'com_parking_type', 'com_review', 'com_resident_relationship')
);

const route = useRoute();
const id = ref('');

const MainForm = ref({
  visible: false
});
// 持有人信息
const MainFormInfo = ref({
  id: '',
  name: '',
  type: '',
  status: '',
  idCard: '',
  phone: '',
  houseName: ''
});
// 重置模态框
function resetMainFormInfo() {
  MainFormInfo.value = {
    id: '',
    name: '',
    type: '',
    status: '',
    idCard: '',
    phone: '',
    houseName: ''
  };
}
// 查询 持有人信息
function getUserInfo() {
  resetMainFormInfo();
  getParkingResidentInfo(parkingReviewInfo.value.parking.residentId).then((res) => {
    MainFormInfo.value = res.data;
  });
  MainForm.value.visible = true;
}
// 关闭模态框
function handleClose() {
  resetMainFormInfo();
  MainForm.value.visible = false;
}

type parkingReviewType = {
  parking: {
    id: string;
    areaId: string;
    areaName: string;
    contactName: string;
    contactPhone: string;
    villageId: string;
    villageName: string;
    parkingCode: string;
    parkingArea: string;
    parkingStatus: string;
    type: string;
    residentId: string;
    residentName: string;
    parkingFloor: string;
    createName: string;
    checkStatus: string;
    remark: string;
    createTime: string;
    delFlag: string;
  };
  car: {
    'id': string;
    'areaId': null;
    'villageId': string;
    'parkingId': string;
    'residentId': null;
    'residentName': null;
    'carNum': string;
    'carBrand': string;
    'carModel': string;
    'carColor': string;
    'remark': null;
    'carImageUrl': string;
    'userName': null;
    'userId': string;

    carImageUrlList?: string[];
  };
  parkingReviewProcess: {
    submitStatus: null;
    propertyStatus: null;
    certificationStatus: null;
    submitTime: string;
    propertyTime: string;
    certificationTime: string;
  };
};

const parkingReviewInfo = ref<parkingReviewType>({
  parking: {
    'id': '',
    'areaId': '',
    'areaName': '',
    'contactName': '',
    'contactPhone': '',
    'villageId': '',
    'villageName': '',
    'parkingCode': '',
    'parkingArea': null,
    'parkingStatus': '',
    'type': '',
    'residentId': null,
    'residentName': null,
    'parkingFloor': '',
    'createName': '',
    'checkStatus': '',
    'remark': '',
    'createTime': '',
    'delFlag': null
  },
  car: {
    'id': '',
    'areaId': null,
    'villageId': '',
    'parkingId': '',
    'residentId': null,
    'residentName': null,
    'carNum': '',
    'carBrand': '',
    'carModel': '',
    'carColor': '',
    'remark': null,
    'carImageUrl': '',
    'userName': null,
    'userId': ''
  },
  parkingReviewProcess: {
    submitStatus: null,
    propertyStatus: null,
    certificationStatus: null,
    submitTime: null,
    propertyTime: null,
    certificationTime: null
  }
});

function getInfo() {
  if (route.query.id) {
    id.value = route.query.id as string;
    getParkingReviewInfo(id.value).then((res) => {
      if (res.data.car) {
        res.data.car.carImageUrlList = res.data.car.carImageUrl.split(',').filter(Boolean) ?? [];
      }
      parkingReviewInfo.value = res.data;
    });
  }
}
getInfo();
// 审核状态
// 物业审核状态 0 待审核 1审核通过 2审核未通过
</script>

<style scoped lang="scss">
.ResidentMainBox {
  display: flex;
  flex-direction: column;

  .item {
    display: flex;
    align-items: center;
    margin-bottom: 20px;
    .label {
      width: 120px;
      text-align: right;
      font-weight: bold;
      margin-right: 10px;
    }
  }

  .ResidentMainBody {
    flex: 1;
    margin-top: 20px;
    .CarInfoBox {
      &.gridBox {
        display: grid;
        grid-template-columns: repeat(3, 1fr);
        grid-template-rows: repeat(3, 1fr);
        gap: 20px;
        row-gap: 40px;
      }
      .carInfo_item {
        display: flex;
        align-items: center;
        font-size: 14px;
        .label {
          font-weight: 600;
          width: 100px;
          text-align: right;
          padding-right: 10px;
        }
        .carInfoImage {
          width: 200px;
          height: 100px;
        }
      }
    }

    &:deep(div.el-step__head.is-process) {
      & > div.el-step__line {
        width: 0;
        border: 1px dashed gray;
        background: transparent;
      }
    }
    &:deep(.el-step.is-vertical .el-step__line) {
      top: 20px;
    }
    &:deep(div.el-step__head.is-finish) {
      & > div.el-step__line {
        width: 0;
        border: 1px solid var(--el-color-primary);
        background: transparent;
      }
    }
  }
}
</style>
