<template>
  <!-- #ifdef H5 -->
  <view class="all-container">
    <view class="bg"></view>
    <Loading
    	:type="3"
    	:loadStatus="loadStatus"
    	:showText="errorText"
    />
    <zj-page-layout
      v-if="detail"
      :isScroll="true"
      :refresherTriggered="refresherTriggered"
      @refresherrefresh="refresherrefresh">
      <view class="content-container">
        <view class="status-container">{{detail.refundState | statusFilter}}<text class="iconfont icon-jinru"></text></view>
        <view class="product-container card">
          <view class="title">配件信息</view>
          <view class="product">
            <view class="it" v-for="(item, index) in detail.items" :key="index">
              <view class="name">{{item.goodsName}}<text>×{{detail.type == 'NEW' ? item.newRefundQty : item.oldRefundQty}}{{item.goodsSalesUnit}}</text></view>
              <view class="price">¥{{item.refundAmount | priceFilter}}</view>
            </view>
            <view class="total">
              <view class="text">合计：</view>
              <view class="price">¥{{detail.totalRefundAmount | priceFilter}}</view>
            </view>
          </view>
        </view>
        <view class="list-container card" v-if="detail.type == 'OLD'">
          <view class="title">旧件信息</view>
          <view class="list">
            <view class="it" v-for="(item, index) in detail.records" :key="index">
              <view class="row">
                <view class="label">工单单号</view>
                <view class="value">{{item.orderId}}</view>
              </view>
              <view class="row">
                <view class="label">配件名称</view>
                <view class="value">{{item.partsName}}</view>
              </view>
              <view class="row">
                <view class="label">配件编号</view>
                <view class="value">{{item.partsCode}}</view>
              </view>
              <view class="row">
                <view class="label">配件数量</view>
                <view class="value">{{item.qty}}{{item.unit}}</view>
              </view>
            </view>
          </view>
        </view>
        <view class="info-container card">
          <view class="title">返还信息</view>
          <view class="row">
            <view class="label">申请单号</view>
            <view class="value">{{detail.partsRetId}}</view>
            <view class="tag" @tap="$copy(detail.partsRetId)">复制</view>
          </view>
          <view class="row">
            <view class="label">申请人员</view>
            <view class="value">{{detail.workerName}}</view>
          </view>
          <view class="row">
            <view class="label">申请时间</view>
            <view class="value">{{detail.createTime}}</view>
          </view>
          <view class="row">
            <view class="label">返还方式</view>
            <view class="value">师傅自还</view>
          </view>
          <view class="row">
            <view class="label">返还网点</view>
            <view class="value">{{detail.websitName}}</view>
            <view class="tag">查看地址</view>
          </view>
        </view>
        <view class="info-container card">
          <view class="title">接收信息</view>
          <view class="row">
            <view class="label">接收人员</view>
            <view class="value">{{detail.confirmBy || '--'}}</view>
          </view>
          <view class="row">
            <view class="label">接收时间</view>
            <view class="value">{{detail.confirmTime || '--'}}</view>
          </view>
          <view class="row">
            <view class="label">备注信息</view>
            <view class="value">{{detail.remark || '--'}}</view>
          </view>
        </view>
      </view>
    </zj-page-layout>
  </view>
  <!-- #endif -->

  <!-- #ifndef H5 -->
  <web-view :src="webViewHref(`/packageMaterial/pages/stock/returnDetail`, pam, crossPagePam)" @message="crossPage.$listener"></web-view>
  <!-- #endif -->
</template>

<script>
  // #ifdef H5
  export default {
    filters: {
      statusFilter(val) {
        const MAP = {
          OK: '已返还',
          WAIT: '待返还',
          FAIL: '返还失败',
        }
        return MAP[val];
      }
    },

    data() {
      return {
        id: null,
        refresherTriggered: false,
        loadStatus: 0,
				errorText: '',
        detail: null,
      }
    },

    onLoad({id}) {
      this.id = id;
      this.getDetail();
    },

    methods: {
      getDetail() {
        this.$api.post('/material/parts/refund/detail', {
          partsRetId: this.id
        }).then(res => {
          this.detail = res.data;
          this.loadStatus = 0;
        }).catch(res => {
      		this.errorText = res.message;
      		this.loadStatus = 2;
      	}).finally(res => {
      		this.refresherTriggered = false;
      	})
      },

      // 下拉刷新
      refresherrefresh() {
        this.refresherTriggered = true;
        this.getDetail();
      },
    },
  }

  // #endif
  // #ifndef H5
  export default {
    data() {
      return {
        pam: {},
      }
    },
    onLoad(pam) {
      this.pam = pam;
    }
  }
  // #endif
</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%);
}
.card {
  @include zj-card;
  margin-top: 30rpx;
  padding: 30rpx;
  .title {
    font-size: 32rpx;
    font-weight: 600;
  }
}
.content-container {
  padding: 20rpx;
}
.status-container {
  font-size: 36rpx;
  font-weight: 500;
  margin-left: 30rpx;
  text {
    margin-left: 12rpx;
  }
}
.product-container {
  .title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    .left {
      font-size: 32rpx;
      font-weight: 600;
    }
    .right {
      font-size: 28rpx;
      color: $theme-color;
    }
  }
  .product {
    background: #f5f5f5;
    border-radius: 12rpx;
    padding: 20rpx;
    margin-top: 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;
      }
    }
  }
}
.list-container {
  .list {
    .it {
      border-bottom: 1px solid #eaeaea;
      &:last-child {
        border: none;
      }
      .row {
        display: flex;
        align-items: center;
        margin: 20rpx 0;
        .label {
          font-size: 28rpx;
          color: $sec-font;
          margin-right: 20rpx;
        }
        .value {
          flex: 1;
          font-size: 28rpx;
        }
      }
    }
  }
}
.info-container {
  .row {
    display: flex;
    align-items: center;
    margin-top: 20rpx;
    .label {
      font-size: 28rpx;
      color: $sec-font;
      margin-right: 20rpx;
    }
    .value {
      flex: 1;
      font-size: 28rpx;
      text {
        color: $minor-color;
      }
      &.price {
        color: $theme-color;
      }
    }
    .tag {
      font-size: 28rpx;
      color: $theme-color;
    }
  }
}
.bottom-container {
  padding: 20rpx;
  display: flex;
  justify-content: space-between;
  .right {
    display: flex;
    ::v-deep .u-button {
      margin-left: 20rpx;
    }
  }
}
</style>
