<template>
|
<view class="content">
|
<cu-custom :bgColor="NavBarColor" :isBack="true" backRouterName="index">
|
<block slot="backText">返回</block>
|
<block slot="content">选择产线</block>
|
</cu-custom>
|
|
<view class="current-line" @tap="showLineSelectModal">
|
<view class="line-label">当前产线:</view>
|
<view class="line-name">{{ currentLineName || '未选择产线' }}</view>
|
</view>
|
|
<view class="line-modal-mask" v-if="showLineModal" @click="closeLineModal"></view>
|
<view class="line-modal" v-if="showLineModal" :class="{ 'line-modal-active': showLineModal }">
|
<view class="line-modal-header">
|
<view class="line-modal-title">选择产线</view>
|
<text class="cuIcon-close" @click="closeLineModal"></text>
|
</view>
|
<view class="line-modal-content">
|
<view v-if="lineLoading" class="loading-view">
|
<view class="cu-load"></view>
|
<view class="text-gray">加载产线中...</view>
|
</view>
|
<view v-else-if="lineList.length === 0" class="empty-view">
|
<text class="cuIcon-meh text-gray text-xl"></text>
|
<view class="text-gray">暂无可用产线</view>
|
</view>
|
<view class="line-item"
|
v-for="(line, index) in lineList"
|
:key="line.id"
|
@click="selectLine(line)"
|
:class="{ 'line-item-selected': selectedLineId === line.id }">
|
<view class="line-name">{{ line.name }}</view>
|
<text class="cuIcon-check text-blue" v-if="selectedLineId === line.id"></text>
|
</view>
|
</view>
|
<view class="line-modal-footer">
|
<button class="cu-btn bg-blue lg"
|
@click="confirmLineSelection"
|
:disabled="!selectedLineId">
|
确认选择
|
</button>
|
</view>
|
</view>
|
</view>
|
</template>
|
|
<script>
|
import { mapActions, mapGetters, mapState } from "vuex";
|
|
export default {
|
data() {
|
return {
|
showLineModal: false,
|
selectedLineId: '',
|
lineLoading: false
|
};
|
},
|
computed: {
|
...mapState(["currentLineId"]),
|
...mapGetters(["lineList"]),
|
currentLineName() {
|
if (!this.currentLineId) return '';
|
const currentLine = this.lineList.find(line => line.id === this.currentLineId);
|
return currentLine ? currentLine.name : '未选择产线';
|
},
|
top() {
|
return this.CustomBar * 2 + 95;
|
},
|
style() {
|
var StatusBar = this.StatusBar;
|
var CustomBar = this.CustomBar;
|
var style = `height:${CustomBar}px;padding-top:${StatusBar}px;`;
|
return style;
|
}
|
},
|
|
created() {
|
this.fetchLineData();
|
},
|
mounted() {
|
this.selectedLineId = this.currentLineId;
|
},
|
methods: {
|
...mapActions(["fetchLineList", "setCurrentLine"]),
|
|
fetchLineData() {
|
this.lineLoading = true;
|
this.fetchLineList()
|
.then(lineList => {
|
this.lineLoading = false;
|
if (lineList.length > 0 && !this.selectedLineId) {
|
this.selectedLineId = lineList[0].id;
|
}
|
})
|
.catch(err => {
|
console.error("获取产线列表失败:", err);
|
this.lineLoading = false;
|
uni.showToast({
|
title: "获取产线列表失败,请重试",
|
icon: "none"
|
});
|
});
|
},
|
|
showLineSelectModal() {
|
this.showLineModal = true;
|
},
|
|
selectLine(line) {
|
this.selectedLineId = line.id;
|
},
|
|
confirmLineSelection() {
|
if (!this.selectedLineId) {
|
uni.showToast({
|
title: "请选择产线",
|
icon: "none"
|
});
|
return;
|
}
|
|
this.setCurrentLine(this.selectedLineId)
|
.then(() => {
|
this.showLineModal = false;
|
uni.showToast({
|
title: "产线设置成功",
|
icon: "success"
|
});
|
})
|
.catch(err => {
|
console.error("保存产线失败:", err);
|
this.showLineModal = false;
|
uni.showToast({
|
title: "产线设置失败,请重试",
|
icon: "none"
|
});
|
});
|
},
|
|
closeLineModal() {
|
this.showLineModal = false;
|
}
|
}
|
};
|
</script>
|
|
<style>
|
.current-line {
|
display: flex;
|
align-items: center;
|
padding: 20upx;
|
background-color: #fff;
|
border-radius: 10upx;
|
margin: 20upx;
|
box-shadow: 0 2upx 10upx rgba(0, 0, 0, 0.1);
|
}
|
|
.line-label {
|
font-size: 28upx;
|
color: #333;
|
margin-right: 10upx;
|
}
|
|
.line-name {
|
font-size: 28upx;
|
color: #666;
|
}
|
|
/* 产线选择弹窗样式 */
|
.line-modal-mask {
|
position: fixed;
|
top: 0;
|
left: 0;
|
right: 0;
|
bottom: 0;
|
background-color: rgba(0, 0, 0, 0.5);
|
z-index: 998;
|
opacity: 0;
|
transition: opacity 0.3s ease;
|
}
|
|
.line-modal {
|
position: fixed;
|
left: 0;
|
right: 0;
|
bottom: -100%;
|
background-color: #fff;
|
border-top-left-radius: 20upx;
|
border-top-right-radius: 20upx;
|
z-index: 999;
|
transition: bottom 0.3s ease;
|
max-height: 80vh;
|
}
|
|
.line-modal-active {
|
bottom: 0;
|
}
|
|
.line-modal-active + .line-modal-mask {
|
opacity: 1;
|
}
|
|
.line-modal-header {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 20upx 30upx;
|
border-bottom: 1px solid #eee;
|
}
|
|
.line-modal-title {
|
font-size: 34upx;
|
font-weight: bold;
|
}
|
|
.line-modal-content {
|
padding: 20upx;
|
overflow-y: auto;
|
max-height: calc(80vh - 180upx);
|
}
|
|
.line-item {
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
padding: 25upx 20upx;
|
border-bottom: 1px solid #f5f5f5;
|
font-size: 30upx;
|
}
|
|
.line-item-selected {
|
background-color: #f0f7ff;
|
}
|
|
.line-item:last-child {
|
border-bottom: none;
|
}
|
|
.line-modal-footer {
|
padding: 20upx 30upx;
|
border-top: 1px solid #eee;
|
}
|
|
.loading-view {
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
justify-content: center;
|
padding: 60upx 0;
|
}
|
|
.empty-view {
|
display: flex;
|
flex-direction: column;
|
align-items: center;
|
justify-content: center;
|
padding: 60upx 0;
|
}
|
</style>
|