Browse Source

共享用车人模块完成

郭宇琦 2 weeks ago
parent
commit
043060b339

+ 13 - 0
common/config_gyq.js

@@ -28,6 +28,19 @@ var config = {
 	
 	// 套餐购买订单列表
 	API_FLK_EXCHANGE_PACKAGE_ORDER_LIST: api_web_url +'?r=flk/exchange-package/order-list',
+	// 车辆共享列表
+	API_FLK_CAR_SHARE_LIST: api_web_url +'?r=flk/car/share-list',
+	//检查邮箱是否存在
+	API_ACCOUNT_CHECK_SHARE_ACCOUNT_EXIST: api_web_url +'?r=flk/account/check-account-exist',
+	//添加用车人
+	API_FLK_CAR_ADD_SHARE_USER: api_web_url +'?r=flk/car/add-share-user',
+	//删除用车人
+	API_FLK_CAR_REMOVE_SHARE_USER: api_web_url +'?r=flk/car/remove-share-user',
 	
+	//修改用车人权限: 
+	API_FLK_CAR_EDIT_SHARE_USER: api_web_url +'?r=flk/car/edit-share-user',
+	
+	//共享用车人详情
+	API_FLK_CAR_EDIT_SHARE_INFO: api_web_url +'?r=flk/car/share-info',
 };
 module.exports = config;

+ 27 - 6
pages/addUser/addUser.vue

@@ -1,19 +1,22 @@
 <template>
 	<view class="add-user-view">
 		<view class="flex-row email-input-view">
-			<input class="email-input-style" type="email" placeholder="请输入被邀人邮箱号"  placeholder-style="font-size: 32rpx; font-weight: 400; color: #BAC1D0;">
+			<input class="email-input-style" type="email" v-model="email" placeholder="请输入被邀人邮箱号"  placeholder-style="font-size: 32rpx; font-weight: 400; color: #BAC1D0;">
 			<img class="clear-btn" src="https://qiniu.bms16.com/Fjpf2YnHUK1_CFf20kKRvjX9YdC3" alt="">
 		</view>
-		<view class="next-btn next-btn-i">下一步</view>
+		<view @click="nextFn" class="next-btn" :class="{'next-btn-i':!isEmailFn(email)}">下一步</view>
 	</view>
 </template>
 
 <script>
-	var config = require('../../common/config.js');
+	var config = require('../../common/config_gyq.js');
+	var http = require('../../common/request.js');
+	import { isEmail } from '../../utils/util.js';
+	import { msg } from '../../utils/util.js';
 	export default {
 		data() {
 			return {
-				
+				email:""
 			};
 		}
 		/**
@@ -23,7 +26,25 @@
 		onLoad: function(options) {
 		},
 		methods: {
-
+			isEmailFn(str){
+				return isEmail(str)
+			},
+			async nextFn(){
+				let {data} = await http.postApi(config.API_ACCOUNT_CHECK_SHARE_ACCOUNT_EXIST,{
+					email:this.email
+				})
+				if(data.code == 200){
+					if(data.data.exist){
+						uni.navigateTo({
+							url:`/pages/powerSetting/powerSetting?email=${this.email}&headimg=${data.data.headimg}&nickname=${data.data.nickname}`
+						})
+					}else{
+						msg('该用户不存在!')
+					}
+				}else{
+					msg(data.msg)
+				}
+			}
 		}
 	};
 </script>
@@ -41,7 +62,7 @@
 	border: 4rpx solid #060809;
 	font-weight: 400;
 	font-size: 32rpx;
-	color: #BAC1D0;
+	color: #333;
 	caret-color: #0A59F7;
 }
 .email-input-view{

+ 7 - 1
pages/carList/carList.vue

@@ -11,7 +11,7 @@
 			</view>
 		</view>
 		<view class="options">
-			<view class="btn btn-left">{{ $t('租赁设备') }}</view>
+			<view @click="navCarDetail" class="btn btn-left">{{ $t('租赁设备') }}</view>
 			<view class="btn btn-right">{{ $t('绑定设备') }}</view>
 		</view>
 	</view>
@@ -40,6 +40,12 @@
 			this.loadUserCarList()
 		},
 		methods: {
+			navCarDetail(){
+				// const me=this
+				// uni.navigateTo({
+				// 	url: '/pages/carDetail/carDetail'
+				// })
+			},
 			clickItem(item){
 				if(item.car_sn == this.car_info.car_sn) return
 				uni.setStorageSync('car_info',item)

+ 115 - 13
pages/powerSetting/powerSetting.vue

@@ -1,24 +1,31 @@
 <template>
 	<view class="power-setting-main">
 		<view class="flex-row power-setting-head">
-			<img class="head-img" src="https://qiniu.bms16.com/FprjgdYTzB9LDkHZT1F-p_kQKNty" alt="">
-			<view class="head-name">名字</view>
-			<text class="head-email">1007929522@Mail.com</text>
+			<img class="head-img" :src="headimg" alt="">
+			<view class="head-name">{{nickname}}</view>
+			<text class="head-email">{{form.email}}</text>
 		</view>
 		<view class="setting-card" style="margin-bottom: 20rpx;">
 			<view class="setting-card-name">权限设置</view>
-			<view class="setting-card-list flex-row">
+			<view @click="selctFn(4)" class="setting-card-list flex-row">
 				<img src="https://qiniu.bms16.com/FgFEr3CUA43kd7yVCDcK4F7v9_zx" alt="">
 				<view class="setting-list-text flex-row flex-between">
-					<text>查看实时位置</text> 
-					<img class="setting-list-arrow" src="https://qiniu.bms16.com/FrA97op1dwM9XWH1ocqnF5FFlqoY" alt="">
+					<text>查看实时位置</text>
+					<img v-if="form.authority_list.indexOf(4) == -1" class="setting-list-arrow"
+						src="https://qiniu.bms16.com/FrA97op1dwM9XWH1ocqnF5FFlqoY" alt="">
+					<img v-else class="setting-list-arrow" src="https://qiniu.bms16.com/FuA5w59wrvsisg3bGhe3hQ2dR3Bk"
+						alt="">
 				</view>
 			</view>
-			<view class="setting-card-list flex-row">
+			<view @click="selctFn(5)" class="setting-card-list flex-row">
 				<img src="https://qiniu.bms16.com/FmcZqGTnt64_v2xpgNbqS9Fa-fwy" alt="">
 				<view class="setting-list-text flex-row flex-between">
-					<text>使用换电</text> 
-					<img class="setting-list-arrow" src="https://qiniu.bms16.com/FuA5w59wrvsisg3bGhe3hQ2dR3Bk" alt="">
+					<text>使用换电</text>
+					<!-- <img class="setting-list-arrow" src="https://qiniu.bms16.com/FuA5w59wrvsisg3bGhe3hQ2dR3Bk" alt=""> -->
+					<img v-if="form.authority_list.indexOf(5) == -1" class="setting-list-arrow"
+						src="https://qiniu.bms16.com/FrA97op1dwM9XWH1ocqnF5FFlqoY" alt="">
+					<img v-else class="setting-list-arrow" src="https://qiniu.bms16.com/FuA5w59wrvsisg3bGhe3hQ2dR3Bk"
+						alt="">
 				</view>
 			</view>
 		</view>
@@ -37,16 +44,29 @@
 				<view class="setting-list-text flex-row">感应解锁</view>
 			</view>
 		</view>
-		<view class="check-btn add-btn">确认添加</view>
-		<!-- <view class="check-btn del-btn">删除成员</view> -->
+		
+		<view v-if="!target_user_id" @click="submit" class="check-btn add-btn">确认添加</view>
+		<view v-else @click="delSubmit" class="check-btn del-btn">删除成员</view>
 	</view>
 </template>
 
 <script>
-	var config = require('../../common/config.js');
+	var config = require('../../common/config_gyq.js');
+	var http = require('../../common/request.js');
+	import {
+		msg
+	} from '../../utils/util.js';
 	export default {
 		data() {
 			return {
+				headimg: "",
+				nickname: "",
+				target_user_id:0,
+				form: {
+					car_sn: "",
+					email: "",
+					authority_list: [5]
+				}
 			};
 		}
 		/**
@@ -54,9 +74,91 @@
 		 */
 		,
 		onLoad: function(options) {
+			this.form.car_sn = uni.getStorageSync('car_info').car_sn || '';
+			if(options.id){
+				this.target_user_id = options.id
+				this.carInfoFn()
+				return
+			}
+			this.form.email = options.email;
+			this.form.headimg = options.headimg;
+			this.form.nickname = options.nickname;
 		},
 		methods: {
-
+			async carInfoFn(){
+				let {
+					data
+				} = await http.postApi(config.API_FLK_CAR_EDIT_SHARE_INFO, {
+					car_sn: this.form.car_sn,
+					target_user_id: this.target_user_id
+				})
+				if(data.code == 200){
+					data.data.authority = data.data.authority.map(item=>{
+						return Number(item)
+					})
+					this.form.authority_list = data.data.authority
+					this.form.email = data.data.email
+					this.nickname = data.data.nickname
+					this.headimg = data.data.headimg
+				}
+			},
+			async delSubmit() {
+				let res = await uni.showModal({
+					content:'确定删除这个成员吗?'
+				})
+				if(!res[1].confirm) return
+				let {
+					data
+				} = await http.postApi(config.API_FLK_CAR_REMOVE_SHARE_USER, {
+					car_sn: this.form.car_sn,
+					email: this.form.email
+				})
+				uni.showLoading({
+					mask:true,
+					title:'删除中...'
+				})
+				msg(data.msg)
+				if(data.code == 200){
+					setTimeout(()=>{
+						uni.navigateBack({
+							delta: 1
+						})
+					},800)
+				}
+			},
+			async submit() {
+				uni.showLoading({
+					mask: true,
+					title: '提交中...'
+				})
+				let {
+					data
+				} = await http.postApi(config.API_FLK_CAR_ADD_SHARE_USER, this.form)
+				if (data.code == 200) {
+					msg("添加成功!")
+					setTimeout(() => {
+						uni.navigateBack({
+							delta: 2
+						})
+					}, 800)
+				} else {
+					msg(data.msg)
+				}
+			},
+			selctFn(type) {
+				if (this.form.authority_list.indexOf(type) != -1) {
+					this.form.authority_list = this.form.authority_list.filter(item => item !== type);
+				} else {
+					this.form.authority_list.push(type)
+				}
+				if(this.target_user_id) this.editFn()
+				
+			},
+			async editFn(){
+				let {
+					data
+				} = await http.postApi(config.API_FLK_CAR_ADD_SHARE_USER,this.form)
+			}
 		}
 	};
 </script>

+ 33 - 16
pages/userManagement/userManagement.vue

@@ -6,23 +6,15 @@
 		</view>
 		<view class="user-card-text">家人、朋友长期共用车辆,授权账户可以使用感应解锁,寻车定位,查看设置等功能;</view>
 		<!-- <view v-for="(item,index) in userList" :key="index"> -->
-		<view class="user-list flex-row align-center">
-			<img class="user-heard-img" src="https://qiniu.bms16.com/FprjgdYTzB9LDkHZT1F-p_kQKNty" alt="">
+		<view  @click="srcFn(`/pages/powerSetting/powerSetting?id=${item.target_user_id}`)" v-for="(item,index) of list" :key="index" class="user-list flex-row align-center">
+			<image class="user-heard-img" :src="item.headimg" mode="aspectFill"></image>
 			<view class="user-name-view">
-				<view class="user-name">名字</view>
-				<view class="user-email">154535486@mail</view>
+				<view class="user-name">{{item.nickname}}</view>
+				<view class="user-email">{{item.email}}</view>
 			</view>
 			<img class="user-nav-img" src="https://qiniu.bms16.com/FqnbZ2iKHmzCGJA8XD30sf5g_CAm" alt="">
 		</view>
-		<view class="user-list flex-row align-center">
-			<img class="user-heard-img" src="https://qiniu.bms16.com/FprjgdYTzB9LDkHZT1F-p_kQKNty" alt="">
-			<view class="user-name-view">
-				<view class="user-name">名字</view>
-				<view class="user-email">154535486@mail</view>
-			</view>
-			<img class="user-nav-img" src="https://qiniu.bms16.com/FqnbZ2iKHmzCGJA8XD30sf5g_CAm" alt="">
-		</view>
-		<view class="flex-row user-card-btn align-center">
+		<view @click="addUser" class="flex-row user-card-btn align-center">
 			<img style="width: 20rpx;height: 20rpx;" src="https://qiniu.bms16.com/FvP_5VTgawzExIHW3kJahXAvE04z" alt="">
 			<text style="margin-left: 6rpx;">添加成员</text>
 		</view>
@@ -30,11 +22,13 @@
 </template>
 
 <script>
-	var config = require('../../common/config.js');
+	var config = require('../../common/config_gyq.js');
+	var http = require('../../common/request.js');
 	export default {
 		data() {
 			return {
-				userList:[]
+				list:[],
+				car_info:{}
 			};
 		}
 		/**
@@ -42,9 +36,32 @@
 		 */
 		,
 		onLoad: function(options) {
+			// this.listFn()
+		},
+		onShow() {
+			this.listFn()
 		},
 		methods: {
-
+			srcFn(url){
+				uni.navigateTo({
+					url
+				})
+			},
+			addUser(){
+				uni.navigateTo({
+					url:`/pages/addUser/addUser`
+				})
+			},
+			async listFn(){
+				this.car_info = uni.getStorageSync('car_info') || {};
+				let {data} = await http.postApi(config.API_FLK_CAR_SHARE_LIST,{
+					car_sn:this.car_info.car_sn
+				})
+				if(data.code == 200){
+					this.list = data.data.list
+				}
+				console.log(data)
+			}
 		}
 	};
 </script>

+ 9 - 1
utils/util.js

@@ -24,7 +24,8 @@ const getLocation = async () => {
 }
 const msg = (str) => {
 	uni.showToast({
-		title: str
+		title: str,
+		icon:'none'
 	})
 }
 /**
@@ -72,7 +73,14 @@ const formatNumber = (n) => {
 	return n[1] ? n : '0' + n;
 };
 
+function isEmail(email) {
+	if(!email) return false
+    // 正则表达式用于匹配邮箱格式
+    const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
+    return emailRegex.test(email);
+}
 module.exports = {
+	isEmail,
 	formatTime: formatTime,
 	getLocation,
 	msg,