浏览代码

增加 连锁组切换

lilei 3 年之前
父节点
当前提交
1ebaa56b8c
共有 10 个文件被更改,包括 102 次插入27 次删除
  1. 3 0
      App.vue
  2. 9 8
      libs/axios.js
  3. 1 0
      pages/login/login.vue
  4. 2 2
      pages/sales/chooseProduct.vue
  5. 4 4
      pages/sales/edit.vue
  6. 3 3
      pages/sales/index.vue
  7. 2 2
      pages/sales/list.vue
  8. 1 1
      pages/stock/index.vue
  9. 74 7
      pages/userCenter/index.vue
  10. 3 0
      store/index.js

+ 3 - 0
App.vue

@@ -3,6 +3,7 @@
 		globalData: {  
 			baseUrl: '',
 			token: '',
+			changeOrg:'',
 			version: '', // 当前版本号
 			buildType: 'uat', // 打包环境对应类型,pro 生产 uat 预发布 dev 本地开发
 			envTips: '', // 环境文字提示
@@ -13,9 +14,11 @@
 			// 非V3模式
 			if (this.$scope) {
 				this.$scope.globalData.token = this.$store.state.vuex_token;
+				this.$scope.globalData.changeOrg = this.$store.state.vuex_changeOrg;
 			} else {
 				// V3模式
 				getApp({ allowDefault: true }).globalData.token = this.$store.state.vuex_token;
+				getApp({ allowDefault: true }).globalData.changeOrg = this.$store.state.vuex_changeOrg;
 			}
 			this.$config('init');
 		},

+ 9 - 8
libs/axios.js

@@ -3,18 +3,19 @@ const baseUrl = getApp().globalData.baseUrl
 //带Token请求
 const request = (opts, hasToken) => {
 	const authorization = getApp().globalData.token
+	const changeOrg = getApp().globalData.changeOrg
 	const curVer = getApp().globalData.version
-	// console.log(authorization, 'authorization')
+	console.log(changeOrg, !hasToken,'changeOrg')
 	//  hasToken是否传入token,为true则不传token
 	const header = {
-			// 'USER-TERM-TYPE': 'ipad', // 支付时需要用到 与pad一致
-			// 'App-Type': 2,
 			'Version': curVer.version?curVer.version.replace(/\./g,''):''
 		}
-	if(!hasToken){
-		// header.authorization = authorization
-		header['access-token'] = authorization
-	}	
+	if(!hasToken || changeOrg){
+		header['access-token'] = authorization || ''
+	}
+    if(changeOrg){
+		header['access-org'] = changeOrg || ''
+	}
 	//此token是登录成功后后台返回保存在storage中的
 	let DefaultOpts = {
 		url: baseUrl+opts.url,
@@ -22,7 +23,7 @@ const request = (opts, hasToken) => {
 		method: opts.method,
 		header: opts.header ? opts.header : header
 	}
-	// console.log(DefaultOpts)
+	console.log(DefaultOpts)
 	let promise = new Promise(function(resolve, reject) {
 		uni.request(DefaultOpts).then(
 			(res) => {

+ 1 - 0
pages/login/login.vue

@@ -142,6 +142,7 @@ export default {
 					console.log(_this.fiterAuthCode(res.data.auth_user))
 					_this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.data.auth_user));
 					_this.$u.vuex('vuex_token', res.data.access_token);
+					_this.$u.vuex('vuex_authOrgs',res.data.auth_orgs);
 					getApp().globalData.token = res.data.access_token;
 					//登录成功将用户名密码存储到用户本地
 					if (_this.isRemember) {

+ 2 - 2
pages/sales/chooseProduct.vue

@@ -111,7 +111,7 @@
 			this.openModal = true
 		},
 		onBackPress() {
-			uni.$emit("refreshBL")
+			uni.$emit("refreshEditBL")
 		},
 		onLoad(opt) {
 			this.theme = getApp().globalData.theme
@@ -237,7 +237,7 @@
 			// 选好了
 			handleChoose(){
 				// uni.redirectTo({ url: '/pages/sales/edit?pageType=edit&data='+JSON.stringify(this.detailData) })
-				uni.$emit("refreshBL")
+				uni.$emit("refreshEditBL")
 				uni.navigateBack()
 			},
 			// 查看已选产品

+ 4 - 4
pages/sales/edit.vue

@@ -160,10 +160,10 @@
 			}
 			this.init()
 			// 监听整改完成后刷新事件
-			uni.$on('refreshBL', this.init)
+			uni.$on('refreshEditBL', this.init)
 		},
 		onUnload() {
-			uni.$off('refreshBL')
+			uni.$off('refreshEditBL')
 		},
 		methods: {
 			init(){
@@ -233,7 +233,7 @@
 				salesSubmit({ id: this.detailData.id }).then(res => {
 					if(res.status == 200){
 						this.toashMsg(res.message)
-						uni.$emit('refreshBL')
+						uni.$emit('refreshSalesBL')
 						uni.navigateBack()
 					}
 				})
@@ -339,7 +339,7 @@
 							this.init()
 						}else{  // 整单删除
 							this.toashMsg(res.message)
-							uni.$emit('refreshBL')
+							uni.$emit('refreshSalesBL')
 							uni.navigateBack()
 						}
 						this.commonModal = false

+ 3 - 3
pages/sales/index.vue

@@ -81,8 +81,8 @@
 			const _this = this
 			this.$nextTick(function(){
 				// 监听整改完成后刷新事件
-				uni.$on('refreshBL', function(data){
-					_this.$refs.salesList.getList(1)
+				uni.$on('refreshSalesBL', function(data){
+					_this.$refs.salesList.refash()
 				})
 			})
 			
@@ -118,7 +118,7 @@
 			})
 		},
 		onUnload() {
-			uni.$off('refreshBL')
+			uni.$off('refreshSalesBL')
 		},
 		onShow() {
 			this.navInd = 0

+ 2 - 2
pages/sales/list.vue

@@ -46,13 +46,13 @@
 			this.getLookUpItem('FINANCIAL_RECEIVE_STATUS')
 			this.$nextTick(function(){
 				// 监听整改完成后刷新事件
-				uni.$on('refreshBL', function(data){
+				uni.$on('refreshSalesBL', function(data){
 					_this.$refs.salesList.getList(1)
 				})
 			})
 		},
 		onUnload() {
-			uni.$off('refreshBL')
+			uni.$off('refreshSalesBL')
 		},
 		methods: {
 			// 获取查询参数 刷新列表

+ 1 - 1
pages/stock/index.vue

@@ -94,7 +94,7 @@
 		    uni.setStorageSync('productEnabledFlag-' + this.$store.state.vuex_userData.orgId, newValue)
 		  },
 		},
-		onLoad() {
+		onShow() {
 			// 是否默认包括禁用产品
 			this.form.productEnabledFlag = uni.getStorageSync('productEnabledFlag-' + this.$store.state.vuex_userData.orgId)
 			this.getTotal()

+ 74 - 7
pages/userCenter/index.vue

@@ -9,8 +9,11 @@
 				<u-avatar :src="userAvatarUrl" size="100" class="avatar"></u-avatar>
 			</view>
 			<view class="user-info">
-				<text class="user-name">{{$store.state.vuex_userData.userNameCN}}</text>
-				<text class="user-phone">{{$store.state.vuex_userData.username}}</text>
+				<text class="user-name">{{userData.orgName}}</text>
+				<text class="user-phone">{{userData.username}}</text>
+			</view>
+			<view class="user-org" @click="show = true" v-if="orglist&&orglist.length">
+				切换 <u-icon name="arrow-right"></u-icon>
 			</view>
 		</view>
 		<!-- 列表 -->
@@ -26,36 +29,94 @@
 		<view class="user-btn">
 			<u-button type="success" :custom-style="{background:$config('primaryColor')}" hover-class="none" @click="quitOutSys" shape="circle">退出登录</u-button>
 		</view>
+		<u-action-sheet :list="orglist" v-model="show" @click="changeAcount" :tips="tips" :cancel-btn="true"></u-action-sheet>
 	</view>
 </template>
 
 <script>
-	import { getUserInfo, logout } from '@/api/user.js'
+	import { getUserInfo, logout, login } from '@/api/user.js'
 	import { getSysVersion } from '@/api/data.js'
 	import { checkVersionToLoadUpdate, clzConfirm } from '@/libs/tools';
 	import market from "@/js_sdk/dc-market/market.js"
 	export default {
 		data() {
 			return {
+				isRemember: false,
+				show:false,
+				tips: {
+					text: '切换账户',
+					color: '#999',
+					fontSize: 32
+				},
 				userInfoData: null,  //  用户信息
 				userAvatarUrl: ''  ,//  用户头像
 				curVer: null
 			};
 		},
 		onShow() {
-			this.getUserInfo()
+			// this.getUserInfo()
+			console.log(this.userData)
+		},
+		computed: {
+			orglist() {
+				// 当前连锁账户
+				const orgs = this.$store.state.vuex_authOrgs;
+				const user = this.$store.state.vuex_userData;
+				orgs.map(item => {
+					item.text = item.orgName
+				})
+				return orgs.filter(item => item.orgSn != user.orgSn) 
+			},
+			userData () {
+				return this.$store.state.vuex_userData;
+			}
 		},
 		onLoad() {
 			uni.setNavigationBarColor({
 				frontColor: '#ffffff',
 				backgroundColor: this.$config('primaryColor')
 			})
+			this.isRemember = this.$store.state.vuex_isRemember;
 			this.curVer = getApp().globalData.version;
 		},
 		methods:{
-			//  获取用户信息
-			getUserInfo(){
-				console.log(this.$store.state.vuex_userData)
+			// 过滤权限code
+			fiterAuthCode(data) {
+				data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
+				return data;
+			},
+			// 切换账户
+			changeAcount(index){
+				const _this = this
+				const item = this.orglist[index]
+				console.log(index,item)
+				this.$store.state.vuex_changeOrg = item.orgSn
+				this.$set(getApp().globalData,'changeOrg',item.orgSn)
+				setTimeout(()=>{
+					//  登录
+					login({ username: '', password: '' }).then(res => {
+						console.log(res)
+						uni.hideLoading();
+						if (res.status == 200) {
+							_this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.data.auth_user));
+							_this.$u.vuex('vuex_token', res.data.access_token);
+							_this.$u.vuex('vuex_authOrgs',res.data.auth_orgs);
+							getApp().globalData.token = res.data.access_token;
+							uni.setStorageSync('loginTimeOut', 'NO');
+							this.toMain()
+							uni.$emit("refreshSalesBL")
+							uni.showToast({ icon: 'none', title: '切换成功!' });
+						}else{
+							uni.showToast({ icon: 'none', title: res.message });
+						}
+					});
+				},100)
+			},
+			// 跳转到首页
+			toMain() {
+				uni.switchTab({
+					url: '/pages/sales/index'
+				});
 			},
 			// 打开对应的页面
 			toPage(index){
@@ -93,6 +154,9 @@
 						// this.$store.commit("$closeWebsocket")
 						this.$store.state.vuex_token = '';
 						this.$store.state.vuex_userData = '';
+						this.$u.vuex('vuex_authOrgs','');
+						getApp().globalData.token = '';
+						this.$set(getApp().globalData,'changeOrg','')
 						uni.setStorageSync('setStatusIndexFunc', 0);
 						setTimeout(function() {
 							uni.reLaunch({
@@ -131,6 +195,9 @@
 				flex-shrink: 0;
 				margin-right: 5rpx;
 			}
+			.user-org{
+				color: #fff;
+			}
 			.user-info{
 				flex-grow: 1;
 				padding: 0 20rpx;

+ 3 - 0
store/index.js

@@ -16,6 +16,7 @@ let saveStateKeys = [
 	'vuex_user',
 	'vuex_token',
 	'vuex_userData',
+	'vuex_authOrgs',
 	'vuex_isRemember',
 	'vuex_isUsrAuthYs',
 	'vuex_versionInfo',
@@ -91,10 +92,12 @@ const store = new Vuex.Store({
 		// 加上vuex_前缀,是防止变量名冲突,也让人一目了然
 		vuex_token: lifeData.vuex_token ? lifeData.vuex_token : '',
 		vuex_userData: lifeData.vuex_userData ? lifeData.vuex_userData : '',
+		vuex_authOrgs: lifeData.vuex_authOrgs ? lifeData.vuex_authOrgs : '',
 		vuex_user: lifeData.vuex_user ? lifeData.vuex_user : {account:'',password:''},
 		vuex_isRemember: lifeData.vuex_isRemember ? lifeData.vuex_isRemember : true,
 		vuex_isUsrAuthYs: lifeData.vuex_isUsrAuthYs ? lifeData.vuex_isUsrAuthYs : false,
 		vuex_versionInfo: lifeData.vuex_versionInfo ? lifeData.vuex_versionInfo : {}, // 版本信息
+		vuex_changeOrg: null, // 要切换的org
 		vuex_socket: null, // 消息通知ws对象
 		vuex_wsMessageData: null, // 消息对象
 		vuex_heartInterId: null, // 心跳id