gui-car-number.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. <template>
  2. <gui-popup
  3. ref="guipopupforcarnumber"
  4. width="750rpx"
  5. position="bottom"
  6. :isSwitchPage="isSwitchPage"
  7. @close="close"
  8. :canCloseByShade="true">
  9. <view
  10. @tap.stop.prevent="stopfun"
  11. class="gui-bg-white gui-dark-bg-level-3">
  12. <view
  13. class="gui-flex gui-rows gui-space-between gui-align-items-center"
  14. style="padding:20rpx;">
  15. <!-- 类型 -->
  16. <view style="width:320rpx;">
  17. <gui-segmented-control
  18. :items="['普通车牌','新能源牌']"
  19. :current="carType"
  20. @change="changeType"></gui-segmented-control>
  21. </view>
  22. <text
  23. class="gui-car-number-submit gui-block gui-primary-color"
  24. @tap="confirm">确定</text>
  25. </view>
  26. <!-- 车牌展示 -->
  27. <view
  28. class="gui-flex gui-rows gui-nowrap gui-justify-content-center"
  29. style="padding-top:20rpx; padding-bottom:20rpx;">
  30. <text
  31. class="gui-car-number-item gui-block gui-border"
  32. :class="[
  33. idx == inputIndex ? 'gui-bg-gray' : '',
  34. idx == inputIndex ? 'gui-a-shade' : ''
  35. ]"
  36. v-for="(item, idx) in carNumberArray"
  37. :key="idx"
  38. @tap="numberTap(idx)">{{item}}</text>
  39. </view>
  40. <!-- 错误信息 -->
  41. <view
  42. v-if="errorshow"
  43. style="padding:20rpx; margin-bottom:10rpx;">
  44. <text
  45. class="gui-text gui-block gui-color-red gui-text-center">请输入完整车牌号码</text>
  46. </view>
  47. <view
  48. style="padding:15rpx;">
  49. <!-- 省份前缀键盘 -->
  50. <view
  51. class="gui-flex gui-rows gui-wrap gui-overflow-hidden"
  52. :style="{height: inputIndex == 0 ? '' : '0px'}">
  53. <view
  54. class="gui-car-number-key gui-border"
  55. hover-class="gui-tap"
  56. :hover-stay-time="50"
  57. v-for="(item, idx) in provinces"
  58. :key="idx"
  59. @tap="provinceTap(item)">
  60. <text class="gui-car-number-key-txt gui-block-text">{{item}}</text>
  61. </view>
  62. </view>
  63. <!-- 号码键盘 -->
  64. <view
  65. class="gui-flex gui-rows gui-wrap gui-space-between gui-overflow-hidden"
  66. :style="{height: inputIndex > 0 ? '' : '0px'}">
  67. <view
  68. class="gui-car-number-key gui-border"
  69. hover-class="gui-tap"
  70. :hover-stay-time="50"
  71. v-for="(item, idx) in keyWords"
  72. :key="idx"
  73. @tap="keyTap(item)">
  74. <text
  75. class="gui-car-number-key-txt gui-block gui-primary-text">{{item}}</text>
  76. </view>
  77. <view
  78. class="gui-car-number-key"
  79. hover-class="gui-tap"
  80. @tap="deleteNumber">
  81. <text
  82. class="gui-car-number-key-txt gui-block gui-primary-text gui-icons">&#xe623;</text>
  83. </view>
  84. </view>
  85. </view>
  86. <gui-iphone-bottom v-if="!isSwitchPage"></gui-iphone-bottom>
  87. </view>
  88. </gui-popup>
  89. </template>
  90. <script>
  91. export default{
  92. name : "gui-car-number",
  93. props : {
  94. isSwitchPage : { type : Boolean, default : false}
  95. },
  96. data() {
  97. return {
  98. carNumber : '',
  99. carNumberArray : [],
  100. carType : 0,
  101. inputIndex : 0,
  102. provinces : ['京','津','沪','渝','冀','豫','云',
  103. '辽','黑','湘','皖','鲁','新','苏',
  104. '浙','赣','鄂','桂','甘','晋','蒙',
  105. '陕','吉','闽','贵','粤','青','藏',
  106. '川','宁','琼','使','领','新'
  107. ],
  108. keyWords : ['1','2','3','4','5','6','7','8','9','0',
  109. 'A','B','C','D','E','F','G','H',
  110. 'J','K','L','M','N','P','Q','R',
  111. 'S','T','U','V','W','X','Y','Z',
  112. '港','澳','学','领','警'],
  113. errorshow : false
  114. }
  115. },
  116. mounted:function(){
  117. this.showNumber();
  118. },
  119. methods:{
  120. showError : function () {
  121. this.errorshow = true;
  122. setTimeout(()=>{this.errorshow = false},2000)
  123. },
  124. confirm : function () {
  125. let carNumberLength = this.carType == 0 ? 7 : 8;
  126. if(this.carNumber.length < carNumberLength){
  127. this.showError();
  128. return ;
  129. }
  130. this.$emit('confirm', this.carNumber);
  131. this.$refs.guipopupforcarnumber.close();
  132. },
  133. numberTap : function (idx) {
  134. this.inputIndex = idx
  135. },
  136. provinceTap : function(key){
  137. this.carNumberArray[0] = key;
  138. this.carNumber = this.carNumberArray.join('');
  139. this.showNumber();
  140. },
  141. keyTap : function(key){
  142. let carNumberLength = this.carType == 0 ? 7 : 8;
  143. if(this.inputIndex >= carNumberLength){return ;}
  144. this.carNumberArray[this.inputIndex] = key;
  145. this.carNumber = this.carNumberArray.join('');
  146. this.showNumber();
  147. },
  148. showNumber : function(){
  149. let carNumberArray = this.carNumber.split('');
  150. let carNumberLength = this.carType == 0 ? 7 : 8;
  151. let carNumberArrLength = carNumberArray.length;
  152. this.carNumberArray = [];
  153. var inputIndex = 0;
  154. for(let i = 0; i < carNumberLength; i++){
  155. if(carNumberArrLength > i){
  156. this.carNumberArray[i] = carNumberArray[i];
  157. inputIndex++;
  158. }else{
  159. this.carNumberArray[i] = '';
  160. }
  161. }
  162. this.carNumber = this.carNumberArray.join('');
  163. this.inputIndex = inputIndex;
  164. },
  165. changeType : function(e){
  166. this.carType = e;
  167. this.showNumber();
  168. },
  169. setType : function(carType){
  170. this.carType = carType;
  171. this.showNumber();
  172. },
  173. setVal : function(carNumber){
  174. this.carNumber = carNumber;
  175. this.showNumber();
  176. },
  177. deleteNumber : function(){
  178. if(this.inputIndex < 0){return ;}
  179. this.carNumberArray.splice((this.inputIndex -1), 1, '');
  180. this.carNumber = this.carNumberArray.join('');
  181. this.showNumber();
  182. },
  183. open : function(){
  184. this.$refs.guipopupforcarnumber.open();
  185. this.$emit('open');
  186. },
  187. stopfun : function(e){
  188. e.stopPropagation();
  189. return ;
  190. },
  191. close : function(){
  192. this.$emit('close');
  193. }
  194. },
  195. emits : ['confirm', 'open', 'close']
  196. }
  197. </script>
  198. <style scoped>
  199. </style>