index.js 4.0 KB

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