<!--

  订单列表页面， 数据渲染 
   业务： 用户管理   迁移自  JFeftCard

  @author terrfly
  @site https://www.jeequan.com
  @date 2022/11/30 07:07
-->
<template>
  <view class="card-wrapper">
    <view class="card-main" hover-class="touch-hover" :style="{ right: right + 'rpx' }">
      <view class="card-item" @tap="toDetails">
        <view class="img-wrapper" :class="{ 'open-state': props.record.state == 1, 'close-state': props.record.state == 0 }">
          <image :src="props.record.avatarUrl" mode="scaleToFill" />
        </view>
        <view class="card-info">
          <view class="info-text">
            <view class="text-main single-text-beyond">{{ props.record.realname }}</view>
            <JeepayTag :type="datamap.userType(props.record.userType).type">{{ datamap.userType(props.record.userType).text }}</JeepayTag>
          </view>
          <view class="info-phone">{{props.record.telphone}}</view>
        </view>
      </view>
      <view class="card-delete" hover-class="u-cell-delete" hover-stay-time="150" @tap="deleteStaff"> 删除 </view>
    </view>
  </view>
</template>

<script setup>
import { reactive, ref } from 'vue'
import cal from '@/commons/utils/cal.js'
import go from '@/commons/utils/go.js'
import datamap from '@/commons/utils/datamap.js'


// 定义传入属性
const props = defineProps({
  record: { type: Object, default: () => {} }, // 渲染对象
})


// 删除确认弹窗
const deleteStaff = (v) => {
  // jeepayPopupConfirmRef.value.open(`确认删除 ${v.name} 员工吗?`).then(() => {
  // 	console.log('确认')
  // });
}

//前往员工详情
const toDetails = () => {
	go.to('PAGES_USER_DETAIL', { sysUserId: props.record.sysUserId })
}

// 该部分 为左滑右滑功能部分
const right = ref(0)
let startX = 0
const touchStart = (e) => {
  startX = e.touches[0].clientX
}
const touchMove = (e) => {
  const endX = e.changedTouches[0].clientX
  const deviationX = startX - endX
  if (deviationX > 0) {
    leftTouch(deviationX)
  } else if (deviationX < 0) {
    rightTouch(deviationX)
  }
}
const touchEnd = (e) => {
  const endX = e.changedTouches[0].clientX
  const deviationX = startX - endX
  if (deviationX == 0) {
    emits('touchDown')
  }
}
const leftTouch = (x) => {
  if (x <= 50) return
  right.value += x
  if (right.value > 232) {
    right.value = 232
  }
}
const rightTouch = (x) => {
  if (right.value > 0) {
    right.value += x
    right.value = right.value > 0 ? 0 : right.value
  } else {
    right.value = 0
  }
}
// 左滑右滑 end
</script>

<style lang="scss" scoped>
.card-wrapper {
  overflow: hidden;
  .card-main {
    position: relative;
    padding: 0 30rpx;
    height: 170rpx;
    background-color: #fff;
    transition: 0.2s ease-in;
    .card-item {
      display: flex;
      align-items: center;
      width: 100%;
      height: 100%;
      .img-wrapper {
        position: relative;
        flex-shrink: 0;
        width: 100rpx;
        height: 100rpx;
        background-color: skyblue;
        border-radius: 50%;
        image {
          width: 100%;
          height: 100%;
          border-radius: 50%;
        }
      }

      .close-state::after {
        content: '';
        position: absolute;
        right: -10rpx;
        bottom: -5rpx;
        width: 25rpx;
        height: 25rpx;
        border: 6rpx solid #fff;
        border-radius: 50%;
        background-color: #d9d9d9;
      }
      .open-state::after {
        content: '';
        position: absolute;
        right: -10rpx;
        bottom: -5rpx;
        width: 25rpx;
        height: 25rpx;
        border: 6rpx solid #fff;
        border-radius: 50%;
        background-color: #168fff;
      }
      .card-info {
        margin-left: 30rpx;
        .info-text {
          display: flex;
          .text-main {
            max-width: 446rpx;
            font-size: 30rpx;
            font-weight: 400;
          }
          .info-state {
            display: flex;
            align-items: center;
            margin-left: 30rpx;
            padding: 0 15rpx;
            height: 40rpx;
            font-size: 23rpx;
            font-weight: 400;
            color: #fff;
            white-space: nowrap;
            background: linear-gradient(270deg, rgba(61, 220, 68, 1) 0%, rgba(23, 187, 118, 1) 100%);
            border-radius: 6rpx;
          }
        }
        .info-phone {
          margin-top: 16rpx;
          font-size: 25rpx;
          font-weight: 400;
          color: $J-color-t99;
        }
      }
    }
    .card-delete {
      position: absolute;
      top: 0;
      right: -232rpx;

      display: flex;
      justify-content: center;
      align-items: center;
      width: 232rpx;
      height: 170rpx;
      color: #fff;
      background-color: #ff5b4c;
    }
  }
}
.u-cell-hover {
  background-color: #f8f9fa;
}
.u-cell-delete {
  opacity: 0.5;
}
</style>
