mp_clyy_details.html 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. /* 当前车辆信息区域 */
  20. .current-car-section {
  21. padding: 10px;
  22. padding-bottom: 0;
  23. }
  24. /* 预约详情 */
  25. .reservation-detail {
  26. margin: 10px 0;
  27. }
  28. /* 电话链接样式 */
  29. .phone-link {
  30. color: #007AFF;
  31. text-decoration: underline;
  32. cursor: pointer;
  33. }
  34. </style>
  35. </head>
  36. <body>
  37. <div id="app" v-cloak>
  38. <!-- 当前车辆信息卡片 -->
  39. <div class="current-car-section">
  40. <ss-car-card
  41. v-if="carData"
  42. :car-data="carData"
  43. :status="carData.status"
  44. />
  45. </div>
  46. <!-- 预约详情 -->
  47. <div v-if="reservationDetail" class="reservation-detail">
  48. <table>
  49. <tr>
  50. <th>开始时间</th>
  51. <td>{{ formatDate(reservationDetail.kssj, 'yyyy-MM-dd HH:mm:ss') }}</td>
  52. </tr>
  53. <tr>
  54. <th>结束时间</th>
  55. <td>{{ formatDate(reservationDetail.jssj, 'yyyy-MM-dd HH:mm:ss') }}</td>
  56. </tr>
  57. <tr>
  58. <th>使用人</th>
  59. <td>{{ reservationDetail.ydr }}</td>
  60. </tr>
  61. <tr>
  62. <th>联系电话</th>
  63. <td>
  64. <span class="phone-link" @click="makePhoneCall(reservationDetail.ydrdh)">
  65. {{ reservationDetail.ydrdh }}
  66. </span>
  67. </td>
  68. </tr>
  69. </table>
  70. </div>
  71. </div>
  72. <script>
  73. // 等待SS框架加载完成
  74. window.SS.ready(function () {
  75. // 使用SS框架的方式创建Vue实例
  76. window.SS.dom.initializeFormApp({
  77. el: '#app',
  78. data() {
  79. return {
  80. // 车辆信息
  81. carData: null,
  82. // 预约详情
  83. reservationDetail: null,
  84. // URL参数
  85. urlParams: {
  86. wpid: '',
  87. yykssj: '',
  88. yyjssj: ''
  89. }
  90. }
  91. },
  92. async mounted() {
  93. // 解析URL参数
  94. this.parseUrlParams()
  95. // 加载预约详情
  96. await this.loadReservationDetail()
  97. },
  98. methods: {
  99. // 解析URL参数
  100. parseUrlParams() {
  101. const urlParams = new URLSearchParams(window.location.search)
  102. this.urlParams.wpid = urlParams.get('wpid') || ''
  103. this.urlParams.yykssj = urlParams.get('yykssj') || ''
  104. this.urlParams.yyjssj = urlParams.get('yyjssj') || ''
  105. // 从 sessionStorage 获取完整的车辆数据(包含 wpcsList 等数组字段)
  106. const carDataStr = sessionStorage.getItem('carDetailData')
  107. if (carDataStr) {
  108. try {
  109. this.carData = JSON.parse(carDataStr)
  110. console.log('从 sessionStorage 获取车辆数据:', this.carData)
  111. // 使用后清除,避免占用空间
  112. sessionStorage.removeItem('carDetailData')
  113. } catch (error) {
  114. console.error('解析车辆数据失败:', error)
  115. }
  116. }
  117. console.log('解析到的URL参数:', this.urlParams)
  118. console.log('解析到的车辆数据:', this.carData)
  119. },
  120. // 加载预约详情
  121. async loadReservationDetail() {
  122. if (!this.urlParams.wpid || !this.urlParams.yykssj || !this.urlParams.yyjssj) {
  123. console.error('缺少必要参数')
  124. window.showToast?.('参数错误', 'error')
  125. return
  126. }
  127. try {
  128. // 查询预约详情
  129. const res = await window.request.post(
  130. `/service?ssServ=cl_searchYd`,
  131. {
  132. wpid: this.urlParams.wpid,
  133. kssj: this.urlParams.yykssj,
  134. jssj: this.urlParams.yyjssj
  135. },
  136. { loading: true, formData: true }
  137. )
  138. console.log('查询预约响应:', res)
  139. if (res.data && res.data.wpydlist && res.data.wpydlist.length > 0) {
  140. this.reservationDetail = res.data.wpydlist[0]
  141. } else {
  142. window.showToast?.('未找到预约信息', 'error')
  143. }
  144. } catch (error) {
  145. console.error('加载预约详情失败:', error)
  146. window.showToast?.('加载失败', 'error')
  147. }
  148. },
  149. // 拨打电话
  150. makePhoneCall(phoneNumber) {
  151. window.location.href = `tel:${phoneNumber}`
  152. },
  153. // 格式化日期 - 使用 dayjs
  154. formatDate(dateStr, format) {
  155. if (!dateStr) return ''
  156. console.log('formatDate 输入:', dateStr, '格式要求:', format)
  157. // 检查 dayjs 是否可用
  158. if (typeof dayjs === 'undefined') {
  159. console.error('dayjs 未加载')
  160. return dateStr
  161. }
  162. // 清理字符串:移除特殊空格字符(如 \u202F),替换为普通空格
  163. const cleanedDateStr = dateStr
  164. .replace(/[\u202F\u00A0]/g, ' ') // 替换不间断空格
  165. .replace(/\s+/g, ' ') // 多个空格合并为一个
  166. .trim()
  167. console.log('清理后的字符串:', cleanedDateStr)
  168. // 尝试使用原生 Date 解析(兼容性最好)
  169. let date = null
  170. try {
  171. const jsDate = new Date(cleanedDateStr)
  172. if (!isNaN(jsDate.getTime())) {
  173. date = dayjs(jsDate)
  174. }
  175. } catch (e) {
  176. console.warn('Date 解析失败:', e)
  177. }
  178. // 如果 Date 解析失败,尝试直接用 dayjs
  179. if (!date || !date.isValid()) {
  180. date = dayjs(cleanedDateStr)
  181. }
  182. console.log('dayjs 解析结果:', date, 'isValid:', date.isValid())
  183. if (!date.isValid()) {
  184. console.warn('无效的日期格式:', dateStr)
  185. return dateStr // 如果无法解析,返回原始字符串
  186. }
  187. // dayjs 的格式化映射
  188. // yyyy -> YYYY, MM -> MM, dd -> DD, HH -> HH, mm -> mm, ss -> ss
  189. const dayjsFormat = format
  190. .replace('yyyy', 'YYYY')
  191. .replace('dd', 'DD')
  192. console.log('dayjs 格式:', dayjsFormat)
  193. const result = date.format(dayjsFormat)
  194. console.log('格式化结果:', result)
  195. return result
  196. }
  197. }
  198. })
  199. })
  200. </script>
  201. </body>
  202. </html>