pointsSettings.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. <template>
  2. <view class="container">
  3. <Step :step="currentStep" :stepsData="currentText" />
  4. <scroll-view class="content" scroll-y>
  5. <!-- 客户积分设置列表 -->
  6. <view class="integral-section">
  7. <view class="section-header">
  8. <view class="section-title">客户姓名</view>
  9. <view class="section-subtitle">积分数值</view>
  10. </view>
  11. <view class="integral-list">
  12. <view class="integral-item" v-for="(customer, index) in customerList" :key="customer.id">
  13. <view class="customer-info">
  14. <view class="customer-name">{{ customer.name }}</view>
  15. </view>
  16. <view class="integral-input-wrapper">
  17. <input class="integral-input" type="number" :placeholder="customer.placeholder"
  18. v-model="customer.integral" :disabled="customer.disabled"
  19. @input="onIntegralInput(customer)" />
  20. <view v-if="customer.integral" class="clear-icon-wrapper"
  21. @click.stop="clearIntegral(customer)">
  22. <image class="clear-icon" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_clear.png"></image>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </view>
  28. </scroll-view>
  29. <!-- 概览悬浮按钮 -->
  30. <view class="suspension" @click="showOverviewPopup">概览</view>
  31. <!-- 概览弹窗 -->
  32. <!-- :show="showOverview" -->
  33. <u-popup :show="showOverview" mode="bottom" @close="closeOverviewPopup" round="20" :safeAreaInsetBottom="true">
  34. <view class="overview-popup">
  35. <!-- 弹窗头部 -->
  36. <view class="popup-header">
  37. <text class="popup-title">概览</text>
  38. <view class="close-btn" @click="closeOverviewPopup">
  39. <image class="close-icon" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_close.png"></image>
  40. </view>
  41. </view>
  42. <!-- 任务信息 -->
  43. <view class="overview-section">
  44. <view class="row">
  45. <text class="line"></text>
  46. <view class="section-title">任务信息</view>
  47. </view>
  48. <view class="info-list">
  49. <view class="info-item">
  50. <view class="info-label">项目归属:</view>
  51. <view class="info-value">{{ taskFormData.belongTypeDisplayText || '-' }}</view>
  52. </view>
  53. <view class="info-item">
  54. <view class="info-label">任务类型:</view>
  55. <view class="info-value">{{ taskFormData.taskTypeDisplayText || '-' }}</view>
  56. </view>
  57. <view class="info-item">
  58. <view class="info-label">项目时间:</view>
  59. <view class="info-value">{{ taskFormData.planStartTime ? taskFormData.planStartTime.replace(/-/g, '/') : '-' }} ~ {{ taskFormData.planEndTime ? taskFormData.planEndTime.replace(/-/g, '/') : '-' }}</view>
  60. </view>
  61. </view>
  62. </view>
  63. <!-- 客户信息 -->
  64. <view class="overview-section">
  65. <view class="row">
  66. <text class="line"></text>
  67. <view class="section-title">客户信息</view>
  68. </view>
  69. <view class="customer-table">
  70. <!-- 表头 -->
  71. <view class="table-header">
  72. <view class="table-cell" style="flex: 1.5;">姓名</view>
  73. <view class="table-cell" style="flex: 1;">级别</view>
  74. <view class="table-cell" style="flex: 1;">积分</view>
  75. <view class="table-cell" style="flex: 2;">联系方式</view>
  76. </view>
  77. <!-- 表格内容 -->
  78. <view class="table-body">
  79. <view class="table-row" v-for="(customer, index) in customerList" :key="customer.id">
  80. <view class="table-cell" style="flex: 1.5;">{{ customer.name }}</view>
  81. <view class="table-cell" style="flex: 1;">{{ customer.level || '-' }}</view>
  82. <view class="table-cell" style="flex: 1;">{{ customer.integral || '0' }}</view>
  83. <view class="table-cell" style="flex: 2;">{{ customer.phone || customer.phonenumber || '-' }}</view>
  84. </view>
  85. </view>
  86. </view>
  87. </view>
  88. <!-- 安全区域占位 -->
  89. <view class="safe-area"></view>
  90. </view>
  91. </u-popup>
  92. <!-- 底部操作栏 -->
  93. <view class="bottom-bar">
  94. <view class="del-box" @click="deleteSelected">
  95. <image class="w40 h40" src="https://ysrw-1395926010.cos.ap-chengdu.myqcloud.com/image/icon_delete.png"></image>
  96. <text>删除</text>
  97. </view>
  98. <view class="action-buttons">
  99. <view class="btn btn-cancel" @click="handlePrev">上一步</view>
  100. <view class="btn btn-submit" @click="submit">提交</view>
  101. </view>
  102. </view>
  103. </view>
  104. </template>
  105. <script>
  106. import { checkIntegralLimit } from '@/api/task.js'
  107. import Step from '@/pages_task/components/step.vue'
  108. import { addInfo} from '@/api/task.js';
  109. export default {
  110. components: {
  111. Step
  112. },
  113. data() {
  114. return {
  115. currentText: [{
  116. id: 1,
  117. stepNumber: 1,
  118. title: '填写任务'
  119. },
  120. {
  121. id: 2,
  122. stepNumber: 2,
  123. title: '选择客户'
  124. },
  125. {
  126. id: 3,
  127. stepNumber: 3,
  128. title: '积分设置'
  129. }
  130. ],
  131. currentStep: 3,
  132. showOverview: false, // 控制概览弹窗显示
  133. customerList: [],
  134. userInfo: uni.getStorageSync('userInfo'),
  135. taskFormData: {}, // 任务表单数据
  136. selectedCustomers: [] // 选中的客户数据
  137. }
  138. },
  139. onLoad() {
  140. // 从本地存储中获取任务表单数据
  141. const taskFormDataStr = uni.getStorageSync('taskFormData')
  142. if (taskFormDataStr) {
  143. try {
  144. this.taskFormData = JSON.parse(taskFormDataStr)
  145. } catch (e) {
  146. console.error('解析任务表单数据失败:', e)
  147. }
  148. }
  149. // 从本地存储中获取选中的客户数据
  150. const selectedCustomersData = uni.getStorageSync('selectedCustomers')
  151. if (selectedCustomersData) {
  152. try {
  153. const selectedCustomers = typeof selectedCustomersData === 'string' ? JSON.parse(selectedCustomersData) : selectedCustomersData
  154. // 确保selectedCustomers是数组
  155. if (Array.isArray(selectedCustomers)) {
  156. // 保存原始选中的客户数据
  157. this.selectedCustomers = selectedCustomers
  158. // 将选中的客户数据转换为积分设置需要的格式
  159. this.customerList = selectedCustomers.map(customer => ({
  160. id: customer.id,
  161. name: customer.doctorName || '未知姓名',
  162. doctorName: customer.doctorName || '未知姓名',
  163. integral: '',
  164. placeholder: '请输入积分',
  165. disabled: false
  166. }))
  167. }
  168. this.checkIntegralLimitApi();//检查积分是否超出限制
  169. } catch (e) {
  170. console.error('解析客户数据失败:', e)
  171. }
  172. }
  173. },
  174. computed: {
  175. totalIntegral() {
  176. let total = 0
  177. this.customerList.forEach(customer => {
  178. const integral = parseInt(customer.integral) || 0
  179. total += integral
  180. })
  181. return total
  182. }
  183. },
  184. methods: {
  185. checkIntegralLimitApi(){
  186. let params = {
  187. companyId: this.userInfo.companyId,
  188. projectId: this.userInfo.projectId,
  189. doctorId: this.userInfo.userId,
  190. pointNum: this.totalIntegral
  191. }
  192. checkIntegralLimit(params).then(res => {
  193. if (res.code === 200 && res.data) {
  194. // 将接口返回的数据映射为页面需要的格式
  195. this.customerList = res.rows;
  196. }
  197. })
  198. },
  199. // 显示概览弹窗
  200. showOverviewPopup() {
  201. this.showOverview = true
  202. },
  203. // 关闭概览弹窗
  204. closeOverviewPopup() {
  205. this.showOverview = false
  206. },
  207. clearIntegral(customer) {
  208. // 使用 $set 确保响应式更新
  209. this.$set(customer, 'integral', '')
  210. },
  211. onIntegralInput(customer) {
  212. // 积分输入验证
  213. if (customer.integral && parseInt(customer.integral) < 0) {
  214. this.$set(customer, 'integral', '0')
  215. }
  216. },
  217. handlePrev() {
  218. uni.navigateBack()
  219. },
  220. submit() {
  221. // 验证所有客户积分是否已填写
  222. const emptyCustomers = this.customerList.filter(customer => !customer.integral || customer.integral === '')
  223. if (emptyCustomers.length > 0) {
  224. uni.showToast({
  225. icon: 'none',
  226. title: '请为所有客户设置积分'
  227. })
  228. return
  229. }
  230. // 验证积分是否为数字
  231. const invalidCustomers = this.customerList.filter(customer => {
  232. const integral = parseInt(customer.integral)
  233. return isNaN(integral) || integral < 0
  234. })
  235. if (invalidCustomers.length > 0) {
  236. uni.showToast({
  237. icon: 'none',
  238. title: '请输入有效的积分数值'
  239. })
  240. return
  241. }
  242. // 获取所有三个页面的数据
  243. const taskFormDataStr = uni.getStorageSync('taskFormData')
  244. const selectedCustomersStr = uni.getStorageSync('selectedCustomers')
  245. const taskFormData = taskFormDataStr ? JSON.parse(taskFormDataStr) : {}
  246. const selectedCustomers = selectedCustomersStr ? JSON.parse(selectedCustomersStr) : []
  247. // 获取用户信息
  248. const userInfoData = uni.getStorageSync('userInfo')
  249. const userInfo = typeof userInfoData === 'string' ? JSON.parse(userInfoData) : userInfoData || {}
  250. // 获取当前时间
  251. const now = new Date()
  252. const applyTime = now.toISOString().slice(0, 19).replace('T', ' ')
  253. // 构建提交数据
  254. const taskData = {
  255. // 任务基本信息
  256. // taskName: taskFormData.taskName || '',
  257. deptId: taskFormData.deptId || 0,
  258. projectId: taskFormData.projectId || 0,
  259. costShareId: taskFormData.costShareId || 0,
  260. taskType: taskFormData.taskType || 0,
  261. taskIntegral: this.totalIntegral || 0,
  262. taskUnit: taskFormData.taskUnit || 0,
  263. productId: taskFormData.productId || 0,
  264. planStartTime: taskFormData.planStartTime || '',
  265. planEndTime: taskFormData.planEndTime || '',
  266. // applyTime: applyTime,
  267. belongType: taskFormData.belongType || 0,
  268. companyId: userInfo.companyId || 0,
  269. companyUserId: userInfo.userId || 0,
  270. remark: taskFormData.remark || '',
  271. // companyUserId: taskFormData.companyUserId || 0,
  272. // 构建doctorIds数组
  273. // doctorIds: this.customerList.map(customer => parseInt(customer.id) || 0),
  274. // 构建doctorTaskList数组
  275. doctorTaskList: this.customerList.map(customer => ({
  276. doctorId: parseInt(customer.id) || 0,
  277. taskIntegral: parseInt(customer.integral) || 0
  278. }))
  279. }
  280. console.log('提交的任务数据:', taskData)
  281. // 调用addInfo接口提交表单
  282. uni.showLoading({
  283. title: '提交中...'
  284. })
  285. addInfo(taskData).then(res => {
  286. uni.hideLoading()
  287. if (res.code === 200) {
  288. // 清除本地存储的数据
  289. uni.removeStorageSync('taskFormData')
  290. uni.removeStorageSync('selectedCustomers')
  291. // 显示提交成功提示
  292. uni.showToast({
  293. title: '任务创建成功',
  294. success: () => {
  295. // 延迟跳转,让用户看到成功提示
  296. setTimeout(() => {
  297. uni.navigateTo({
  298. url: '/pages_task/success'
  299. })
  300. }, 1500)
  301. }
  302. })
  303. } else {
  304. uni.showToast({
  305. icon: 'none',
  306. title: res.message || '提交失败'
  307. })
  308. }
  309. }).catch(err => {
  310. uni.hideLoading()
  311. uni.showToast({
  312. icon: 'none',
  313. title: '网络错误,请重试'
  314. })
  315. })
  316. },
  317. deleteSelected() {
  318. // 删除所有客户数据
  319. uni.showModal({
  320. title: '提示',
  321. content: '确定要删除所有客户数据吗?删除后不可恢复。',
  322. success: (res) => {
  323. if (res.confirm) {
  324. // 清空所有客户的积分数据
  325. this.customerList.forEach(customer => {
  326. this.$set(customer, 'integral', '')
  327. })
  328. uni.showToast({
  329. title: '已清空所有客户积分',
  330. icon: 'success'
  331. })
  332. }
  333. }
  334. })
  335. }
  336. }
  337. }
  338. </script>
  339. <style lang="scss" scoped>
  340. .container {
  341. min-height: 100vh;
  342. background: #F7F8FA;
  343. display: flex;
  344. flex-direction: column;
  345. &::before {
  346. content: '';
  347. position: absolute;
  348. top: 0;
  349. left: 0;
  350. right: 0;
  351. width: 100%;
  352. height: 544rpx;
  353. background: linear-gradient(180deg, #E4EFFE 0%, rgba(228, 239, 254, 0) 100%);
  354. }
  355. }
  356. .content {
  357. flex: 1;
  358. padding: 24rpx;
  359. box-sizing: border-box;
  360. padding-bottom: 200rpx;
  361. position: relative;
  362. }
  363. .integral-section {
  364. background-color: #ffffff;
  365. border-radius: 24rpx;
  366. padding: 32rpx 24rpx;
  367. margin-bottom: 24rpx;
  368. .section-header {
  369. display: flex;
  370. justify-content: space-between;
  371. align-items: center;
  372. margin-bottom: 32rpx;
  373. padding: 32rpx 0;
  374. background: #F5F9FF;
  375. border-radius: 16rpx;
  376. font-size: 28rpx;
  377. color: #666666;
  378. text-align: center;
  379. font-weight: 600;
  380. .section-title {
  381. flex: 1;
  382. }
  383. .section-subtitle {
  384. flex: 1;
  385. }
  386. }
  387. .integral-list {
  388. .integral-item {
  389. display: flex;
  390. justify-content: space-between;
  391. align-items: center;
  392. padding: 32rpx 0;
  393. border-bottom: 1rpx solid #F2F3F5;
  394. &:last-child {
  395. border-bottom: none;
  396. }
  397. .customer-info {
  398. flex: 1;
  399. text-align: center;
  400. .customer-name {
  401. font-size: 32rpx;
  402. font-weight: 500;
  403. color: #333333;
  404. }
  405. }
  406. .integral-input-wrapper {
  407. flex: 1;
  408. display: flex;
  409. align-items: center;
  410. justify-content: center;
  411. position: relative;
  412. .integral-input {
  413. width: 100%;
  414. font-size: 32rpx;
  415. color: #333333;
  416. text-align: center;
  417. padding: 12rpx 60rpx 12rpx 16rpx;
  418. background: #F7F8FA;
  419. border-radius: 8rpx;
  420. &::placeholder {
  421. color: #C8C9CC;
  422. font-size: 28rpx;
  423. text-align: center;
  424. }
  425. &:disabled {
  426. background: transparent;
  427. opacity: 0.8;
  428. }
  429. }
  430. .clear-icon-wrapper {
  431. position: absolute;
  432. right: 8rpx;
  433. width: 48rpx;
  434. height: 48rpx;
  435. display: flex;
  436. align-items: center;
  437. justify-content: center;
  438. z-index: 10;
  439. cursor: pointer;
  440. &:active {
  441. opacity: 0.6;
  442. }
  443. .clear-icon {
  444. width: 28rpx;
  445. height: 28rpx;
  446. }
  447. }
  448. }
  449. }
  450. }
  451. }
  452. .suspension {
  453. position: fixed;
  454. text-align: center;
  455. line-height: 96rpx;
  456. right: 36rpx;
  457. top: 70%;
  458. width: 96rpx;
  459. height: 96rpx;
  460. background: linear-gradient(0deg, #388BFF 0%, #388BFF 100%);
  461. box-shadow: inset 0rpx 4rpx 8rpx 0rpx rgba(255, 255, 255, 0.25),
  462. inset 0rpx -6rpx 8rpx 0rpx rgba(255, 255, 255, 0.25),
  463. 4rpx 8rpx 12rpx 0rpx rgba(88, 144, 239, 0.29);
  464. border-radius: 110rpx;
  465. font-size: 28rpx;
  466. color: #FFFFFF;
  467. z-index: 999;
  468. cursor: pointer;
  469. &:active {
  470. opacity: 0.8;
  471. }
  472. }
  473. /* 概览弹窗样式 */
  474. .overview-popup {
  475. background-color: #fff;
  476. border-radius: 32rpx 32rpx 0 0;
  477. max-height: 80vh;
  478. overflow-y: auto;
  479. padding-bottom: env(safe-area-inset-bottom);
  480. }
  481. .popup-header {
  482. display: flex;
  483. justify-content: center;
  484. align-items: center;
  485. padding: 32rpx 40rpx;
  486. .popup-title {
  487. font-weight: 500;
  488. font-size: 32rpx;
  489. color: #333333;
  490. }
  491. .close-btn {
  492. width: 48rpx;
  493. height: 48rpx;
  494. display: flex;
  495. align-items: center;
  496. justify-content: center;
  497. cursor: pointer;
  498. position: absolute;
  499. right: 0;
  500. .close-icon {
  501. width: 44rpx;
  502. height: 44rpx;
  503. margin-right: 32rpx;
  504. flex-shrink: 0;
  505. }
  506. &:active {
  507. opacity: 0.6;
  508. }
  509. }
  510. }
  511. .overview-section {
  512. padding: 32rpx 40rpx;
  513. .row {
  514. display: flex;
  515. align-items: center;
  516. margin-bottom: 24rpx;
  517. &:last-child {
  518. border-bottom: none;
  519. }
  520. .line {
  521. width: 6rpx;
  522. height: 32rpx;
  523. background: #388BFF;
  524. border-radius: 36rpx;
  525. margin-right: 20rpx;
  526. }
  527. .section-title {
  528. font-size: 28rpx;
  529. font-weight: 600;
  530. color: #333333;
  531. }
  532. }
  533. .info-list {
  534. .info-item {
  535. display: flex;
  536. margin-bottom: 16rpx;
  537. align-items: flex-start;
  538. font-size: 28rpx;
  539. &:last-child {
  540. margin-bottom: 0;
  541. }
  542. .info-label {
  543. color: #999999;
  544. flex-shrink: 0;
  545. width: 140rpx;
  546. }
  547. .info-value {
  548. color: #333333;
  549. flex: 1;
  550. line-height: 1.4;
  551. }
  552. }
  553. }
  554. .customer-table {
  555. .table-header {
  556. display: flex;
  557. background: #F5F9FF;
  558. border-radius: 8rpx;
  559. padding: 20rpx 16rpx;
  560. margin-bottom: 8rpx;
  561. .table-cell {
  562. font-size: 24rpx;
  563. font-weight: 600;
  564. color: #666666;
  565. text-align: center;
  566. }
  567. }
  568. .table-body {
  569. .table-row {
  570. display: flex;
  571. padding: 20rpx 16rpx;
  572. border-bottom: 1rpx solid #F2F3F5;
  573. &:last-child {
  574. border-bottom: none;
  575. }
  576. .table-cell {
  577. font-size: 28rpx;
  578. color: #333333;
  579. text-align: center;
  580. &:first-child {
  581. font-weight: 500;
  582. }
  583. }
  584. }
  585. }
  586. }
  587. }
  588. .total-section {
  589. padding: 32rpx 40rpx;
  590. background: #F5F9FF;
  591. border-radius: 16rpx;
  592. margin: 24rpx 40rpx 40rpx;
  593. .total-item {
  594. display: flex;
  595. justify-content: space-between;
  596. align-items: center;
  597. margin-bottom: 16rpx;
  598. &:last-child {
  599. margin-bottom: 0;
  600. }
  601. .total-label {
  602. font-size: 28rpx;
  603. color: #666666;
  604. }
  605. .total-value {
  606. font-size: 28rpx;
  607. font-weight: 600;
  608. color: #388BFF;
  609. }
  610. }
  611. }
  612. .safe-area {
  613. height: env(safe-area-inset-bottom);
  614. }
  615. .bottom-bar {
  616. position: fixed;
  617. bottom: 0;
  618. left: 0;
  619. right: 0;
  620. background: #fff;
  621. padding: 24rpx 32rpx;
  622. border-top: 1rpx solid #F2F3F5;
  623. z-index: 100;
  624. display: flex;
  625. align-items: center;
  626. .del-box {
  627. display: flex;
  628. flex-direction: column;
  629. align-items: center;
  630. font-size: 24rpx;
  631. color: #666666;
  632. margin-right: 32rpx;
  633. cursor: pointer;
  634. &:active {
  635. opacity: 0.6;
  636. }
  637. }
  638. .action-buttons {
  639. display: flex;
  640. flex: 1;
  641. justify-content: space-between;
  642. .btn {
  643. width: 292rpx;
  644. height: 88rpx;
  645. display: flex;
  646. align-items: center;
  647. justify-content: center;
  648. font-size: 32rpx;
  649. font-weight: 500;
  650. border-radius: 200rpx 200rpx 200rpx 200rpx;
  651. cursor: pointer;
  652. &.btn-cancel {
  653. background: #fff;
  654. border: 2rpx solid #388BFF;
  655. color: #388BFF;
  656. }
  657. &.btn-submit {
  658. background: #388BFF;
  659. color: #fff;
  660. }
  661. }
  662. }
  663. }
  664. .w40 {
  665. width: 40rpx;
  666. }
  667. .h40 {
  668. height: 40rpx;
  669. }
  670. </style>