<template>
  <view class="item">
    <view class="item-img">
      <!-- <up-image :show-loading="true" :src="data.volunteerPicture"></up-image> -->
      <image :show-loading="true" :src="data.volunteerPicture"></image>
    </view>
    <view class="item-info">
      <view class="item-serviceTotalPrice">￥{{ data.serviceTotalPrice }}</view>
      <view class="item-title-box">
        <view class="item-title">
          <view class="item-name">
            {{ data.name }}
          </view>
        </view>
        <view class="item-de">
          服务类别：{{ data.businessTierName }}
        </view>
        <view class="item-de">
          下单日期：{{ data.createTime }}
        </view>
        <view class="item-time">
          服务描述：{{ data.businessDescribe }}
        </view>
        <view class="item-status-box">
          <!-- <image src="/static/img/矩形 413@1x.png" class="item-status-img"></image> -->
          <!-- class="item-status" -->
          <dict-tag :options="order_status" :value="String(data.orderStatus)"  />
        </view>
      </view>
      <view class="item-box">
        <view class="item-btns">
          <view v-for="item in btns" :key="item.name">
            <view :class="['btn-m', (item.name === '取消' || item.name === '退款') ? 'btn-cancel-refund' : '']" v-if="item.show ? item.show(data) : true" :type="item.type" text="取消"
              @click="item.onClick(data)">
              <image v-if="item.name === '查看'" src="/static/img/组 14145@1x.png" class="btn-icon"></image>
              <image v-if="item.name === '沟通'" src="/static/img/容器 165@1x.png" class="btn-icon"></image>
              {{ item.name }}
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
import { inject } from 'vue';
import DictTag from '@/components/DictTag/index.vue'

const props = defineProps({
  data: {
    type: Object,
    default: () => {
      return {}
    }
  },
});

const order_status = inject('order_status');
console.log("TCL: order_status", order_status)

const btns = [
  {
    name: '沟通',
    onClick: (e) => {
      console.log("TCL: e", e)
      uni.navigateTo({
        url: `/pages_orderuser/pages/talk/pages/index/index?orderId=${e.mainOrderId}&conversationType=2`
      });
    },
    type: 'primary'
  },
  {
    name: '退款',
    onClick: (e) => handleRefund(e),
    show: (item) => ['3'].includes(item.orderStatus),
    type: 'error'
  },
  {
    name: '取消',
    onClick: (e) => handleCancel(e),
    show: (item) => ['1'].includes(item.orderStatus),
    type: 'warning'
  },
  {
    name: '查看',
    onClick: (e) => handlClick(e),
    // show: (item) => item.orderStatus !== '1',
    type: 'info'
  },
]

//申请退款 
const handleRefund = (item) => {
  const mainOrderId = item.mainOrderId; // 获取详情id
  uni.navigateTo({
    url: `/pages_classify/pages/requestaRefund/requestaRefund?mainOrderId=${mainOrderId}`
  });
};
// 取消订单
const handleCancel = (item) => {
  const mainOrderId = item.mainOrderId;
  uni.navigateTo({
    url: `/pages_classify/pages/cancelationOforder/cancelationOforder?mainOrderId=${mainOrderId}`
  });
};
//查看
const handlClick = (item) => {
  const mainOrderId = item.mainOrderId; // 获取详情id
  uni.navigateTo({
    url: `/pages_classify/pages/orderItem/orderdetails?mainOrderId=${mainOrderId}`
  });
}
</script>

<style lang="scss" scoped>
.item {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
  width: 702rpx;
  height: 347rpx;
  // background: red;
  border-radius: 18rpx;
  background: #FFFFFF;
  box-shadow: 0rpx 4rpx 10rpx 0rpx rgba(0, 0, 0, 0.04);
  margin-bottom: 25rpx;

  .item-img {
    width: 122rpx;
    height: 122rpx;
    display: flex;
    justify-content: center;
    align-items: center;

    image {
      width: 100%;
      height: 100%;
      border-radius: 122rpx;
    }
  }

  .item-info {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    height: 100%;
    padding: 20rpx;
    box-sizing: border-box;
    position: relative;

    // 价格
    .item-serviceTotalPrice {
      position: absolute;
      top: 20rpx;
      right: 20rpx;
      width: 96rpx;
      height: 42rpx;
      font-family: PingFang SC;
      font-size: 32rpx;
      font-weight: 600;
      line-height: 42rpx;
      letter-spacing: normal;
      color: rgba(0, 0, 0, 0.8);
    }

    // 志愿者姓名
    .item-name {
      width: 374rpx;
      height: 42rpx;
      font-family: PingFang SC;
      font-size: 32rpx;
      font-weight: 600;
      line-height: 42rpx;
      letter-spacing: normal;
      color: rgba(0, 0, 0, 0.8);
      margin-bottom: 10rpx;
    }
    
    .item-title-box {
      margin-top: 60rpx;
    }

    // 服务类别/下单日期
    .item-de {
      width: 532rpx;
      height: 34rpx;
      font-family: PingFang SC;
      font-size: 28rpx;
      font-weight: normal;
      line-height: 34rpx;
      letter-spacing: normal;
      color: rgba(0, 0, 0, 0.5);
      margin-bottom: 10rpx;
    }

    // 服务描述
    .item-time {
      width: 280rpx;
      /* Approximately 8 Chinese characters */
      height: 34rpx;
      font-family: PingFang SC;
      font-size: 28rpx;
      font-weight: normal;
      line-height: 34rpx;
      letter-spacing: normal;
      color: rgba(0, 0, 0, 0.5);

      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      // max-width: 100%;
      margin-bottom: 10rpx;
    }

    .item-status-box {
      background: linear-gradient(90deg, #FED593 0%, #FDC58C 100%);
      // width: 130rpx;
      height: 47rpx;
      position: absolute;
      left: -130rpx;
      top: 2rpx;
      border-top-left-radius: 16rpx;
      border-bottom-right-radius: 16rpx;

      font-size: 24rpx;
        font-weight: 500;
        line-height: 44rpx;
        letter-spacing: normal;
        color: #843816;
        padding: 0 21rpx;

      // .item-status-img {
      //   width: 130rpx;
      //   height: 47rpx;
      //   position: absolute;
      //   top: 0rpx;
      //   left: -135rpx;

      // }

      // .item-status {
      //   width: 100rpx;
      //   height: 46rpx;
      //   font-family: PingFang SC;
      //   font-size: 24rpx;
      //   font-weight: 500;
      //   line-height: 44rpx;
      //   letter-spacing: normal;
      //   color: #843816;
      //   position: absolute;
      //   left: -116rpx;
      //   top: 2rpx;
      // }
    }
  }

  .item-box {
    display: flex;
    justify-content: flex-end;
    align-items: center;

    .item-btns {
      display: flex;
      justify-content: flex-end;
      align-items: center;
      gap: 20rpx;

      .btn-m {
        width: 140rpx;
        height: 60rpx;
        font-family: PingFang SC;
        font-size: 24rpx;
        font-weight: 500;
        line-height: 60rpx;
        text-align: center;
        letter-spacing: normal;
        color: #FFFFFF;
        background: #D94342;
        border-radius: 36rpx;
        padding: 0;
        display: flex;
        justify-content: center;
        align-items: center;
        
        .btn-icon {
          width: 24rpx;
          height: 24rpx;
          margin-right: 8rpx;
        }
      }
      
      .btn-cancel-refund {
        background: #E9E9E9;
        color: #333333;
      }
    }
  }
}
</style>