<template>
  <view class="card">
    <view class="flex header">
      <view class="flex left">
        <view class="avatar">
          <image class="avatar-img" :src="data.user.avatar"></image>
        </view>
        <view class="info">
          <view class="name">{{ data.user.name }}</view>
          <view>{{ $dayjs(data.createTime).format('YYYY-MM-DD') }}</view>
          <!-- <view>{{ `${data.countDesc || ''} | ${$dayjs(data.createTime).format('YYYY-MM-DD')}` }}</view> -->
        </view>
      </view>
      <view class="right" v-if="mode == 'edit'">
        <button class="btn" @click="onDelete">
          <image class="btn-icon" src="@/pages_order/static/comment/icon-delete.png" mode="widthFix"></image>
        </button>
      </view>
    </view>
    <view class="section content">{{ data.content }}</view>
    <view class="flex section imgs">
      <image class="img" 
        v-for="(url, iIdx) in images" 
        :key="iIdx" :src="url" 
        mode="scaleToFill"
      ></image>
    </view>
    <view class="section score">
      <view class="flex score-item">
        <view class="score-item-label">产品服务度</view>
        <uv-rate :value="data.productNum" size="48rpx" gutter="16rpx" activeColor="#F7BA1E" :allowHalf="true" :minCount="0.5" readonly></uv-rate>
      </view>
      <view class="flex score-item">
        <view class="score-item-label">问卷体验</view>
        <uv-rate :value="data.paperNum" size="48rpx" gutter="16rpx" activeColor="#F7BA1E" :allowHalf="true" :minCount="0.5" readonly></uv-rate>
      </view>
      <view class="flex score-item">
        <view class="score-item-label">物流速度</view>
        <uv-rate :value="data.logisticsNum" size="48rpx" gutter="16rpx" activeColor="#F7BA1E" :allowHalf="true" :minCount="0.5" readonly></uv-rate>
      </view>
    </view>
  </view>
</template>

<script>
  export default {
    props: {
      data: {
        type: Object,
        default() {
          return {}
        }
      },
      mode: {
        type: String,
        default: 'read' // read | edit
      }
    },
    computed: {
      images() {
        const { image } = this.data || {}

        return image?.split?.(',')
      }
    },
    methods: {
			async fetchDelete() {
        
        uni.showToast({
          icon: 'loading',
          title: '正在删除',
        });

				try {
					await this.$fetch('deleteEvaluate', { id: this.data.id })

					uni.showToast({
						icon: 'success',
						title: '删除成功',
					});

          this.$emit('deleteSucc')

				} catch (err) {

				}
			},
      onDelete() {
        uni.showModal({
          title: '确认删除？',
          success : e => {
            if(e.confirm){
							this.fetchDelete()
            }
          }
        })
      }
    },
  }
</script>

<style scoped lang="scss">
  .card {
    width: 100%;
    padding: 32rpx;
    box-sizing: border-box;
    background: #FAFAFF;
    border: 2rpx solid #FFFFFF;
    border-radius: 32rpx;
  }

  .header {

    .left {
      flex: 1;
      justify-content: flex-start;
      column-gap: 24rpx;
    }

    .avatar {
      width: 100rpx;
      height: 100rpx;
      border: 4rpx solid #FFFFFF;
      border-radius: 50%;
      overflow: hidden;

      &-img {
        width: 100%;
        height: 100%;
      }
    }

    .info {
      font-family: PingFang SC;
      font-weight: 400;
      font-size: 24rpx;
      line-height: 1.5;
      color: #8B8B8B;

      .name {
        font-weight: 600;
        font-size: 36rpx;
        line-height: 1.2;
        color: #252545;
        margin-bottom: 8rpx;
      }
    }

    .btn {
      &-icon {
        width: 44rpx;
        height: auto;
      }
    }
    
  }

  .section {
    margin-top: 24rpx;
  }

  .content {
    font-family: PingFang SC;
    font-weight: 400;
    font-size: 32rpx;
    line-height: 1.4;
    color: #181818;
  }

  .imgs {
    justify-content: flex-start;
    flex-wrap: wrap;
    gap: 24rpx;

    .img {
      width: 190rpx;
      height: 190rpx;
    }
  }

  .score {
    &-item {
      padding: 12rpx 0;
      justify-content: space-between;

      & + & {
        margin-top: 4rpx;
      }
      
      &-label {
        font-family: PingFang SC;
        font-weight: 400;
        font-size: 26rpx;
        line-height: 1.4;
        color: #181818;
      }
      
    }
  }
</style>