<template>
  <el-dialog title="委托详情" v-model="showDialog" width="800px" @close="closeDialog">
    <el-descriptions
      class="margin-top"
      :title="'车位编号：'+data.parkingNumber"
      :column="3"
      border
    >
      <el-descriptions-item width="250" label="区县">
        {{ data.districtName }}
      </el-descriptions-item>
      <el-descriptions-item width="250" label="小区">
        {{ data.communityName }}
      </el-descriptions-item>
      <el-descriptions-item width="250" label="楼号">
        {{ data.buildingNumber }}
      </el-descriptions-item>
      <el-descriptions-item width="250" label="车位类型">
        {{ data.parkingType == 1 ? "车库" : "车位" }}
      </el-descriptions-item>
      <el-descriptions-item label="面积">
        {{ data.area }}
      </el-descriptions-item>
      <el-descriptions-item label="售卖方式">
        <el-tag style="margin: 0px 3px" v-if="data.entrustType==0">租售</el-tag>
        <el-tag style="margin: 0px 3px" v-if="data.entrustType==1">出租</el-tag>
        <el-tag style="margin: 0px 3px" v-if="data.entrustType==2">出售</el-tag>
      </el-descriptions-item>
      <el-descriptions-item label="售价">
        {{ data.salePrice }}
      </el-descriptions-item>
      <el-descriptions-item label="租金">
        {{ data.hirePrice }}
      </el-descriptions-item>
      <el-descriptions-item label="委托人联系电话">
        {{ data.contactNumber }}
      </el-descriptions-item>
      <el-descriptions-item label="证明文件">
        <el-image v-if="data.evidenceFile.length>0"
                  style="width: 100px; height: 100px"
                  :src="data.evidenceFile[0]"
                  :zoom-rate="1.2"
                  :preview-src-list="data.evidenceFile"
                  fit="cover"
        />
      </el-descriptions-item>
    </el-descriptions>

    <template #footer>
      <el-button type="success" @click="submit(true)">审核通过</el-button>
      <el-button type="danger" @click="submit(false)">拒绝</el-button>
    </template>

  </el-dialog>
</template>

<script setup>

import { ref } from "vue";
import request from "/@/api/request";
import { entrust } from "/@/api/controllerUrls";


let showDialog = ref(false);


defineExpose({
  open
});


let data = ref({});

function open(event) {
  data.value = event;
  data.value.evidenceFile = data.value.evidenceFile ? JSON.parse(data.value.evidenceFile) : [];
  showDialog.value = true;
  console.log(data.value);
}

function submit(e) {
  request.edit(entrust, {
    id: data.value.id,
    operate: e ? 1 : 0
  }, "release").then((res) => {
    if (res.code == 1) {
      showDialog.value = false;
    }
  });
}

const emit = defineEmits(["close"]);

function closeDialog() {
  emit("close");
}

</script>

<style scoped>

</style>
