方龙
方龙
  • 发布:2020-05-25 12:53
  • 更新:2021-07-07 15:30
  • 阅读:5464

uniapp checkbox在无法选中

分类:uni-app

uniapp checkbox在无法选中

<template>  
    <view>  
        <betterScroll title="选择库存">  
            <view class="cu-bar bg-white solid-bottom">  
                <view class="action">  
                    <text class="cuIcon-title text-theme"></text>  
                    所需试剂  
                </view>  
            </view>  
            <view class="bg-white padding">  
                <view class="">  
                    <text class="text-black">{{ reagent.CommonName }}</text>  
                    <text class="text-gray">(规格:{{ reagent.Model }})</text>  
                </view>  
                <view class="flex justify-between">  
                    <view class="">  
                        <view class="cu-tag bg-orange" v-if="reagent.Label">{{ reagent.Label }}</view>  
                        <view class="cu-tag bg-orange" v-if="reagent.Consistency">{{ reagent.Consistency }}</view>  
                        <view class="cu-tag bg-red" v-if="reagent.Brand">{{ reagent.Brand }}</view>  
                    </view>  
                    <view class="">  
                        <view class="cu-capsule radius">  
                            <view class="cu-tag bg-olive">领用量</view>  
                            <view class="cu-tag line-olive">{{ reagent.Amount }}</view>  
                        </view>  
                    </view>  
                </view>  
            </view>  
            <view class="cu-bar bg-white solid-bottom margin-top">  
                <view class="action">  
                    <text class="cuIcon-title text-theme"></text>  
                    库存参考  
                </view>  
            </view>  
            <view class="">  
                <view class="flex bg-white">  
                    <view class="width-35 text-bold">有效期</view>  
                    <view class="width-35 text-bold">位置</view>  
                    <view class="width-20 text-bold">剩余量</view>  
                    <view class="width-10 text-bold"></view>  
                </view>  
            </view>  
            <scroll-view  
                scroll-y="true"  
                class="bg-white"  
                :style="{ height: scrollH + 'px' }"  
                @scrolltoupper="upper"  
                @scrolltolower="lower"  
                @scroll="scroll"  
            >  
                <view class="">  
                    <block v-for="(item, index) in searchArr" :key="item.Reagent.Id">  
                        <view class="flex bg-white dashed-bottom">  
                            <view class="width-35 text-sm">{{ item.Reagent.ExpiryTime | format }}</view>  
                            <view class="width-35 text-sm">{{ item.Box.Name + '-' + item.Container.Name }}</view>  
                            <view class="width-20 text-sm">{{ item.Reagent.Volumn }}</view>  
                            <view class="width-10 text-sm">  

                                <checkbox-group @change="checkboxChange($event, index)">  
                                    <label><checkbox :value="index" :checked="item.select" color="#015478" style="transform:scale(0.7)" /></label>  
                                </checkbox-group>  
                            </view>  
                        </view>  
                    </block>  
                </view>  
            </scroll-view>  
            <view class="button-wrap flex bg-white">  
                <view class="flex-sub padding"><button class="cu-btn bg-green shadow full-height full-width" @tap="confrimforClick">确认选择</button></view>  
                <view class="flex-sub padding"><button class="cu-btn bg-blue shadow full-height full-width" @tap="barCodeSelect">扫码选择</button></view>  
            </view>  
        </betterScroll>  
    </view>  
</template>  

<script>  
import { reagentDetail } from '../../common/js/api/reagent-api.js';  

import { mapMutations } from 'vuex';  
import { SET_STOCK_LIST } from '../../store/mutation-types.js';  
export default {  
    data() {  
        return {  
            reagent: {},  
            searchArr: [],  
            scrollTop: 0  
        };  
    },  
    onLoad(option) {  
        console.log(option);  
        this.reagent = JSON.parse(option.item);  
        this.getSearchArr();  
    },  
    created() {},  
    computed: {  
        scrollH() {  
            let WHeight = uni.getSystemInfoSync().windowHeight;  
            return WHeight - this.CustomBar - 50 - 86 - 50 - 15 - 28 - 50 + 10;  
        }  
    },  
    methods: {  
        ...mapMutations({  
            setStockList: SET_STOCK_LIST  
        }),  
        barCodeSelect() {  

            uni.scanCode({  
                onlyFromCamera: true,  
                scanType: ['barCode'],  
                success: function(res) {  
                    const barCodeIndex = this.searchArr.findIndex(item => item.Reagent.Barcode);  
                    if (barCodeIndex === -1) {  
                        uni.showModal({  
                            title: '提示',  
                            showCancel: false,  
                            content: '未找到该条码对应的试剂'  
                        });  
                    } else {  
                        this.searchArr[barCodeIndex].select = true;  
                        uni.showToast({  
                            title: '扫码选择成功',  
                            icon: 'success'  
                        });  
                    }  
                }  
            });  
        },  
        checkboxChange(event, index) {  
            if (event.detail.value.length === 0) {  
                this.searchArr[index].select = false;  
            } else {  
                this.searchArr[index].select = true;  
            }  
        },  
        async getSearchArr() {  
            let [err, res] = await reagentDetail(this.reagent.id);  
            if (!this.$http.errorCheck(err, res)) return;  
            for (let i = 0; i < res.data.response.length; i++) {  
                res.data.response[i].select = false;  
            }  
            this.searchArr = res.data.response;  
        },  
        upper(e) {  
            console.log(e);  
        },  
        lower(e) {  
            console.log(e);  
        },  
        scroll(e) {  
            console.log(e);  
        },  
        confrimforClick() {  
            const searchArr = this.searchArr.filter(item => item.select);  
            if (searchArr.length !== this.reagent.Amount) {  
                uni.showModal({  
                    title: '提示',  
                    showCancel: false,  
                    content: '选择的数量不正确,请重新选择,所需数量为' + this.reagent.Amount  
                });  
            } else if (searchArr.length === 0) {  
                uni.showModal({  
                    title: '提示',  
                    showCancel: false,  
                    content: '请选择需要出库的试剂'  
                });  
            } else {  
                this.setStockList(searchArr);  
                uni.navigateBack();  
            }  
        }  
    }  
};  
</script>  

<style lang="scss" scoped>  
.width-10 {  
    width: 10%;  
    text-align: center;  
}  
.width-20 {  
    width: 20%;  
    text-align: center;  
}  
.width-35 {  
    width: 35%;  
    text-align: center;  
}  
.button-wrap {  
    height: 100rpx;  
    box-sizing: border-box;  
}  
.padding {  
    padding: 20rpx 50rpx;  
}  
</style>  
2020-05-25 12:53 负责人:无 分享
已邀请:
5***@qq.com

5***@qq.com

我的是在两个main.css(我的这两个文件一样,路径不同)中注销掉这下面两行代码就可以了

  • 队长给我球

    牛X啊,看了一上午,找到你这个方法,就解决了,应该就是项目引入太多的样式了,然后这块给覆盖了

    2020-07-07 14:07

  • 7***@qq.com

    这样做是能够解决 但是单选按钮样式就出问题了

    2021-07-07 15:31

  • pulada

    666

    2023-03-08 09:37

方龙

方龙 (作者)

就是点选择框,但是并没有选中,问下大家有没有遇到同样的问题,请问这么解决

  • 2***@qq.com

    一样的,还没解决,官网实例copy进来都是选中不了

    2020-05-27 09:42

方龙

方龙 (作者)

小程序端可以选中,安卓的无法选中

5***@qq.com

5***@qq.com

我也碰到了,不知道啥原因,

  • 2***@qq.com

    同样遇到这个问题

    2020-05-27 09:42

teller306

teller306

更新到最新sdk后也是点击后没有勾选,请问谁解决这个问题了

9***@qq.com

9***@qq.com

问题解决了吗

7***@qq.com

7***@qq.com

我也遇到这个问题 解决了吗

  • 9***@qq.com

    是不是引入了别的样式库

    2020-06-09 10:03

  • 5***@qq.com

    回复 9***@qq.com: 没有,单独开的新项目,拿的官网示例,一样选不中

    2020-06-09 18:11

  • 5***@qq.com

    回复 5***@qq.com: 好像是的确因为引入了别的样式库的问题,大佬牛逼,但是咋解决呢,我看了别的样式库没找到可能会影响的css属性啊

    2020-06-09 18:17

wgf_hnhuodong

wgf_hnhuodong

不是选不中,因为他的机制是一赋值马上渲染,可以从这个先后的顺序来改改,应该就可以了。

1***@qq.com

1***@qq.com

我也是遇到这种问题

勇敢的心_

勇敢的心_ - 始于1994

我也遇到了,很气啊!

8***@qq.com

8***@qq.com

把其它引用的UI库里关于checkbox的都删掉就好了(我之前用的colorUI,删了就好了)

该问题目前已经被锁定, 无法添加新回复