ListReception.uvue 13.4 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460
<template>
  <!-- 接待复盘记录列表:与接待接口字段对齐,数据由父级拉取后传入 -->
  <view class="reception-record-list">
    <view v-if="showUnsubmittedPendingSubmitTip" class="unsubmitted-tip">
      <view class="unsubmitted-tip__inner">
        <view class="unsubmitted-tip__icon-dot"></view>
        <text class="unsubmitted-tip__text">以下非正常结束的接待记录,需要进行信息确认后才能提交到系统。</text>
      </view>
    </view>
    <!-- ✅ 首次加载或强制显示骨架屏:使用接待中心 CSS 变量控制列数 -->
    <view v-if="shouldShowSkeleton" class="skeleton-grid">
      <view v-for="i in skeletonCardCount" :key="'skeleton-' + i" class="skeleton-card-wrapper">
        <view class="list-card glass-card skeleton-card-inner">
          <un-skeleton
            :loading="true"
            :animate="true"
            :title="true"
            titleWidth="70%"
            titleHeight="18px"
            :rows="4"
            rowsWidth="90%,80%,70%,60%"
            rowsHeight="14px,14px,14px,14px"
            :avatar="true"
            avatarSize="40px"
            avatarShape="circle" />
        </view>
      </view>
    </view>
    <!-- ✅ 空状态提示:非加载状态且列表为空 -->
    <view v-else-if="isEmpty" class="empty-container">
      <un-empty text="暂无记录" />
    </view>
    <!-- ✅ 列表内容 -->
    <view
      v-else
      v-for="(item, idx) in currentDisplayList"
      :key="getBatchKey(item, idx)"
      :class="['list-card', 'glass-card']"
      @click="onCardClick(item)"
    >
      <view class="card-header-row">
          <view class="card-title-box">
            <text class="card-name">{{ getCustomerName(item) }}</text>
            <text class="card-car">{{ getCarType(item) }}</text>
          </view>
          <view class="card-status-box">
            <view
              v-if="hasResult(item)"
              :class="['status-badge', getResultBadgeBgClass(item)]"
            >
              <text :class="['status-text', getResultBadgeTextClass(item)]">{{
                getResult(item)
              }}</text>
            </view>
          </view>
        </view>
        <view class="card-info-list">
          <view class="info-row"><text class="info-label">客户类型</text><text class="info-value">{{ getCustomerType(item) }}</text></view>
          <view class="info-row"><text class="info-label">客户电话</text><text class="info-value">{{ getFormattedPhone(item) }}</text></view>
          <view class="info-row"><text class="info-label">开始接待</text><text class="info-value">{{ getStartTime(item) }}</text></view>
          <view class="info-row"><text class="info-label">结束接待</text><text class="info-value">{{ getEndTime(item) }}</text></view>
          <view class="info-row info-row-last"><text class="info-label">接待时长</text><text class="info-value">{{ getDuration(item) }}</text></view>
        </view>
    </view>
  </view>
</template>

<script setup lang="uts">
import { computed, watch } from 'vue'
import { getStr } from '../types/reception-center-helpers.uts'
import { textOrDash, formatPhone, isBlankDisplayText } from '@/utils/format-utils.uts'
import { getCustomerPhone, formatReceptionDateTime, getDurationStr, getReceptionResultBadgeBgClass, getReceptionResultBadgeTextClass } from './reception-list-helpers.uts'

// ✅ UVUE 模板包装函数(模板不能直接调用 .uts 导入的函数)
function getBatchKey(item: UTSJSONObject, idx: number): string {
	const batchId = getStr(item, 'batchId')
	return batchId != '' ? `${batchId}-${idx}` : `recv-${idx}`
}

function getCustomerName(item: UTSJSONObject): string {
	return textOrDash(getStr(item, 'customerName'))
}

function getCarType(item: UTSJSONObject): string {
	return textOrDash(getStr(item, 'carType'))
}

function getResult(item: UTSJSONObject): string {
	return getStr(item, 'result')
}

function hasResult(item: UTSJSONObject): boolean {
	return !isBlankDisplayText(getStr(item, 'result'))
}

function getResultBadgeBgClass(item: UTSJSONObject): string {
	return getReceptionResultBadgeBgClass(getStr(item, 'result'))
}

function getResultBadgeTextClass(item: UTSJSONObject): string {
	return getReceptionResultBadgeTextClass(getStr(item, 'result'))
}

function getCustomerType(item: UTSJSONObject): string {
	return textOrDash(getStr(item, 'customerType'))
}

function getFormattedPhone(item: UTSJSONObject): string {
	return textOrDash(formatPhone(getCustomerPhone(item)))
}

function getStartTime(item: UTSJSONObject): string {
	return textOrDash(formatReceptionDateTime(item, 'start'))
}

function getEndTime(item: UTSJSONObject): string {
	return textOrDash(formatReceptionDateTime(item, 'end'))
}

function getDuration(item: UTSJSONObject): string {
	return textOrDash(getDurationStr(item))
}

const props = defineProps<{
  /** 接待记录列表(由父级拉取并传入) */
  receptionRecordList: UTSJSONObject[]
  /** 加载中:骨架屏覆盖卡片内容;列表为空时用骨架卡片占位 */
  loading?: boolean
  /** ✅ 新增:强制显示骨架屏(用于横竖屏切换、Tab 切换等场景) */
  showListSkeleton?: boolean
  /**
   * 一级筛选 tab 索引(父级:接待列表筛选)
   * - 约定:1 表示“未提交”
   */
  filterTabIndex?: number
  /**
   * “未提交”二级筛选 tab 索引
   * - 约定:1 表示“待提交”
   */
  unsubmittedPendingTabIndex?: number
}>()

const loading = computed<boolean>(() => {
	// ✅ UTS 避免 Boolean === true 比较
	const val = props.loading;
	return val != null && val;
})

/** ✅ 当前显示的列表数据 */
const currentDisplayList = computed((): UTSJSONObject[] => {
	return props.receptionRecordList
})

/** 调试:列表变化时打印 currentDisplayList(控制台 / HBuilderX 运行日志) */
watch(
	(): UTSJSONObject[] => currentDisplayList.value,
	(list: UTSJSONObject[]): void => {
		if (list == null) {
			console.log('[ListReception] currentDisplayList: null')
			return
		}
		const n = list.length
		// console.log('[ListReception] currentDisplayList length=', n)
		// console.log('[ListReception] currentDisplayList JSON=', JSON.stringify(list))
	},
	{ immediate: true, deep: true }
)

/** ✅ 性能优化:判断是否应该显示骨架屏 */
const shouldShowSkeleton = computed(() => {
	// ✅ 优先检查强制显示标志(用于横竖屏切换、Tab 切换等场景)
	if (props.showListSkeleton == true) {
		return true;
	}
	// 其次检查加载状态(首次加载且列表为空)
	const showByLoading = loading.value && (currentDisplayList.value == null || currentDisplayList.value.length == 0);
	return showByLoading;
});

/** ✅ 判断列表是否为空(非加载状态) */
const isEmpty = computed(() => {
	return !loading.value && (currentDisplayList.value == null || currentDisplayList.value.length == 0);
});

/** ✅ 性能优化:根据屏幕高度动态计算骨架屏数量(填满一屏) */
const skeletonCardCount = computed(() => {
	// ✅ 只有在需要显示骨架屏时才计算
	if (!shouldShowSkeleton.value) {
		return 0;
	}

	const info = uni.getWindowInfo();
	const windowHeight = info.windowHeight;
	const headerHeight = 60; // 标题栏估算
	const availableHeight = windowHeight - headerHeight;

	// 每个卡片的高度约 180px + 间距 12px = 192px
	const cardHeight = 192;
	const rows = Math.floor(availableHeight / cardHeight);

	// ✅ 统一双列布局(横竖屏都是2列)
	const columns = 2;

	const count = Math.max(rows * columns, 8); // 最少显示 8 个卡片

	return count;
})

const showUnsubmittedPendingSubmitTip = computed((): boolean => {
  const list = currentDisplayList.value
  const hasData = list != null && list.length > 0
  const isUnsubmitted = props.filterTabIndex == 1
  const isPendingSubmit = props.unsubmittedPendingTabIndex == 1
  return hasData && isUnsubmitted && isPendingSubmit
})

const emit = defineEmits<{
  /** 点击卡片:父级根据 filterTabIndex 等处理跳转/提示 */
  'reception-click': [item: UTSJSONObject]
}>()

function onCardClick(item: UTSJSONObject): void {
  if (loading.value) {
    return
  }
  // 未提交 + 待提交:无系统 id 的卡片需先补全信息,进入编辑页
  const idMissing = getStr(item, 'id') == ''
  const isUnsubmittedTab = props.filterTabIndex == 1
  const isPendingSubmitTab = props.unsubmittedPendingTabIndex == 1
  if (idMissing && isUnsubmittedTab && isPendingSubmitTab) {
    uni.navigateTo({
      url: `/pages/receptionCenter/forms/ReceptionRecordEdit?record=${encodeURIComponent(JSON.stringify(item))}`
    })
    return
  }
  // ✅ 导航逻辑下沉:直接在组件内部处理,避免事件层层传递
  uni.navigateTo({
    url: `/pages/receptionCenter/receptionDetail?record=${encodeURIComponent(JSON.stringify(item))}`,
    success(res: any) {
      const ec = (res as UTSJSONObject)["eventChannel"] as any | null;
      if (ec != null) {
        const emitFn = (ec as UTSJSONObject)["emit"] as any | null;
        if (emitFn != null && typeof emitFn == "function") {
          (emitFn as (name: string, data: any) => void)("getData", item);
        }
      }
    }
  });
}
</script>

<style scoped lang="scss">
@import "../styles/common.scss";
.reception-record-list {
  flex: 1;
  flex-direction: var(--reception-list-container-direction, column);
  flex-wrap: var(--reception-list-container-wrap, nowrap);
  justify-content: var(--reception-list-container-justify, flex-start);
  width: 100%;
  min-height: 0;
  /* ✅ 骨架屏网格布局:使用负 margin + padding 实现间距 */
  margin-left: -6px;
  margin-right: -6px;
}

.unsubmitted-tip {
  width: 100%;
  background: #f58e341a;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  box-sizing: border-box;
  justify-content: center;
  align-items: center;
}

.unsubmitted-tip__inner {
  flex-direction: row;
  align-items: center;
  justify-content: center;
}

.unsubmitted-tip__icon-dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background-color: #f58e34;
  margin-right: 8px;
}

.unsubmitted-tip__text {
  color: #f58e34;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
}

.glass-card {
  background-color: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.6);
  // ✅ 性能优化:移除 box-shadow
  // box-shadow: 0 4px 12px rgba(0, 0, 0, 0.03);
  border-radius: 16px;
  flex-direction: column;
}

/* ✅ 骨架屏网格容器 - 使用 space-between 均匀分布 */
.skeleton-grid {
  width: 100%;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: space-between;  /* ✅ 卡片均匀分布 */
  box-sizing: border-box;
}

/* ✅ 骨架屏卡片 wrapper - 使用接待中心 CSS 变量控制列数 */
.skeleton-card-wrapper {
  width: var(--reception-list-card-min-width, 48%);  /* ✅ 竖屏 48%,横屏由 CSS 变量覆盖为 48% */
  flex-shrink: 0;
  box-sizing: border-box;
  padding-bottom: 12px;
}

.list-card {
  padding: 16px;
  border-radius: 16px;
  margin-bottom: 12px;
  /* ✅ 移除左右 margin,由 space-between 控制间距 */
  box-sizing: border-box;
  /* ✅ 使用 width 控制列数(与骨架屏一致) */
  width: var(--reception-list-card-min-width, 48%);
  /* 骨架屏与真实卡片保持一致的高度,避免 loading 时卡片"塌陷" */
  min-height: 200px;
}

/* ✅ 骨架屏内部卡片 - 移除 margin 和 width,因为 wrapper 已控制布局 */
.skeleton-grid .skeleton-card-wrapper .skeleton-card-inner {
  margin-left: 0;
  margin-right: 0;
  width: 100%;  /* ✅ 填满 wrapper 的可用空间(减去 padding) */
}

.card-header-row {
  flex-direction: row;
  justify-content: space-between;
  margin-bottom: 16px;
  align-items: flex-start;
}

.card-title-box {
  flex-direction: column;
}

.card-name {
  font-size: var(--reception-list-card-name-font-size, 18px);
  font-weight: 600;
  color: #1e293b;
}

.card-car {
  font-size: var(--reception-list-card-car-font-size, 14px);
  font-weight: 600;
  color: #1677ff;
  margin-top: var(--reception-list-card-car-margin-top, 6px);
}

.card-status-box {
  flex-direction: row;
  align-items: flex-start;
}

.status-badge {
  padding-top: 4px;
  padding-bottom: 4px;
  padding-left: 8px;
  padding-right: 8px;
  border-radius: 6px;
  margin-left: 6px;
  justify-content: center;
  align-items: center;
  flex-direction: row;
}

.bg-slate-100 {
  background-color: #f1f5f9;
}
.bg-result-defeat {
  background-color: #fdece9;
}
.bg-result-deal {
  background-color: #eaf9f1;
}
.bg-red-50 {
  background-color: #fef2f2;
}
.bg-green-50 {
  background-color: #f0fdf4;
}
.status-text {
  font-size: var(--reception-list-status-badge-font-size, 11px);
  font-weight: 500;
}
.text-slate-400 {
  color: #94a3b8;
}
.text-result-defeat {
  color: #f24724;
}
.text-result-deal {
  color: #35c376;
}
.text-red-400 {
  color: #f87171;
}
.text-green-400 {
  color: #4ade80;
}

.card-info-list {
  flex-direction: column;
  /* 移除内层块的背景色和 padding,使得内容与大标题对齐 */
  background-color: transparent;
  padding: 0;
  margin-top: 6px;
}

.info-row {
  flex-direction: row;
  justify-content: space-between;
  margin-bottom: 10px;
}

.info-row-last {
  margin-bottom: 0;
}

.info-label {
  font-size: var(--reception-list-info-label-font-size, 13px);
  color: #64748b;
  flex-shrink: 0;
}

.info-value {
  font-size: var(--reception-list-info-value-font-size, 13px);
  color: #64748b;
  font-weight: 500;
  text-align: right;
  flex: 1;
}

/* ✅ 空状态样式 */
.empty-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 400px;
}
</style>