<template>
  <div class="reportdetail">
    <!-- <nav-header title="预约详情" @back="$router.go(-1)" /> -->
    <div class="main">
      <div class="stateInfo">
        当前预约状态：<span>{{ detail.stateName }}</span>
      </div>
      <div class="address" v-if="detail.address">
        <div class="info">
          <p class="label">仓库地址：</p>
          <p class="value">{{ detail.address }}</p>
        </div>
        <img src="@/assets/coldfood/map_icon.png" alt="" @click="location" />
      </div>
      <div class="reprtInfo" v-if="detail.state === 9">
        <div class="title">
          <div class="icon"></div>
          <p>出库信息</p>
        </div>
        <div class="cell">
          <p class="cell-title">出库证明</p>
          <div class="prove">
            <img
              style="max-width: 200px; max-height: 200px"
              :src="detail.driverUrl"
              alt=""
              @click="imgpreview(detail.driverUrl)"
            />
          </div>
          <div class="cell-detail">
            <p class="label">出库车牌号</p>
            <p class="value">{{ detail.deliveryCar }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">出库司机姓名</p>
            <p class="value">{{ detail.deliveryName }}</p>
          </div>
        </div>
      </div>
      <div class="reason" v-if="detail.reason">
        拒绝原因：<span>{{ detail.reason }}</span>
      </div>
      <div class="reprtInfo">
        <div class="title">
          <div class="icon"></div>
          <p>订单信息</p>
        </div>
        <div class="cell">
          <p class="cell-title">联系人信息</p>
          <div class="cell-detail">
            <p class="label">联系人姓名</p>
            <p class="value">{{ detail.name }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">手机号码</p>
            <p class="value">{{ detail.phone }}</p>
          </div>
        </div>
        <div class="cell">
          <p class="cell-title">车辆信息</p>
          <div class="cell-detail">
            <p class="label">车牌号</p>
            <p class="value">{{ detail.carNumber }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">司机姓名</p>
            <p class="value">{{ detail.driverName }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">联系方式</p>
            <p class="value">{{ detail.driverPhone }}</p>
          </div>
        </div>
        <div class="cell">
          <p class="cell-title">照片信息</p>
          <div class="photo">
            <div
              class="photo-card"
              v-for="photo in detail.picture"
              :key="photo.pictureType"
            >
              <img :src="photo.picture" alt="" @click="imgpreview(photo.picture)" />
              <p>
                {{
                  photo.pictureType === 4
                    ? "驾驶员苏康码"
                    :photo.pictureType === 7
                    ? "驾驶员7天内核酸检测报告"
                    : photo.pictureType === 5
                    ? "营业执照照片"
                    : "食品经营许可证"
                }}
              </p>
            </div>
          </div>
        </div>
        <div class="cell" v-for="item in detail.goods" :key="item.code">
          <p class="cell-title">商品信息</p>
          <div class="cell-detail">
            <p class="label">货物商品类型</p>
            <p class="value">{{ item.goodsStateName }}</p>
          </div>
          <div class="cell-detail" v-if="item.hsName">
            <p class="label">货物商品分类</p>
            <p class="value">{{ item.hsName }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">报关单号(海关编号)</p>
            <p class="value">{{ item.customs }}</p>
          </div>
          
          <div class="cell-detail">
            <p class="label">货主名称</p>
            <p class="value">{{ item.shipper }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">统一社会信用代码</p>
            <p class="value">{{ item.credit }}</p>
          </div>
          <div class="cell-detail" v-if="item.certNo">
            <p class="label">检验检疫证编号</p>
            <p class="value">{{ item.certNo }}</p>
          </div>
          <div class="cell-detail" v-if="item.entryDate">
            <p class="label">入境时间</p>
            <p class="value">{{ item.entryDate }}</p>
          </div>
          <div class="cell-detail" v-if="item.portEntryName">
            <p class="label">入境口岸</p>
            <p class="value">{{ item.portEntryName }}</p>
          </div>
          <div class="cell-detail" v-if="item.sourceType">
            <p class="label">食品来源</p>
            <p class="value">{{ item.sourceType ? '口岸' : '' }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">集装箱号</p>
            <p class="value">{{ item.container }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">商品名称</p>
            <p class="value">{{ item.goodsName }}</p>
          </div>
          <div class="cell-detail" v-if="item.consigner">
            <p class="label">发货人</p>
            <p class="value">{{ item.consigner }}</p>
          </div>
          <div class="cell-detail" v-if="item.tradeWeight">
            <p class="label">报关单重量(KG)</p>
            <p class="value">{{ item.tradeWeight }}</p>
          </div>
          <div class="cell-detail" v-if="item.weight">
            <p class="label">入库重量(KG)</p>
            <p class="value">{{ item.weight }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">件数</p>
            <p class="value">{{ item.number }}</p>
          </div>
          <div class="cell-detail" v-if="item.specification">
            <p class="label">包装规格(千克/件)</p>
            <p class="value">{{ item.specification }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">注册号</p>
            <p class="value">{{ item.register }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">原产地</p>
            <p class="value">{{ item.placeOrigin }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">生产日期</p>
            <p class="value">{{ item.productionTime }}</p>
          </div>
          <div class="cell-detail" v-if="item.verifyMonth">
            <p class="label">保质期</p>
            <p class="value">{{ item.verifyMonth }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">生产批号</p>
            <p class="value">{{ item.productionNumber }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">商品流向地区</p>
            <p class="value">{{ item.goodsFlowRegion }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">商品流向(详细地址)</p>
            <p class="value">{{ item.goodsFlowAddress }}</p>
          </div>
          <div class="cell-detail">
            <p class="label">企业经营类型</p>
            <p class="value">{{ item.operateName }}</p>
          </div>
          <div class="photo">
            <div
              class="photo-card"
              v-for="photo in item.pictureList"
              :key="photo.pictureType"
            >
              <img :src="photo.picture" alt="" @click="imgpreview(photo.picture)" />
              <p>
                {{
                  photo.pictureType === 1
                    ? "报关单照片"
                    : photo.pictureType === 2
                    ? "货物清单照片"
                    : "检疫证照片"
                }}
              </p>
            </div>
          </div>
          <div v-for="trace in item.goodsTracing" :key="trace.code">
            <div class="cell-detail">
              <p class="label">商品流向单位（个人）</p>
              <p class="value">{{ trace.company }}</p>
            </div>
            <div class="cell-detail">
              <p class="label">商品流向重量(KG)</p>
              <p class="value">{{ trace.goodsWeight }}</p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import Vue from "vue";
// import NavHeader from "@/components/NavHeader";
import { ImagePreview } from "vant";
import { detail } from "@/api/coldfood";
import { coldfoodEnume } from "@/utils/utils";

Vue.use(ImagePreview);

export default {
  components: {
    // NavHeader
  },
  data() {
    return {
      goodsStateList: [
        { name: "进口水果或其他", id: 1 },
        { name: "进口冷冻肉制品或水产品", id: 2 },
      ], //货物商品类型
      driverCode: null,
      detail: {},
    };
  },
  methods: {
    init() {
      this.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: "加载中...",
      });
      let params = {
        appId: 1234,
        driverCode: this.driverCode,
      };
      detail(params).then((res) => {
        this.$toast.clear();
        this.detail = res.data;
        this.detail.stateName = coldfoodEnume(res.data.state);
        this.detail.name = res.data.name.substring(0,1)+(res.data.name.length == 2 ? '*' : '**');
        this.detail.phone = res.data.phone.substring(0,3)+'****'+res.data.phone.substring(7,12);
      });
    },
    // 处理货物商品类型
    operateGoodsState(id) {
      const list = this.goodsStateList.filter((item) => {
        return item.id == id;
      });
      if (list.length > 0) {
        return list[0].name;
      } else {
        return "";
      }
    },
    imgpreview(url) {
      ImagePreview({
        images: [url],
      });
    },
    location() {
      if (window.android !== undefined) {
        window.android.doNavitagion(
          this.detail.address,
          this.detail.latitude,
          this.detail.longitude
        );
      } else if (window.webkit) {
        const data = {
          poiName: this.detail.address,
          lat: this.detail.latitude,
          lng: this.detail.longitude,
        };
        window.webkit && window.webkit.messageHandlers.doNavitagion.postMessage(data);
      } else {
        this.$toast("无法支持该功能");
      }
    },
  },
  created() {
    this.driverCode = this.$route.query.code;
    if (this.driverCode) {
      this.init();
    }
  },
};
</script>

<style lang="stylus" scoped>
.reportdetail {
  .main {
    height: 100vh;
    overflow-y: auto;

    .stateInfo {
      background: #fff;
      height: 80px;
      padding: 0 30px;
      line-height: 80px;
      font-size: 28px;
      color: #666666;

      span {
        color: #EB4E3F;
        font-weight: 600;
      }
    }

    .address {
      margin-top: 6px;
      padding: 20px 30px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: #fff;

      .info {
        display: flex;
        align-items: center;

        .label {
          font-size: 28px;
          color: #666666;
        }

        .value {
          width: 448px;
          font-size: 28px;
          color: #333333;
        }
      }

      img {
        width: 72px;
        height: 72px;
      }
    }

    .reason {
      margin-top: 6px;
      padding: 20px 30px;
      background: #fff;
      font-size: 28px;
      color: #666666;

      span {
        color: #EB4E3F;
        font-weight: 600;
      }
    }

    .reprtInfo {
      margin-top: 20px;

      .title {
        height: 80px;
        padding: 0 20px;
        display: flex;
        align-items: center;
        background: #fff;

        .icon {
          width: 6px;
          height: 32px;
          margin-right: 10px;
          background: #EB4E3F;
        }

        p {
          font-size: 32px;
          font-weight: 600;
          color: #333333;
        }
      }

      .prove {
        padding: 10px 30px;
        background: #fff;
        border-bottom: 1px solid #eee;
      }

      .cell {
        margin-top: 6px;
        background: #fff;

        .cell-title {
          height: 80px;
          padding: 0 30px;
          line-height: 80px;
          font-size: 28px;
          font-weight: 600;
          color: #333333;
          border-bottom: 1px solid #eee;
        }

        .cell-detail {
          padding: 30px;
          display: flex;
          border-bottom: 1px solid #eee;

          .label {
            width: 200px;
            font-size: 28px;
            font-weight: 400;
            color: #666666;
          }

          .value {
            margin-left: 30px;
            font-size: 28px;
            color: #333333;
          }
        }

        .cell-detail:last-child {
          border-bottom: 0;
        }

        .photo {
          padding: 30px;
          display: flex;
          align-items: center;
          justify-content flex-start;
          flex-wrap: wrap;
          .photo-card {
            height 280px;
            padding: 15px;
            img {
              width: 200px;
              height: 200px;
            }

            p {
              margin-top: 20px;
              text-align: center;
              font-size: 28px;
              color: #999999;
              width 200px;
            }
          }
        }
      }
    }
  }
}
</style>
