assign.vue 5.7 KB
<template>
    <view class="page">
        <scroll-view class="scroll" scroll-y>
            <view class="section" v-if="users.length > 0">
                <view
                    v-for="it in users"
                    :key="it.id"
                    class="card"
                    :class="{ 'is-selected': selectedId === it.id }"
                    @click="onSelect(it)"
                >
                    <view class="card-row">
                        <text class="card-name">{{ safeText(it.name) }}</text>
                        <text class="card-check" v-if="selectedId === it.id">✓</text>
                    </view>
                    <view class="card-row sub">
                        <text class="card-label">部门:</text>
                        <text class="card-value">{{ safeText(it.deptName) }}</text>
                    </view>
                    <view class="card-row sub">
                        <text class="card-label">角色:</text>
                        <text class="card-value">{{ safeText(it.roleName) }}</text>
                    </view>
                    <view class="card-row sub">
                        <text class="card-label">用户名:</text>
                        <text class="card-value">{{ safeText(it.username) }}</text>
                    </view>
                </view>
            </view>
            <view v-else-if="!loading" class="empty">暂无可分配人员</view>
        </scroll-view>

        <view class="footer">
            <button class="btn submit" :disabled="!selectedId" @click="onSubmit">确定分配</button>
        </view>
    </view>
</template>

<script>
import { supplierQuotationDealAssignUsersApi, supplierQuotationDealAssignApi } from '@/api/procure-manage/supplierQuotationDeal.js'

export default {
    name: 'AssignQuoteManage',
    data() {
        return {
            id: '',
            purchaseDepartment: '',
            loading: false,
            users: [],
            selectedId: ''
        }
    },
    onLoad(options) {
        this.id = (options && options.id) ? options.id : ''
        this.purchaseDepartment = (options && options.purchaseDepartment) ? options.purchaseDepartment : ''
        if (!this.id) {
            uni.showToast({ title: '缺少主键ID', icon: 'none' })
            return
        }
        this.loadUsers()
    },
    methods: {
        safeText(v) {
            const s = v == null ? '' : String(v)
            return s.trim() ? s : '-'
        },
        async loadUsers() {
            this.loading = true
            try {
                const res = await supplierQuotationDealAssignUsersApi({ purchaseDepartment: this.purchaseDepartment })
                const data = (res && res.data) ? res.data : []
                this.users = Array.isArray(data) ? data : []
            } catch (e) {
                this.users = []
                uni.showToast({ title: '加载人员失败', icon: 'none' })
            } finally {
                this.loading = false
            }
        },
        onSelect(it) {
            this.selectedId = it.id
        },
        async onSubmit() {
            if (!this.selectedId) {
                uni.showToast({ title: '请选择负责人', icon: 'none' })
                return
            }
            const confirmRes = await new Promise(resolve => {
                uni.showModal({ title: '提示', content: '确定分配给该负责人吗?', confirmText: '确定', cancelText: '取消', success: resolve })
            })
            if (!(confirmRes && confirmRes.confirm)) return
            try {
                await supplierQuotationDealAssignApi({ id: this.id, principalId: this.selectedId })
                uni.showToast({ title: '分配成功', icon: 'none' })
                try { uni.setStorageSync('QUOTE_MANAGE_LIST_NEED_REFRESH', '1') } catch (e) {}
                setTimeout(() => { uni.navigateBack() }, 400)
            } catch (e) {
                uni.showToast({ title: e.msg || '分配失败', icon: 'none' })
            }
        }
    }
}
</script>

<style lang="scss" scoped>
.page {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #f3f3f3;
}

.scroll {
    flex: 1;
    padding: 20rpx 0 200rpx;
}

.section {
    padding: 0 24rpx;
}

.card {
    background: #fff;
    border-radius: 12rpx;
    padding: 28rpx 32rpx;
    margin-bottom: 20rpx;
    border: 2rpx solid transparent;

    &.is-selected {
        border-color: $theme-primary;
        background: rgba($theme-primary, 0.04);
    }

    .card-row {
        display: flex;
        align-items: center;
        margin-bottom: 12rpx;

        &.sub {
            margin-bottom: 8rpx;
        }

        &:last-child {
            margin-bottom: 0;
        }
    }

    .card-name {
        flex: 1;
        font-size: 32rpx;
        font-weight: 600;
        color: rgba(0, 0, 0, 0.9);
    }

    .card-check {
        color: $theme-primary;
        font-size: 36rpx;
        font-weight: 700;
    }

    .card-label {
        font-size: 28rpx;
        color: rgba(0, 0, 0, 0.6);
    }

    .card-value {
        flex: 1;
        font-size: 28rpx;
        color: rgba(0, 0, 0, 0.9);
    }
}

.empty {
    text-align: center;
    color: rgba(0, 0, 0, 0.4);
    font-size: 28rpx;
    padding: 120rpx 0;
}

.footer {
    z-index: 2;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 32rpx;
    padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
    background: #fff;
    box-shadow: 0 -8rpx 24rpx rgba(0, 0, 0, 0.06);

    .btn {
        height: 80rpx;
        line-height: 80rpx;
        border-radius: 12rpx;
        font-size: 32rpx;
    }

    .submit {
        background: $theme-primary;
        color: #fff;

        &[disabled] {
            opacity: 0.5;
        }
    }
}
</style>