角色(单选)联动小区(多选)再联动楼栋(多选)

在这里插入图片描述

add页面

 <div class="row">
            	<div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-2 control-label">角色:</label>
                        <div class="col-xs-10">
                            <label th:each="role:${roles}" class="rad">
								<input name="roleId" type="radio" th:value="${role.roleId}" th:text="${role.roleName}" th:disabled="${role.status == '1'}" th:checked="${role.flag}">
							</label>
                        </div>
                    </div>
                </div>
            </div>
            
            <div class="form-group" name="xiaoqu" >
                <label class="col-sm-2 control-label is-required">小区:</label>
                <div class="col-sm-4">

                    <select name="communityId" id="project" class=" form-control m-b select2-multiple" onchange="getBuilding()" multiple required>

                        <option th:each="qt:${data}" th:value="${qt.id}"
                                th:text="${qt.name}" ></option>
                    </select>
                </div>
            </div>
            <div class="form-group" name="lou" >
                <label class="col-sm-2 control-label is-required">楼栋:</label>
                <div class="col-sm-4">
                    <select name="building" id="building" class="form-control m-b select2-multiple" multiple required>

                    </select>
                </div>
            </div>
function getBuilding() {
            // var community = new Array();
             // community = $("#community option:selected").value();
            var community = $.form.selectSelects("project").toString();
            debugger;
            if (community == '') {
                return;
            }
            $.ajax({
                type: "get",
                url: prefix + "/getBuilding?community=" + community,
                success: function (result) {
                    console.log(result);
                    var datas=result;
                    var optionstring = "";
                    for (var j = 0; j < datas.length; j++) {
                        optionstring += "<option value=\"" + datas[j].id + "\" >" + datas[j].name + "</option>";
                    }

                    $("#building").html(optionstring);
                }
            });
        }


        $(":radio").click(function() {
            var num = $(this).val();  // 当前按钮的value值对应需要显示文本框的位置
            debugger;
            if(num == 2){
                $("div[name='xiaoqu']").show();
                $("div[name='lou']").show();
            }else if(num == 100){
                $("div[name='xiaoqu']").show();
                $("div[name='lou']").hide();
            }else {
                $("div[name='lou']").hide();
                $("div[name='xiaoqu']").hide();
            }
        });

edit页面

 <div class="row">
            	<div class="col-sm-12">
                    <div class="form-group">
                        <label class="col-xs-2 control-label">角色:</label>
                        <div class="col-xs-10">
                            <label th:each="role:${roles}" class="rad">
								<input name="roleId"  type="radio" th:value="${role.roleId}" th:text="${role.roleName}" th:checked="${role.flag}" th:disabled="${role.status == '1'}">
							</label>
                        </div>
                    </div>
                </div>
            </div>

            <div class="form-group" name="xiaoqu" hidden>
                <label class="col-sm-2 control-label is-required">小区:</label>
                <div class="col-sm-4">
                    <select name="communityId" id="project" class=" form-control m-b select2-multiple" onchange="getBuild()" multiple required>
                        <option th:each="qt:${data}" th:value="${qt.id}"
                                th:text="${qt.name}" th:selected="${qt.flag}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group" name="lou" hidden>
                <label class="col-sm-2 control-label is-required">楼栋:</label>
                <div class="col-sm-4">
                    <select name="building"  id="build" class="form-control m-b select2-multiple" multiple required>
                        <option th:each="dept:${building}" th:value="${dept.id}" th:text="${dept.name}"
                                th:selected="${dept.flag}"></option>
                    </select>
                </div>
            </div>
$(function() {
           
            var num = $( "input[name='roleId']:checked ").val();
            if(num == 2){
                $("div[name='xiaoqu']").show();
                $("div[name='lou']").show();
            }else if(num == 100){
                $("div[name='xiaoqu']").show();
                $("div[name='lou']").hide();
            }else {
                $("div[name='lou']").hide();
                $("div[name='xiaoqu']").hide();
            }
        });
 function getBuild() {
           
                var num = $( "input[name='roleId']:checked ").val();
                if(num == 2){
                    $("div[name='lou']").show();
                }else if(num == 100){
                    $("div[name='lou']").hide();
                }
            var community = $.form.selectSelects("project").toString();
            debugger;
            if (community == '') {
                return;
            }
            $.ajax({
                type: "get",
                url: prefix + "/getBuilding?community=" + community,
                success: function (result) {
                    console.log(result);
                    var datas=result;
                    var optionstring = "";
                    for (var j = 0; j < datas.length; j++) {
                        optionstring += "<option value=\"" + datas[j].id + "\" >" + datas[j].name + "</option>";
                    }

                    $("#build").html(optionstring);
                }
            });
        }
        

        $(":radio").click(function() {
            var num = $(this).val();  // 当前按钮的value值对应需要显示文本框的位置
            if(num == 2){
                $("div[name='xiaoqu']").show();
                $("div[name='lou']").show();
            }else if(num == 100){
                $("div[name='xiaoqu']").show();
                $("div[name='lou']").hide();
            }else {
                $("div[name='lou']").hide();
                $("div[name='xiaoqu']").hide();
            }
        });

后台

 @GetMapping("/getBuilding")
    @ResponseBody
    public List<HdBuilding> getBuilding(String community)
    {
        return hdBuildingService.selectBuildingListByCommunity(community);
    }
@Override
    public List<HdBuilding> selectBuildingListByCommunity(String communityId)
    {
        return hdBuildingMapper.selectBuildingListByCommunity(Convert.toStrArray(communityId));
    }
public List<HdBuilding> selectBuildingListByCommunity(String[] communityId);
<select id="selectBuildingListByCommunity"  resultMap="HdBuildingResult">
        <include refid="selectHdBuildingVo"/>
        <where>
        community_id in
            <foreach item="id" collection="array" open="(" separator="," close=")">
                #{id}
            </foreach>
        </where>

    </select>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值