master-keyboard.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <template>
  2. <view class="master_wrap" v-show="show" hover-stop-propagation>
  3. <block v-if="keyboardtype == 'number' || keyboardtype == 'digit' || keyboardtype == 'idcard'">
  4. <view class="down_wrap">
  5. <image src="../../static/icon_down.png" @tap.stop="handleCloseKeyboard(false)"></image>
  6. </view>
  7. <view class="kerboard_number">
  8. <view @tap.stop="handleNumberKeyboardClick(item)" :hover-stay-time="100"
  9. :class="item== '-1' ? keyboardtype == 'number' ? 'number_empty' :'number_item' : item=='-2' ? 'number_delete' : 'number_item' "
  10. :hover-class="item== '-1' ? keyboardtype == 'number' ? 'number_empty_active' : 'number_item_active' : item=='-2' ? 'number_delete_active' : 'number_item_active'"
  11. v-for="(item,index) in randomNumberArr" :key="index">
  12. <block v-if="item == '-1'">
  13. <view v-if="keyboardtype == 'digit'">
  14. ·
  15. </view>
  16. <view v-else-if=" keyboardtype == 'idcard'">
  17. X
  18. </view>
  19. </block>
  20. <block v-else-if="item == '-2'">
  21. <image class="delete_img" src="../../static/icon_delete.png"></image>
  22. </block>
  23. <block v-else>
  24. {{item}}
  25. </block>
  26. </view>
  27. </view>
  28. <view class="next-btn">
  29. <view class='number_next' @click="nextBtnClick(0)">上一项</view>
  30. <view class='number_next' @click="nextBtnClick(1)">下一项</view>
  31. </view>
  32. </block>
  33. <block v-else-if="keyboardtype == 'car'">
  34. <view class="keyboard_car">
  35. <image @tap.stop="handleCloseKeyboard(false)" class="car_down" src="../../static/icon_down.png"></image>
  36. <view class="tab_wrap">
  37. <view @tap.stop="handleCarTabItemClick(index)"
  38. :class=" carType === index ?'tab_item_active' : 'tab_item'" hover-class="tab_item_active"
  39. v-for="(item,index) in carTabArr" :key="index">
  40. {{item}}
  41. </view>
  42. </view>
  43. <view class="car_content">
  44. <block v-if="carType === 0">
  45. <view class="car_province">
  46. <view @tap.stop="handleCarKerboardClick(item)"
  47. :class="computedDefaultValueLength ===0 ? 'province_item' :'province_item_disable'"
  48. :hover-class="computedDefaultValueLength ===0 ? 'province_item_active' : 'none'"
  49. :hover-stay-time="100" v-for="(item,index) in sliceProvinceArr" :key="index">
  50. {{item}}
  51. </view>
  52. </view>
  53. <view class="car_province_1">
  54. <view @tap.stop="handleCarKerboardClick(item)"
  55. :class=" (formatCarProvinceFirst(item) === -1 && computedDefaultValueLength ===0 ) ? 'province_item1' :
  56. ((newCar && computedDefaultValueLength ===7 && formatCarProvinceFirst(item) !== -1) ||
  57. (!newCar && computedDefaultValueLength ===6 && formatCarProvinceFirst(item) !== -1) ) ? 'province_item1' : 'province_item_disable'"
  58. :hover-class=" (formatCarProvinceFirst(item) === -1 && computedDefaultValueLength ===0) ? 'province_item_active' : 'none'"
  59. :hover-stay-time="100" :style="{'margin-left' : computeItemSpace + '%'}"
  60. v-for="(item,index) in sliceSecondProvinceArr" :key="index">
  61. {{item}}
  62. </view>
  63. </view>
  64. </block>
  65. <block v-else="carType === 1">
  66. <view class="car_latter">
  67. <view @tap.stop="handleCarKerboardClick(item)"
  68. :class=" (computedDefaultValueLength ===1 && formatCarProvinceSecond(item) >-1 || computedDefaultValueLength ===0) ? 'province_item_disable' : 'latter_item'"
  69. :hover-class=" (computedDefaultValueLength ===1 && formatCarProvinceSecond(item) >-1 || computedDefaultValueLength ===0) ? 'none' : 'province_item_active'"
  70. :hover-stay-time="100" v-for="(item,index) in sliceLatterArr" :key="index">
  71. <text>{{item}}</text>
  72. </view>
  73. </view>
  74. <view class="car_province_1">
  75. <view @tap.stop="handleCarKerboardClick(item)"
  76. :class=" (computedDefaultValueLength ===1 && formatCarProvinceSecond(item) >-1 || computedDefaultValueLength ===0) ? 'province_item_disable' : 'province_item1'"
  77. :hover-class=" (computedDefaultValueLength ===1 && formatCarProvinceSecond(item) >-1 || computedDefaultValueLength ===0) ? 'none' : 'province_item_active'"
  78. :hover-stay-time="100" :style="{'margin-left' : computeItemSpace + '%'}"
  79. v-for="(item,index) in sliceSecondLatterArr" :key="index">
  80. {{item}}
  81. </view>
  82. </view>
  83. </block>
  84. <view @tap.stop="handleCarKerboardDeleteClick" class="car_delete" hover-class="car_delete_active"
  85. :hover-stay-time="100"
  86. :style="{'top':computeDeleteTop + 'rpx','right' :computeItemSpace + '%' }">
  87. <image class="delete_img" src="../../static/icon_delete.png"></image>
  88. </view>
  89. </view>
  90. </view>
  91. </block>
  92. </view>
  93. </template>
  94. <script>
  95. export default {
  96. name: "master-keyboard",
  97. props: {
  98. fatherMethod: {
  99. type: Function,
  100. default: null
  101. },
  102. keyboardtype: {
  103. type: String,
  104. default: 'number' // number=数字键盘 digit=带小数点的数字键盘 idcard=身份证号键盘 car=车牌号键盘
  105. },
  106. guastatus:{
  107. type: Boolean,
  108. default: false
  109. },
  110. defaultValue: {
  111. type: String,
  112. default: ''
  113. },
  114. newCar: {
  115. type: Boolean,
  116. default: false
  117. },
  118. randomNumber: {
  119. type: Boolean,
  120. default: false
  121. }
  122. },
  123. data() {
  124. return {
  125. numberArr: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0'],
  126. carProvinceArr: ['京', '津', '渝', '沪', '冀', '晋', '辽', '吉', '黑', '苏', '浙', '皖', '闽', '赣', '鲁', '豫',
  127. '鄂', '湘', '粤', '琼', '川', '贵', '云', '陕', '甘', '青', '蒙', '桂', '宁', '新', '藏', '使',
  128. '领', '警', '学', '港', '澳'
  129. ],
  130. carLatterArr: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
  131. 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',
  132. 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'
  133. ],
  134. carTabArr: ['省份', '字母'],
  135. carType: 0,
  136. show: false,
  137. };
  138. },
  139. computed: {
  140. sliceProvinceArr: function() {
  141. return this.carProvinceArr.slice(0, 30)
  142. },
  143. sliceSecondProvinceArr: function() {
  144. return this.carProvinceArr.slice(30, this.carProvinceArr.length)
  145. },
  146. sliceLatterArr: function() {
  147. return this.carLatterArr.slice(0, 30)
  148. },
  149. sliceSecondLatterArr: function() {
  150. return this.carLatterArr.slice(30, this.carLatterArr.length)
  151. },
  152. computeDeleteTop: function() {
  153. return 80 * 3 + 10 * 3
  154. },
  155. computeItemSpace: function() {
  156. return (1 - 0.095 * 10) / 11 * 100
  157. },
  158. computedDefaultValueLength: function() {
  159. return this.$props.defaultValue.length
  160. },
  161. randomNumberArr: function() {
  162. if(this.$props.randomNumber){
  163. this.numberArr.sort(function() {
  164. return 0.5 - Math.random()
  165. })
  166. }
  167. const size = this.numberArr.length
  168. this.numberArr.splice(size - 1, 0, "-1")
  169. this.numberArr.push("-2")
  170. return this.numberArr
  171. }
  172. },
  173. watch: {
  174. show: function(value) {
  175. }
  176. },
  177. onLoad() {},
  178. methods: {
  179. nextBtnClick(type){
  180. let that = this
  181. if (this.fatherMethod) {
  182. this.fatherMethod(type);
  183. }
  184. },
  185. formatCarProvinceFirst(value) {
  186. const list = ['使', '领', '警', '学', '港', '澳', ]
  187. return list.indexOf(value)
  188. },
  189. formatCarProvinceSecond(value) {
  190. const list = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '0']
  191. return list.indexOf(value)
  192. },
  193. handleCloseKeyboard() {
  194. this.open(false)
  195. },
  196. open(value) {
  197. this.show = value
  198. if(!value&&this.keyboardtype == 'car'){
  199. this.carType=0
  200. }
  201. },
  202. //车牌tab点击事件
  203. handleCarTabItemClick(index) {
  204. this.carType = index
  205. },
  206. //车牌键盘点击事件
  207. handleCarKerboardClick(e) {
  208. const keyValue = e
  209. let value = this.$props.defaultValue
  210. if (/^[\u4e00-\u9fa5]*$/.test(value) && value.length >= 2) {
  211. value = ''
  212. }
  213. var pattern = new RegExp("[\u4E00-\u9FA5]+");
  214. var pattern2 = new RegExp("[A-Za-z]+");
  215. var pattern3 = new RegExp("[0-9]+");
  216. if (value.length == 0) {
  217. if (!pattern.test(keyValue) || this.formatCarProvinceFirst(keyValue) !== -1) {
  218. return
  219. }
  220. this.carType = 1
  221. } else if (value.length == 1) {
  222. if (!pattern2.test(keyValue)) {
  223. return
  224. }
  225. } else {
  226. if(this.$props.guastatus){
  227. if (value.length === 5 && pattern.test(keyValue) && this
  228. .formatCarProvinceFirst(keyValue) == -1) {
  229. return
  230. }
  231. if (pattern.test(keyValue) && value.length !== 5) {
  232. return
  233. }
  234. }else{
  235. if (value.length === (this.$props.newCar ? 7 : 6) && pattern.test(keyValue) && this
  236. .formatCarProvinceFirst(keyValue) == -1) {
  237. return
  238. }
  239. if (pattern.test(keyValue) && value.length !== (this.$props.newCar ? 7 : 6)) {
  240. return
  241. }
  242. }
  243. }
  244. if(this.$props.guastatus){
  245. if (value.length < 6 ) {
  246. this.$emit('keyboardClick', {
  247. value: value + keyValue
  248. })
  249. }
  250. }
  251. else{
  252. if (value.length < 7 && !this.$props.newCar) {
  253. this.$emit('keyboardClick', {
  254. value: value + keyValue
  255. })
  256. }
  257. if (value.length < 8 && this.$props.newCar) {
  258. this.$emit('keyboardClick', {
  259. value: value + keyValue
  260. })
  261. }
  262. }
  263. },
  264. //车牌键盘删除事件
  265. handleCarKerboardDeleteClick() {
  266. let deleteValue = this.$props.defaultValue
  267. if (deleteValue == '' || (/^[\u4e00-\u9fa5]*$/.test(deleteValue) && deleteValue.length !== 1)) {
  268. return
  269. }
  270. if (deleteValue.length > 0) {
  271. let count = deleteValue.length
  272. this.$emit('keyboardClick', {
  273. value: deleteValue.substr(0, count - 1)
  274. })
  275. }
  276. },
  277. //数字键盘点击事件
  278. handleNumberKeyboardClick(e) {
  279. const keyValue = e
  280. if (this.$props.keyboardtype == 'number' || this.$props.keyboardtype == 'digit' || this.$props
  281. .keyboardtype == 'idcard') {
  282. switch (keyValue) {
  283. case '-1':
  284. if (this.$props.keyboardtype == 'number' || this.$props.defaultValue == '') {
  285. return
  286. }
  287. let value = this.$props.defaultValue
  288. if (/^[\u4e00-\u9fa5]*$/.test(value) || value.indexOf('.') > -1 || value.indexOf('X') > -1) {
  289. return
  290. }
  291. if (this.$props.keyboardtype == 'idcard') {
  292. if (value.length === 17) {
  293. this.$emit('keyboardClick', {
  294. value: value + 'X'
  295. })
  296. }
  297. }
  298. if (this.$props.keyboardtype == 'digit') {
  299. this.$emit('keyboardClick', {
  300. value: value + '.'
  301. })
  302. }
  303. break
  304. case '-2':
  305. let deleteValue = this.$props.defaultValue
  306. if (deleteValue == '' || /^[\u4e00-\u9fa5]*$/.test(deleteValue)) {
  307. return
  308. }
  309. if (deleteValue.length > 0) {
  310. let count = deleteValue.length
  311. this.$emit('keyboardClick', {
  312. value: deleteValue.substr(0, count - 1)
  313. })
  314. }
  315. break
  316. default:
  317. let initValue = this.$props.defaultValue
  318. if (/^[\u4e00-\u9fa5]*$/.test(initValue)) {
  319. initValue = ''
  320. }
  321. if (this.$props.keyboardtype == 'idcard') {
  322. if (initValue.length < 18) {
  323. this.$emit('keyboardClick', {
  324. value: initValue + keyValue
  325. })
  326. }
  327. return
  328. }
  329. this.$emit('keyboardClick', {
  330. value: initValue + keyValue
  331. })
  332. break
  333. }
  334. }
  335. }
  336. }
  337. }
  338. </script>
  339. <style scoped lang="scss">
  340. @import './master-keyboard.scss';
  341. .next-btn{
  342. display: flex;
  343. justify-content: space-evenly;
  344. .number_next{
  345. width: 45%;
  346. }
  347. }
  348. </style>