<template>
  <div class="container">
    <div class="top-box">
      <img src="../../assets/bg_top.jpg" class="top-img" alt="" />
      <div class="card">
        <div class="info">
          <div class="title">{{ organization.name }}</div>
          <div class="address">
            <div class="text" v-if="rateInfo.change">
              南京市{{ organization.district }} {{ rateInfo.changeAddress }}
            </div>
            <div class="text" v-else>
              南京市{{ organization.district }} {{ organization.address }}
            </div>
            <!-- <div class="img">
              <img src="../../assets/icon_dizhi.png" alt="" />
              <span>导航</span>
            </div> -->
          </div>
          <hr v-if="organization.owner" />
          <div class="owner" v-if="organization.owner">
            <div class="owner-item">
              <div class="text1">负责人</div>
            </div>
            <div class="owner-item" v-if="organization.ownerPhone">
              <div class="text2">{{ organization.owner }}</div>
              <div class="text2">{{ organization.ownerPhone }}</div>

              <img
                @click="takePhone(organization.ownerPhone)"
                src="../../assets/icon_dianhua.svg"
                alt=""
              />
            </div>
          </div>
        </div>
      </div>

      <div class="card setting">
        <img src="../../assets/icon_lianjie.svg" class="left-icon" alt="" />
        <img src="../../assets/icon_lianjie.svg" class="right-icon" alt="" />

        <div class="time">
          <div class="title">审查时间</div>

          <div
            class="time-box not"
            @click="setting"
            v-if="!rateInfo.reviewTime"
          >
            <span>暂未设置审查时间</span>
            <van-icon name="arrow" :size="16" color="#000000" />
          </div>
          <div class="time-box" v-else>
            <div class="time-content " @click="setting">
              <span>{{ rateInfo.reviewTime }}</span>
              <van-icon
                v-if="rateInfo.status === 'REVIEW_PENDING'"
                name="arrow"
                :size="16"
                color="#000000"
              />
            </div>
            <div class="time-list" v-if="rateInfo.reviewTimes.length > 0">
              <div>时间设置记录</div>
              <div v-for="(item, index) in rateInfo.reviewTimes" :key="index">
                {{ item.operatingTime }}
              </div>
            </div>
          </div>
        </div>
        <div class="userlist">
          <div class="title">专家组员</div>
          <div class="user-item" v-for="(item, index) in userList" :key="index">
            <span>{{ item.name }}</span>
            <span>{{ item.phone }}</span>
            <img
              src="../../assets/icon_dianhua.svg"
              @click="takePhone(item.phone)"
            />
          </div>
        </div>
      </div>
    </div>

    <template v-if="rateInfo.status === 'REVIEW_PENDING'">
      <div class="bottom" v-if="!rateInfo.reviewTime">
        <van-button @click="setting" round block :color="$colors.prim">
          设置审查时间
        </van-button>
      </div>

      <template v-else>
        <div class="empty">
          <img src="../../assets/img_cailiao_kong.svg" alt="" />
          <div class="text">暂未上传考察材料</div>
        </div>

        <div class="bottom">
          <van-button @click="add" round block :color="$colors.prim">
            上传评分及考察材料
          </van-button>
        </div>
      </template>
    </template>

    <rate-info-box v-else :info="rateList" :rateInfo="rateInfo"></rate-info-box>

    <picker ref="time" @confirm="updateReviewTime" />
  </div>
</template>

<script>
import picker from "../../components/picker.vue";
import expert from "../../mixins/expert";
import dayjs from "dayjs";
import RateInfoBox from "../../components/rateInfo.vue";
export default {
  components: { picker, RateInfoBox },
  name: "expertdetail",
  mixins: [expert],
  metaInfo() {
    return {
      title: "评分详情"
    };
  },
  data() {
    return {
      rateInfo: {},
      organization: {},
      rateList: [],
      userList: [],
      address: ""
    };
  },
  mounted() {
    this.getInfo(this.$route.query.id);
  },
  methods: {
    getInfo(id) {
      this.$toast.loading({
        message: "加载中...",
        forbidClick: true
      });

      this.$http
        .get("/rate/get1/" + id)
        .then(res => {
          this.rateInfo = res;
          this.userList = Object.keys(res.expertUser || []).map(item => {
            return {
              phone: item,
              name: res.expertUser[item]
            };
          });
          this.$http
            .post(
              "/rateExpertAudit/all",
              {
                query: {
                  rateId: res.id
                }
              },
              { body: "json" }
            )
            .then(res => {
              this.rateList = res.content;
            });
          return this.$http.get("/organization/get/" + res.organizationId);
        })
        .then(res => {
          this.$toast.clear();
          this.organization = res;
        });
    },
    add() {
      this.$router.push({
        name: "expertAdd",
        query: {
          rateId: this.rateInfo.id
        }
      });
    },
    takePhone(phone) {
      window.location.href = "tel://" + phone;
    },
    setting() {
      if (this.rateInfo.status === "REVIEW_PENDING") {
        this.$refs.time.show = true;
      }
    },
    updateReviewTime(time) {
      this.$http
        .get("/rate/saveReviewTime", {
          id: this.rateInfo.id,
          time: dayjs(time).format("YYYY-MM-DD HH:mm:ss")
        })
        .then(res => {
          this.$toast.success("审查时间设置成功");
          this.rateInfo = res;
        });
    }
  }
};
</script>
<style lang="less" scoped>
.container {
  position: relative;
  padding-bottom: 100px;
}
.top-box {
  position: relative;
  padding: 134px 16px 16px;
  .top-img {
    display: block;
    width: 100%;
    height: auto;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 0;
  }

  .card {
    position: relative;
    background: #ffffff;
    border-radius: 12px;
    padding: 20px;
    z-index: 1;
    .info {
      .title {
        font-size: 22px;
        font-weight: bold;
        color: #000000;
        line-height: 32px;
      }
    }
    .address {
      display: flex;
      .text {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: 400;
        color: #000000;
        line-height: 24px;
      }
    }
    .img {
      display: flex;
      width: 16px;
      height: 16px;
      flex-direction: column;
      min-width: 24px;
      padding-left: 12px;
      font-size: 12px;
      color: #2c96ff;
      line-height: 22px;
    }
    hr {
      width: 100%;
      height: 1px;
      background: #f5f7fa;
      border: 0;
      margin: 20px 0;
    }
    .owner {
      .owner-item {
        display: flex;
        align-items: center;
        .text1 {
          font-size: 14px;
          color: #939599;
          line-height: 24px;
        }

        .text2 {
          font-size: 16px;
          color: #000000;
          line-height: 24px;
          min-width: 84px;
        }
        .text2 + .text2 {
          flex-grow: 1;
          margin-left: 5px;
        }
      }
    }
  }

  .left-icon,
  .right-icon {
    position: absolute;
    width: 10px;
    height: 54px;
    top: -30px;
  }
  .left-icon {
    left: 16px;
  }
  .right-icon {
    right: 16px;
  }
}

.setting {
  margin-top: 8px;
  .title {
    font-size: 15px;
    color: #00000020;
    line-height: 24px;
    padding-top: 30px;
  }
  .user-item {
    display: flex;
    align-items: center;
    height: 64px;
    border-bottom: 1px solid #f5f7fa;

    span {
      font-size: 16px;
      color: #000000;
      line-height: 24px;
      min-width: 80px;
    }

    span + span {
      flex-grow: 1;
      margin-left: 12px;
    }
  }
  .time-box {
    border-bottom: 1px solid #f5f7fa;
    padding-bottom: 10px;
    &.not {
      .time-content {
        span {
          font-size: 16px;
          color: #2c96ff;
          line-height: 24px;
        }
      }
    }
  }
  .time-content {
    padding: 2px 0 10px;
    display: flex;
    align-items: center;
    span {
      flex-grow: 1;
    }
  }
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 54px;

  img {
    width: 140px;
    display: block;
  }
  .text {
    font-size: 14px;
    color: #c4c7cc;
    line-height: 22px;
    margin-top: 13px;
  }
}

.submitInfo {
  padding: 0 16px;
}

.bottom {
  position: fixed;
  padding: 6px 48px calc(env(safe-area-inset-bottom) + 6px);
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 20;
  background-color: #fff;
}

.score-card {
  background: #ffffff;
  border-radius: 12px;
  margin-top: 30px;
  overflow: hidden;

  .score {
    font-size: 20px;
    font-weight: bold;
    color: #ffffff;
    line-height: 28px;
    line-height: 60px;
    text-align: center;
    background: #ffcf6a;
  }

  .score-ratelist {
    padding: 20px;

    .rate-item {
      .rate-title {
        font-size: 15px;
        color: #00000080;
        line-height: 24px;
        padding-bottom: 8px;
      }

      .rate-info {
        padding-bottom: 10px;
        display: flex;
        justify-content: space-between;
        .name {
          font-size: 15px;
          font-weight: bold;
          color: #313233;
          line-height: 24px;
        }
        .val {
          font-size: 15px;
          color: #313233;
          line-height: 24px;
        }
      }
    }
  }
}

.remark-card {
  .title {
    font-size: 20px;
    font-weight: bold;
    color: #000000;
    line-height: 30px;
    padding: 36px 0 10px;
  }

  .card {
    padding: 20px;
    background-color: #fff;
    font-size: 16px;
    color: #000000;
    line-height: 26px;
    border-radius: 8px;
  }
}

.img-card {
  .title {
    font-size: 20px;
    font-weight: bold;
    color: #000000;
    line-height: 30px;
    padding: 36px 0 10px;
  }

  .card {
    img {
      display: block;
      border-radius: 8px;
      width: 100%;
      margin-bottom: 12px;
    }
  }
}

.time-list {
  font-size: 13px;
  color: #c8c9cc;
  line-height: 24px;
}
</style>
