clyy_inp.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. <template>
  2. <Form :rules="fieldConfigs" v-model="formData" ref="formRef">
  3. <template v-if="step == 1">
  4. <up-table>
  5. <up-tr>
  6. <up-th>预约开始时间</up-th>
  7. <Td field="yykssj">
  8. <SsDatetimePicker v-model="formData.yykssj" mode="datetime" :min-date="yykssjMinDate"
  9. :z-index="99999" placeholder="YYYY-MM-DD HH:mm" @change="onYykssjChange" />
  10. </Td>
  11. </up-tr>
  12. <up-tr>
  13. <up-th width="150">预约结束时间</up-th>
  14. <Td field="yyjssj">
  15. <SsDatetimePicker v-model="formData.yyjssj" mode="datetime" :min-date="yyjssjMinDate"
  16. :z-index="99999" placeholder="YYYY-MM-DD HH:mm" @change="onYyjssjChange" />
  17. </Td>
  18. </up-tr>
  19. </up-table>
  20. <!-- 车辆选择列表 -->
  21. <view class="car-list">
  22. <SsCarCard v-for="car in carList" :key="car.id" :car-data="car" :status="car.status"
  23. @select="handleCarSelect" />
  24. <!-- 加载中提示 -->
  25. <view v-if="loadingMore" class="loading-more">
  26. <text>加载中...</text>
  27. </view>
  28. </view>
  29. </template>
  30. <template v-if="step == 2">
  31. <!-- 当前车辆信息卡片 -->
  32. <view class="current-car-section">
  33. <SsCarCard
  34. v-if="selectedCar"
  35. :car-data="selectedCar"
  36. :status="selectedCar.status"
  37. />
  38. </view>
  39. <!-- 预约详情(点击已预约车辆) -->
  40. <view v-if="reservationDetail" class="reservation-detail">
  41. <up-table>
  42. <up-tr>
  43. <up-th>开始时间</up-th>
  44. <up-td>{{ formatDate(reservationDetail.kssj,'yyyy-MM-dd HH:mm:ss') }}</up-td>
  45. </up-tr>
  46. <up-tr>
  47. <up-th>结束时间</up-th>
  48. <up-td>{{ formatDate(reservationDetail.jssj,'yyyy-MM-dd HH:mm:ss') }}</up-td>
  49. </up-tr>
  50. <up-tr>
  51. <up-th>使用人</up-th>
  52. <up-td>{{ reservationDetail.ydr }}</up-td>
  53. </up-tr>
  54. <up-tr>
  55. <up-th>联系电话</up-th>
  56. <up-td>
  57. <text class="phone-link" @click="makePhoneCall(reservationDetail.ydrdh)">
  58. {{ reservationDetail.ydrdh }}
  59. </text>
  60. </up-td>
  61. </up-tr>
  62. </up-table>
  63. </view>
  64. <!-- 预约表单(点击可预约车辆) -->
  65. <view v-if="!reservationDetail" class="reservation-form">
  66. <up-table>
  67. <up-tr>
  68. <up-th>开始时间</up-th>
  69. <up-td>{{ formData.yykssj }}</up-td>
  70. </up-tr>
  71. <up-tr>
  72. <up-th>结束时间</up-th>
  73. <up-td>{{ formData.yyjssj }}</up-td>
  74. </up-tr>
  75. <up-tr>
  76. <up-th>人数</up-th>
  77. <Td field="rs">
  78. <SsInput v-model="formData.rs" placeholder="请输入人数" />
  79. </Td>
  80. </up-tr>
  81. <up-tr>
  82. <up-th>办事地点</up-th>
  83. <Td field="bsdd">
  84. <SsInput v-model="formData.bsdd" placeholder="请输入办事地点" />
  85. </Td>
  86. </up-tr>
  87. <up-tr>
  88. <up-th>事由</up-th>
  89. <Td field="sy">
  90. <SsInput v-model="formData.sy" placeholder="请输入事由" />
  91. </Td>
  92. </up-tr>
  93. </up-table>
  94. </view>
  95. </template>
  96. </Form>
  97. <SsBottom v-if="step == 2" :buttons="step2BottomButtons" @button-click="step2HandleBottomAction"></SsBottom>
  98. <!-- 确认弹窗 -->
  99. <SsConfirm
  100. :visible="showConfirm"
  101. title="预约确认"
  102. width="90%"
  103. height="42vh"
  104. @button-click="handleConfirm"
  105. >
  106. <view class="confirm-content">
  107. <view class="confirm-item">
  108. <text class="label">预约开始时间:</text>
  109. <text class="value">{{ formData.yykssj }}</text>
  110. </view>
  111. <view class="confirm-item">
  112. <text class="label">预约结束时间:</text>
  113. <text class="value">{{ formData.yyjssj }}</text>
  114. </view>
  115. <view class="confirm-item">
  116. <text class="label">人数:</text>
  117. <text class="value">{{ formData.rs }}</text>
  118. </view>
  119. <view class="confirm-item">
  120. <text class="label">办事地点:</text>
  121. <text class="value">{{ formData.bsdd }}</text>
  122. </view>
  123. <view class="confirm-item">
  124. <text class="label">事由:</text>
  125. <text class="value">{{ formData.sy }}</text>
  126. </view>
  127. </view>
  128. </SsConfirm>
  129. </template>
  130. <script setup>
  131. import { ref, onMounted, computed } from 'vue'
  132. import { onReachBottom } from '@dcloudio/uni-app'
  133. import Form from '@/components/Form/index.vue'
  134. import Td from '@/components/Td/index.vue'
  135. import SsDatetimePicker from '@/components/SsDatetimePicker/index.vue'
  136. import SsInput from '@/components/SsInput/index.vue'
  137. import SsBottom from '@/components/SsBottom/index.vue'
  138. import SsConfirm from '@/components/SsConfirm/index.vue'
  139. import SsCarCard from '@/components/SsCarCard/index.vue'
  140. import { clyyApi } from '@/api/clyy'
  141. import { commonApi } from '@/api/common'
  142. import { formatDate } from '@/utils/date'
  143. import { goBack } from '@/utils/navigation'
  144. const step = ref(1)
  145. const formRef = ref(null)
  146. const formData = ref({
  147. yykssj: '',
  148. yyjssj: '',
  149. // 预约表单数据
  150. rs: '', // 人数
  151. bsdd: '', // 办事地点
  152. sy: '' // 事由
  153. })
  154. const yykssjMinDate = ref(new Date())
  155. const yyjssjMinDate = ref(new Date() + 3600 * 1000)
  156. // 车辆列表数据
  157. const carList = ref([])
  158. // 选中的车辆
  159. const selectedCar = ref(null)
  160. // 当前查看的预约详情(点击已预约车辆时)
  161. const reservationDetail = ref(null)
  162. // 加载状态
  163. const loading = ref(false)
  164. const loadingMore = ref(false) // 加载更多状态
  165. const hasMoreData = ref(false) // 是否还有更多数据
  166. const fieldConfigs = {
  167. yykssj: {
  168. rules: [{ required: true, message: '请选择预约开始时间' }]
  169. },
  170. yyjssj: {
  171. rules: [{ required: true, message: '请选择预约结束时间' }]
  172. },
  173. rs: {
  174. rules: [{ required: true, message: '请输入人数' }]
  175. },
  176. bsdd: {
  177. rules: [{ required: true, message: '请输入办事地点' }]
  178. },
  179. sy: {
  180. rules: [{ required: true, message: '请输入事由' }]
  181. }
  182. }
  183. const onYykssjChange = (val) => {
  184. console.log('开始时间变化:', val)
  185. yyjssjMinDate.value = new Date(val)
  186. // 开始时间变化时清空结束时间
  187. if (formData.value.yyjssj) {
  188. formData.value.yyjssj = ''
  189. }
  190. }
  191. const onYyjssjChange = (val) => {
  192. console.log('结束时间变化:', val)
  193. // 结束时间变化时查询车辆(但要排除清空操作)
  194. if (val && formData.value.yykssj) {
  195. queryAvailableCars()
  196. }
  197. }
  198. // 分页相关状态
  199. const pageInfo = ref({
  200. pageNo: 1,
  201. rowNumPer: 10,
  202. total: 0
  203. })
  204. /**
  205. * 查询可用车辆(支持分页)
  206. * @param {string} startTime 开始时间
  207. * @param {string} endTime 结束时间
  208. * @param {number} pageNo 页码
  209. */
  210. const queryAvailableCars = async (startTime = null, endTime = null, pageNo = 1) => {
  211. // 如果没有传入时间参数,使用表单中的时间
  212. const queryStartTime = startTime || formData.value.yykssj
  213. const queryEndTime = endTime || formData.value.yyjssj
  214. if (!queryStartTime || !queryEndTime) {
  215. return
  216. }
  217. loading.value = true
  218. console.log('查询车辆:', {
  219. beginTime: queryStartTime,
  220. endTime: queryEndTime,
  221. pageNo: pageNo
  222. })
  223. try {
  224. // 调用PC端的cl_search接口(分页)
  225. const response = await clyyApi.cl_search({
  226. beginTime: queryStartTime,
  227. endTime: queryEndTime,
  228. pageNo: pageNo,
  229. rowNumPer: pageInfo.value.rowNumPer
  230. })
  231. console.log('response.data内容:',JSON.stringify(response.data))
  232. if (response && response.data) {
  233. // 更新分页信息
  234. if (response.wdPage) {
  235. pageInfo.value = {
  236. pageNo: response.wdPage.pageNo,
  237. rowNumPer: response.wdPage.rowNumPer,
  238. total: response.wdPage.rowNum
  239. }
  240. }
  241. // 处理返回的车辆数据,转换为SsCarCard需要的格式
  242. const processedCars = await Promise.all(response.data.data.map(async (item) => {
  243. console.log('处理车辆数据:', item)
  244. // 简单的状态判断
  245. let status = 'available' // 默认可预约
  246. // 根据PC端返回的数据判断状态
  247. if (item.zt == 1) { // 使用中
  248. status = 'reserved'
  249. } else {
  250. status = 'available'
  251. }
  252. // 获取车辆类型
  253. let carType = '车辆' // 默认类型
  254. if (item.wplbm) {
  255. try {
  256. const typeResult = await commonApi.getDictByCbNameAndValue('wplb', item.wplbm)
  257. if (typeResult && typeResult.data && typeResult.data.result && typeResult.data.result[item.wplbm]) {
  258. carType = typeResult.data.result[item.wplbm]
  259. }
  260. } catch (error) {
  261. console.warn('获取车辆类型失败:', error)
  262. }
  263. }
  264. return {
  265. id: item.wpid || item.id,
  266. plateNumber: item.mc, // 使用解码后的车辆名称
  267. seats: 7, // 默认座位数
  268. name: item.mc, // 车辆名称
  269. color: '白色', // 默认颜色
  270. type: carType, // 从后台获取的真实类型
  271. image: item.sltwj, // 使用默认图片
  272. wph: item.wph,
  273. wpcsList: item.wpcsList,
  274. wplbm: item.wplbm,
  275. wpid: item.wpid,
  276. status: status,
  277. // 如果是已预约状态,添加预约信息
  278. // reservationInfo: status === 'reserved' ? {
  279. // startTime: queryStartTime,
  280. // endTime: queryEndTime,
  281. // userName: '已预约',
  282. // phone: '未知'
  283. // } : null
  284. }
  285. }))
  286. // 如果是第一页,直接替换;否则追加
  287. if (pageNo === 1) {
  288. carList.value = processedCars
  289. // 重置分页状态
  290. hasMoreData.value = pageInfo.value.total > pageInfo.value.rowNumPer
  291. } else {
  292. carList.value = [...carList.value, ...processedCars]
  293. // 检查是否还有更多数据
  294. hasMoreData.value = pageInfo.value.pageNo * pageInfo.value.rowNumPer < pageInfo.value.total
  295. }
  296. } else {
  297. console.log('数据格式不正确或为空')
  298. if (pageNo === 1) {
  299. carList.value = []
  300. }
  301. }
  302. } catch (error) {
  303. console.error('查询车辆失败:', error)
  304. uni.showToast({
  305. title: '查询车辆失败',
  306. icon: 'none'
  307. })
  308. if (pageNo === 1) {
  309. carList.value = []
  310. }
  311. } finally {
  312. loading.value = false
  313. }
  314. }
  315. /**
  316. * 加载更多车辆数据
  317. */
  318. const loadMoreCars = async () => {
  319. // 防止重复加载
  320. if (loadingMore.value || !hasMoreData.value) {
  321. return
  322. }
  323. // 检查是否还有更多数据
  324. if (pageInfo.value.pageNo * pageInfo.value.rowNumPer >= pageInfo.value.total) {
  325. hasMoreData.value = false
  326. return
  327. }
  328. loadingMore.value = true
  329. const nextPage = pageInfo.value.pageNo + 1
  330. try {
  331. await queryAvailableCars(null, null, nextPage)
  332. } catch (error) {
  333. console.error('加载更多失败:', error)
  334. uni.showToast({
  335. title: '加载失败',
  336. icon: 'none'
  337. })
  338. } finally {
  339. loadingMore.value = false
  340. }
  341. }
  342. /**
  343. * 处理车辆选择
  344. */
  345. const handleCarSelect = async(car) => {
  346. console.log('选择车辆:', car)
  347. // 检查是否已选择时间
  348. if (!formData.value.yykssj || !formData.value.yyjssj) {
  349. uni.showToast({
  350. title: '请先选择预约时间',
  351. icon: 'none'
  352. })
  353. return
  354. }
  355. selectedCar.value = car
  356. if (car.status === 'reserved') {
  357. const res = await clyyApi.cl_searchYd({wpid:car.wpid})
  358. console.log('查询预约响应:', res.data.wpydlist.length>0)
  359. if(res.data.wpydlist.length>0){
  360. // // 点击已预约车辆,显示预约详情
  361. // reservationDetail.value = car.reservationInfo
  362. reservationDetail.value = res.data.wpydlist[0]
  363. step.value = 2
  364. }
  365. } else if (car.status === 'available') {
  366. // 点击可预约车辆,显示预约表单
  367. reservationDetail.value = null
  368. step.value = 2
  369. }
  370. }
  371. /**
  372. * 初始化页面数据
  373. */
  374. const initPageData = () => {
  375. // 设置默认查询时间(一天后到两天后)
  376. const tomorrow = new Date()
  377. tomorrow.setDate(tomorrow.getDate() + 1)
  378. tomorrow.setHours(9, 0, 0, 0)
  379. const dayAfterTomorrow = new Date()
  380. dayAfterTomorrow.setDate(dayAfterTomorrow.getDate() + 2)
  381. dayAfterTomorrow.setHours(17, 0, 0, 0)
  382. // 格式化为PC端接口需要的格式:yyyy-MM-dd HH:mm
  383. const formatDateTime = (date) => {
  384. const year = date.getFullYear()
  385. const month = String(date.getMonth() + 1).padStart(2, '0')
  386. const day = String(date.getDate()).padStart(2, '0')
  387. const hours = String(date.getHours()).padStart(2, '0')
  388. const minutes = String(date.getMinutes()).padStart(2, '0')
  389. return `${year}-${month}-${day} ${hours}:${minutes}`
  390. }
  391. const defaultStartTime = formatDateTime(tomorrow)
  392. const defaultEndTime = formatDateTime(dayAfterTomorrow)
  393. console.log('初始化查询车辆:', { defaultStartTime, defaultEndTime })
  394. queryAvailableCars(defaultStartTime, defaultEndTime)
  395. }
  396. /**
  397. * 拨打电话
  398. */
  399. const makePhoneCall = (phoneNumber) => {
  400. uni.makePhoneCall({
  401. phoneNumber: phoneNumber,
  402. success: () => {
  403. console.log('拨打电话成功')
  404. },
  405. fail: (err) => {
  406. console.error('拨打电话失败:', err)
  407. uni.showToast({
  408. title: '拨打电话失败',
  409. icon: 'none'
  410. })
  411. }
  412. })
  413. }
  414. /**
  415. * 底部按钮配置
  416. */
  417. const step2BottomButtons = computed(() => {
  418. if (reservationDetail.value) {
  419. // 查看预约详情时只显示返回按钮
  420. return [{ text: '返回', action: 'back' }]
  421. } else {
  422. // 预约表单时显示取消和预约按钮
  423. return [
  424. { text: '取消', action: 'back' },
  425. { text: '预约', action: 'save' }
  426. ]
  427. }
  428. })
  429. /**
  430. * 底部按钮事件处理
  431. * @param {Object} data - 按钮数据
  432. * @param {string} data.action - 按钮动作类型
  433. */
  434. const step2HandleBottomAction = (data) => {
  435. switch (data.action) {
  436. case 'back':
  437. // 返回处理
  438. step.value = 1
  439. selectedCar.value = null
  440. reservationDetail.value = null
  441. break
  442. case 'save':
  443. // 校验预约表单
  444. if (formRef.value && formRef.value.validateForm) {
  445. try {
  446. const isValid = formRef.value.validateForm(formData.value, fieldConfigs)
  447. console.log('表单校验结果:', isValid)
  448. if (isValid) {
  449. // 显示二次确认弹窗
  450. showConfirmDialog()
  451. }
  452. } catch (error) {
  453. console.error('表单校验出错:', error)
  454. uni.showToast({
  455. title: '表单校验失败',
  456. icon: 'none'
  457. })
  458. }
  459. } else {
  460. console.log('formRef或validateForm不可用')
  461. uni.showToast({
  462. title: '表单初始化失败',
  463. icon: 'none'
  464. })
  465. }
  466. break
  467. }
  468. }
  469. // 确认弹窗显示状态
  470. const showConfirm = ref(false)
  471. /**
  472. * 显示确认弹窗
  473. */
  474. const showConfirmDialog = () => {
  475. showConfirm.value = true
  476. }
  477. /**
  478. * 确认弹窗回调
  479. */
  480. const handleConfirm = (button, index) => {
  481. console.log('确认弹窗按钮点击:', button)
  482. showConfirm.value = false
  483. // 根据按钮类型判断是确认还是取消
  484. if (button.button.type === 'primary' || button.button.text === '确认') {
  485. submitReservation()
  486. }
  487. }
  488. /**
  489. * 提交预约
  490. */
  491. const submitReservation = async () => {
  492. try {
  493. // uni.showLoading({ title: '预约中...' })
  494. console.log('预约中:')
  495. // 基于formData组织新的param对象,参考PC端cl_ydAdd.ss.jsp的数据结构
  496. const reservationParam = {
  497. // 车辆ID(对应PC端的cdids)
  498. cdids: selectedCar.value.id,
  499. // 开始时间和结束时间(对应PC端的beginTime和endTime)
  500. beginTime: formData.value.yykssj,
  501. endTime: formData.value.yyjssj,
  502. // 目的地(对应PC端的mdd)
  503. mdd: formData.value.bsdd,
  504. // 使用要求/事由(对应PC端的syyq)
  505. syyq: formData.value.sy,
  506. // 使用人数(对应PC端的syrs)
  507. syrs: formData.value.rs,
  508. // 是否预警(对应PC端的sfyj,默认否)
  509. sfyj: 0,
  510. // 预警时间长度(对应PC端的yjsjcd,默认空)
  511. yjsjcd: '',
  512. // 预警描述(对应PC端的yjms,默认空)
  513. yjms: ''
  514. }
  515. console.log('提交预约参数:', reservationParam)
  516. console.log('原始表单数据:', formData.value)
  517. // 调用PC端的cl_sureYd接口
  518. const response = await clyyApi.cl_sureYd(reservationParam)
  519. console.log('预约响应:', response)
  520. uni.hideLoading()
  521. if (response && response.success !== false) {
  522. uni.showToast({
  523. title: '预约成功',
  524. icon: 'success'
  525. })
  526. // 返回上一页
  527. setTimeout(() => {
  528. uni.navigateBack()
  529. }, 1500)
  530. } else {
  531. uni.showToast({
  532. title: response.message || '预约失败',
  533. icon: 'none'
  534. })
  535. }
  536. } catch (error) {
  537. uni.hideLoading()
  538. console.error('预约失败:', error)
  539. uni.showToast({
  540. title: '预约失败,请重试',
  541. icon: 'none'
  542. })
  543. }
  544. }
  545. /**
  546. * 页面初始化
  547. */
  548. onMounted(() => {
  549. initPageData()
  550. })
  551. /**
  552. * 页面触底事件
  553. */
  554. onReachBottom(() => {
  555. // 只在第一步且有更多数据时触发
  556. if (step.value === 1 && hasMoreData.value) {
  557. loadMoreCars()
  558. }
  559. })
  560. </script>
  561. <style lang="scss" scoped>
  562. :deep(.u-th) {
  563. max-width: 35% !important;
  564. }
  565. .car-list {
  566. margin-top: 34rpx;
  567. padding: 0 20rpx;
  568. display: flex;
  569. flex-direction: column;
  570. }
  571. .load-more {
  572. padding: 30rpx;
  573. text-align: center;
  574. color: #007AFF;
  575. font-size: 28rpx;
  576. border-top: 1rpx solid #f0f0f0;
  577. margin-top: 20rpx;
  578. &:active {
  579. background-color: #f8f8f8;
  580. }
  581. }
  582. .no-more {
  583. padding: 30rpx;
  584. text-align: center;
  585. color: #999;
  586. font-size: 26rpx;
  587. border-top: 1rpx solid #f0f0f0;
  588. margin-top: 20rpx;
  589. }
  590. .current-car-section {
  591. padding: 20rpx;
  592. padding-bottom: 0;
  593. }
  594. .reservation-detail,
  595. .reservation-form {
  596. margin: 20rpx 0;
  597. }
  598. .phone-link {
  599. color: #007AFF;
  600. text-decoration: underline;
  601. }
  602. .confirm-content {
  603. padding: 40rpx;
  604. display: flex;
  605. flex-direction: column;
  606. gap: 20rpx;
  607. }
  608. .confirm-item {
  609. display: flex;
  610. align-items: center;
  611. justify-content: center;
  612. font-size: 34rpx;
  613. color: #333;
  614. .label {
  615. text-align: right;
  616. flex: 1;
  617. margin-right: 20rpx;
  618. }
  619. .value {
  620. flex: 1;
  621. font-weight: 500;
  622. }
  623. }
  624. </style>