mp_clyy_inp.html 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  6. <title>车辆预约</title>
  7. <script src="/js/mp_base/base.js"></script>
  8. <style>
  9. /* 防止Vue模板闪烁 */
  10. [v-cloak] {
  11. display: none !important;
  12. }
  13. #app {
  14. background: #f5f5f5;
  15. min-height: 100vh;
  16. display: flex;
  17. flex-direction: column;
  18. }
  19. th{
  20. max-width: 35% !important;
  21. }
  22. /* 车辆列表区域 */
  23. .car-list {
  24. margin-top: 17px;
  25. padding: 0 10px;
  26. display: flex;
  27. flex-direction: column;
  28. }
  29. /* 加载中提示 */
  30. .loading-more {
  31. padding: 15px;
  32. text-align: center;
  33. color: #666;
  34. font-size: 14px;
  35. }
  36. </style>
  37. </head>
  38. <body>
  39. <div id="app" v-cloak>
  40. <!-- 选择时间和车辆 -->
  41. <table style="padding-top: 8px;">
  42. <tr>
  43. <th width="200">预约开始时间</th>
  44. <td>
  45. <ss-datetime-picker
  46. v-model="formData.yykssj"
  47. name="yykssj"
  48. mode="datetime"
  49. :min-date="yykssjMinDate"
  50. placeholder="YYYY-MM-DD HH:mm"
  51. @change="onYykssjChange"
  52. />
  53. </td>
  54. </tr>
  55. <tr>
  56. <th width="200">预约结束时间</th>
  57. <td>
  58. <ss-datetime-picker
  59. v-model="formData.yyjssj"
  60. name="yyjssj"
  61. mode="datetime"
  62. :min-date="yyjssjMinDate"
  63. placeholder="YYYY-MM-DD HH:mm"
  64. @change="onYyjssjChange"
  65. />
  66. </td>
  67. </tr>
  68. </table>
  69. <!-- 车辆选择列表 -->
  70. <div class="car-list">
  71. <ss-car-card
  72. v-for="car in carList"
  73. :key="car.id"
  74. :car-data="car"
  75. :status="car.status"
  76. @select="handleCarSelect"
  77. />
  78. <!-- 加载中提示 -->
  79. <div v-if="loadingMore" class="loading-more">
  80. 加载中...
  81. </div>
  82. </div>
  83. </div>
  84. <script>
  85. // 等待SS框架加载完成
  86. window.SS.ready(function () {
  87. // 使用SS框架的方式创建Vue实例
  88. window.SS.dom.initializeFormApp({
  89. el: '#app',
  90. data() {
  91. return {
  92. // 表单数据
  93. formData: {
  94. yykssj: '', // 预约开始时间
  95. yyjssj: '' // 预约结束时间
  96. },
  97. // 时间选择器最小值
  98. yykssjMinDate: new Date().toISOString().slice(0, 16),
  99. yyjssjMinDate: new Date(new Date().getTime() + 3600 * 1000).toISOString().slice(0, 16),
  100. // 车辆列表数据
  101. carList: [],
  102. // 加载状态
  103. loading: false,
  104. loadingMore: false,
  105. hasMoreData: false,
  106. // 分页信息
  107. pageInfo: {
  108. pageNo: 1,
  109. rowNumPer: 10,
  110. total: 0
  111. }
  112. }
  113. },
  114. async mounted() {
  115. // 初始化页面数据
  116. this.initPageData()
  117. },
  118. methods: {
  119. // 初始化页面数据
  120. initPageData() {
  121. // 设置默认查询时间(一天后到两天后)
  122. const tomorrow = new Date()
  123. tomorrow.setDate(tomorrow.getDate() + 1)
  124. tomorrow.setHours(9, 0, 0, 0)
  125. const dayAfterTomorrow = new Date()
  126. dayAfterTomorrow.setDate(dayAfterTomorrow.getDate() + 2)
  127. dayAfterTomorrow.setHours(17, 0, 0, 0)
  128. // 格式化为 yyyy-MM-dd HH:mm 格式
  129. const formatDateTime = (date) => {
  130. const year = date.getFullYear()
  131. const month = String(date.getMonth() + 1).padStart(2, '0')
  132. const day = String(date.getDate()).padStart(2, '0')
  133. const hours = String(date.getHours()).padStart(2, '0')
  134. const minutes = String(date.getMinutes()).padStart(2, '0')
  135. return `${year}-${month}-${day} ${hours}:${minutes}`
  136. }
  137. this.formData.yykssj = formatDateTime(tomorrow)
  138. this.formData.yyjssj = formatDateTime(dayAfterTomorrow)
  139. console.log('初始化查询车辆:', {
  140. yykssj: this.formData.yykssj,
  141. yyjssj: this.formData.yyjssj
  142. })
  143. // 自动查询车辆
  144. this.queryAvailableCars()
  145. },
  146. // 开始时间变化
  147. onYykssjChange(val) {
  148. console.log('📅 开始时间变化:', val)
  149. if (val) {
  150. // 更新结束时间的最小值
  151. this.yyjssjMinDate = new Date(new Date(val).getTime() + 3600 * 1000).toISOString().slice(0, 16)
  152. // 自动设置结束时间为开始时间 +1 天
  153. const startDate = new Date(val)
  154. const endDate = new Date(startDate.getTime() + 24 * 3600 * 1000) // +1天(24小时)
  155. // 格式化为 yyyy-MM-dd HH:mm 格式
  156. const year = endDate.getFullYear()
  157. const month = String(endDate.getMonth() + 1).padStart(2, '0')
  158. const day = String(endDate.getDate()).padStart(2, '0')
  159. const hours = String(endDate.getHours()).padStart(2, '0')
  160. const minutes = String(endDate.getMinutes()).padStart(2, '0')
  161. this.formData.yyjssj = `${year}-${month}-${day} ${hours}:${minutes}`
  162. console.log('⏰ 自动设置结束时间为:', this.formData.yyjssj)
  163. // 清空车辆列表,等待用户确认时间后再查询
  164. this.carList = []
  165. this.onYyjssjChange(this.formData.yyjssj)
  166. } else {
  167. // 如果开始时间被清空,也清空结束时间和车辆列表
  168. this.formData.yyjssj = ''
  169. this.carList = []
  170. console.log('🧹 已清空结束时间和车辆列表')
  171. }
  172. // 手动触发校验
  173. this.$nextTick(() => {
  174. if (window.ssVm) {
  175. window.ssVm.validateField('yyjssj')
  176. }
  177. })
  178. },
  179. // 结束时间变化
  180. onYyjssjChange(val) {
  181. console.log('📅 结束时间变化:', val)
  182. // 只有同时存在开始时间和结束时间才查询车辆
  183. if (val && this.formData.yykssj) {
  184. console.log('🚗 开始查询车辆...')
  185. this.queryAvailableCars()
  186. } else {
  187. console.log('⏸️ 时间不完整,暂不查询车辆')
  188. }
  189. },
  190. // 查询可用车辆
  191. async queryAvailableCars(pageNo = 1) {
  192. const queryStartTime = this.formData.yykssj
  193. const queryEndTime = this.formData.yyjssj
  194. if (!queryStartTime || !queryEndTime) {
  195. return
  196. }
  197. this.loading = true
  198. try {
  199. // 调用PC端的cl_search接口(分页)
  200. const response = await window.request.post(
  201. `/service?ssServ=cl_searchRcpt`,
  202. {
  203. beginTime: queryStartTime,
  204. endTime: queryEndTime,
  205. pageNo: pageNo,
  206. rowNumPer: this.pageInfo.rowNumPer
  207. },
  208. {
  209. loading: true,
  210. formData: true
  211. }
  212. )
  213. console.log('response.data内容:', response)
  214. if (response && response.data) {
  215. // 更新分页信息
  216. if (response.wdPage) {
  217. this.pageInfo = {
  218. pageNo: response.wdPage.pageNo,
  219. rowNumPer: response.wdPage.rowNumPer,
  220. total: response.wdPage.rowNum
  221. }
  222. }
  223. // 处理返回的车辆数据
  224. const processedCars = await Promise.all(response.data.data.map(async (item) => {
  225. console.log('📦 原始车辆数据:', item)
  226. // 简单的状态判断
  227. let status = 'available'
  228. if (item.zt == 1) {
  229. status = 'reserved'
  230. } else {
  231. status = 'available'
  232. }
  233. // 获取车辆类型
  234. let carType = '车辆'
  235. if (item.wplbm) {
  236. try {
  237. const typeOptions = await window.getDictOptions('wplb')
  238. const typeOption = typeOptions.find(opt => opt.v == item.wplbm)
  239. if (typeOption) {
  240. carType = typeOption.n
  241. }
  242. } catch (error) {
  243. console.warn('获取车辆类型失败:', error)
  244. }
  245. }
  246. const processedData = {
  247. id: item.wpid || item.id,
  248. plateNumber: item.mc,
  249. seats: 7,
  250. name: item.mc,
  251. color: '白色',
  252. type: carType,
  253. image: item.sltwj,
  254. wph: item.wph || '',
  255. wpcsList: item.wpcsList || [],
  256. wplbm: item.wplbm,
  257. wpid: item.wpid,
  258. status: status
  259. }
  260. console.log('✅ 处理后车辆数据:', processedData)
  261. return processedData
  262. }))
  263. // 如果是第一页,直接替换;否则追加
  264. if (pageNo === 1) {
  265. this.carList = processedCars
  266. this.hasMoreData = this.pageInfo.total > this.pageInfo.rowNumPer
  267. } else {
  268. this.carList = [...this.carList, ...processedCars]
  269. this.hasMoreData = this.pageInfo.pageNo * this.pageInfo.rowNumPer < this.pageInfo.total
  270. }
  271. } else {
  272. if (pageNo === 1) {
  273. this.carList = []
  274. }
  275. }
  276. } catch (error) {
  277. console.error('查询车辆失败:', error)
  278. if (pageNo === 1) {
  279. this.carList = []
  280. }
  281. } finally {
  282. this.loading = false
  283. }
  284. },
  285. // 处理车辆选择
  286. async handleCarSelect(car) {
  287. console.log('选择车辆:', car)
  288. // 检查是否已选择时间
  289. if (!this.formData.yykssj || !this.formData.yyjssj) {
  290. window.showToast?.('请先选择预约时间', 'error')
  291. return
  292. }
  293. if (car.status === 'reserved') {
  294. // 点击已预约车辆,跳转到详情页
  295. this.navigateToDetail(car)
  296. } else if (car.status === 'available') {
  297. // 点击可预约车辆,跳转到预约表单页
  298. this.navigateToForm(car)
  299. }
  300. },
  301. // 跳转到预约详情页
  302. navigateToDetail(car) {
  303. console.log('🔗 跳转到预约详情页', car)
  304. // 将完整的车辆数据存储到 sessionStorage(避免URL传递复杂对象)
  305. sessionStorage.setItem('carDetailData', JSON.stringify(car))
  306. // 获取当前 URL 的查询参数
  307. const currentParams = new URLSearchParams(window.location.search)
  308. // 构建跳转参数
  309. const params = new URLSearchParams({
  310. wpid: car.wpid || '',
  311. yykssj: this.formData.yykssj || '',
  312. yyjssj: this.formData.yyjssj || '',
  313. // 保留必要的认证参数
  314. JSESSIONID: currentParams.get('JSESSIONID') || '',
  315. devId: currentParams.get('devId') || '',
  316. sbmc: currentParams.get('sbmc') || ''
  317. })
  318. // 跳转到详情页
  319. const targetUrl = `./mp_clyy_details.html?${params.toString()}`
  320. console.log('🎯 目标 URL:', targetUrl)
  321. window.location.href = targetUrl
  322. },
  323. // 跳转到预约表单页
  324. navigateToForm(car) {
  325. console.log('🔗 跳转到预约表单页', car)
  326. // 将完整的车辆数据存储到 sessionStorage(避免URL传递复杂对象)
  327. sessionStorage.setItem('carFormData', JSON.stringify(car))
  328. // 获取当前 URL 的查询参数
  329. const currentParams = new URLSearchParams(window.location.search)
  330. // 构建跳转参数
  331. const params = new URLSearchParams({
  332. wpid: car.wpid || '',
  333. yykssj: this.formData.yykssj || '',
  334. yyjssj: this.formData.yyjssj || '',
  335. // 保留必要的认证参数
  336. JSESSIONID: currentParams.get('JSESSIONID') || '',
  337. devId: currentParams.get('devId') || '',
  338. sbmc: currentParams.get('sbmc') || ''
  339. })
  340. // 跳转到表单页
  341. const targetUrl = `./mp_clyy_form.html?${params.toString()}`
  342. console.log('🎯 目标 URL:', targetUrl)
  343. window.location.href = targetUrl
  344. },
  345. // 拨打电话
  346. makePhoneCall(phoneNumber) {
  347. window.location.href = `tel:${phoneNumber}`
  348. },
  349. // 格式化日期 - 使用 dayjs
  350. formatDate(dateStr, format) {
  351. if (!dateStr) return ''
  352. console.log('📅 formatDate 输入:', dateStr, '格式要求:', format)
  353. // 检查 dayjs 是否可用
  354. if (typeof dayjs === 'undefined') {
  355. console.error('❌ dayjs 未加载')
  356. return dateStr
  357. }
  358. // 清理字符串:移除特殊空格字符(如 \u202F),替换为普通空格
  359. const cleanedDateStr = dateStr
  360. .replace(/[\u202F\u00A0]/g, ' ') // 替换不间断空格
  361. .replace(/\s+/g, ' ') // 多个空格合并为一个
  362. .trim()
  363. console.log('📅 清理后的字符串:', cleanedDateStr)
  364. // 尝试使用原生 Date 解析(兼容性最好)
  365. let date = null
  366. try {
  367. const jsDate = new Date(cleanedDateStr)
  368. if (!isNaN(jsDate.getTime())) {
  369. date = dayjs(jsDate)
  370. }
  371. } catch (e) {
  372. console.warn('⚠️ Date 解析失败:', e)
  373. }
  374. // 如果 Date 解析失败,尝试直接用 dayjs
  375. if (!date || !date.isValid()) {
  376. date = dayjs(cleanedDateStr)
  377. }
  378. console.log('📅 dayjs 解析结果:', date, 'isValid:', date.isValid())
  379. if (!date.isValid()) {
  380. console.warn('⚠️ 无效的日期格式:', dateStr)
  381. return dateStr // 如果无法解析,返回原始字符串
  382. }
  383. // dayjs 的格式化映射
  384. // yyyy -> YYYY, MM -> MM, dd -> DD, HH -> HH, mm -> mm, ss -> ss
  385. const dayjsFormat = format
  386. .replace('yyyy', 'YYYY')
  387. .replace('dd', 'DD')
  388. console.log('📅 dayjs 格式:', dayjsFormat)
  389. const result = date.format(dayjsFormat)
  390. console.log('📅 格式化结果:', result)
  391. return result
  392. }
  393. }
  394. })
  395. })
  396. </script>
  397. </body>