gaoluyang
2025-08-06 6abe22fc75b115d2a68103a4d8b24d0815a016f8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<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>