单选开关根据后端传值显示开与关

控制器代码

/**
     * 系统设置
     * @auth true
     * @menu true
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \think\exception\PDOException
     */
    public function setting_index()
    {
        $this->title="系统设置";
        if($this->request->isGet()){
            $res = Db::table('rht_medicine_seting')->field('pid,deployment_img,audit_img,review_img,close')->where('pid',12)->find();
            $this->assign('data',$res);
            $this->fetch('prescription/setting_index');
        }elseif ($this->request->isPost()){
            $post_data = $this->request->post();
            //处理数据
            $res = $this->logic->setting_index($post_data);
            if ($res['code']==1){
                $this->success($res['info']);
            }else{
                $this->error($res['info']);
            }
        }
    }

逻辑代码

 //系统设置
    public function setting_index($post_data)
    {
        $data = [
            'deployment_img'=>$post_data['deployment_img'],//调配人img
            'audit_img'=>$post_data['audit_img'],//审批人img
            'review_img'=>$post_data['review_img'],//复核人img
            'close'=>$post_data['close']??'off'//自动审核开关
        ];
        $res = MedicineSetingModel::where('pid',$post_data['pid'])->update($data);
        if($res==1){
            return ['code'=>'1','info'=>'数据修改成功'];
        }else{
            return ['code'=>0, 'info'=>'数据未做修改'];
        }
    }

html代码

 <div class="layui-row margin-bottom-15">
            <span class="color-text" style="font-size:22px">2. </span>
            <span class="color-text" style="font-size:18px">处方单自动审核</span>
        </div>
        <div class="layui-row margin-bottom-15 margin-left-20">
                <div class="layui-form-item">
                    <label class="layui-form-label" style="color: #5FB878">开关-默认关闭</label>
                    <div class="layui-input-block" id="close">
                        <!--<input type="checkbox" name="close" lay-skin="switch" lay-text="ON|OFF"  checked="">-->
                        <input type="checkbox" name="close" lay-skin="switch" lay-filter="switchTest" lay-text="ON|OFF" >
                    </div>
                </div>
            <span class="layui-col-xs8">
                规则:开启后,系统每5分钟执行一次自动检测,检测是否存在订单状态为已完成且处在待审核的处方单,若是,则执行系统自动审核、自动加盖水印操作,无需手工操作审核
               关闭后,需手动操作审核,审核流程为调配人 -> 复核人
            </span>
        </div>

js代码

<script>
    window.form.render();
    //根据后端数据显示开关
    $(function () {
        var close ="{$data['close']}";
        if(close=='on'){
            $("#close").children("div").attr('class',"layui-unselect layui-form-switch layui-form-onswitch");
        }else{
            $("#close").children("div").attr('class',"layui-unselect layui-form-switch");
        }
    });

    layui.use(['form'], function(){
        var form = layui.form
            ,layer = layui.layer
        //监听指定开关
        form.on('switch(switchTest)', function(data){
            if(this.checked==true){

            }else{

            }
//            alert(this.checked);
           /* layer.msg('开关checked:'+ (this.checked ? 'true' : 'false'), {
                offset: '6px'
            });
            layer.tips('温馨提示:已开启自动审核', data.othis)*/
        });

    });
</script>

显示页面
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值