index.js 3.6 KB

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