vehicleManagement.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. import uniPop from '@/components/uni-popup/uni-popup.vue';
  2. import { Dialog } from 'vant';
  3. import LoginDom from '@/components/Login/Login.vue';
  4. // const app = getApp()
  5. const app = {};
  6. import {
  7. kipGetMemberVehicles,
  8. kipDeleteMemberVehicles,
  9. } from '@/utils/api-kip.js';
  10. import { LICENSE_PLATE_TYPE_ARR } from '@/constants.js';
  11. import { mapState } from 'vuex';
  12. // import authorize from '@/components/authorize/authorize.vue';
  13. import { isCruMarketByKey } from '@/utils/location-util.js';
  14. import MemberCacheTool from '@/utils/member-cache-tool.js';
  15. import { REG_SOURCE } from '@/constants.js';
  16. import uni from '@/utils/uniHooks.js';
  17. // import { vehicles as vehiclesList } from './list';
  18. import { wxToLoginCallback } from '@/utils/index';
  19. import { Toast } from 'vant';
  20. import { getVehicles, delVehicle } from '@/api/parking/index'
  21. export default {
  22. components: {
  23. uniPop,
  24. // authorize,
  25. LoginDom,
  26. },
  27. computed: {
  28. ...mapState({
  29. custTypeId: (state) => state.custTypeId,
  30. member: (state) => state.member,
  31. groupId: (state) => state.groupId,
  32. openid: (state) => state.openid,
  33. mallid: (state) => state.mallId,
  34. mobile: (state) => state.mobile,
  35. kipUserId: (state) => state.kipUserId,
  36. }),
  37. isNoLogin() {
  38. return JSON.stringify(this.member) === '{}'
  39. }
  40. },
  41. data() {
  42. return {
  43. list: [],
  44. activeId: '',
  45. activeCarno: '',
  46. licensePlateList: [],
  47. isBeijing: false,
  48. options: null,
  49. preUrl: '',
  50. deleteDialogSwitch: false,
  51. deleteSuccessDialogSwitch: false,
  52. show: false, // 删除车牌时提示内容
  53. };
  54. },
  55. async created() {
  56. this.options = this.$route.query;
  57. },
  58. async mounted() {
  59. setTimeout(() => {
  60. uni.setNavigationBarTitle({
  61. title: '车辆管理',
  62. });
  63. }, 300);
  64. setTimeout(() => {
  65. window?.toWXSendMsg({
  66. type: 'uni_func',
  67. funcName: 'setNavigationBarColor',
  68. options: {
  69. frontColor: '#000000',
  70. backgroundColor: '#FBFCFF',
  71. },
  72. });
  73. }, 500)
  74. this.$store.dispatch('clearUnlicensed');
  75. const member = uni.getStorageSync('member');
  76. if (member && JSON.stringify(this.member) !== '{}') {
  77. this.getKipMemberVehicles();
  78. } else {
  79. wxToLoginCallback('vehicleManagement', (options) => {
  80. if (options?.noLoginParkingFeeWebView === 'fail') {
  81. // 如果是用户明确拒绝登录,执行这段逻辑
  82. setTimeout(() => {
  83. Toast({
  84. message: '您还未登录,请登录',
  85. icon: 'none',
  86. onClose: () => {
  87. this.$router.back();
  88. return
  89. },
  90. });
  91. }, 300)
  92. } else {
  93. this.$router.back();
  94. }
  95. });
  96. }
  97. },
  98. onUnload() {
  99. // #ifdef MP-WEIXIN
  100. var pages = getCurrentPages();
  101. var prevPage = pages[pages.length - 2];
  102. console.log('==> 车牌管理-返回上一页');
  103. prevPage.setData({
  104. parkData: 'parkData',
  105. });
  106. // #endif
  107. // #ifdef H5
  108. uni.setStorage({
  109. key: 'parkData',
  110. data: 'parkData',
  111. success: function () {
  112. console.log('parkData-success');
  113. },
  114. });
  115. // #endif
  116. },
  117. methods: {
  118. // 添加车牌号
  119. toAdd() {
  120. if(this.isNoLogin) return
  121. this.$router.push({ path: 'vehicleAddOrEdit' });
  122. },
  123. // 跳转支付页面
  124. toPay(carno) {
  125. if(this.isNoLogin) return
  126. this.$store.commit('cachedViews/DEL_CACHED_VIEW', {
  127. name: 'parkingFeeDetail',
  128. });
  129. uni.setStorageSync('carList', [...new Set([carno, ...JSON.parse(uni.getStorageSync('carList') || '[]')])].slice(0, 6));
  130. this.$store.commit('cachedViews/DEL_CACHED_VIEW', {
  131. name: 'parkingFeeDetail',
  132. });
  133. this.$nextTick(() => {
  134. this.$router.push({
  135. path: 'parkingFeeDetail',
  136. query: {
  137. vehicleNo: carno,
  138. },
  139. });
  140. });
  141. return
  142. // 查询车费信息
  143. uni.showLoading({
  144. title: '加载中',
  145. });
  146. // const openId = MemberCacheTool.getOpenId(app)
  147. const params = {
  148. carno,
  149. mallid: this.mallid,
  150. openid: this.openid,
  151. vipcode: this.member?.vipcode,
  152. mobile: this.mobile,
  153. groupId: this.groupId,
  154. createuser: 'sys_miniprogram',
  155. };
  156. this.$md(params);
  157. this.$request({
  158. url: this.$baseURL + 'api/1.0/park/checkCarIsInPark',
  159. data: params,
  160. method: 'POST',
  161. header: JSON.parse(uni.getStorageSync('handleUser')),
  162. timeout: 10000,
  163. })
  164. .then((res) => {
  165. // console.log(227, res);
  166. uni.hideLoading();
  167. if (res.data.code === 0) {
  168. this.$router.push({
  169. path: 'parkingFeeDetail?carno=' + carno,
  170. });
  171. } else if (res.data.code === 1) {
  172. // 当前车辆没有查到账单
  173. this.$router.push({
  174. path: 'parkingFeePayment?msg=' + res.data.msg + '&carno=' + carno,
  175. });
  176. } else if (res.data.code === 2) {
  177. // 月租车
  178. this.$router.push({
  179. path: './parkingFeeHint/parkingFeeHint?carno=' + carno,
  180. });
  181. } else {
  182. uni.showToast({
  183. title: res.data.msg,
  184. duration: 2000,
  185. icon: 'none',
  186. });
  187. }
  188. })
  189. .catch((err) => {
  190. uni.hideLoading();
  191. uni.showToast({
  192. title: '网络超时请稍后再试',
  193. duration: 2000,
  194. icon: 'none',
  195. });
  196. console.log(err);
  197. });
  198. },
  199. // 编辑
  200. toEdit(item) {
  201. if(this.isNoLogin) return
  202. if (!item) {
  203. return;
  204. }
  205. const { id, vehicleNo, licensePlateType } = item;
  206. const carType = LICENSE_PLATE_TYPE_ARR.findIndex(
  207. (e) => e.value == licensePlateType
  208. );
  209. this.$router.push({
  210. path: `vehicleAddOrEdit?id=${id}&carno=${vehicleNo}&carType=${carType}`,
  211. });
  212. },
  213. activeCarnoFilter(str){
  214. return str.replace(/(.{2})/, '$1·')
  215. },
  216. async delVehicleInTMP() {
  217. const res = await delVehicle(this.activeId)
  218. if (res.langMessage) {
  219. const message = res.langMessage || '删除失败';
  220. uni.showToast({
  221. title: message,
  222. duration: 2000,
  223. icon: 'none',
  224. });
  225. return
  226. }
  227. Toast({
  228. message: '删除成功',
  229. type: 'success',
  230. position: 'top',
  231. duration: 5000,
  232. className: 'top300',
  233. icon: require('../static/images/success.svg')
  234. });
  235. setTimeout(() => {
  236. this.getKipMemberVehicles();
  237. }, 1000)
  238. },
  239. // 删除
  240. toDelete(item) {
  241. this.activeId = item.id;
  242. this.activeCarno = item.vehicleNo;
  243. this.show = true
  244. // Dialog.confirm({
  245. // title: '删除已绑定车牌',
  246. // message: '是否确认删除已经绑定车牌' + '\n' + this.activeCarno,
  247. // confirmButtonColor: '#333',
  248. // })
  249. // .then(() => {
  250. // // on confirm
  251. // this.doDelete();
  252. // })
  253. // .catch(() => {
  254. // // on cancel
  255. // // this.cancelDelete();
  256. // });
  257. // this.deleteDialogSwitch = true;
  258. },
  259. doDelete() {
  260. this.delVehicleInTMP();
  261. return
  262. uni.showLoading({
  263. title: '加载中',
  264. });
  265. const _this = this;
  266. kipDeleteMemberVehicles(this.activeId)
  267. .then((result) => {
  268. uni.hideLoading();
  269. // console.log(resp)
  270. // const result = resp.data
  271. if (result && result.code == '000000') {
  272. if (result.data) {
  273. // this.deleteDialogSwitch = false;
  274. // this.deleteSuccessDialogSwitch = true;
  275. Toast({
  276. message: '删除成功',
  277. type: 'success',
  278. position: 'top',
  279. duration: 5000,
  280. className: 'top300',
  281. icon: require('../static/images/success.svg')
  282. });
  283. setTimeout(() => {
  284. this.getKipMemberVehicles();
  285. }, 1500)
  286. // _this.$refs.deleteSuccessDialog.open()
  287. return;
  288. }
  289. }
  290. const message = result.message || '删除失败';
  291. uni.showToast({
  292. title: message,
  293. duration: 2000,
  294. icon: 'none',
  295. });
  296. })
  297. .catch((err) => {
  298. uni.hideLoading();
  299. console.log(err);
  300. uni.showToast({
  301. title: '删除失败',
  302. duration: 2000,
  303. icon: 'none',
  304. });
  305. });
  306. },
  307. cancelDelete() {
  308. this.deleteDialogSwitch = true;
  309. },
  310. confirmDialog() {
  311. // this.$refs.deleteSuccessDialog.close()
  312. this.deleteSuccessDialogSwitch = false;
  313. this.getKipMemberVehicles();
  314. },
  315. // 获取会员绑定的车牌列表
  316. async getVehiclesINTMP() {
  317. const res = await getVehicles(this.kipUserId)
  318. this.licensePlateList = this.setLicensePlateList(res.content);
  319. },
  320. getKipMemberVehicles() {
  321. this.getVehiclesINTMP();
  322. return
  323. // console.log(453);
  324. uni.showLoading({
  325. title: '加载中',
  326. });
  327. kipGetMemberVehicles()
  328. .then((result) => {
  329. uni.hideLoading();
  330. console.log(result);
  331. // const result = resp.data
  332. if (result && result.code == '000000') {
  333. const data = result.data || [];
  334. if (data && data.length > 0) {
  335. // data.forEach((item) => {
  336. // const curLicensePlateType = LICENSE_PLATE_TYPE_ARR.find(
  337. // (e) => e.value == item.licensePlateType
  338. // )
  339. // if (curLicensePlateType) {
  340. // item.licensePlateTypeDesc = curLicensePlateType.label
  341. // }
  342. // })
  343. this.licensePlateList = this.setLicensePlateList(data);
  344. } else {
  345. this.licensePlateList = [];
  346. }
  347. // this.licensePlateList = vehiclesList.data;
  348. } else {
  349. const message = result.message || '获取信息失败';
  350. uni.showToast({
  351. title: message,
  352. duration: 2000,
  353. icon: 'none',
  354. });
  355. }
  356. // console.log(380, this.licensePlateList);
  357. })
  358. .catch((err) => {
  359. uni.hideLoading();
  360. console.error(err);
  361. });
  362. // this.licensePlateList = this.setLicensePlateList(vehiclesList.data);
  363. },
  364. setLicensePlateList(data) {
  365. if (!data.length) return [];
  366. return data.map((item) => {
  367. const curLicensePlateType = LICENSE_PLATE_TYPE_ARR.find(
  368. (e) => e.value == item.licensePlateType
  369. );
  370. if (curLicensePlateType) {
  371. item.licensePlateTypeDesc = curLicensePlateType.label;
  372. }
  373. return item;
  374. });
  375. },
  376. },
  377. };