<template>
|
<view class="content">
|
<view>
|
<view class="currentFactory">
|
<up-text type="primary" :text="userStore.currentFactoryName" @click="show = true"
|
class="factoryName" suffixIcon="arrow-right" :iconStyle="iconStyle"></up-text>
|
</view>
|
<up-picker :show="show" :columns="factoryList" @confirm="changeFactory"></up-picker>
|
<view>
|
<view class="bg-img"></view>
|
</view>
|
<view class="bg-img">
|
<up-grid
|
:border="false"
|
col="4"
|
>
|
<up-grid-item
|
v-for="(listItem,listIndex) in list"
|
:key="listIndex"
|
>
|
<up-icon
|
:customStyle="{paddingTop:20+'rpx'}"
|
:name="listItem.name"
|
:size="22"
|
></up-icon>
|
<text class="grid-text">{{listItem.title}}</text>
|
</up-grid-item>
|
</up-grid>
|
</view>
|
</view>
|
<!-- <view class="select-container">-->
|
<!-- <up-picker-data-->
|
<!-- class="picker"-->
|
<!-- v-model="currentFatoryId"-->
|
<!-- title="请选择公司"-->
|
<!-- :options="factoryList"-->
|
<!-- valueKey="id"-->
|
<!-- labelKey="name">-->
|
<!-- </up-picker-data>-->
|
<!-- </view>-->
|
</view>
|
</template>
|
|
<script setup>
|
import {ref, onMounted, nextTick, reactive} from 'vue';
|
import {userLoginFacotryList} from "@/api/login";
|
import modal from "@/plugins/modal";
|
import useUserStore from "@/store/modules/user";
|
|
const userStore = useUserStore()
|
const factoryId = ref('');
|
const show = ref(false);
|
const factoryList = ref([]);
|
const factoryListTem = ref([]);
|
const iconStyle = {
|
fontSize: '14px',
|
color: '#165DFF'
|
}
|
// 创建响应式数据
|
const list = reactive([
|
{
|
name: 'photo',
|
title: '图片'
|
},
|
{
|
name: 'lock',
|
title: '锁头'
|
},
|
{
|
name: 'star',
|
title: '星星'
|
},
|
{
|
name: 'hourglass',
|
title: '沙漏'
|
},
|
{
|
name: 'home',
|
title: '首页'
|
},
|
{
|
name: 'volume', // 注意:这里修改了 name 从 'star' 改为 'volume',以避免列表中两个元素具有相同的 name
|
title: '音量'
|
},
|
]);
|
// 创建对子组件的引用
|
const uToastRef = ref(null);
|
|
function getUserLoginFacotryList() {
|
userLoginFacotryList({userName: userStore.nickName}).then(res => {
|
// 检查res.data是否为数组
|
factoryList.value[0] = []
|
if (res.data && Array.isArray(res.data)) {
|
factoryListTem.value = res.data
|
res.data.forEach(item => {
|
factoryList.value[0].push(item.deptName)
|
})
|
factoryId.value = userStore.currentDeptId
|
} else {
|
// 如果res.data不是数组,设置为空数组
|
factoryList.value = []
|
}
|
}).catch(error => {
|
modal.msgError('获取公司列表失败:', error)
|
factoryList.value = []
|
})
|
}
|
const changeFactory = async (arr) => {
|
show.value = false;
|
const factoryId = factoryListTem.value[arr.indexs[0]].deptId
|
const loginForm = {
|
username: userStore.name,
|
password: uni.getStorageSync('remembered_password'),
|
factoryId: factoryId,
|
}
|
modal.loading("刷新中,请耐心等待...")
|
userStore.loginCheckFactory(loginForm).then(() => {
|
modal.closeLoading()
|
nextTick(() => {
|
loginSuccess()
|
});
|
}).catch(() => {
|
modal.closeLoading()
|
})
|
}
|
function loginSuccess(result) {
|
uni.reLaunch({
|
url: '/pages/index'
|
});
|
}
|
|
// 定义方法
|
const click = (name) => {
|
if (uToastRef.value) {
|
uToastRef.value.success(`点击了第${name + 1}个`); // 注意:这里加1是因为通常我们是从第1个开始计数的
|
}
|
};
|
|
onMounted(() => {
|
// 设置用户信息
|
userStore.getInfo()
|
getUserLoginFacotryList()
|
});
|
</script>
|
|
<style scoped lang="scss">
|
.content {
|
background-color: transparent !important;
|
padding: 14px;
|
}
|
.currentFactory {
|
margin-top: 12px;
|
margin-left: 6px;
|
font-weight: 400;
|
font-size: 14px;
|
display: flex;
|
}
|
.factoryName {
|
width: auto;
|
}
|
:deep(.u-text) {
|
align-items: flex-end;
|
}
|
.bg-img {
|
margin-top: 12px;
|
width: 100%;
|
height: 145px;
|
background-color: #ffffff;
|
border-radius: 10px 10px 10px 10px;
|
}
|
.grid-text {
|
font-size: 14px;
|
color: #909399;
|
padding: 10rpx 0 20rpx 0rpx;
|
/* #ifndef APP-PLUS */
|
box-sizing: border-box;
|
/* #endif */
|
}
|
</style>
|