VehicleInquiry20230427..vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. <!-- 车辆查询 -->
  2. <template>
  3. <view class="container">
  4. <view class="container-title">
  5. <text>输入车牌,查询车费</text>
  6. </view>
  7. <!-- 车牌输入 -->
  8. <view class="container-input" @click="vehicleNoInputClick">
  9. <u-message-input :maxlength="8" width="60" font-size="40" :disabled-keyboard="true" v-model="form.vehicleNo" />
  10. </view>
  11. <!-- 车辆下拉 -->
  12. <view class="container-select">
  13. <u-collapse ref="refValue" :head-style="{ fontSize: '28rpx' }">
  14. <u-collapse-item title="点击选择车牌" align="center">
  15. <scroll-view class="container-select-scroll" scroll-y="true">
  16. <u-cell-group v-if="vehicleList.length">
  17. <u-cell-item :title="item.value" v-for="(item, index) in vehicleList" :key="index" :arrow="false">
  18. <u-radio-group v-model="form.vehicleNo" @change="radioGroupChange">
  19. <u-radio :name="item.value" :key="index" />
  20. </u-radio-group>
  21. </u-cell-item>
  22. </u-cell-group>
  23. <template v-else>
  24. <view class="container-select-empty">暂无绑定车牌</view>
  25. </template>
  26. </scroll-view>
  27. </u-collapse-item>
  28. </u-collapse>
  29. </view>
  30. <view class="container-btn">
  31. <u-button type="primary" :loading="loading" :disabled="!form.vehicleNo" @click="submitVehicleInquiry">确定</u-button>
  32. </view>
  33. <!-- 选择颜色 -->
  34. <u-action-sheet :list="bindVehiclePop.colorList" @click="confirmColor" v-model="bindVehiclePop.colorShow" />
  35. <!-- 车牌号键盘 -->
  36. <u-keyboard ref="uKeyboard" mode="car" @change="keyboardChange" @confirm="keyboardConfirm" @backspace="backspace" v-model="keyboardshow" />
  37. <u-toast ref="uToast" />
  38. </view>
  39. </template>
  40. <script>
  41. import { base64Encrypt } from '@/utils';
  42. export default {
  43. data() {
  44. return {
  45. form: {
  46. vehicleNo: '',
  47. parkNo: ''
  48. },
  49. vehicleList: [],
  50. keyboardshow: false,
  51. loading: false,
  52. showChangeVehicleNo: false,
  53. bindVehiclePop: {
  54. colorShow: false,
  55. colorList: [
  56. {
  57. text: '蓝色',
  58. colorCode: 0
  59. },
  60. {
  61. text: '黄色',
  62. colorCode: 1
  63. },
  64. {
  65. text: '黑色',
  66. colorCode: 2
  67. },
  68. {
  69. text: '白色',
  70. colorCode: 3
  71. },
  72. {
  73. text: '绿色',
  74. colorCode: 4
  75. },
  76. {
  77. text: '其他',
  78. colorCode: 99
  79. }
  80. ]
  81. },
  82. parkNo: null,
  83. parkInfo: {}
  84. };
  85. },
  86. onLoad(options) {
  87. const { parkNo } = options;
  88. if (parkNo) {
  89. this.form.parkNo = parkNo;
  90. this.getVehicleInquiryList(parkNo);
  91. } else {
  92. uni.showModal({
  93. title: '提示',
  94. content: '参数丢失, 返回首页',
  95. showCancel: false,
  96. success: function (res) {
  97. if (res.confirm) {
  98. uni.switchTab({
  99. url: '/pages/index/index'
  100. });
  101. }
  102. }
  103. });
  104. }
  105. },
  106. methods: {
  107. /**
  108. * @description: 车牌输入框点击
  109. * @return {*}
  110. */
  111. vehicleNoInputClick() {
  112. this.keyboardshow = true;
  113. this.form.vehicleNo = '';
  114. },
  115. /**
  116. * @description: 单击车牌
  117. * @param {*} e
  118. * @return {*}
  119. */
  120. radioGroupChange(e) {
  121. this.form.vehicleNo = e;
  122. },
  123. /**
  124. * @description: 颜色下拉确认
  125. * @return {*}
  126. */
  127. confirmColor() {
  128. this.bindVehiclePop.colorShow = false;
  129. },
  130. /**
  131. * @description: 车牌键盘输入变化
  132. * @param {*} val
  133. * @return {*}
  134. */
  135. keyboardChange(val) {
  136. // 将每次按键的值拼接到value变量中,注意+=写法
  137. this.form.vehicleNo += val;
  138. },
  139. /**
  140. * @description: 键盘输入完成确认时
  141. * @return {*}
  142. */
  143. keyboardConfirm() {
  144. this.bindVehiclePop.colorShow = true;
  145. },
  146. /**
  147. * @description: 退格键被点击
  148. * @return {*}
  149. */
  150. backspace() {
  151. // 删除value的最后一个字符
  152. if (this.form.vehicleNo.length) this.form.vehicleNo = this.form.vehicleNo.substr(0, this.form.vehicleNo.length - 1);
  153. },
  154. /**
  155. * @description: 获取当前用户车辆
  156. * @return {*}
  157. */
  158. async getVehicleInquiryList(parkNo) {
  159. try {
  160. const { data, code } = await this.$u.api.getVehicleInquiryListApi({ parkNo });
  161. if (code === 200) {
  162. this.parkInfo = data;
  163. this.vehicleList = data.vehicleList.map((item) => {
  164. return { label: item, value: item };
  165. });
  166. await this.$nextTick();
  167. this.$refs.refValue.init();
  168. }
  169. } catch (error) {}
  170. },
  171. /**
  172. * @description: 确认车费查询
  173. * @return {*}
  174. */
  175. async submitVehicleInquiry() {
  176. const { vehicleNo } = this.form;
  177. const reg =
  178. /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领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})$/;
  179. if (reg.test(vehicleNo)) {
  180. this.loading = true;
  181. try {
  182. const { code } = await this.$u.api.getOrderInfoByParknoApi({ ...this.form });
  183. if (code === 200) {
  184. this.$refs.uToast.show({
  185. title: '查询成功!',
  186. type: 'success',
  187. url: '/pages/OnsitePayment/OnsitePayment',
  188. params: {
  189. ...this.form,
  190. vehicleNo: base64Encrypt(this.form.vehicleNo)
  191. },
  192. callback: () => {
  193. this.loading = false;
  194. }
  195. });
  196. }
  197. } catch (error) {
  198. this.loading = false;
  199. // this.showToast(error?.msg, 'error');
  200. }
  201. } else {
  202. this.loading = false;
  203. this.showToast('请输入有效的车牌号!', 'error');
  204. }
  205. },
  206. /**
  207. * @description: 提示
  208. * @param {*} title
  209. * @param {*} type
  210. * @return {*}
  211. */
  212. showToast(title = '操作失败!', type = 'error') {
  213. this.$refs.uToast.show({
  214. title,
  215. type
  216. });
  217. }
  218. }
  219. };
  220. </script>
  221. <style lang="scss" scoped>
  222. @import './VehicleInquiry.scss';
  223. </style>