<template>
|
<view class="binding-detail-page">
|
<PageHeader :title="'绑定关系: ' + standardNo" @back="goBack" />
|
|
<view class="detail-info-header">
|
<view class="info-row">
|
<text class="info-label">标准编号:</text>
|
<text class="info-value">{{ standardNo }}</text>
|
</view>
|
</view>
|
|
<view class="list-container" v-if="bindingList.length > 0">
|
<view v-for="(item, index) in bindingList" :key="index" class="list-item">
|
<view class="item-content">
|
<text class="product-name">{{ item.productName }}</text>
|
</view>
|
<view class="item-actions">
|
<up-button type="error" size="mini" @click.stop="handleUnbind(item)">解除绑定</up-button>
|
</view>
|
</view>
|
</view>
|
|
<view v-else class="no-data">
|
<up-empty mode="data" text="暂无绑定关系"></up-empty>
|
</view>
|
|
<view class="fab-button" @click="openBindingDialog">
|
<up-icon name="plus" size="24" color="#ffffff"></up-icon>
|
</view>
|
|
<!-- 添加绑定弹窗 -->
|
<up-popup v-model:show="showBindingDialog" mode="bottom" round closeable @close="showBindingDialog = false">
|
<view class="binding-dialog">
|
<view class="dialog-header">
|
<text class="dialog-title">添加产品绑定</text>
|
</view>
|
<view class="search-box">
|
<up-search
|
placeholder="搜索产品"
|
v-model="productSearch"
|
@search="filterProducts"
|
@custom="filterProducts"
|
@clear="filterProducts"
|
:show-action="true"
|
action-text="筛选"
|
:animation="true"
|
></up-search>
|
</view>
|
<scroll-view scroll-y class="product-list">
|
<up-checkbox-group v-model="selectedProductIds" placement="column">
|
<up-checkbox
|
v-for="item in filteredProducts"
|
:key="item.id"
|
:label="item.productName"
|
:name="item.id"
|
customStyle="margin-bottom: 20rpx"
|
></up-checkbox>
|
</up-checkbox-group>
|
</scroll-view>
|
<view class="dialog-footer">
|
<up-button type="primary" text="确认绑定" @click="submitBinding" :loading="submitLoading"></up-button>
|
</view>
|
</view>
|
</up-popup>
|
</view>
|
</template>
|
|
<script setup>
|
import { ref, reactive, onMounted, computed } from 'vue';
|
import { onLoad } from '@dcloudio/uni-app';
|
import {
|
qualityTestStandardBindingList,
|
qualityTestStandardBindingAdd,
|
qualityTestStandardBindingDel
|
} from '@/api/qualityManagement/qualityTestStandardBinding.js';
|
import { productTreeList } from '@/api/basicData/product.js';
|
import { toast, showConfirm } from '@/utils/common';
|
|
const standardId = ref(null);
|
const standardNo = ref('');
|
|
const bindingList = ref([]);
|
const loading = ref(false);
|
|
const showBindingDialog = ref(false);
|
const productSearch = ref('');
|
const allProducts = ref([]);
|
const filteredProducts = ref([]);
|
const selectedProductIds = ref([]);
|
const submitLoading = ref(false);
|
|
const getList = () => {
|
loading.value = true;
|
qualityTestStandardBindingList({ standardId: standardId.value }).then(res => {
|
bindingList.value = res.data || [];
|
}).finally(() => {
|
loading.value = false;
|
});
|
};
|
|
const openBindingDialog = () => {
|
selectedProductIds.value = [];
|
productSearch.value = '';
|
filteredProducts.value = allProducts.value;
|
showBindingDialog.value = true;
|
};
|
|
const filterProducts = () => {
|
if (!productSearch.value) {
|
filteredProducts.value = allProducts.value;
|
} else {
|
filteredProducts.value = allProducts.value.filter(p =>
|
p.productName.toLowerCase().includes(productSearch.value.toLowerCase())
|
);
|
}
|
};
|
|
const submitBinding = () => {
|
if (selectedProductIds.value.length === 0) {
|
toast('请选择要绑定的产品');
|
return;
|
}
|
|
submitLoading.value = true;
|
const data = selectedProductIds.value.map(productId => ({
|
standardId: standardId.value,
|
productId
|
}));
|
|
qualityTestStandardBindingAdd(data).then(() => {
|
toast('绑定成功');
|
showBindingDialog.value = false;
|
getList();
|
}).finally(() => {
|
submitLoading.value = false;
|
});
|
};
|
|
const handleUnbind = (row) => {
|
showConfirm('确认解除该产品的绑定关系吗?').then(res => {
|
if (res.confirm) {
|
qualityTestStandardBindingDel([row.id]).then(() => {
|
toast('解绑成功');
|
getList();
|
});
|
}
|
});
|
};
|
|
const goBack = () => {
|
uni.navigateBack();
|
};
|
|
onLoad((options) => {
|
standardId.value = options.id;
|
standardNo.value = options.standardNo;
|
getList();
|
|
productTreeList().then(res => {
|
allProducts.value = res.data || [];
|
filteredProducts.value = allProducts.value;
|
});
|
});
|
</script>
|
|
<style lang="scss" scoped>
|
.binding-detail-page {
|
padding-bottom: 120rpx;
|
background-color: #f5f7fa;
|
min-height: 100vh;
|
}
|
|
.detail-info-header {
|
padding: 30rpx;
|
background-color: #ffffff;
|
margin-bottom: 20rpx;
|
}
|
|
.info-row {
|
display: flex;
|
align-items: center;
|
}
|
|
.info-label {
|
color: #909399;
|
font-size: 28rpx;
|
width: 160rpx;
|
}
|
|
.info-value {
|
color: #303133;
|
font-size: 28rpx;
|
font-weight: bold;
|
}
|
|
.list-container {
|
padding: 20rpx;
|
}
|
|
.list-item {
|
background-color: #ffffff;
|
border-radius: 16rpx;
|
padding: 30rpx;
|
margin-bottom: 20rpx;
|
display: flex;
|
justify-content: space-between;
|
align-items: center;
|
}
|
|
.product-name {
|
font-size: 30rpx;
|
color: #303133;
|
font-weight: 500;
|
}
|
|
.no-data {
|
padding-top: 200rpx;
|
}
|
|
.fab-button {
|
position: fixed;
|
right: 40rpx;
|
bottom: 60rpx;
|
width: 100rpx;
|
height: 100rpx;
|
background-color: #3c9cff;
|
border-radius: 50%;
|
display: flex;
|
align-items: center;
|
justify-content: center;
|
box-shadow: 0 4rpx 16rpx rgba(60, 156, 255, 0.4);
|
z-index: 99;
|
}
|
|
.binding-dialog {
|
background-color: #ffffff;
|
padding: 40rpx;
|
max-height: 80vh;
|
display: flex;
|
flex-direction: column;
|
border-radius: 24rpx 24rpx 0 0;
|
overflow: hidden;
|
}
|
|
.dialog-header {
|
margin-bottom: 30rpx;
|
text-align: center;
|
}
|
|
.dialog-title {
|
font-size: 32rpx;
|
font-weight: bold;
|
}
|
|
.search-box {
|
margin-bottom: 30rpx;
|
}
|
|
.product-list {
|
flex: 1;
|
min-height: 400rpx;
|
}
|
|
.dialog-footer {
|
margin-top: 40rpx;
|
padding-bottom: env(safe-area-inset-bottom);
|
}
|
</style>
|