selectCustomer.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_clear.png" v-if="searchKeyword"
  12. @click="clearSearch"></image>
  13. </view>
  14. <view class="section-title">已选择 {{ selectedCustomers.length||'0' }} 人:</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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/my_heads_icon.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="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/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. let params = {
  114. companyId: uni.getStorageSync('userInfo').companyId
  115. }
  116. // 调用speakerList接口获取数据
  117. const res = await speakerList(params)
  118. if (res.code === 200 && res.rows) {
  119. // 将接口返回的数据映射为页面需要的格式
  120. this.customerList = res.rows;
  121. }
  122. } catch (error) {
  123. console.error('获取客户数据失败:', error)
  124. uni.showToast({
  125. icon: 'none',
  126. title: '获取客户数据失败'
  127. })
  128. } finally {
  129. this.loading = false
  130. }
  131. },
  132. handleSearch() {
  133. // 清除之前的定时器
  134. if (this.debounceTimer) {
  135. clearTimeout(this.debounceTimer)
  136. }
  137. // 设置新的定时器,500毫秒后执行搜索
  138. this.debounceTimer = setTimeout(() => {
  139. // 搜索逻辑已经在computed中处理,这里可以添加额外的搜索逻辑
  140. console.log('执行搜索:', this.searchKeyword)
  141. }, 500)
  142. },
  143. clearSearch() {
  144. this.searchKeyword = ''
  145. },
  146. isSelected(customerId) {
  147. return this.selectedCustomers.some(customer => customer.id === customerId)
  148. },
  149. toggleCustomer(customer) {
  150. const index = this.selectedCustomers.findIndex(item => item.id === customer.id)
  151. if (index > -1) {
  152. // 已选中,移除
  153. this.selectedCustomers.splice(index, 1)
  154. } else {
  155. // 未选中,添加
  156. this.selectedCustomers.push(customer)
  157. }
  158. },
  159. removeCustomer(customerId) {
  160. const index = this.selectedCustomers.findIndex(item => item.id === customerId)
  161. if (index > -1) {
  162. this.selectedCustomers.splice(index, 1)
  163. }
  164. },
  165. deleteSelected() {
  166. if (this.selectedCustomers.length === 0) {
  167. uni.showToast({
  168. icon: 'none',
  169. title: '请先选择要删除的客户'
  170. })
  171. return
  172. }
  173. // 这里可以添加删除逻辑,比如从列表中移除已选中的客户
  174. uni.showModal({
  175. title: '提示',
  176. content: `确定要删除选中的 ${this.selectedCustomers.length} 个客户吗?`,
  177. success: (res) => {
  178. if (res.confirm) {
  179. // 从客户列表中移除已选中的客户
  180. const selectedIds = this.selectedCustomers.map(item => item.id)
  181. this.customerList = this.customerList.filter(
  182. customer => !selectedIds.includes(customer.id)
  183. )
  184. // 清空已选中的客户
  185. this.selectedCustomers = []
  186. uni.showToast({
  187. title: '删除成功'
  188. })
  189. }
  190. }
  191. })
  192. },
  193. handlePrev() {
  194. uni.navigateBack()
  195. },
  196. handleNext() {
  197. if (this.selectedCustomers.length === 0) {
  198. uni.showToast({
  199. icon: 'none',
  200. title: '请至少选择一个客户'
  201. })
  202. return
  203. }
  204. // 保存选中的客户到本地存储,以便pointsSettings.vue获取
  205. uni.setStorageSync('selectedCustomers', JSON.stringify(this.selectedCustomers))
  206. // 跳转到下一步(积分设置)
  207. uni.navigateTo({
  208. url: '/pages_task/pointsSettings'
  209. })
  210. }
  211. }
  212. }
  213. </script>
  214. <style lang="scss" scoped>
  215. .container {
  216. min-height: 100vh;
  217. background: #F7F8FA;
  218. display: flex;
  219. flex-direction: column;
  220. &::before {
  221. content: '';
  222. position: absolute;
  223. top: 0;
  224. left: 0;
  225. right: 0;
  226. width: 100%;
  227. height: 544rpx;
  228. background: linear-gradient(180deg, #E4EFFE 0%, rgba(228, 239, 254, 0) 100%);
  229. }
  230. }
  231. .step-container {
  232. display: flex;
  233. align-items: center;
  234. justify-content: center;
  235. background: #fff;
  236. padding: 32rpx 0;
  237. margin-bottom: 20rpx;
  238. .step-item {
  239. display: flex;
  240. flex-direction: column;
  241. align-items: center;
  242. position: relative;
  243. .step-number {
  244. width: 48rpx;
  245. height: 48rpx;
  246. border-radius: 50%;
  247. background: #F2F3F5;
  248. color: #C8C9CC;
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. font-size: 28rpx;
  253. font-weight: 500;
  254. margin-bottom: 8rpx;
  255. transition: all 0.3s;
  256. &.active {
  257. background: #388BFF;
  258. color: #fff;
  259. }
  260. }
  261. .step-text {
  262. font-size: 28rpx;
  263. color: #C8C9CC;
  264. transition: all 0.3s;
  265. &.active {
  266. color: #388BFF;
  267. font-weight: 500;
  268. }
  269. }
  270. &.active {
  271. .step-number {
  272. background: #388BFF;
  273. color: #fff;
  274. }
  275. .step-text {
  276. color: #388BFF;
  277. font-weight: 500;
  278. }
  279. }
  280. }
  281. .step-divider {
  282. width: 80rpx;
  283. height: 2rpx;
  284. background: #EBEDF0;
  285. margin: 0 20rpx;
  286. }
  287. }
  288. .content {
  289. flex: 1;
  290. padding: 24rpx;
  291. box-sizing: border-box;
  292. padding-bottom: 200rpx;
  293. }
  294. .search-section {
  295. background-color: #ffffff;
  296. border-radius: 24rpx 24rpx 24rpx 24rpx;
  297. padding: 24rpx;
  298. margin-bottom: 24rpx;
  299. .section-title {
  300. font-size: 24rpx;
  301. color: #999999;
  302. margin-bottom: 24rpx;
  303. }
  304. .selected-tags {
  305. display: flex;
  306. flex-wrap: wrap;
  307. gap: 16rpx;
  308. .selected-tag {
  309. display: flex;
  310. align-items: center;
  311. border-radius: 76rpx 76rpx 76rpx 76rpx;
  312. border: 2rpx solid #F5F5F5;
  313. padding: 12rpx 24rpx;
  314. font-size: 28rpx;
  315. .tag-name {
  316. color: #333;
  317. margin-right: 8rpx;
  318. }
  319. .tag-remove {
  320. color: #C8C9CC;
  321. font-size: 36rpx;
  322. line-height: 1;
  323. cursor: pointer;
  324. }
  325. }
  326. }
  327. .search-input-wrapper {
  328. background: #F7F8FA;
  329. border-radius: 38rpx 38rpx 38rpx 38rpx;
  330. position: relative;
  331. display: flex;
  332. align-items: center;
  333. padding: 0 28rpx;
  334. height: 72rpx;
  335. margin-bottom: 24rpx;
  336. .search-icon {
  337. width: 36rpx;
  338. height: 36rpx;
  339. margin-right: 16rpx;
  340. }
  341. .search-input {
  342. flex: 1;
  343. height: 100%;
  344. font-size: 28rpx;
  345. color: #333;
  346. }
  347. .clear-icon {
  348. width: 32rpx;
  349. height: 32rpx;
  350. margin-left: 16rpx;
  351. }
  352. }
  353. }
  354. .customer-list {
  355. .customer-item {
  356. border-radius: 24rpx 24rpx 24rpx 24rpx;
  357. display: flex;
  358. align-items: center;
  359. justify-content: space-between;
  360. padding: 32rpx;
  361. margin-bottom: 12rpx;
  362. background-color: #ffffff;
  363. cursor: pointer;
  364. transition: all 0.3s;
  365. &.active {
  366. background: rgba(56,139,255,0.06);
  367. }
  368. &:last-child {
  369. margin-bottom: 0;
  370. }
  371. .left {
  372. display: flex;
  373. align-items: center;
  374. .head {
  375. width: 88rpx;
  376. height: 88rpx;
  377. border-radius: 50%;
  378. margin-right: 24rpx;
  379. }
  380. .customer-info {
  381. flex: 1;
  382. .customer-header {
  383. display: flex;
  384. align-items: center;
  385. margin-bottom: 12rpx;
  386. .customer-name {
  387. font-weight: 500;
  388. font-size: 32rpx;
  389. color: #333333;
  390. margin-right: 16rpx;
  391. }
  392. .customer-level {
  393. font-size: 24rpx;
  394. color: #C89743;
  395. background: #FFF6E5;
  396. border-radius: 8rpx;
  397. padding: 4rpx 12rpx;
  398. }
  399. }
  400. .customer-details {
  401. display: flex;
  402. align-items: center;
  403. .customer-hospital {
  404. font-size: 28rpx;
  405. color: #666;
  406. margin-right: 24rpx;
  407. border-right: 2rpx solid #EAEBEE;
  408. padding-right: 24rpx;
  409. }
  410. .customer-department {
  411. font-size: 28rpx;
  412. color: #666;
  413. }
  414. }
  415. }
  416. }
  417. }
  418. }
  419. .bottom-bar {
  420. position: fixed;
  421. bottom: 0;
  422. left: 0;
  423. right: 0;
  424. background: #fff;
  425. padding: 24rpx 32rpx;
  426. border-top: 1rpx solid #F2F3F5;
  427. z-index: 100;
  428. display: flex;
  429. align-items: center;
  430. .del-box {
  431. display: flex;
  432. flex-direction: column;
  433. align-items: center;
  434. font-size: 24rpx;
  435. color: #666666;
  436. margin-right: 32rpx;
  437. cursor: pointer;
  438. }
  439. .action-buttons {
  440. display: flex;
  441. flex: 1;
  442. justify-content: space-between;
  443. .btn {
  444. width: 292rpx;
  445. height: 88rpx;
  446. display: flex;
  447. align-items: center;
  448. justify-content: center;
  449. font-size: 32rpx;
  450. font-weight: 500;
  451. border-radius: 200rpx 200rpx 200rpx 200rpx;
  452. cursor: pointer;
  453. &.btn-cancel {
  454. background: #fff;
  455. border: 2rpx solid #388BFF;
  456. color: #388BFF;
  457. }
  458. &.btn-submit {
  459. background: #388BFF;
  460. color: #fff;
  461. }
  462. }
  463. }
  464. }
  465. </style>