team-customers.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <view class="page-team-customers">
  3. <view class="page-header">
  4. <text class="header-title">团队客户</text>
  5. <text class="header-subtitle">查看上级供应商下的客户归属</text>
  6. </view>
  7. <view class="content-area">
  8. <view v-if="isLoading" class="loading-indicator">
  9. <image class="loading-avatar" src="/static/images/avatar_default.png" mode="aspectFill"></image>
  10. <text class="loading-text">加载中...</text>
  11. </view>
  12. <view v-else class="customer-list">
  13. <!-- 状态筛选 Tab -->
  14. <view class="status-tabs" v-if="statusOptions.length > 0">
  15. <view
  16. class="status-tab"
  17. v-for="(option, index) in statusOptions"
  18. :key="index"
  19. :class="{ 'status-tab-active': status === option.key }"
  20. @click="handleStatusChange(option.key)"
  21. >
  22. <text>{{ option.label }}</text>
  23. </view>
  24. </view>
  25. <!-- 列表区域 -->
  26. <view v-else>
  27. <view class="no-data" v-if="filteredCustomers.length === 0">
  28. <view class="empty-state">
  29. <image src="/static/images/icon_empty_state.png" class="empty-icon"></image>
  30. <text>暂无客户数据</text>
  31. </view>
  32. </view>
  33. <view class="customer-item" v-for="customer in filteredCustomers" :key="customer.id">
  34. <view class="customer-avatar-wrap">
  35. <image
  36. v-if="customer.avatar"
  37. class="customer-avatar-img"
  38. :src="customer.avatar"
  39. mode="aspectFill"></image>
  40. <text v-else class="customer-avatar-icon">👤</text>
  41. </view>
  42. <view class="customer-info">
  43. <view class="customer-name">{{ customer.nickname || '微信用户' }}</view>
  44. <view class="customer-meta">
  45. <text class="member-type">{{ customer.memberType || '本地用户' }}</text>
  46. <text class="join-time">{{ formatJoinTime(customer.joinTime) }}</text>
  47. </view>
  48. </view>
  49. <view class="customer-right">
  50. <view class="order-count">
  51. <text>{{ customer.orderCount || 0 }}</text>
  52. <text>订单</text>
  53. </view>
  54. <view class="source-tag" :class="getSourceTagClass(customer.source)">
  55. <text>{{ getSourceTagLabel(customer.source) }}</text>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- 加载更多 -->
  60. <view class="load-more" v-if="hasMore && !loading">
  61. <view @click="loadMore" class="load-more-btn">
  62. <text>加载更多</text>
  63. <image v-if="loadingMore" src="/static/images/arrow_down.png" class="spinner"></image>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </template>
  71. <script>
  72. export default {
  73. data() {
  74. return {
  75. // 页面状态
  76. status: 'all', // all | referred | order | manual
  77. page: 1,
  78. hasMore: true,
  79. loading: false,
  80. refreshing: false,
  81. // 数据
  82. customers: [], // 所有客户列表
  83. filteredCustomers: [], // 筛选后的客户列表
  84. statusOptions: [ // 筛选选项
  85. { key: 'all', label: '全部' },
  86. { key: 'referred', label: '推荐人' },
  87. { key: 'order', label: '下单' },
  88. { key: 'manual', label: '人工' }
  89. ],
  90. // 查询参数
  91. systemId: '', // 供应商体系ID
  92. parentId: '' // 上级供应商用户ID
  93. }
  94. },
  95. onLoad(options) {
  96. // 从路由参数获取系统ID和上级用户ID
  97. this.systemId = options.systemId || ''
  98. this.parentId = options.parentId || ''
  99. this.loadCustomers()
  100. this._onLoadFired = true
  101. },
  102. onShow() {
  103. if (this._onLoadFired) {
  104. // 首次进入:onLoad 已加载,跳过避免双发
  105. this._onLoadFired = false
  106. } else {
  107. // 切Tab返回时刷新
  108. this.page = 1
  109. this.customers = []
  110. this.hasMore = true
  111. this.loadCustomers()
  112. }
  113. },
  114. methods: {
  115. // 加载客户列表
  116. async loadCustomers() {
  117. if (this.loading || this.refreshing) return
  118. this.loading = true
  119. try {
  120. // 并发请求:获取客户列表 + 获取统计概览
  121. var res = await this.$http.getTeamCustomers({
  122. systemId: this.systemId,
  123. parentId: this.parentId,
  124. page: this.page,
  125. size: 20
  126. })
  127. if (res && res.data) {
  128. this.customers = this.page === 1 ? res.data.records || [] : this.customers.concat(res.data.records || [])
  129. this.hasMore = (res.data.records || []).length >= 20
  130. this.page++
  131. // 计算筛选后的列表
  132. this.filteredCustomers = this.filterByStatus(this.customers, this.status)
  133. }
  134. } catch (error) {
  135. console.error('获取团队客户失败:', error)
  136. } finally {
  137. this.loading = false
  138. this.refreshing = false
  139. }
  140. },
  141. // 根据状态筛选
  142. filterByStatus(customers, status) {
  143. if (status === 'all') return customers
  144. return customers.filter(c => c.source === status)
  145. },
  146. // 处理状态筛选切换
  147. handleStatusChange(key) {
  148. this.status = key
  149. this.page = 1
  150. this.customers = []
  151. this.hasMore = true
  152. this.loadCustomers()
  153. },
  154. // 加载更多
  155. async loadMore() {
  156. if (this.loading || !this.hasMore) return
  157. this.loadingMore = true
  158. try {
  159. await this.loadCustomers()
  160. } finally {
  161. this.loadingMore = false
  162. }
  163. this.$nextTick(() => {
  164. this.loadingMore = false
  165. })
  166. },
  167. // 格式化加入时间
  168. formatJoinTime(timeStr) {
  169. if (!timeStr) return '-'
  170. var d = this.parseDate(timeStr)
  171. return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0')
  172. },
  173. // 获取来源标签样式
  174. getSourceTagClass(source) {
  175. const classes = {
  176. 'manual': 'tag-manual',
  177. 'order': 'tag-order',
  178. 'referral': 'tag-referral'
  179. }
  180. return classes[source] || 'tag-default'
  181. },
  182. // 获取来源标签文字
  183. getSourceTagLabel(source) {
  184. const labels = {
  185. 'manual': '人工绑定',
  186. 'order': '下单自动',
  187. 'referral': '推荐码'
  188. }
  189. return labels[source] || source
  190. }
  191. }
  192. }
  193. </script>
  194. <style>
  195. /* 页面整体样式 */
  196. .page-team-customers {
  197. background-color: #FFF7ED;
  198. min-height: 100vh;
  199. }
  200. /* 页面头部 */
  201. .page-header {
  202. padding: 24rpx 30rpx;
  203. background-color: #fff;
  204. border-bottom: 1rpx solid #FED7AA;
  205. display: flex;
  206. justify-content: space-between;
  207. align-items: center;
  208. }
  209. .header-title {
  210. font-size: 32rpx;
  211. font-weight: bold;
  212. color: #333333;
  213. }
  214. .header-subtitle {
  215. font-size: 20rpx;
  216. color: #94A3B8;
  217. }
  218. /* 内容区 */
  219. .content-area {
  220. padding: 0 30rpx 30rpx;
  221. }
  222. /* 状态筛选 Tab */
  223. .status-tabs {
  224. display: flex;
  225. background-color: #F5FAFE;
  226. border-radius: 20rpx;
  227. padding: 6rpx 12rpx;
  228. margin-bottom: 24rpx;
  229. }
  230. .status-tab {
  231. padding: 10rpx 20rpx;
  232. font-size: 24rpx;
  233. color: #666666;
  234. text-align: center;
  235. }
  236. .status-tab-active {
  237. color: #F97316;
  238. border-bottom: 2rpx solid #F97316;
  239. }
  240. /* 列表项 */
  241. .customer-item {
  242. background-color: #fff;
  243. border-radius: 20rpx;
  244. padding: 24rpx;
  245. margin-bottom: 24rpx;
  246. box-shadow: 0 2rpx 12rpx rgba(249,115,22,0.08);
  247. display: flex;
  248. align-items: center;
  249. }
  250. .customer-avatar-wrap {
  251. width: 64rpx;
  252. height: 64rpx;
  253. border-radius: 50%;
  254. margin-right: 24rpx;
  255. position: relative;
  256. }
  257. .customer-avatar-img {
  258. width: 100%;
  259. height: 100%;
  260. border-radius: 50%;
  261. object-fit: cover;
  262. }
  263. .customer-avatar-icon {
  264. width: 100%;
  265. height: 100%;
  266. border-radius: 50%;
  267. background-color: #F5FAFE;
  268. display: flex;
  269. align-items: center;
  270. justify-content: center;
  271. color: #94A3B8;
  272. font-size: 32rpx;
  273. }
  274. .customer-info {
  275. flex: 1;
  276. }
  277. .customer-name {
  278. font-size: 28rpx;
  279. color: #333333;
  280. white-space: nowrap;
  281. overflow: hidden;
  282. text-overflow: ellipsis;
  283. }
  284. .member-type {
  285. font-size: 20rpx;
  286. color: #94A3B8;
  287. margin-top: 4rpx;
  288. }
  289. .join-time {
  290. font-size: 20rpx;
  291. color: #B5B5B5;
  292. }
  293. /* 右侧信息 */
  294. .customer-right {
  295. flex-shrink: 0;
  296. text-align: right;
  297. margin-left: 24rpx;
  298. }
  299. .order-count {
  300. margin-bottom: 8rpx;
  301. }
  302. .order-count .number {
  303. font-size: 32rpx;
  304. font-weight: bold;
  305. color: #F97316;
  306. }
  307. .order-count .label {
  308. font-size: 20rpx;
  309. color: #666666;
  310. }
  311. /* 来源标签 */
  312. .source-tag {
  313. padding: 4rpx 12rpx;
  314. border-radius: 12rpx;
  315. font-size: 16rpx;
  316. margin-top: 4rpx;
  317. }
  318. .tag-manual {
  319. background-color: #E6F7EE;
  320. color: #65C29A;
  321. }
  322. .tag-order {
  323. background-color: #FFF7EE;
  324. color: #F97316;
  325. }
  326. .tag-referral {
  327. background-color: #EEF8FF;
  328. color: #2F5496;
  329. }
  330. .tag-default {
  331. background-color: #F5FAFE;
  332. color: #666666;
  333. }
  334. /* 加载更多 */
  335. .load-more {
  336. padding: 24rpx;
  337. text-align: center;
  338. color: #94A3B8;
  339. font-size: 24rpx;
  340. }
  341. /* 加载更多按钮 */
  342. .load-more-btn {
  343. display: inline-flex;
  344. align-items: center;
  345. justify-content: center;
  346. width: 120rpx;
  347. height: 40rpx;
  348. border: 1rpx solid #FED7AA;
  349. border-radius: 20rpx;
  350. color: #666666;
  351. font-size: 24rpx;
  352. }
  353. .load-more-btn .spinner {
  354. width: 16rpx;
  355. height: 16rpx;
  356. margin-left: 6rpx;
  357. animation: spin 0.8s linear infinite;
  358. }
  359. @keyframes spin {
  360. from { transform: rotate(0deg); }
  361. to { transform: rotate(360deg); }
  362. }
  363. /* 空状态 */
  364. .no-data .empty-state {
  365. text-align: center;
  366. padding: 80rpx 30rpx;
  367. color: #94A3B8;
  368. }
  369. .empty-icon {
  370. width: 64rpx;
  371. height: 64rpx;
  372. margin: 0 auto 12rpx;
  373. display: block;
  374. }
  375. </style>