index.js 3.4 KB

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