VehicleInquiry.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. <!-- 车辆查询 -->
  2. <template>
  3. <view class="container">
  4. <view class="container-vehicle">
  5. <u-image width="100%" height="100%" src="/static/img/vehicle-icon.png" />
  6. </view>
  7. <view class="container-content">
  8. <view class="container-content-search">
  9. <view class="container-content-search-title">输入车牌查询</view>
  10. <view class="container-content-search-input" @click="clickCarKeyboard">
  11. <u-message-input :maxlength="8" width="55" font-size="40" :disabled-keyboard="true" v-model="form.vehicleNo" />
  12. </view>
  13. </view>
  14. <view class="container-content-choose" @click="toggleVehicleList">
  15. <view class="container-content-choose-text">点击选择车牌</view>
  16. <view class="container-content-choose-icon">
  17. <u-icon name="arrow-up" v-if="toggle"></u-icon>
  18. <u-icon name="arrow-down" v-else></u-icon>
  19. </view>
  20. </view>
  21. <template v-if="toggle">
  22. <view class="container-content-list" v-if="vehicleList.length">
  23. <radio-group @change="radioChange">
  24. <view class="container-content-list-item" v-for="(item, index) in vehicleList" :key="index" @click="form.vehicleNo = item.value">
  25. <view class="left">{{ item.label }}</view>
  26. <view class="right">
  27. <radio :value="item.value" :checked="item.value === form.vehicleNo" />
  28. </view>
  29. </view>
  30. </radio-group>
  31. </view>
  32. <view v-else>
  33. <u-empty text="车牌记录为空" mode="list"></u-empty>
  34. </view>
  35. </template>
  36. <view class="container-content-confirm">
  37. <u-button type="primary" :loading="loading" :disabled="!form.vehicleNo" @click="submitVehicleConfirm">确认</u-button>
  38. </view>
  39. </view>
  40. <!-- 车牌号键盘 -->
  41. <u-keyboard ref="uKeyboard" mode="car" @change="keyboardChange" @confirm="keyboardConfirm" @backspace="backspace" v-model="carKeyboard.show" />
  42. <!-- 选择颜色 -->
  43. <u-action-sheet :list="colorPop.colorList" @click="confirmColor" v-model="colorPop.show" />
  44. <!-- 参数丢失弹框 -->
  45. <parmas-loss-pop :show="lossPopShow" />
  46. <!-- 页面报错弹框 -->
  47. <page-error-pop :show="pageErrorShow" :tipText="pageErrorTxt" @pageErrorPopClose="pageErrorPopClose" />
  48. <u-toast ref="uToast" />
  49. </view>
  50. </template>
  51. <script>
  52. import ParmasLossPop from '@/components/params-loss-pop/params-loss-pop.vue';
  53. import PageErrorPop from '@/components/page-error-pop/page-error-pop.vue';
  54. import { base64Encrypt } from '@/utils';
  55. export default {
  56. components: {
  57. ParmasLossPop,
  58. PageErrorPop
  59. },
  60. data() {
  61. return {
  62. form: {
  63. vehicleNo: '',
  64. parkNo: ''
  65. },
  66. carKeyboard: {
  67. show: false
  68. },
  69. colorPop: {
  70. show: false,
  71. colorList: [
  72. {
  73. text: '蓝色',
  74. colorCode: 0
  75. },
  76. {
  77. text: '黄色',
  78. colorCode: 1
  79. },
  80. {
  81. text: '黑色',
  82. colorCode: 2
  83. },
  84. {
  85. text: '白色',
  86. colorCode: 3
  87. },
  88. {
  89. text: '绿色',
  90. colorCode: 4
  91. },
  92. {
  93. text: '其他',
  94. colorCode: 99
  95. }
  96. ]
  97. },
  98. toggle: false,
  99. loading: false,
  100. vehicleList: [],
  101. parkInfo: {},
  102. lossPopShow: false,
  103. pageErrorShow: false,
  104. pageErrorTxt: ''
  105. };
  106. },
  107. onLoad(options) {
  108. const { parkNo } = options;
  109. if (parkNo) {
  110. this.form.parkNo = parkNo;
  111. this.getVehicleInquiryList(parkNo);
  112. } else {
  113. this.lossPopShow = true;
  114. }
  115. },
  116. methods: {
  117. /**
  118. * @description: 点击车牌输入框
  119. * @return {*}
  120. */
  121. clickCarKeyboard() {
  122. this.carKeyboard.show = true;
  123. },
  124. /**
  125. * @description: 车牌键盘变化(将每次按键的值拼接到value变量中,注意+=写法)
  126. * @param {*} val
  127. * @return {*}
  128. */
  129. keyboardChange(val) {
  130. this.form.vehicleNo += val;
  131. },
  132. /**
  133. * @description: 获取当前用户车辆
  134. * @return {*}
  135. */
  136. async getVehicleInquiryList(parkNo) {
  137. try {
  138. const { data, code } = await this.$u.api.getVehicleInquiryListApi({ parkNo });
  139. if (code === 200) {
  140. this.parkInfo = data;
  141. if (data.vehicleList && data.vehicleList.length) {
  142. this.vehicleList = data.vehicleList.map((item) => {
  143. return { label: item, value: item };
  144. });
  145. await this.$nextTick();
  146. this.$refs.refValue.init();
  147. }
  148. }
  149. } catch (error) {
  150. console.log(error);
  151. }
  152. },
  153. /**
  154. * @description: 车牌键盘确认
  155. * @return {*}
  156. */
  157. keyboardConfirm() {
  158. this.colorPop.show = true;
  159. },
  160. /**
  161. * @description: 车牌键盘删除键(删除value的最后一个字符)
  162. * @return {*}
  163. */
  164. backspace() {
  165. if (this.form.vehicleNo.length) this.form.vehicleNo = this.form.vehicleNo.substr(0, this.form.vehicleNo.length - 1);
  166. },
  167. /**
  168. * @description: 选取颜色弹框确认
  169. * @return {*}
  170. */
  171. confirmColor() {
  172. this.colorPop.show = false;
  173. },
  174. /**
  175. * @description: 点击收起和展开车牌列表
  176. * @return {*}
  177. */
  178. toggleVehicleList() {
  179. this.toggle = !this.toggle;
  180. },
  181. /**
  182. * @description:
  183. * @param {*} e
  184. * @return {*}
  185. */
  186. radioChange(e) {
  187. this.form.vehicleNo = e.detail.value;
  188. },
  189. /**
  190. * @description: 确认提交
  191. * @return {*}
  192. */
  193. async submitVehicleConfirm() {
  194. const { vehicleNo } = this.form;
  195. const reg =
  196. /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[a-zA-Z](([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})$/;
  197. if (reg.test(vehicleNo)) {
  198. this.loading = true;
  199. try {
  200. const { code } = await this.$u.api.getOrderInfoByParknoApi({ ...this.form });
  201. if (code === 200) {
  202. this.$refs.uToast.show({
  203. title: '查询成功!',
  204. type: 'success',
  205. url: '/pages/OnsitePayment/OnsitePayment',
  206. duration: 1000,
  207. params: {
  208. ...this.form,
  209. vehicleNo: base64Encrypt(this.form.vehicleNo)
  210. },
  211. callback: () => {
  212. this.loading = false;
  213. }
  214. });
  215. }
  216. } catch (error) {
  217. this.loading = false;
  218. this.pageErrorShow = true;
  219. this.pageErrorTxt = error?.msg ?? '查询出错啦!';
  220. }
  221. } else {
  222. this.loading = false;
  223. this.showToast('请输入有效的车牌号!', 'error');
  224. }
  225. },
  226. /**
  227. * @description: 提示
  228. * @param {*} title
  229. * @param {*} type
  230. * @return {*}
  231. */
  232. showToast(title = '操作失败!', type = 'error') {
  233. this.$refs.uToast.show({
  234. title,
  235. type
  236. });
  237. },
  238. /**
  239. * @description: 关闭报错弹框
  240. * @return {*}
  241. */
  242. pageErrorPopClose() {
  243. this.pageErrorShow = false;
  244. }
  245. }
  246. };
  247. </script>
  248. <style lang="scss" scoped>
  249. @import './VehicleInquiry.scss';
  250. </style>