<template>
  <div class="right-wrap" style="margin-top: 20px;">
    <el-breadcrumb separator="/" style="margin-bottom: 13px">
      <el-breadcrumb-item :to="{ path: '/myCenter' }">个人中心</el-breadcrumb-item>
      <el-breadcrumb-item>兑换详情</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>兑换详情</span>
      </div>
      <div class="goodDetail">
                <div class="goods-image">
                    <!-- 左侧大图-->
                    <div class="middle" ref="target">
                        <img style=" width: 400px;height: 400px;" :src="imageList[activeIndex]" alt="" />
                    </div>
                    <!-- 小图列表 -->
                    <ul class="small">
                        <li v-for="(img, i) in imageList" :key="i" v-if="i<5" @mouseenter="enterhandler(i)"
                            :class="{ active: i == activeIndex }">
                            <img style="width: 68px;height: 68px;" :src="img" alt="" />
                        </li>
                    </ul>
                </div>
                <div class="goods-content">
                    <div class="goods-name">{{ data.name }}</div>
                    <div class="goods-redeemPoints">兑换积分：{{ data.redeemPoints }} 
                      <!-- <span style="color: red;margin-left: 150px;">参 考 价：￥{{  data.hisPrice}}</span> -->
                    </div>
                    <div class="goods-redeemPoints">物品类别：{{ data.skuType==0 ? '积分商品' : '活动礼品' }}</div> 
                    <div class="goods-redeemPoints">兑换方式：{{ data.deliveryTypeName }}</div>
                    <div class="goods-redeemPoints">是否包邮：{{ data.freightType == '0' ? '不包邮' : '包邮' }}</div>
                    <div class="footer">
                        <div class="left-info" style="width: 100%;">
                            <span class="info-title">
                                兑换说明
                            </span>
                            <div v-html="data.comment"></div>
                        </div>
                    </div>
                </div>
            </div>

      <div v-if="data.deliveryType == 1">
        <p class="label">收货地址</p>
          <div class="address">
            <div class="address-container">
              <div class="header">
                <div class="left">
                  <span>{{ data.contact }}</span>
                </div>
              </div>
              <p class="phone">{{ data.contactPhone }}</p>
              <p class="address">{{ data.addressStr + data.street + data.contactAddr }}</p>
            </div>
          </div>
      </div>
      
      <p class="label">物品信息</p>
      <div v-if="data.skuType == 0">
        <table class="table">
          <thead>
            <tr>
              <th width="35%">兑换物品</th>
              <th style="text-align: center;">数量</th>
              <th style="text-align: center;">单价</th>
              <th style="text-align: center;">兑换方式</th>
              <th v-if="data.reclaimAddrName" style="text-align: center;">领取地点</th>
              <th style="text-align: center;">总计</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>
                <div class="prize-info">
                  <div class="prize-img-container">
                    <el-image :src="data.imgUrl" v-if="data.imgUrl" :preview-src-list="[data.imgUrl]"
                                        class="prize-img"></el-image>
                  </div>
                  <div class="prize-detail-info">
                    <h3 style="color: #1e80ff;" class="title" @click="handleClickGood(data.skuDesc)">{{ data.name }}</h3>
                    <!-- <p class="desc">
                      <span v-if="data.location">{{ data.location }}</span>
                    </p> -->
                  </div>
                </div>
              </td>
              <td style="text-align: center;">{{ data.skuCount }}</td>
              <td style="text-align: center;">{{ data.redeemPoints }} 积分 <span v-if="data.wxPay!='0'"> + {{ data.wxPay }} 元</span></td>
              <td style="text-align: center;">{{ data.deliveryTypeName }}</td>
              <td v-if="data.reclaimAddrName" style="text-align: center;">{{ data.reclaimAddrName }}</td>
              <td style="text-align: center;" class="finlly-redeemPoints">
                {{ data.total }} 积分
                <span v-if="data.wxPay!='0'"> + {{ data.totalWxPay }} 元</span>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
      <div v-else>
        <table class="table">
          <thead>
            <tr>
              <th width="35%">兑换物品</th>
              <!-- <th>数量</th> -->
              <th style="text-align: center;">物品属性</th>
              <th style="text-align: center;">兑换卷</th>
              <th style="text-align: center;">兑换方式</th>
              <th v-if="data.deliveryType == '1' && data.freightType=='0'" style="text-align: center;">快递费</th>
              <th v-if="data.deliveryType == '0'" style="text-align: center;">领取地点</th>
            </tr>
          </thead>
          <tbody>
            <tr>
              <td>
                <div class="prize-info">
                  <div class="prize-img-container">
                    <el-image :src="data.imgUrl" v-if="data.imgUrl" :preview-src-list="imgUrls.length==0?[data.imgUrl]:imgUrls"
                                        class="prize-img"></el-image>
                  </div>
                  <div class="prize-detail-info">
                    <h3 class="title">{{ data.name }}</h3>
                    <!-- <p class="desc">
                      <span v-if="data.location">{{ data.location }}</span>
                    </p> -->
                  </div>
                </div>
              </td>
              <!-- <td>{{ skuCount }}</td> -->
              <td style="text-align: center;">{{ data.productAttributeName }}</td>
              <td style="text-align: center;">{{ data.couponName }}</td>
              <td style="text-align: center;">{{ data.deliveryTypeName }}</td>
              <td v-if="data.deliveryType == '1' && data.freightType=='0'" style="text-align: center;">180 积分</td>
              <td v-if="data.deliveryType == '0'" style="text-align: center;">{{ data.reclaimAddrName }}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <p class="label">兑换记录</p>
      <el-table :data="logs" border style="width: 100%;margin-bottom: 20px;" size="mini">
        <el-table-column align="center" prop="auditor" label="处理人"></el-table-column>
        <el-table-column align="center" prop="comment" label="处理结果"></el-table-column>
        <el-table-column align="center" prop="orderStatus" label="状态"></el-table-column>
        <el-table-column align="center" prop="createTime" label="处理时间"></el-table-column>
      </el-table>
      <div class="footer" v-if="(data.orderType == 3 || data.orderType == 4) && (data.deliveryType == 0 || data.deliveryType == 1 || data.deliveryType == 2)">
        <div class="left-info">
          <span class="info-title">
            <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"
              class="info-icon">
              <path fill-rule="evenodd" clip-rule="evenodd"
                d="M8 1C11.866 1 15 4.13401 15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1Z"
                fill="#165DFF"></path>
              <path fill-rule="evenodd" clip-rule="evenodd"
                d="M8.54189 6.70582C8.67075 6.70582 8.77522 6.81029 8.77522 6.93915L8.77511 10.2335L9.46743 10.2343C9.61176 10.2343 9.72876 10.3513 9.72876 10.4956V11.3319C9.72876 11.4762 9.61176 11.5932 9.46743 11.5932H6.58458C6.44025 11.5932 6.32324 11.4762 6.32324 11.3319V10.4956C6.32324 10.3513 6.44025 10.2343 6.58458 10.2343L7.28178 10.2335V8.08122L7.14759 8.08198C7.00326 8.08198 6.88626 7.96498 6.88626 7.82065V6.97073C6.88626 6.8264 7.00326 6.70939 7.14759 6.70939L7.47956 6.70859C7.49132 6.70677 7.50337 6.70582 7.51565 6.70582H8.54189ZM8.40513 4.41602C8.54946 4.41602 8.66646 4.53302 8.66646 4.67735V5.64802C8.66646 5.79235 8.54946 5.90935 8.40513 5.90935H7.43446C7.29013 5.90935 7.17313 5.79235 7.17313 5.64802V4.67735C7.17313 4.53302 7.29013 4.41602 7.43446 4.41602H8.40513Z"
                fill="white"></path>
            </svg>
            领取详情
          </span>
          <p class="info-content" v-if="data.deliveryType == 1">
            快递类物品兑换后，将在这里显示兑换的物流单号，请保存好该信息自行查阅快递物流信息。<br>
            物流单号：<span style="font-weight: 600;color: #ff834e;">{{ data.trackingNumber }}</span><br>
          </p>
          <p class="info-content" v-if="data.deliveryType == 2">
            虚拟类物品兑换后，将在这里显示兑换的券码，请保存好该信息自行兑换。<br>
            券码：<span style="font-weight: 600;color: #ff834e;">{{ data.trackingNumber }}</span><br>
          </p>
          <p class="info-content" v-if="data.deliveryType == 0">
            办公室领取的物品请到各地公司进行领取<br>
            <!-- 领取联系人<br>
            上海办公室：茅玮婷<br>
            北京办公室：刘琳<br>
            洛阳办公室：吴燕敏<br> -->
          </p>
        </div>
        <div class="right" v-if="data.orderType == 3">
          <!-- <div class="remark-line">
            <span>备注：</span>
            <el-input v-model="comment" class="remark" placeholder="请输入备注，例如兑换商品出现的问题等" type="textarea"></el-input>
          </div> -->
          <div class="btn-line">
            <el-button @click="handleClickConfirm(0)" type="primary" round>确认收货</el-button>
            <!-- <el-button @click="handleClickConfirm(1)" type="warning" round>商品问题反馈</el-button> -->
          </div>
        </div>
      </div>
      <div v-if="data.deliveryType == 3 || data.deliveryType == 4">
        <div class="right" style="text-align: right;" v-if="data.orderType == 3">
          <div class="btn-line">
            <el-button @click="handleClickConfirm(0)" type="primary" round>确认收货</el-button>
          </div>
        </div>
      </div>
      <div class="footer">
                <div class="left-info" style="width: 100%">
                    <span class="info-title">
                        <svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg"
                            class="info-icon">
                            <path fill-rule="evenodd" clip-rule="evenodd"
                                d="M8 1C11.866 1 15 4.13401 15 8C15 11.866 11.866 15 8 15C4.13401 15 1 11.866 1 8C1 4.13401 4.13401 1 8 1Z"
                                fill="#165DFF"></path>
                            <path fill-rule="evenodd" clip-rule="evenodd"
                                d="M8.54189 6.70582C8.67075 6.70582 8.77522 6.81029 8.77522 6.93915L8.77511 10.2335L9.46743 10.2343C9.61176 10.2343 9.72876 10.3513 9.72876 10.4956V11.3319C9.72876 11.4762 9.61176 11.5932 9.46743 11.5932H6.58458C6.44025 11.5932 6.32324 11.4762 6.32324 11.3319V10.4956C6.32324 10.3513 6.44025 10.2343 6.58458 10.2343L7.28178 10.2335V8.08122L7.14759 8.08198C7.00326 8.08198 6.88626 7.96498 6.88626 7.82065V6.97073C6.88626 6.8264 7.00326 6.70939 7.14759 6.70939L7.47956 6.70859C7.49132 6.70677 7.50337 6.70582 7.51565 6.70582H8.54189ZM8.40513 4.41602C8.54946 4.41602 8.66646 4.53302 8.66646 4.67735V5.64802C8.66646 5.79235 8.54946 5.90935 8.40513 5.90935H7.43446C7.29013 5.90935 7.17313 5.79235 7.17313 5.64802V4.67735C7.17313 4.53302 7.29013 4.41602 7.43446 4.41602H8.40513Z"
                                fill="white"></path>
                        </svg>
                        物品介绍
                    </span>
                    <div v-html="data.skuDesc"></div>
                </div>
            </div>
    </el-card>
    <el-dialog title="物品详情" :visible.sync="dialogVisibleGoods" width="40%">
            <div v-html="data.skuDesc"></div>
        </el-dialog>
  </div>
</template>
<script>
import { setTab } from '@/utils/auth';
import { orderInfo, orderConfirm,notice } from "@/api/allApi";
export default {
  data() {
    return {
      noticeContent: '',
            activeIndex: 0,
            imageList: [
                // "https://yanxuan-item.nosdn.127.net/d917c92e663c5ed0bb577c7ded73e4ec.png",
                // "https://yanxuan-item.nosdn.127.net/e801b9572f0b0c02a52952b01adab967.jpg",
                // "https://yanxuan-item.nosdn.127.net/b52c447ad472d51adbdde1a83f550ac2.jpg",
                // "https://yanxuan-item.nosdn.127.net/f93243224dc37674dfca5874fe089c60.jpg",
                // "https://yanxuan-item.nosdn.127.net/f881cfe7de9a576aaeea6ee0d1d24823.jpg"
            ],
      skuDesc:'',
      dialogVisibleGoods:false,
      orderId: this.$route.query.orderId,
      comment: '',
      logs: [],
      skuCount: 1,
      data: {},
      imgUrls:[],
    };
  },
  created() {
    const orderId = this.$route.query.orderId;
    this.getInfo(orderId);
    this.getNotice('goodsNotice');
  },
  methods: {
    getNotice(val) {
            notice({ noticeType: val }).then(response => {
                console.log(response.data.data);
                this.noticeContent = response.data.data.content
            })
        },
        enterhandler(i) {
            this.activeIndex = i;
        },
    handleClickGood(val) {
            this.skuDesc = val;
            if(this.skuDesc){
                this.dialogVisibleGoods = true;
            }
            // this.$router.push({
            //     path: '/home/pointsMall/goodDetail',
            //     query: {
            //         id: id,
            //     }
            // });
        },
    getInfo(orderId) {
      orderInfo({ orderId: orderId }).then((response) => {
        this.data = response.data.data;
        this.logs = response.data.data.logs;
        let imgs = response.data.data.imgs;
        if(imgs){
          imgs.forEach(element => {
            this.imgUrls.push(element.url);
            this.imageList.push(element.url);
            });
        }               
      })
    },
    handleClickConfirm(val) {
      if (val == 1 && this.comment == '') {
        this.$message.error('请填写备注内容');
        return
      };
      const params = {
        orderId: this.orderId,
        flag: val,
        comment: this.comment
      }
      orderConfirm(params).then(response => {
        console.log(response.data.data);
        this.$message({
          message: '提交成功！',
          type: 'success'
        });
        setTab('exchange');
        this.$router.push({
          path: '/home/myCenter',
        });
      })
    }

  },
};
</script>
<style scoped>
::v-deep .el-card__body {
    padding: 20px !important;
}
.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 100%;
}

/* .label:first-child {
  margin-top: 0;
} */

.label {
  font-size: 16px;
  line-height: 24px;
  margin: 16px 0 24px;
}

.address-container {
  padding: 16px;
  min-height: 112px;
  background-color: #f7f8fa;
  box-sizing: border-box;
  border-radius: 4px;
  width: 320px;
  border: 1px solid #abcdff;
}

.address-container .header {
  font-weight: 500;
  font-size: 14px;
  line-height: 24px;
  color: #252933;
  display: flex;
  justify-content: space-between;
  margin: 0 0 8px;
}

.address-container .header .left {
  display: flex;
  justify-content: center;
  align-items: center;
}

.address-container .btn {
  flex: none;
  color: #1e80ff;
  cursor: pointer;
  font-weight: 400;
  margin-left: 1em;
}

.address-container .address,
.address-container .phone {
  margin: 0;
  font-size: 14px;
  line-height: 24px;
  color: #515767;
}

.address-container.new {
  border: 1px dashed #e4e6eb;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-flow: column nowrap;
}

.address-container {
  padding: 16px;
  min-height: 112px;
  background-color: #f7f8fa;
  box-sizing: border-box;
  border-radius: 4px;
  width: 320px;
  border: 1px solid #abcdff;
}

.address-container.new .add-icon {
  font-size: 16px;
  color: #515767;
}

.byte-icon {
  width: 1em;
  height: 1em;
  display: inline-block;
  vertical-align: middle;
  line-height: 1;
}

svg:not(:root) {
  overflow-clip-margin: content-box;
  overflow: hidden;
}

.byte-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
  pointer-events: none;
}

.address-container.new .add-label {
  font-size: 14px;
  line-height: 24px;
  color: #8a919f;
  margin: 18px 0 0;
}

.table {
  border-collapse: collapse;
  border: 1px solid #e4e6eb;
  box-sizing: border-box;
  border-radius: 2px;
  width: 100%;
  text-align: left;
  font-size: 14px;
  line-height: 24px;
  border-collapse: separate;
  border-spacing: 0;
  border-radius: 4px;
}

.table tr {
  border: 1px solid #e4e6eb;
}

.table th {
  padding: 12px 16px;
  background-color: #f7f8fa;
  font-weight: 500;
  color: #282f38;
}

.table td {
  padding: 16px;
  vertical-align: middle;
  color: #515767;
}

.table .prize-info {
  display: flex;
}

.table .prize-img-container {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f7f8fa;
  width: 80px;
  height: 80px;
}

.table .prize-detail-info {
  margin-left: 16px;
  display: flex;
  flex-flow: column;
  align-items: flex-start;
  justify-content: center;
}

.table .prize-img-container .prize-img {
  max-height: 64px;
}

.lazy {
  position: relative;
  -o-object-fit: cover;
  object-fit: cover;
}

img {
  border-style: none;
}

.table .prize-detail-info {
  margin-left: 16px;
  display: flex;
  flex-flow: column;
  align-items: flex-start;
  justify-content: center;
}

.table .prize-detail-info .title {
  cursor: pointer;
  font-weight: 400;
  font-size: 14px;
  line-height: 24px;
  color: #1d2129;
  margin: 0 0 3px;
}

.table .prize-detail-info .desc {
  margin: 0;
  line-height: 18px;
  height: 18px;
}

.table .prize-detail-info .desc span {
  font-size: 12px;
  line-height: 14px;
  color: #ff7d00;
  background: #fff7e8;
  padding: 2px 4px;
}

.table .finlly-redeemPoints {
  font-weight: 500;
  font-size: 14px;
  line-height: 24px;
  color: #1e80ff;
}

.footer {
  margin-top: 16px;
  display: flex;
  justify-content: space-between;
}

.footer .left-info {
  box-sizing: border-box;
  width: 400px;
  height: -webkit-fit-content;
  height: -moz-fit-content;
  height: fit-content;
  background-color: #e8f3ff;
  border-radius: 4px;
  padding: 16px;
}

.footer .left-info .info-title {
  font-size: 14px;
  line-height: 24px;
  color: #282f38;
  display: flex;
  align-items: center;
}

.footer .left-info .info-icon {
  margin-right: 8px;
}

.footer .left-info .info-content {
  margin: 4px 0 4px 2em;
  white-space: pre-line;
  font-size: 12px;
  line-height: 20px;
  color: #8a919f;
}

.footer .right {
  font-size: 14px;
  line-height: 24px;
  color: #282f38;
}

.footer .right .remark-line {
  display: flex;
  position: relative;
}

.footer .right .remark {
  width: 400px;
}

.footer .right .btn-line {
  margin-top: 16px;
  text-align: right;
}

.addButton-address {
  background: #1e80ff;
  border-color: #1e80ff;
  color: #fff;
  width: 160px;
  height: 48px;
  border-radius: 50px;
  line-height: 46px;
  padding: 0;
  font-size: 16px;
  border: 1px solid transparent;
}
.goodDetail {
    display: flex;
    height: 485px;
}

.goods-image {
    width: 400px;
    height: 480px;
    position: relative;
    display: flex;
    flex-direction: column;
}

.goods-image .middle {
    width: 400px;
    height: 400px;
    background: #f5f5f5;
}

.goods-image .small {
    height: 80px;
    display: flex;
    /* justify-content: space-between; */
}

.goods-image .small li {
    width: 68px;
    height: 68px;
    margin-right: 12px;
    margin-top: 15px;
    cursor: pointer;
}

.goods-image .small li:hover {
    border: 2px solid red;
}

.active {
    border: 2px solid red;
}

.goods-content {
    flex: 1;
    margin-left: 10px;
    height: 100%;
    scrollbar-width: none; /* firefox */
    -ms-overflow-style: none; /* IE 10+ */
    overflow-x: hidden;
    overflow-y: auto;
}
.goods-content::-webkit-scrollbar {
  display: none; /* Chrome Safari */
}
.goods-content .goods-name{
    font-size: 18px;
    font-weight: bold;
    line-height: 36px;
}
.goods-content .goods-redeemPoints{
    font-size: 16px;
    line-height: 32px;
}
</style>

