Browse Source

用户车辆管理

wkyy 3 năm trước cách đây
mục cha
commit
8fc2dafdec
6 tập tin đã thay đổi với 253 bổ sung44 xóa
  1. 37 1
      apis/user.js
  2. 1 8
      pages.json
  3. 74 13
      pages/user/car/carAdd.vue
  4. 35 9
      pages/user/car/index.vue
  5. 79 7
      pages/user/data.vue
  6. 27 6
      pages/user/index.vue

+ 37 - 1
apis/user.js

@@ -1,6 +1,41 @@
 import request from '../utils/request.js';
 import requestWhite from '../utils/requestWhite.js';
+import Qs from 'qs';
 
+export function updatePersonInformation (data) {
+	 
+	return request({
+		method: 'post',
+		data:data ,
+		url: '/mobile/regUser/updatePersonInformation'
+	})
+}
+
+export function regUserCarList () {
+	 
+	return request({
+		method: 'get',
+		url: '/mobile/regUser/regUserCarList'
+	})
+}
+
+export function addRegUserCar (data) {
+	 
+	return request({
+		method: 'post',
+		data:data ,
+		url: '/mobile/regUser/addRegUserCar'
+	})
+}
+
+export function deleteRegUserCar (data) {
+	 
+	return request({
+		method: 'post',
+		data:data ,
+		url: '/mobile/regUser/deleteRegUserCar'
+	})
+}
 
 export function helpList (data) {
 	 
@@ -9,5 +44,6 @@ export function helpList (data) {
 		data:data ,
 		url: '/mobile/roleSharing/helpList'
 	})
-} 
+}
+
 

+ 1 - 8
pages.json

@@ -72,19 +72,12 @@
 			}
 		},
 		{
-			"name": "车量信息",
+			"name": "车量管理",
 			"path": "pages/user/car/carAdd",
 			"style": {
 				//"navigationStyle": "custom" // 隐藏系统导航栏
 			}
 		},
-		{
-			"name": "添加车牌",
-			"path": "pages/user/car/carDet",
-			"style": {
-				//"navigationStyle": "custom" // 隐藏系统导航栏
-			}
-		},
 		{
 			"name": "我的余额",
 			"path": "pages/user/finance/balance",

+ 74 - 13
pages/user/car/carAdd.vue

@@ -1,8 +1,8 @@
 <template>
 	<view>
 		<u-navbar title="车辆管理">
-			<view class="slot-wrap" @click="showDelete">
-				<span class="navBtn">删除车辆</span>
+			<view class="slot-wrap">
+				<span class="navBtn" @click="showDelete">删除车辆</span>
 			</view>
 		</u-navbar>
 		<view>
@@ -10,9 +10,9 @@
 		</view>
 		<view class="carDet">
 			<u-form :model="form" ref="uForm">
-				<u-form-item label="姓名"><u-input v-model="form.name" /></u-form-item>
-				<u-form-item label="简介"><u-input v-model="form.intro" /></u-form-item>
-				<u-form-item label="开关"><u-switch slot="right" v-model="switchVal"></u-switch></u-form-item>
+				<u-form-item label="车牌号码" label-width="150rpx"><u-input input-align="right" v-model="form.carNum" /></u-form-item>
+				<u-form-item label="车辆类型" label-width="150rpx"><u-input input-align="right" placeholder="新能源车" placeholder-style="color:black" disabled /></u-form-item>
+				<u-form-item label="设为默认车辆" label-width="180rpx"><u-switch slot="right" v-model="form.defaultFlag"></u-switch></u-form-item>
 			</u-form>
 		</view>
 		<u-button class="login-btn" type="success" shape="circle" @click="keepCar">保存</u-button>
@@ -20,6 +20,8 @@
 </template>
 
 <script>
+	import * as userApi from '@/apis/user.js'
+	
 	export default {
 		data() {
 			return {
@@ -27,25 +29,84 @@
 				title: '删除车辆',
 				content: '是否删除此车牌号?',
 				form: {
-					name: '',
-					intro: '',
+					id: '',
+					carNum: '',
+					defaultFlag: true,
 				},
-				switchVal: false
+				carList: [],
+			}
+		},
+		onLoad(op) {
+			if(op.id){
+				this.form.id = op.id;
+				this.getCarList();
 			}
 		},
 		methods: {
+			getCarList() {
+				
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})		
+				userApi.regUserCarList().then((res) => {
+					uni.hideLoading();
+					this.carList = res.data;
+
+					for(var i=0;i<this.carList.length;i++) {
+						var carId = this.carList[i].id
+						if(this.form.id == carId) {			
+							this.form.carNum = this.carList[i].carNum;
+							this.form.defaultFlag = this.carList[i].defaultFlag;
+						}
+					}
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
+				})
+			},
 			showDelete() {
 				this.show = true;
 			},
 			confirmDelete() {
-				this.show = false;
-				uni.redirectTo({
-					url: '/pages/user/car/index'
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})		
+				userApi.deleteRegUserCar({
+					id: this.form.id
+				}).then((res) => {
+					uni.hideLoading();
+					
+					this.show = false;
+					uni.redirectTo({
+						url: '/pages/user/car/index'
+					})
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
 				})
 			},
 			keepCar() {
-				uni.redirectTo({
-					url: '/pages/user/car/index'
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})		
+				userApi.addRegUserCar(this.form).then((res) => {
+					uni.hideLoading();				
+					
+					uni.redirectTo({
+						url: '/pages/user/car/index'
+					})
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
 				})
 			}
 		}

+ 35 - 9
pages/user/car/index.vue

@@ -1,17 +1,17 @@
 <template>
 	<view>
 		<u-navbar title="车辆管理"></u-navbar>
-		<!-- <view class="carNone">
+		<view class="carNone" v-if="carList.length == 0">
 			<img src="/static/img/none2.svg" alt="">
 			<p>暂无绑定车辆</p>
-			<view class="carNone-btn">
+			<view class="carNone-btn" @click="addCar">
 				添加车牌
 			</view>
-		</view> -->
-		<view class="car">
-			<view class="car-item" @click="gotoUrl('pages/user/car/carAdd?id=')">
-				<span>默认</span>
-				<font>鄂D 999999</font>
+		</view>
+		<view class="car" v-else>
+			<view class="car-item" v-for="(item,index) in carList" :key="item.id" @click="toCarAdd(item)">
+				<span v-if="item.defaultFlag">默认</span>
+				<font>{{item.carNum}}</font>
 			</view>
 			<view class="car-btn" @click="addCar">添加车牌</view>
 		</view>
@@ -19,16 +19,42 @@
 </template>
 
 <script>
+	import * as userApi from '@/apis/user.js'
+	
 	export default {
 		data() {
 			return {
-				
+				carList: [],
 			}
 		},
+		onReady() {
+			this.getCarList();
+		},
 		methods: {
+			toCarAdd(item) {
+				uni.navigateTo({
+					url: '/pages/user/car/carAdd?id=' + item.id
+				})
+			},
+			getCarList() {
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})		
+				userApi.regUserCarList().then((res) => {
+					uni.hideLoading();
+					
+					this.carList = res.data;
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
+				})
+			},
 			addCar() {
 				uni.navigateTo({
-					url: '/pages/user/car/carDet'
+					url: '/pages/user/car/carAdd'
 				})
 			}
 		}

+ 79 - 7
pages/user/data.vue

@@ -6,11 +6,11 @@
 				<view class="data-icon">
 					<u-icon name="camera-fill" custom-prefix="custom-icon" color="#fff" size="32"></u-icon>
 				</view>
-				<u-avatar src="/static/img/head.png" size="216"></u-avatar>
+				<u-avatar :src="form.headImg+'?x-oss-process=image/resize,m_fill,w_256,h_256'" size="216" @click="uploadPhoto"></u-avatar>
 			</view>
 			<view class="data-input">
 				<u-form :model="form" ref="uForm" >
-					<u-form-item label-position="top" label="昵称"><u-input v-model="form.name" /></u-form-item>
+					<u-form-item label-position="top" label="昵称"><u-input v-model="form.nickName" /></u-form-item>
 				</u-form>
 			</view>
 			<u-button class="login-btn" type="success" shape="circle" @click="submit">提交</u-button>
@@ -19,21 +19,93 @@
 </template>
 
 <script>
+	import * as userApi from '@/apis/user.js'
+	import * as loginApi from '@/apis/login.js'
+	
 	export default {
 		data() {
 			return {
 				userId: '',
 				form: {
-					name: '',
+					nickName: '',
+					headImg: '',
 				},
 			}
 		},
-		onReady() {
-			if(this.carhelp.getPersonInfo() != null) {
-				this.userId = this.carhelp.getPersonInfo().id;
-			}
+		onReady() {	
+			this.getUserInfo();
 		},
 		methods: {
+			getUserInfo() {
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})		
+				loginApi.findByOpenId({
+					openId: this.carhelp.getOpenId(),
+				}).then((res) => {
+					uni.hideLoading();
+					
+					this.form.headImg = res.data.regUser.headImg;
+					this.form.nickName = res.data.regUser.nickName;
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
+				})
+			},
+			uploadPhoto() {
+				// 上传图片
+				let _self = this;
+				uni.chooseImage({
+					count: 1, //默认9
+					sourceType: ['album', 'camera'], //从相册选择
+					success: (res) => {
+						let imgFile = res.tempFilePaths;
+
+						var token = this.carhelp.getToken()
+						for (let i = 0; i < imgFile.length; i++) {
+			
+							wx.uploadFile({
+								url: process.car.BASE_URL + "uploadPicture",	
+								name: 'photoFile',
+								header: {		 
+									'Authorization': token,	 
+									'accept': 'application/json',
+									//#ifdef MP-WEIXIN
+									"Content-Type": "multipart/form-data", //记得设置
+									//#endif
+			
+								},
+								filePath: imgFile[0],
+								success: function(result) {
+									let imgUrls = JSON.parse(result.data)
+									_self.form.headImg = imgUrls.data;
+								}
+							})
+						}
+					},
+				});
+			},
+			submit() {
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})		
+				userApi.updatePersonInformation(this.form).then((res) => {
+					uni.hideLoading();
+					
+					uni.redirectTo({
+						url: '/pages/user/index'
+					})
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
+				})
+			}
 		}
 	}
 </script>

+ 27 - 6
pages/user/index.vue

@@ -78,6 +78,8 @@
 </template>
 
 <script>
+	import * as userApi from '@/apis/user.js'
+	import * as loginApi from '@/apis/login.js'
 	import Tabbar from '@/components/Tabbar.vue'
 	
 	export default {
@@ -101,15 +103,34 @@
 		onReady() {
 			if(this.carhelp.getPersonInfo() != null) {
 				this.userId = this.carhelp.getPersonInfo().id;
-				this.headImg = this.carhelp.getPersonInfo().headImg;
-				
-				var phone = this.carhelp.getPersonInfo().phone;
-				var phone1 = phone.slice(0,3);
-				var phone2 = phone.slice(-4);
-				this.userPhone = phone1 + '****' + phone2;
 			}
+			
+			this.getUserInfo();
 		},
 		methods: {
+			getUserInfo() {
+				uni.showLoading({
+					title: "加载中",
+					mask: true,
+				})		
+				loginApi.findByOpenId({
+					openId: this.carhelp.getOpenId(),
+				}).then((res) => {
+					uni.hideLoading();
+					
+					this.headImg = res.data.regUser.headImg;
+					
+					var phone = res.data.regUser.phone;
+					var phone1 = phone.slice(0,3);
+					var phone2 = phone.slice(-4);
+					this.userPhone = phone1 + '****' + phone2;
+				}).catch(error => {
+					uni.showToast({
+						title: error,
+						icon: "none"
+					})
+				})
+			},
 			toData() {			
 				if(this.userId != '') {
 					uni.navigateTo({