vehicleAddOrEdit.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  1. import uniPop from '@/components/uni-popup/uni-popup.vue';
  2. import plateNumber from '@/components/plate-number/plateNumber.vue';
  3. import uni from '@/utils/uniHooks';
  4. import { Toast } from 'vant';
  5. import { LICENSE_PLATE_TYPE_ARR } from '@/constants.js';
  6. import {
  7. kipAddMemberVehicles,
  8. kipModifyMemberVehicles,
  9. } from '@/utils/api-kip.js';
  10. import { mapState } from 'vuex';
  11. import { addVehicles, editVehicles } from '@/api/parking/index'
  12. export default {
  13. components: {
  14. uniPop,
  15. plateNumber,
  16. },
  17. data() {
  18. return {
  19. carInfo: {},
  20. carType: 0,
  21. active: null,
  22. ind: null,
  23. numArr: ['', '', '', '', '', '', ''],
  24. vehicleNumber: '',
  25. licensePlateTypeArr: LICENSE_PLATE_TYPE_ARR,
  26. preUrl: '',
  27. };
  28. },
  29. created() {
  30. // 埋点本地化
  31. this.preUrl = uni.getStorageSync('previousUrl');
  32. uni.setStorageSync('previousUrl', '/pages/parkingFee/vehicleAddOrEdit.vue');
  33. },
  34. mounted() {
  35. const params = this.$route.query;
  36. console.log(55555, params);
  37. if (params.carType) {
  38. this.carInfo = {
  39. ...params,
  40. };
  41. this.carType = Number.parseInt(this.carInfo.carType);
  42. this.$refs['k-tab'].changeTab(this.carType)
  43. this.numArr = this.carInfo.carno.split('');
  44. this.vehicleNumber = this.carInfo.carno;
  45. }
  46. },
  47. computed: {
  48. disabledBtn() {
  49. return this.numArr.findIndex((val) => !val) !== -1;
  50. },
  51. ...mapState({
  52. custTypeId: (state) => state.custTypeId, // custTypeId: 0 默认版本,1 上海静安 2 上海浦东
  53. kipUserId: (state) => state.kipUserId,
  54. }),
  55. },
  56. methods: {
  57. // 切换车牌类型
  58. toggleType(index) {
  59. this.ind = 0;
  60. this.active = 0;
  61. this.carType = index;
  62. if (this.carType == '1') {
  63. this.numArr = [
  64. this.numArr[0],
  65. this.numArr[1],
  66. this.numArr[2],
  67. this.numArr[3],
  68. this.numArr[4],
  69. this.numArr[5],
  70. this.numArr[6],
  71. this.numArr[7],
  72. ];
  73. } else {
  74. this.numArr = [
  75. this.numArr[0],
  76. this.numArr[1],
  77. this.numArr[2],
  78. this.numArr[3],
  79. this.numArr[4],
  80. this.numArr[5],
  81. this.numArr[6],
  82. ];
  83. }
  84. },
  85. // 唤起键盘
  86. clickShowKeyboard(index) {
  87. if ( this.carType !== 1 && index === 7) return
  88. this.ind = index;
  89. this.active = index;
  90. // console.log('唤起键盘', this.ind, this.active);
  91. this.$nextTick(() => {
  92. // return;
  93. if (index === 0) {
  94. this.$refs['plateKeyboard'].openKeyboardCN();
  95. } else {
  96. // this.$refs['plateKeyboard'].closeKeyboardCN();
  97. this.$refs['plateKeyboard'].openKeyboardEN();
  98. }
  99. });
  100. },
  101. // 接收子组件数据
  102. updateCarno(val) {
  103. // console.log(320, val);
  104. this.numArr = val.numArr;
  105. this.active = val.active;
  106. this.ind = val.ind;
  107. this.vehicleNumber = this.numArr.join('');
  108. },
  109. // 车牌号校验
  110. // isVehicleNumber(vehicleNumber) {
  111. // if (vehicleNumber.length == 7) {
  112. // this.vehicleNumber = vehicleNumber.join("");
  113. // var express =
  114. // /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z](([0-9]{5}[DF])|([DF]([A-HJ-NP-Z0-9])[0-9]{4})))|([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4}[A-HJ-NP-Z0-9挂学警港澳使领]))$/;
  115. // if (!express.test(this.vehicleNumber)) {
  116. // uni.showToast({
  117. // title: "请输入正确的车牌号",
  118. // duration: 2000,
  119. // icon: "none",
  120. // });
  121. // return false;
  122. // }
  123. // return true;
  124. // }
  125. // if (vehicleNumber.length == 8) {
  126. // this.vehicleNumber = vehicleNumber.join("");
  127. // var express =
  128. // /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[a-zA-Z](([DF]((?![IO])[a-zA-Z0-9](?![IO]))[0-9]{4})|([0-9]{5}[DF]))|[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1})$/;
  129. // if (!express.test(this.vehicleNumber)) {
  130. // uni.showToast({
  131. // title: "请输入正确的车牌号",
  132. // duration: 2000,
  133. // icon: "none",
  134. // });
  135. // return false;
  136. // }
  137. // return true;
  138. // }
  139. // },
  140. async handleAddLicensePlateByTMP() {
  141. const params = {
  142. userId: this.kipUserId,
  143. licensePlateType: this.licensePlateTypeArr[this.carType].value,
  144. vehicleNo: this.vehicleNumber,
  145. };
  146. if(this.carInfo?.id) {
  147. // 修改
  148. const res = await editVehicles(this.carInfo?.id, {
  149. id: this.carInfo?.id,
  150. ...params
  151. })
  152. if(res.id) {
  153. Toast({
  154. message: '修改车牌成功',
  155. position: 'top',
  156. onClose: () => {
  157. // this.$router.replace({
  158. // path: `vehicleManagement`,
  159. // });
  160. setTimeout(() => {
  161. this.$router.go(-1)
  162. }, 300)
  163. }
  164. });
  165. } else {
  166. const message = res.langMessage || '修改车牌失败';
  167. Toast({
  168. message: message,
  169. });
  170. }
  171. return
  172. }
  173. // 添加
  174. const res= await addVehicles( this.kipUserId, params )
  175. if(res?.id) {
  176. Toast({
  177. message: '绑定车牌成功',
  178. position: 'top',
  179. onClose: () => {
  180. // this.$router.replace({
  181. // path: `vehicleManagement`,
  182. // });
  183. setTimeout(() => {
  184. this.$router.go(-1)
  185. }, 300)
  186. }
  187. });
  188. } else {
  189. const message = res.langMessage || '绑定车牌失败';
  190. Toast({
  191. message: message,
  192. position: 'top',
  193. });
  194. }
  195. },
  196. handleAddLicensePlateByKipMember() {
  197. this.handleAddLicensePlateByTMP()
  198. return
  199. // console.log('handleAddLicensePlateByKipMember执行');
  200. uni.showLoading({
  201. title: '加载中',
  202. });
  203. const params = {
  204. licensePlateType: this.licensePlateTypeArr[this.carType].value,
  205. vehicleNo: this.vehicleNumber,
  206. };
  207. let confirmType;
  208. this.$md(params);
  209. if (this.carInfo.id) {
  210. params.id = this.carInfo.id;
  211. kipModifyMemberVehicles(
  212. params,
  213. JSON.parse(uni.getStorageSync('handleUser'))
  214. )
  215. .then((result) => {
  216. uni.hideLoading();
  217. if (result && result.code == '000000') {
  218. if (result.data) {
  219. Toast({
  220. message: '修改车牌成功',
  221. position: 'top',
  222. onClose: () => {
  223. this.$router.replace({
  224. path: `vehicleManagement`,
  225. query:{
  226. ...this.$route.query,
  227. }
  228. });
  229. }
  230. });
  231. }
  232. } else {
  233. const message = result.message || '修改车牌失败';
  234. Toast({
  235. message: message,
  236. });
  237. }
  238. })
  239. .catch((err) => {
  240. uni.hideLoading();
  241. Toast({
  242. message: '修改车牌失败',
  243. position: 'top',
  244. });
  245. });
  246. } else {
  247. kipAddMemberVehicles(
  248. params,
  249. JSON.parse(uni.getStorageSync('handleUser') || '{}')
  250. )
  251. .then((result) => {
  252. uni.hideLoading();
  253. // const result = resp.data;
  254. if (result && result.code == '000000') {
  255. if (result.data) {
  256. Toast({
  257. message: '绑定车牌成功',
  258. position: 'top',
  259. onClose: () => {
  260. this.$router.replace({
  261. path: `vehicleManagement`,
  262. query:{
  263. ...this.$route.query,
  264. }
  265. });
  266. }
  267. });
  268. /* Dialog.alert({
  269. message: '绑定车牌成功',
  270. confirmButtonColor: '#333',
  271. }).then(() => {
  272. // on confirm
  273. this.$router.replace({
  274. path: `vehicleManagement`,
  275. });
  276. // this.$router.back();
  277. });*/
  278. // setTimeout(() => {
  279. // // this.$router.back();
  280. // this.$router.replace({
  281. // path: '/vehicleManagement',
  282. // });
  283. // }, 1500);
  284. }
  285. } else {
  286. const message = result.message || '绑定车牌失败';
  287. Toast({
  288. message: message,
  289. position: 'top',
  290. });
  291. /* Dialog.alert({
  292. message: message,
  293. confirmButtonColor: '#333',
  294. }).then(() => {
  295. // on confirm
  296. // this.$router.back();
  297. }); */
  298. }
  299. })
  300. .catch((err) => {
  301. uni.hideLoading();
  302. // console.log(366);
  303. // console.error(err);
  304. // uni.showToast({
  305. // title: '绑定车牌失败',
  306. // duration: 2000,
  307. // icon: 'none',
  308. // });
  309. Toast({
  310. message: '绑定车牌失败',
  311. });
  312. /* Dialog.alert({
  313. message: '绑定车牌失败',
  314. confirmButtonColor: '#333',
  315. }).then(() => {
  316. // on confirm
  317. // this.$router.back();
  318. }); */
  319. });
  320. }
  321. },
  322. },
  323. };