editSelectCustomer.vue 11 KB

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