123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328 |
- import uniPop from '@/components/uni-popup/uni-popup.vue';
- import plateNumber from '@/components/plate-number/plateNumber.vue';
- import uni from '@/utils/uniHooks';
- import { Toast } from 'vant';
- import { LICENSE_PLATE_TYPE_ARR } from '@/constants.js';
- import {
- kipAddMemberVehicles,
- kipModifyMemberVehicles,
- } from '@/utils/api-kip.js';
- import { mapState } from 'vuex';
- import { addVehicles, editVehicles } from '@/api/parking/index'
- export default {
- components: {
- uniPop,
- plateNumber,
- },
- data() {
- return {
- carInfo: {},
- carType: 0,
- active: null,
- ind: null,
- numArr: ['', '', '', '', '', '', ''],
- vehicleNumber: '',
- licensePlateTypeArr: LICENSE_PLATE_TYPE_ARR,
- preUrl: '',
- };
- },
- created() {
- // 埋点本地化
- this.preUrl = uni.getStorageSync('previousUrl');
- uni.setStorageSync('previousUrl', '/pages/parkingFee/vehicleAddOrEdit.vue');
- },
- mounted() {
- const params = this.$route.query;
- console.log(55555, params);
- if (params.carType) {
- this.carInfo = {
- ...params,
- };
- this.carType = Number.parseInt(this.carInfo.carType);
- this.$refs['k-tab'].changeTab(this.carType)
- this.numArr = this.carInfo.carno.split('');
- this.vehicleNumber = this.carInfo.carno;
- }
- },
- computed: {
- disabledBtn() {
- return this.numArr.findIndex((val) => !val) !== -1;
- },
- ...mapState({
- custTypeId: (state) => state.custTypeId, // custTypeId: 0 默认版本,1 上海静安 2 上海浦东
- kipUserId: (state) => state.kipUserId,
- }),
- },
- methods: {
- // 切换车牌类型
- toggleType(index) {
- this.ind = 0;
- this.active = 0;
- this.carType = index;
- if (this.carType == '1') {
- this.numArr = [
- this.numArr[0],
- this.numArr[1],
- this.numArr[2],
- this.numArr[3],
- this.numArr[4],
- this.numArr[5],
- this.numArr[6],
- this.numArr[7],
- ];
- } else {
- this.numArr = [
- this.numArr[0],
- this.numArr[1],
- this.numArr[2],
- this.numArr[3],
- this.numArr[4],
- this.numArr[5],
- this.numArr[6],
- ];
- }
- },
- // 唤起键盘
- clickShowKeyboard(index) {
- if ( this.carType !== 1 && index === 7) return
- this.ind = index;
- this.active = index;
- // console.log('唤起键盘', this.ind, this.active);
- this.$nextTick(() => {
- // return;
- if (index === 0) {
- this.$refs['plateKeyboard'].openKeyboardCN();
- } else {
- // this.$refs['plateKeyboard'].closeKeyboardCN();
- this.$refs['plateKeyboard'].openKeyboardEN();
- }
- });
- },
- // 接收子组件数据
- updateCarno(val) {
- // console.log(320, val);
- this.numArr = val.numArr;
- this.active = val.active;
- this.ind = val.ind;
- this.vehicleNumber = this.numArr.join('');
- },
- // 车牌号校验
- // isVehicleNumber(vehicleNumber) {
- // if (vehicleNumber.length == 7) {
- // this.vehicleNumber = vehicleNumber.join("");
- // var express =
- // /^(([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][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挂学警港澳使领]))$/;
- // if (!express.test(this.vehicleNumber)) {
- // uni.showToast({
- // title: "请输入正确的车牌号",
- // duration: 2000,
- // icon: "none",
- // });
- // return false;
- // }
- // return true;
- // }
- // if (vehicleNumber.length == 8) {
- // this.vehicleNumber = vehicleNumber.join("");
- // var express =
- // /^([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领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})$/;
- // if (!express.test(this.vehicleNumber)) {
- // uni.showToast({
- // title: "请输入正确的车牌号",
- // duration: 2000,
- // icon: "none",
- // });
- // return false;
- // }
- // return true;
- // }
- // },
- async handleAddLicensePlateByTMP() {
- const params = {
- userId: this.kipUserId,
- licensePlateType: this.licensePlateTypeArr[this.carType].value,
- vehicleNo: this.vehicleNumber,
- };
- if(this.carInfo?.id) {
- // 修改
- const res = await editVehicles(this.carInfo?.id, {
- id: this.carInfo?.id,
- ...params
- })
- if(res.id) {
- Toast({
- message: '修改车牌成功',
- position: 'top',
- onClose: () => {
- // this.$router.replace({
- // path: `vehicleManagement`,
- // });
- setTimeout(() => {
- this.$router.go(-1)
- }, 300)
- }
- });
- } else {
- const message = res.langMessage || '修改车牌失败';
- Toast({
- message: message,
- });
- }
- return
- }
- // 添加
- const res= await addVehicles( this.kipUserId, params )
- if(res?.id) {
- Toast({
- message: '绑定车牌成功',
- position: 'top',
- onClose: () => {
- // this.$router.replace({
- // path: `vehicleManagement`,
- // });
- setTimeout(() => {
- this.$router.go(-1)
- }, 300)
- }
- });
- } else {
- const message = res.langMessage || '绑定车牌失败';
- Toast({
- message: message,
- position: 'top',
- });
- }
- },
- handleAddLicensePlateByKipMember() {
- this.handleAddLicensePlateByTMP()
- return
- // console.log('handleAddLicensePlateByKipMember执行');
- uni.showLoading({
- title: '加载中',
- });
- const params = {
- licensePlateType: this.licensePlateTypeArr[this.carType].value,
- vehicleNo: this.vehicleNumber,
- };
- let confirmType;
- this.$md(params);
- if (this.carInfo.id) {
- params.id = this.carInfo.id;
- kipModifyMemberVehicles(
- params,
- JSON.parse(uni.getStorageSync('handleUser'))
- )
- .then((result) => {
- uni.hideLoading();
- if (result && result.code == '000000') {
- if (result.data) {
- Toast({
- message: '修改车牌成功',
- position: 'top',
- onClose: () => {
- this.$router.replace({
- path: `vehicleManagement`,
- query:{
- ...this.$route.query,
- }
- });
- }
- });
- }
- } else {
- const message = result.message || '修改车牌失败';
- Toast({
- message: message,
- });
- }
- })
- .catch((err) => {
- uni.hideLoading();
- Toast({
- message: '修改车牌失败',
- position: 'top',
- });
- });
- } else {
- kipAddMemberVehicles(
- params,
- JSON.parse(uni.getStorageSync('handleUser') || '{}')
- )
- .then((result) => {
- uni.hideLoading();
- // const result = resp.data;
- if (result && result.code == '000000') {
- if (result.data) {
- Toast({
- message: '绑定车牌成功',
- position: 'top',
- onClose: () => {
- this.$router.replace({
- path: `vehicleManagement`,
- query:{
- ...this.$route.query,
- }
- });
- }
- });
- /* Dialog.alert({
- message: '绑定车牌成功',
- confirmButtonColor: '#333',
- }).then(() => {
- // on confirm
- this.$router.replace({
- path: `vehicleManagement`,
- });
- // this.$router.back();
- });*/
- // setTimeout(() => {
- // // this.$router.back();
- // this.$router.replace({
- // path: '/vehicleManagement',
- // });
- // }, 1500);
- }
- } else {
- const message = result.message || '绑定车牌失败';
- Toast({
- message: message,
- position: 'top',
- });
- /* Dialog.alert({
- message: message,
- confirmButtonColor: '#333',
- }).then(() => {
- // on confirm
- // this.$router.back();
- }); */
- }
- })
- .catch((err) => {
- uni.hideLoading();
- // console.log(366);
- // console.error(err);
- // uni.showToast({
- // title: '绑定车牌失败',
- // duration: 2000,
- // icon: 'none',
- // });
- Toast({
- message: '绑定车牌失败',
- });
- /* Dialog.alert({
- message: '绑定车牌失败',
- confirmButtonColor: '#333',
- }).then(() => {
- // on confirm
- // this.$router.back();
- }); */
- });
- }
- },
- },
- };
|