index.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. // components/CarNumInput/index.js
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. isKeyboard: {
  8. type: Boolean,
  9. value: false,
  10. },
  11. isNewEnergy:{//是否显示新能源按钮
  12. type: Boolean,
  13. value: false,
  14. },
  15. inputPlates:{////默认显示车牌号
  16. type: Object,
  17. value: '',
  18. },
  19. inputOnFocusIndex:{
  20. type: String,
  21. value: '',
  22. },
  23. },
  24. /**
  25. * 组件的初始数据
  26. */
  27. data: {
  28. isLoading: false,
  29. appUserId: "",
  30. escapeOrderList: [],
  31. carNumList: [],
  32. hasOrder: false,
  33. isKeyboard: false,//键盘弹窗显示
  34. isNumberKB: true,
  35. tapNum: false,
  36. disableKey: "1234567890港澳学",
  37. // keyboardNumber: "1234567890ABCDEFGHJKLMNPQRSTUVWXYZ港澳学",
  38. keyboardNumber: "1234567890QWERTYUP港澳ASDFGHJKL学ZXCVBNM",
  39. keyboard1: "渝川京沪粤津冀晋蒙辽吉黑苏浙皖闽赣鲁豫鄂湘桂琼贵云藏陕甘青宁新",
  40. inputPlates: {
  41. index0: "",
  42. index1: "",
  43. index2: "",
  44. index3: "",
  45. index4: "",
  46. index5: "",
  47. index6: "",
  48. index7: ""
  49. },
  50. inputOnFocusIndex: "",
  51. isNewEnergy: false,
  52. carNum: ""
  53. },
  54. /**
  55. * 组件的方法列表
  56. */
  57. methods: {
  58. //切换车牌
  59. changeplate: function (t) {
  60. var that = this;
  61. that.setData({
  62. 'inputPlates.index7':'',//切换是否是新能源时将其置空
  63. isNewEnergy: !that.data.isNewEnergy,
  64. });
  65. this.tapKeyboard(t)
  66. this.checkCarNum();
  67. },
  68. //切换车牌
  69. changeplate1: function () {
  70. var that = this;
  71. that.setData({
  72. flag: true,
  73. inputPlates: {
  74. index0: "",
  75. index1: "",
  76. index2: "",
  77. index3: "",
  78. index4: "",
  79. index5: "",
  80. index6: "",
  81. index7: ""
  82. },
  83. })
  84. },
  85. inputClick: function (t) {
  86. var that = this;
  87. //console.log('输入框:', t);
  88. //console.log('输入框:', t.target.dataset.id);
  89. if (t.target.dataset.id == 0) {
  90. that.setData({
  91. inputOnFocusIndex: t.target.dataset.id,
  92. isNumberKB: true,
  93. isKeyboard: true,
  94. tapNum: false,
  95. })
  96. };
  97. if (t.target.dataset.id == 1) {
  98. that.setData({
  99. inputOnFocusIndex: t.target.dataset.id,
  100. isNumberKB: false,
  101. isKeyboard: true,
  102. tapNum: false,
  103. })
  104. }
  105. if (t.target.dataset.id > 1) {
  106. that.setData({
  107. inputOnFocusIndex: t.target.dataset.id,
  108. isNumberKB: false,
  109. isKeyboard: true,
  110. tapNum: true,
  111. })
  112. }
  113. },
  114. //键盘点击事件
  115. tapKeyboard: function (t) {
  116. t.target.dataset.index;
  117. var a = t.target.dataset.val;
  118. //console.log("data",this.data);
  119. //console.log('键盘:',a);
  120. //console.log("index",t.target.dataset.index);
  121. //console.log("focus",this.data.inputOnFocusIndex);
  122. switch (parseInt(this.data.inputOnFocusIndex)) {
  123. case 0:
  124. this.setData({
  125. "inputPlates.index0": a,
  126. inputOnFocusIndex: "1"
  127. });
  128. break;
  129. case 1:
  130. this.setData({
  131. "inputPlates.index1": a,
  132. inputOnFocusIndex: "2"
  133. });
  134. break;
  135. case 2:
  136. this.setData({
  137. "inputPlates.index2": a,
  138. inputOnFocusIndex: "3"
  139. });
  140. break;
  141. case 3:
  142. this.setData({
  143. "inputPlates.index3": a,
  144. inputOnFocusIndex: "4"
  145. });
  146. break;
  147. case 4:
  148. this.setData({
  149. "inputPlates.index4": a,
  150. inputOnFocusIndex: "5"
  151. });
  152. break;
  153. case 5:
  154. this.setData({
  155. "inputPlates.index5": a,
  156. inputOnFocusIndex: "6"
  157. });
  158. break;
  159. case 6:
  160. this.setData({
  161. "inputPlates.index6": a,
  162. inputOnFocusIndex: "7"
  163. });
  164. break;
  165. case 7:
  166. this.setData({
  167. "inputPlates.index7": a,
  168. inputOnFocusIndex: "7"
  169. });
  170. }
  171. var n = this.data.inputPlates.index0 + this.data.inputPlates.index1 + this.data.inputPlates.index2 + this.data.inputPlates.index3 + this.data.inputPlates.index4 + this.data.inputPlates.index5 + this.data.inputPlates.index6
  172. if(this.data.isNewEnergy&&this.data.inputPlates.index7){
  173. n = n + this.data.inputPlates.index7
  174. }
  175. // console.log('车牌号:', n, '--',this.data.inputPlates.index7);
  176. this.data.carNum = n;
  177. this.checkedSubmitButtonEnabled();
  178. this.checkCarNum();
  179. },
  180. //键盘关闭按钮点击事件
  181. tapSpecBtn: function (t) {
  182. var a = this,
  183. e = t.target.dataset.index;
  184. if (0 == e) {
  185. switch (parseInt(this.data.inputOnFocusIndex)) {
  186. case 0:
  187. this.setData({
  188. "inputPlates.index0": "",
  189. inputOnFocusIndex: "0"
  190. });
  191. break;
  192. case 1:
  193. this.setData({
  194. "inputPlates.index1": "",
  195. inputOnFocusIndex: "0"
  196. });
  197. break;
  198. case 2:
  199. this.setData({
  200. "inputPlates.index2": "",
  201. inputOnFocusIndex: "1"
  202. });
  203. break;
  204. case 3:
  205. this.setData({
  206. "inputPlates.index3": "",
  207. inputOnFocusIndex: "2"
  208. });
  209. break;
  210. case 4:
  211. this.setData({
  212. "inputPlates.index4": "",
  213. inputOnFocusIndex: "3"
  214. });
  215. break;
  216. case 5:
  217. this.setData({
  218. "inputPlates.index5": "",
  219. inputOnFocusIndex: "4"
  220. });
  221. break;
  222. case 6:
  223. this.setData({
  224. "inputPlates.index6": "",
  225. inputOnFocusIndex: "5"
  226. });
  227. break;
  228. case 7:
  229. this.setData({
  230. "inputPlates.index7": "",
  231. inputOnFocusIndex: "6"
  232. });
  233. }
  234. this.checkedSubmitButtonEnabled();
  235. } else 1 == e && a.setData({
  236. isKeyboard: !1,
  237. isNumberKB: !1,
  238. inputOnFocusIndex: ""
  239. });
  240. var n = ''
  241. if(this.data.inputPlates){
  242. n = this.data.inputPlates.index0 + this.data.inputPlates.index1 + this.data.inputPlates.index2 + this.data.inputPlates.index3 + this.data.inputPlates.index4 + this.data.inputPlates.index5 + this.data.inputPlates.index6
  243. if(this.data.isNewEnergy&&this.data.inputPlates.index7){
  244. n = n + this.data.inputPlates.index7
  245. }
  246. }
  247. //console.log('车牌号:', n);
  248. this.data.carNum = n;
  249. this.checkCarNum();
  250. },
  251. //键盘切换
  252. checkedKeyboard: function () {
  253. var t = this;
  254. //console.log("键盘切换", this.data.inputOnFocusIndex);
  255. if (this.data.inputOnFocusIndex == 0) {
  256. t.setData({
  257. tapNum: false,
  258. isNumberKB: true
  259. })
  260. }
  261. if (this.data.inputOnFocusIndex == 1) {
  262. t.setData({
  263. tapNum: false,
  264. isNumberKB: false
  265. })
  266. }
  267. if (this.data.inputOnFocusIndex > 1) {
  268. t.setData({
  269. tapNum: true,
  270. isNumberKB: false
  271. })
  272. }
  273. },
  274. checkedSubmitButtonEnabled: function () {
  275. this.checkedKeyboard();
  276. var t = !0;
  277. for (var a in this.data.inputPlates)
  278. if ("index7" != a && this.data.inputPlates[a].length < 1) {
  279. t = !1;
  280. break;
  281. }
  282. },
  283. //校验车牌号-车牌输入限制了正确格式只判断车牌位数
  284. checkCarNum: function () {
  285. if (this.data.isNewEnergy && this.data.carNum.length < 8) {
  286. let res = {
  287. carNum: this.data.carNum,
  288. isPlate: false
  289. }
  290. this.triggerEvent("setCarNum", res);
  291. return false
  292. }
  293. if (!this.data.isNewEnergy) {
  294. if (this.data.carNum.length < 7) {
  295. let res = {
  296. carNum: this.data.carNum,
  297. isPlate: false
  298. }
  299. this.triggerEvent("setCarNum", res);
  300. return false
  301. } else {
  302. var carNum = this.data.carNum.substr(0, 7);
  303. let res = {
  304. carNum: carNum,
  305. isPlate: true
  306. }
  307. this.triggerEvent("setCarNum", res);
  308. return true;
  309. }
  310. }
  311. let res = {
  312. carNum: this.data.carNum,
  313. isPlate: true
  314. }
  315. this.triggerEvent("setCarNum", res);
  316. return true;
  317. }
  318. }
  319. })