<template>
  <view class="container">
    <u-divider
      text="隐患信息"
      text-position="left"
      text-color="rgb(42, 86, 247)"
      line-color="rgb(42, 86, 247)"
      dashed
    />
    <u-cell-group>
      <u-cell title="检查内容" :label="info.INSPECT_CONTENT" />
      <u-cell title="隐患编码" :label="info.CODE" />
      <u-cell title="隐患描述" :label="info.HIDDENDESCR" />
      <u-cell title="隐患部位" :value="info.HIDDENPART" />
      <u-cell title="隐患级别" :value="info.HIDDENLEVELNAME" />
      <u-cell title="检查人">
        <template #value>
          <view
            style="
              width: 70%;
              display: flex;
              flex-direction: column;
              text-align: right;
            "
          >
            <view v-for="(item, index) in info.inspectUserList" :key="index">
              {{ item }}
            </view>
          </view>
        </template>
      </u-cell>
      <u-cell title="发现时间" :value="info.DISCOVER_TIME" />
      <u-cell title="整改截止时间" :value="info.RECTIFY_DEADLINE" />
      <u-cell title="整改意见" :value="info.DISPOSE" />
      <u-cell title="隐患状态">
        <template #value>
          <text v-if="info.STATE === '1'">
            {{ info.QUALIFIED === "0" ? "打回" : "" }}待整改
          </text>
          <text v-else-if="info.STATE === '2'"> 待复查 </text>
          <text v-else-if="info.STATE === '3'"> 已复查 </text>
        </template>
      </u-cell>
      <u-cell title="隐患图片">
        <template #label>
          <u-row :gutter="12">
            <u-col v-for="item in info.hImgs" :key="item.FILEPATH" span="3">
              <u--image
                :show-loading="true"
                :src="item.FILEPATH"
                width="80px"
                height="80px"
                @click="fnPreview(item.FILEPATH, 'hImgs')"
              />
            </u-col>
          </u-row>
        </template>
      </u-cell>
      <u-cell
        v-if="info.QUALIFIED === '0' && info.REVIEW_CONTENT"
        title="打回原因"
        :value="info.REVIEW_CONTENT"
      />
      <u-cell
        v-if="info.QUALIFIED === '0' && info.REVIEW_TIME"
        title="打回时间"
        :value="info.REVIEW_TIME"
      />
      <u-cell
        v-if="info.QUALIFIED === '0' && info.reviewImgs"
        title="现场复查照片"
      >
        <template #label>
          <u-row :gutter="12">
            <u-col
              v-for="item in info.reviewImgs"
              :key="item.FILEPATH"
              span="3"
            >
              <u--image
                :show-loading="true"
                :src="item.FILEPATH"
                width="80px"
                height="80px"
                @click="fnPreview(item.FILEPATH, 'reviewImgs')"
              />
            </u-col>
          </u-row>
        </template>
      </u-cell>
    </u-cell-group>
    <template v-if="info.STATE > 1">
      <u-divider
        text="整改信息"
        text-position="left"
        text-color="rgb(42, 86, 247)"
        line-color="rgb(42, 86, 247)"
        dashed
      />
      <u-cell-group>
        <u-cell title="整改人" :value="info.RECTIFYER_NAME" />
        <u-cell title="整改时间" :value="info.RECTIFY_TIME" />
        <u-cell title="整改描述" :label="info.RECTIFY_DESCR" />
        <u-cell title="整改图片">
          <template #label>
            <u-row :gutter="12">
              <u-col v-for="item in info.rImgs" :key="item.FILEPATH" span="3">
                <u--image
                  :show-loading="true"
                  :src="item.FILEPATH"
                  width="80px"
                  height="80px"
                  @click="fnPreview(item.FILEPATH, 'rImgs')"
                />
              </u-col>
            </u-row>
          </template>
        </u-cell>
        <u-cell title="本次整改报告照片">
          <template #label>
            <u-row :gutter="12">
              <u-col v-for="item in info.rfImgs" :key="item.FILEPATH" span="3">
                <u--image
                  :show-loading="true"
                  :src="item.FILEPATH"
                  width="80px"
                  height="80px"
                  @click="fnPreview(item.FILEPATH, 'rfImgs')"
                />
              </u-col>
            </u-row>
          </template>
        </u-cell>
      </u-cell-group>
    </template>
    <template v-if="info.STATE === '3'">
      <u-divider
        text="复查信息"
        text-position="left"
        text-color="rgb(42, 86, 247)"
        line-color="rgb(42, 86, 247)"
        dashed
      />
      <u-cell-group>
        <u-cell title="是否合格">
          <template #value>
            <text v-if="info.QUALIFIED === '1'"> 是 </text>
            <text v-else-if="info.QUALIFIED === '0'"> 否 </text>
          </template>
        </u-cell>
        <u-cell title="复查部门" :value="info.REVIEW_DEPT_NAME" />
        <u-cell title="复查人" :value="info.REVIEWER_NAME" />
        <u-cell title="复查时间" :value="info.REVIEW_TIME" />
        <u-cell title="现场复查照片">
          <template #label>
            <u-row :gutter="12">
              <u-col
                v-for="item in info.reviewImgs"
                :key="item.FILEPATH"
                span="3"
              >
                <u--image
                  :show-loading="true"
                  :src="item.FILEPATH"
                  width="80px"
                  height="80px"
                  @click="fnPreview(item.FILEPATH, 'reviewImgs')"
                />
              </u-col>
            </u-row>
          </template>
        </u-cell>
      </u-cell-group>
    </template>
  </view>
</template>

<script>
import { getSpecialRectificationInspectionRecordHiddenView } from "@/api";

export default {
  props: {
    specialRectificationInspectHiddenId: {
      type: String,
      default: "",
    },
  },
  data() {
    return {
      info: {},
    };
  },
  created() {
    if (this.specialRectificationInspectHiddenId) {
      this.fnGetData(this.specialRectificationInspectHiddenId);
    }
  },
  onLoad(query) {
    this.fnGetData(query.SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID);
  },
  methods: {
    async fnGetData(SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID) {
      const resData = await getSpecialRectificationInspectionRecordHiddenView({
        SPECIAL_RECTIFICATION_INSPECT_HIDDEN_ID,
      });
      const inspectUserList = [];
      resData.pd.INSPECT_USER_NAME.split("_").forEach((user) => {
        inspectUserList.push(user ? user.replace(/,/g, "/") : "");
      });
      resData.pd.inspectUserList = inspectUserList;
      const imgs = ["hImgs", "rImgs", "rfImgs", "reviewImgs"];
      for (let i = 0; i < imgs.length; i++) {
        for (let j = 0; j < resData.pd[imgs[i]].length; j++) {
          resData.pd[imgs[i]][j].FILEPATH =
            this.$filePath + resData.pd[imgs[i]][j].FILEPATH;
        }
      }
      this.info = resData.pd;
    },
    fnPreview(current, key) {
      uni.previewImage({
        current,
        urls: this.info[key].map((item) => item.FILEPATH),
      });
    },
  },
};
</script>

<style scoped lang="scss">
.container {
  padding: 20upx;
}
</style>
