selectCustomer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514
  1. <template>
  2. <view class="container">
  3. <Step :step="currentStep" :stepsData="currentText" />
  4. <scroll-view class="content" scroll-y>
  5. <!-- 搜索栏 -->
  6. <view class="search-section">
  7. <view class="search-input-wrapper">
  8. <image class="search-icon" src="/static/image/icon_search.png"></image>
  9. <input class="search-input" type="text" placeholder="输入客户名称" v-model="searchKeyword"
  10. @input="handleSearch" />
  11. <image class="clear-icon" src="/static/image/icon_clear.png" v-if="searchKeyword"
  12. @click="clearSearch"></image>
  13. </view>
  14. <view class="section-title">已选择 {{ selectedCustomers.length }} 人:</view>
  15. <view class="selected-tags">
  16. <view class="selected-tag" v-for="(customer, index) in selectedCustomers" :key="customer.id">
  17. <text class="tag-name">{{ customer.doctorName }}</text>
  18. <text class="tag-remove" @click="removeCustomer(customer.id)">×</text>
  19. </view>
  20. </view>
  21. </view>
  22. <!-- 已选择客户 -->
  23. <view class="selected-section">
  24. </view>
  25. <!-- 客户列表 -->
  26. <view class="customer-list">
  27. <view class="customer-item" :class="{ active: isSelected(customer.id) }"
  28. v-for="(customer, index) in filteredCustomers" :key="customer.id" @click="toggleCustomer(customer)">
  29. <view class="left">
  30. <image class="head" src="/static/image/img_avatar_client.png"></image>
  31. <view class="customer-info">
  32. <view class="customer-header">
  33. <view class="customer-name">{{ customer.doctorName }}</view>
  34. <view class="customer-level" v-if="customer.jobTitle">{{ customer.jobTitle }}</view>
  35. </view>
  36. <view class="customer-details">
  37. <view class="customer-hospital">{{ customer.cityName }}</view>
  38. <view class="customer-department">{{ customer.department }}</view>
  39. </view>
  40. </view>
  41. </view>
  42. <checkbox :value="customer.id" :checked="isSelected(customer.id)" @click.stop="toggleCustomer(customer)"
  43. color="#388BFF" />
  44. </view>
  45. </view>
  46. </scroll-view>
  47. <!-- 底部操作栏 -->
  48. <view class="bottom-bar">
  49. <view class="del-box" @click="deleteSelected">
  50. <image class="w40 h40" src="/static/image/icon_delete.png"></image>
  51. <text>删除</text>
  52. </view>
  53. <view class="action-buttons">
  54. <view class="btn btn-cancel" @click="handlePrev">上一步</view>
  55. <view class="btn btn-submit" @click="handleNext">下一步</view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import Step from '@/pages_task/components/step.vue'
  62. import { speakerList } from '@/api/speaker.js'
  63. export default {
  64. components: {
  65. Step
  66. },
  67. data() {
  68. return {
  69. currentText: [{
  70. id: 1,
  71. stepNumber: 1,
  72. title: '填写任务'
  73. },
  74. {
  75. id: 2,
  76. stepNumber: 2,
  77. title: '选择客户'
  78. },
  79. {
  80. id: 3,
  81. stepNumber: 3,
  82. title: '积分设置'
  83. }
  84. ],
  85. currentStep: 2,
  86. searchKeyword: '',
  87. selectedCustomers: [],
  88. customerList: [],
  89. loading: false,
  90. debounceTimer: null
  91. }
  92. },
  93. onLoad() {
  94. this.loadCustomerData()
  95. },
  96. computed: {
  97. filteredCustomers() {
  98. if (!this.searchKeyword.trim()) {
  99. return this.customerList
  100. }
  101. const keyword = this.searchKeyword.toLowerCase()
  102. return this.customerList.filter(customer =>
  103. (customer.doctorName && customer.doctorName.toLowerCase().includes(keyword)) ||
  104. (customer.cityName && customer.cityName.toLowerCase().includes(keyword)) ||
  105. (customer.department && customer.department.toLowerCase().includes(keyword))
  106. )
  107. }
  108. },
  109. methods: {
  110. async loadCustomerData() {
  111. try {
  112. this.loading = true
  113. // 调用speakerList接口获取数据
  114. const res = await speakerList({})
  115. if (res.code === 200 && res.rows) {
  116. // 将接口返回的数据映射为页面需要的格式
  117. this.customerList = res.rows;
  118. }
  119. } catch (error) {
  120. console.error('获取客户数据失败:', error)
  121. uni.showToast({
  122. icon: 'none',
  123. title: '获取客户数据失败'
  124. })
  125. } finally {
  126. this.loading = false
  127. }
  128. },
  129. handleSearch() {
  130. // 清除之前的定时器
  131. if (this.debounceTimer) {
  132. clearTimeout(this.debounceTimer)
  133. }
  134. // 设置新的定时器,500毫秒后执行搜索
  135. this.debounceTimer = setTimeout(() => {
  136. // 搜索逻辑已经在computed中处理,这里可以添加额外的搜索逻辑
  137. console.log('执行搜索:', this.searchKeyword)
  138. }, 500)
  139. },
  140. clearSearch() {
  141. this.searchKeyword = ''
  142. },
  143. isSelected(customerId) {
  144. return this.selectedCustomers.some(customer => customer.id === customerId)
  145. },
  146. toggleCustomer(customer) {
  147. const index = this.selectedCustomers.findIndex(item => item.id === customer.id)
  148. if (index > -1) {
  149. // 已选中,移除
  150. this.selectedCustomers.splice(index, 1)
  151. } else {
  152. // 未选中,添加
  153. this.selectedCustomers.push(customer)
  154. }
  155. },
  156. removeCustomer(customerId) {
  157. const index = this.selectedCustomers.findIndex(item => item.id === customerId)
  158. if (index > -1) {
  159. this.selectedCustomers.splice(index, 1)
  160. }
  161. },
  162. deleteSelected() {
  163. if (this.selectedCustomers.length === 0) {
  164. uni.showToast({
  165. icon: 'none',
  166. title: '请先选择要删除的客户'
  167. })
  168. return
  169. }
  170. // 这里可以添加删除逻辑,比如从列表中移除已选中的客户
  171. uni.showModal({
  172. title: '提示',
  173. content: `确定要删除选中的 ${this.selectedCustomers.length} 个客户吗?`,
  174. success: (res) => {
  175. if (res.confirm) {
  176. // 从客户列表中移除已选中的客户
  177. const selectedIds = this.selectedCustomers.map(item => item.id)
  178. this.customerList = this.customerList.filter(
  179. customer => !selectedIds.includes(customer.id)
  180. )
  181. // 清空已选中的客户
  182. this.selectedCustomers = []
  183. uni.showToast({
  184. title: '删除成功'
  185. })
  186. }
  187. }
  188. })
  189. },
  190. handlePrev() {
  191. uni.navigateBack()
  192. },
  193. handleNext() {
  194. if (this.selectedCustomers.length === 0) {
  195. uni.showToast({
  196. icon: 'none',
  197. title: '请至少选择一个客户'
  198. })
  199. return
  200. }
  201. // 保存选中的客户到本地存储,以便pointsSettings.vue获取
  202. uni.setStorageSync('selectedCustomers', JSON.stringify(this.selectedCustomers))
  203. // 跳转到下一步(积分设置)
  204. uni.navigateTo({
  205. url: '/pages_task/pointsSettings'
  206. })
  207. }
  208. }
  209. }
  210. </script>
  211. <style lang="scss" scoped>
  212. .container {
  213. min-height: 100vh;
  214. background: #F7F8FA;
  215. display: flex;
  216. flex-direction: column;
  217. &::before {
  218. content: '';
  219. position: absolute;
  220. top: 0;
  221. left: 0;
  222. right: 0;
  223. width: 100%;
  224. height: 544rpx;
  225. background: linear-gradient(180deg, #E4EFFE 0%, rgba(228, 239, 254, 0) 100%);
  226. }
  227. }
  228. .step-container {
  229. display: flex;
  230. align-items: center;
  231. justify-content: center;
  232. background: #fff;
  233. padding: 32rpx 0;
  234. margin-bottom: 20rpx;
  235. .step-item {
  236. display: flex;
  237. flex-direction: column;
  238. align-items: center;
  239. position: relative;
  240. .step-number {
  241. width: 48rpx;
  242. height: 48rpx;
  243. border-radius: 50%;
  244. background: #F2F3F5;
  245. color: #C8C9CC;
  246. display: flex;
  247. align-items: center;
  248. justify-content: center;
  249. font-size: 28rpx;
  250. font-weight: 500;
  251. margin-bottom: 8rpx;
  252. transition: all 0.3s;
  253. &.active {
  254. background: #388BFF;
  255. color: #fff;
  256. }
  257. }
  258. .step-text {
  259. font-size: 28rpx;
  260. color: #C8C9CC;
  261. transition: all 0.3s;
  262. &.active {
  263. color: #388BFF;
  264. font-weight: 500;
  265. }
  266. }
  267. &.active {
  268. .step-number {
  269. background: #388BFF;
  270. color: #fff;
  271. }
  272. .step-text {
  273. color: #388BFF;
  274. font-weight: 500;
  275. }
  276. }
  277. }
  278. .step-divider {
  279. width: 80rpx;
  280. height: 2rpx;
  281. background: #EBEDF0;
  282. margin: 0 20rpx;
  283. }
  284. }
  285. .content {
  286. flex: 1;
  287. padding: 24rpx;
  288. box-sizing: border-box;
  289. padding-bottom: 200rpx;
  290. }
  291. .search-section {
  292. background-color: #ffffff;
  293. border-radius: 24rpx 24rpx 24rpx 24rpx;
  294. padding: 24rpx;
  295. margin-bottom: 24rpx;
  296. .section-title {
  297. font-size: 24rpx;
  298. color: #999999;
  299. margin-bottom: 24rpx;
  300. }
  301. .selected-tags {
  302. display: flex;
  303. flex-wrap: wrap;
  304. gap: 16rpx;
  305. .selected-tag {
  306. display: flex;
  307. align-items: center;
  308. border-radius: 76rpx 76rpx 76rpx 76rpx;
  309. border: 2rpx solid #F5F5F5;
  310. padding: 12rpx 24rpx;
  311. font-size: 28rpx;
  312. .tag-name {
  313. color: #333;
  314. margin-right: 8rpx;
  315. }
  316. .tag-remove {
  317. color: #C8C9CC;
  318. font-size: 36rpx;
  319. line-height: 1;
  320. cursor: pointer;
  321. }
  322. }
  323. }
  324. .search-input-wrapper {
  325. background: #F7F8FA;
  326. border-radius: 38rpx 38rpx 38rpx 38rpx;
  327. position: relative;
  328. display: flex;
  329. align-items: center;
  330. padding: 0 28rpx;
  331. height: 72rpx;
  332. margin-bottom: 24rpx;
  333. .search-icon {
  334. width: 36rpx;
  335. height: 36rpx;
  336. margin-right: 16rpx;
  337. }
  338. .search-input {
  339. flex: 1;
  340. height: 100%;
  341. font-size: 28rpx;
  342. color: #333;
  343. }
  344. .clear-icon {
  345. width: 32rpx;
  346. height: 32rpx;
  347. margin-left: 16rpx;
  348. }
  349. }
  350. }
  351. .customer-list {
  352. .customer-item {
  353. border-radius: 24rpx 24rpx 24rpx 24rpx;
  354. display: flex;
  355. align-items: center;
  356. justify-content: space-between;
  357. padding: 32rpx;
  358. margin-bottom: 12rpx;
  359. background-color: #ffffff;
  360. cursor: pointer;
  361. transition: all 0.3s;
  362. &.active {
  363. background: rgba(56,139,255,0.06);
  364. }
  365. &:last-child {
  366. margin-bottom: 0;
  367. }
  368. .left {
  369. display: flex;
  370. align-items: center;
  371. .head {
  372. width: 88rpx;
  373. height: 88rpx;
  374. border-radius: 50%;
  375. margin-right: 24rpx;
  376. }
  377. .customer-info {
  378. flex: 1;
  379. .customer-header {
  380. display: flex;
  381. align-items: center;
  382. margin-bottom: 12rpx;
  383. .customer-name {
  384. font-weight: 500;
  385. font-size: 32rpx;
  386. color: #333333;
  387. margin-right: 16rpx;
  388. }
  389. .customer-level {
  390. font-size: 24rpx;
  391. color: #C89743;
  392. background: #FFF6E5;
  393. border-radius: 8rpx;
  394. padding: 4rpx 12rpx;
  395. }
  396. }
  397. .customer-details {
  398. display: flex;
  399. align-items: center;
  400. .customer-hospital {
  401. font-size: 28rpx;
  402. color: #666;
  403. margin-right: 24rpx;
  404. border-right: 2rpx solid #EAEBEE;
  405. padding-right: 24rpx;
  406. }
  407. .customer-department {
  408. font-size: 28rpx;
  409. color: #666;
  410. }
  411. }
  412. }
  413. }
  414. }
  415. }
  416. .bottom-bar {
  417. position: fixed;
  418. bottom: 0;
  419. left: 0;
  420. right: 0;
  421. background: #fff;
  422. padding: 24rpx 32rpx;
  423. border-top: 1rpx solid #F2F3F5;
  424. z-index: 100;
  425. display: flex;
  426. align-items: center;
  427. .del-box {
  428. display: flex;
  429. flex-direction: column;
  430. align-items: center;
  431. font-size: 24rpx;
  432. color: #666666;
  433. margin-right: 32rpx;
  434. cursor: pointer;
  435. }
  436. .action-buttons {
  437. display: flex;
  438. flex: 1;
  439. justify-content: space-between;
  440. .btn {
  441. width: 292rpx;
  442. height: 88rpx;
  443. display: flex;
  444. align-items: center;
  445. justify-content: center;
  446. font-size: 32rpx;
  447. font-weight: 500;
  448. border-radius: 200rpx 200rpx 200rpx 200rpx;
  449. cursor: pointer;
  450. &.btn-cancel {
  451. background: #fff;
  452. border: 2rpx solid #388BFF;
  453. color: #388BFF;
  454. }
  455. &.btn-submit {
  456. background: #388BFF;
  457. color: #fff;
  458. }
  459. }
  460. }
  461. }
  462. </style>