index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // components/addCarNumber/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. value: { //输入值
  8. value: null
  9. },
  10. placeholder: {
  11. type: String,
  12. value: '请输入车牌号'
  13. },
  14. isAudit: { //是否禁用
  15. type: Boolean,
  16. value: false
  17. },
  18. disabled: { //是否禁用
  19. type: Boolean,
  20. value: false
  21. },
  22. },
  23. /**
  24. * 组件的初始数据
  25. */
  26. data: {
  27. areaWordList: ['浙','京','沪','苏','粤','鲁','晋','冀','豫','川','渝','辽','吉','黑','皖','鄂','湘','赣','闽','陕','甘','宁','蒙','津','贵','云','桂','琼','青','新','藏','港','澳','台'], //地域中文表
  28. numberList: [],//数字表
  29. wordList: [], //字母表
  30. show: false, //是否显示键盘弹窗
  31. showAreaWord: true, //是否显示地域中文表
  32. showCompleteButton: false //是否显示完成按钮
  33. },
  34. /**
  35. * 组件的方法列表
  36. */
  37. methods: {
  38. // 点击拉起键盘输入
  39. showpopup() {
  40. if(!this.data.isAudit && !this.data.disabled) {
  41. this.setData({
  42. show: true
  43. })
  44. this.matchValue(this.data.value)
  45. }
  46. },
  47. // 获得初始化英文数字数组
  48. getNumberList() {
  49. let numberArr = Array.from(new Array(10)).map((item,index) => {return index.toString()})
  50. let wordArr = Array.from(new Array(26)).map((item,index) => {return String.fromCharCode(index+65)});
  51. wordArr = wordArr.concat(['挂','领','港','澳','学','警'])
  52. this.setData({
  53. numberList: numberArr,
  54. wordList: wordArr,
  55. })
  56. },
  57. // 点击获得输入值
  58. getValue(e) {
  59. let word = e.currentTarget.dataset.value
  60. let { value } = this.data;
  61. value = value?(value+word):word;
  62. if(value.length == 2) {
  63. let charCode = word.charCodeAt()
  64. if(charCode < 65 || charCode > 90) {
  65. wx.showToast({
  66. title: '车牌号的第二位必需是字母',
  67. icon: 'none'
  68. });
  69. return
  70. }
  71. }
  72. this.matchValue(value)
  73. },
  74. // 判断输入值操作
  75. matchValue(value) {
  76. if(value && value.length > 8) return;
  77. this.setData({
  78. value
  79. });
  80. this.triggerEvent('change', value);
  81. if(!this.data.showCompleteButton && value && value.length >= 7) {
  82. this.setData({
  83. showCompleteButton: true
  84. });
  85. } else if(this.data.showCompleteButton && value && value.length < 7) {
  86. this.setData({
  87. showCompleteButton: false
  88. });
  89. }
  90. },
  91. // 删除
  92. delete() {
  93. let { value } = this.data;
  94. value = value.slice(0, value.length-1);
  95. this.matchValue(value)
  96. },
  97. // 关闭键盘
  98. onClose() {
  99. this.setData({
  100. show: false
  101. })
  102. },
  103. //取消
  104. cancel() {
  105. this.setData({
  106. show: false,
  107. value: null
  108. })
  109. this.triggerEvent('change', this.data.value);
  110. }
  111. },
  112. observers: {
  113. "value":function(value) {
  114. let showAreaWord = value?false:true
  115. this.setData({
  116. showAreaWord: showAreaWord
  117. });
  118. }
  119. },
  120. lifetimes: {
  121. attached() {
  122. this.getNumberList();
  123. this.matchValue(this.data.value)
  124. }
  125. }
  126. })