<template>
  <view class="all-container">
    <view class="bg"></view>
    <zj-page-layout
      :isScroll="true"
      :hasFooter="true"
      :refresherTriggered="refresherTriggered"
      @refresherrefresh="refresherrefresh"
    >
      <!-- 状态 -->
      <view class="status-container">
        <view class="status">{{ detail ? detail.orderStatusText : '' }}</view>
      </view>
      <view class="content-container" v-if="detail">
        <view class="goods-container card mt30">
          <view class="common-title">商品信息</view>
          <view class="item" v-for="(item, index) in detail.pgOrderProducts" :key="index">
            <view class="main">
              <image :src="item.imgUrl ? item.imgUrl : require('@/static/images/logo.png')" mode="aspectFill"></image>
              <view class="info">
                <view class="name">
                  <view class="left" v-if="detail.isZl">{{ item.mainName || '' }}</view>
                  <view class="left" v-else>{{ item.smallName || '' }} {{ item.productName || '' }}</view>
                  <view class="right">x{{ item.num }}</view>
                </view>
                <view class="tags" v-if="!detail.isZl">
                  <view class="it">{{ item.brandName }}</view>
                  <!-- <view class="it">家用空调</view> -->
                </view>
              </view>
            </view>
          </view>
        </view>
        <!-- 订单信息 -->
        <view class="info-container card mt30" v-if="detail.saleOrderId && !detail.pgIncreId">
          <view class="common-title">订单信息</view>
          <view>
            <view class="row">
              <view class="label">订单编号</view>
              <view class="value">{{ detail.saleOrderId }}</view>
              <view v-if="detail && detail.orderStatus !== 'DQD'" class="ctrl" @tap="$copy(detail.saleOrderId)"
                >复制</view
              >
            </view>
            <view class="row">
              <view class="label">下单时间</view>
              <view class="value">{{ detail.saleCreateTime || '' }}</view>
            </view>
            <view class="row">
              <view class="label">订单金额</view>
              <view class="value">¥{{ detail.saleTotalAmount | priceFilter }}</view>
            </view>
            <view class="row">
              <view class="label">订单备注</view>
              <view class="value">{{ detail.saleRemark || '' }}</view>
            </view>
          </view>
        </view>
      </view>
    </zj-page-layout>
  </view>
</template>

<script>
export default {
  components: {},

  data() {
    return {
      id: null,
      imageUrl: this.$imageUrl,
      detail: null,
      increDetail: null,
      loadStatus: 1,
      errorText: '',
      refresherTriggered: false,
      curTab: 1,
      tabList: [
        { name: '基本信息', value: 1 },
        { name: '服务信息', value: 2 },
        { name: '电子支付', value: 3 },
        { name: '员工结算', value: 4 }
      ],
      isOpenGoods: false,

      payList: [], // 支付信息列表
      settleList: [], // 结算列表

      isShowFeedback: false,
      feedbackList: [],
      behavior: ''
    }
  },

  async onLoad({ id }) {
    this.id = id
  },

  methods: {
    // 触发下拉刷新
    async refresherrefresh(e) {
      this.refresherTriggered = true
      await this.refreshData()
    },

    async changeTab(e) {
      await this.refreshData()
    },

    async refreshData() {
      try {
        await this.getDetail()
        this.refresherTriggered = false
      } catch (e) {}
    },

    // 获取详情
    getDetail() {
      return new Promise((resolve, reject) => {
        this.$api
          .post('/settlementOrder/detail', {
            id: this.id
          })
          .then(res => {
            this.detail = res.data
            resolve(1)
          })
          .catch(res => {
            reject(0)
          })
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.all-container {
  position: relative;
}

.bg {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 300rpx;
  background: linear-gradient(179.48deg, rgba(200, 224, 251, 1) 0.45%, rgba(247, 247, 247, 1) 98.96%);
}

.status-container {
  padding: 30rpx;

  .status {
    font-size: 36rpx;
    font-weight: 500;

    text {
      margin-left: 12rpx;
    }
  }

  .time {
    font-size: 24rpx;
    color: $sec-font;
    margin-top: 12rpx;
  }
}

.tab-container {
  margin-bottom: 30rpx;
}

.card {
  @include zj-card;
}

.common-title {
  font-size: 36rpx;
  font-weight: 600;
  padding-bottom: 20rpx;
}

.common-title2 {
  padding-bottom: 20rpx;
  display: flex;
  align-items: center;
  justify-content: space-between;

  .title {
    font-size: 36rpx;
    font-weight: 600;
  }

  .right {
    font-size: 28rpx;
    color: $theme-color;
    display: flex;
    align-items: center;

    text {
      font-size: 28rpx;
      opacity: 0.5;
    }
  }
}

.content-container {
  padding: 0 30rpx 30rpx;
}

.user-container {
  .top {
    padding: 30rpx;

    .type {
      display: flex;
      align-items: center;
      justify-content: space-between;

      .left {
        font-size: 36rpx;
        color: $theme-color;
        font-weight: 500;
      }

      .right {
        font-size: 28rpx;
        color: $theme-color;
      }
    }

    .user {
      font-weight: 500;
      margin-top: 20rpx;
    }

    .address {
      display: flex;
      justify-content: space-between;
      margin-top: 20rpx;

      .text {
        font-size: 28rpx;
        flex: 1;
        margin-right: 20rpx;
      }

      .ctrl {
        font-size: 28rpx;
        color: $theme-color;

        .iconfont {
          font-size: 28rpx;
          margin-right: 4rpx;
        }
      }
    }
  }

  .bottom {
    border-top: 1px solid #eaeaea;
    display: flex;
    height: 80rpx;

    .it {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 28rpx;
      color: $theme-color;

      &:last-child {
        border-left: 1px solid #eaeaea;
      }

      .iconfont {
        font-size: 36rpx;
        margin-right: 8rpx;
      }
    }
  }
}

.goods-container {
  padding: 30rpx;

  .item {
    border-bottom: 1px solid #d6e0f2;
    padding: 20rpx 0;

    &:last-child {
      border: none;
    }

    .main {
      display: flex;

      image {
        width: 140rpx;
        height: 140rpx;
        flex-shrink: 0;
      }

      .info {
        flex: 1;
        margin-left: 20rpx;

        .name {
          display: flex;
          justify-content: space-between;

          .left {
            font-weight: 500;
          }

          .right {
            margin-left: 30rpx;
            color: $sec-font;
          }
        }

        .tags {
          display: flex;
          flex-wrap: wrap;

          .it {
            height: 42rpx;
            padding: 0 16rpx;
            background: #f4f5f9;
            border-radius: 8rpx;
            font-size: 24rpx;
            display: flex;
            align-items: center;
            justify-content: center;
            margin-top: 12rpx;
            margin-right: 8rpx;

            &:last-child {
              margin-right: 0;
            }
          }
        }
      }
    }

    .images {
      display: flex;
      flex-wrap: wrap;
      margin-top: 24rpx;

      .it {
        margin-right: 30rpx;

        image {
          width: 116rpx;
          height: 116rpx;
        }

        .text {
          text-align: center;
          color: $sec-font;
          margin-top: 8rpx;
        }
      }
    }
  }

  .ctrl {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 10rpx;

    text {
      color: $sec-font;
    }

    .iconfont {
      font-size: 24rpx;
      transform: rotate(-90deg);
      margin-left: 10rpx;

      &.is {
        transform: rotate(90deg);
      }
    }
  }
}

.info-container {
  padding: 30rpx;

  .row {
    display: flex;
    margin-top: 20rpx;

    &:first-child {
      margin-top: 0;
    }

    .label {
      font-size: 28rpx;
      color: $sec-font;
      margin-right: 20rpx;
      flex-shrink: 0;
    }

    .value {
      font-size: 28rpx;
    }

    .ctrl {
      font-size: 28rpx;
      color: $theme-color;
      margin-left: 20rpx;
    }
  }
}

.product-container {
  padding: 30rpx;
  margin-bottom: 30rpx;

  .row {
    display: flex;

    .label {
      font-size: 28rpx;
      color: $sec-font;
      margin-right: 20rpx;
      flex-shrink: 0;
    }

    .value {
      font-size: 28rpx;
      flex: 1;
    }
  }

  .product {
    background: #f5f5f5;
    border-radius: 12rpx;
    padding: 20rpx;

    .it {
      display: flex;
      align-items: flex-end;
      margin-bottom: 20rpx;

      .name {
        flex: 1;
        font-size: 28rpx;
        font-weight: 500;

        text {
          color: $sec-font;
          margin-left: 12rpx;
          font-weight: normal;
        }
      }

      .price {
        margin-left: 30rpx;
        font-size: 28rpx;
        font-weight: 500;
      }
    }

    .total {
      display: flex;
      align-items: center;
      justify-content: flex-end;
      margin-top: 30rpx;

      .text {
        font-size: 28rpx;
        color: $sec-font;
      }

      .price {
        font-size: 28rpx;
        color: $minor-color;
        font-weight: 500;
      }
    }
  }

  .bottom {
    margin-top: 20rpx;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .left {
      font-size: 28rpx;
      font-weight: 500;
    }

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

      .text {
        font-size: 28rpx;
        color: $sec-font;
      }

      .price {
        font-size: 28rpx;
        color: $minor-color;
        font-weight: 500;
      }
    }
  }
}

.feedback-container {
  padding: 30rpx;

  .list {
    .item {
      display: flex;
      padding: 10rpx 0;

      .main {
        margin-left: 20rpx;

        .name {
          font-weight: 500;
          line-height: 32rpx;
        }

        .time {
          font-size: 28rpx;
          margin-top: 12rpx;
          color: $sec-font;
          line-height: 32rpx;
        }

        .content {
          font-size: 28rpx;
          margin-top: 12rpx;
          line-height: 32rpx;
        }
      }
    }
  }
}

.bottom-container {
  padding: 20rpx;
  display: flex;
  justify-content: space-between;

  .right {
    display: flex;

    ::v-deep .u-button {
      width: 160rpx;
      margin-left: 20rpx;
    }
  }
}

.feedback-dialog {
  padding: 30rpx 30rpx 0;
  .title {
    margin-bottom: 30rpx;
    text-align: center;
    font-weight: 600;
    font-size: 36rpx;
  }
  .content {
    padding-bottom: 30rpx;
    max-height: 800rpx;
    overflow-y: scroll;
  }
}
.imgs {
  display: flex;
  flex-wrap: wrap;

  .it {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    margin-top: 30rpx;
    margin-right: 30rpx;

    &:nth-child(3n) {
      margin-right: 0;
    }

    image {
      width: 190rpx;
      height: 190rpx;
      background: #f4f4f7;
      border-radius: 20rpx;
      overflow: hidden;
    }

    .name {
      margin-top: 24rpx;
      color: $sec-font;

      text {
        color: $minor-color;
      }
    }
  }
}
</style>
