【Vegas原创】PHP+jquery实现select的三级联动

2年前 (2022) 程序员胖胖胖虎阿
204 0 0

 

【Vegas原创】PHP+jquery实现select的三级联动

需求:选择科别,可以调出科别的医生;选择医生,可以调出医生所在的诊室

方法:

 

1, HTML js:

<script src="../js/jquery-1.3.2.js"></script>
   1:  
   2: <script type="text/javascript">
   3:  
   4: $(document).ready(function(){
   5:     $("#dept_no").change(changeDept);
   6:     $("#doc_no").change(changeDoc);    
   7: });
   8:  
   9: function changeDept(){
  10:     var deptno = $("#dept_no").val();
  11:     var timeshift=$("#time_shift").val();
  12:     var opddate=$("#opd_date").val();
  13:     
  14:     //更新医师select
  15:     $.post("changeDeptDocRoom.php",{dept_no:deptno,type:"doc",time_shift:timeshift,opd_date:opddate},function(data){
  16:             var docs = $("#doc_no");//存放医师列表
  17:             var json = eval(data);
  18:             docs.html("");
  19:             if(json.length == 0){
  20:                 docs.append("<option>无医师排程</option>");
  21:                 $("#room_no").val("");
  22:                 $("#room_sno").val("");
  23:             }else{
  24:               for(var i in json){
  25:                   docs.append("<option value='"+json[i].no+"'>"+json[i].no+"  "+json[i].name+"</option>");
  26:               }
  27:             changeDoc();
  28:             }    
  29:         });
  30: }
  31:  
  32: function changeDoc(){
  33:     var docno = $("#doc_no").val();
  34:     var deptno = $("#dept_no").val();
  35:     var timeshift=$("#time_shift").val();
  36:     var opddate=$("#opd_date").val();
  37:  
  38:     //触发roomno text
  39:     $.post("changeDeptDocRoom.php",{doc_no:docno,type:"room",dept_no:deptno,time_shift:timeshift,opd_date:opddate},function(data){
  40:         var roomno = $("#room_no");//存放ROOM No text
  41:         var roomsno= $("#room_sno");//存放ROOM No hidden
  42:         var json=eval(data);
  43:         for (var i in json){
  44:             roomno.val(json[i].name);
  45:             roomsno.val(json[i].no);
  46:             }
  47:     });
  48: }
  49:  
</script>

 

2,HTML代码:

<tr>
            <td class="textRowLong">看诊日期:</td>
            <td class="textRowLong">
                <input type="text" class="textboxReadOnly"  value="<?php printf (getDateFormat(uf_get_ctrl_file_sys_date()));?>" name="opd_date" id="opd_date" readonly>
            </td>
        </tr>
        <tr>
            <td class="textRowLong">时段:</td>
            <td class="textRowLong">
             <select class="selectBoxNoWidth" id="time_shift" name="time_shift">
              <?php 
            prtCodeDTL("0115",uf_get_time_coder()); ?>
            </select>
            </td>
        </tr>
      <tr>
            <td class="textRowLong">
                科别:</td>
            <td class="textRowLong">
                <select class="selectBoxNoWidth"  name="dept_no" id="dept_no">
                  <?php prtdept(""); ?>
                </select>
            </td>
        </tr>
        <tr>
          <td class="textRowLong"> 医师:</td>
          <td class="textRowLong">
            <select class="selectBoxNoWidth"  name="doc_no" id="doc_no">

            </select>
            </td>
            </tr>
            <tr>
            <td class="textRowLong">
                诊间: </td>
                <td class="textRowLong">
            <input type="text" class="textboxReadOnly"  name="room_no" id="room_no" readonly>
            <input type="hidden"  name="room_sno" id="room_sno" ></input>
            </td>
            </tr>

 

3, prtdept(“) php函数:

//部门
function prtdept($dept)
{
    $query = " SELECT DEPT_FILE.DEPT_NO,DEPT_FILE.S_NAME,DEPT_FILE.INS_DEPT FROM DEPT_FILE order by dept_no ";

    $stmt = ociparse(connected_resource(), $query);
    ociexecute($stmt,OCI_DEFAULT);
    $dept_nrows = OCIFetchStatement($stmt,$dept_rows);
    OCIFreeStatement($stmt);
    
   print '<option value=""></option>';
   for ($i = 0;$i < $dept_nrows;$i++)
   {
      if($dept == $dept_rows["S_NAME"][$i])
     $selected = "selected";
      else
     $selected = "";       
      print("<OPTION value=".$dept_rows["DEPT_NO"][$i]." ". $selected.">".$dept_rows["DEPT_NO"][$i]."  ".$dept_rows["S_NAME"][$i]."  ".$dept_rows["INS_DEPT"][$i]."</OPTION>\n"); 
   }
}
 

4,  changeDeptDocRoom.php:

 

 

 

 

 

<?php
$minpath = '/';
include_once  '../comm/common.inc';
include_once $minpath . 'reg020view.inc';


if ($_POST["type"] == "doc"){
    listDoctor($_POST["dept_no"]);
}else if ($_POST["type"] == "room")
{
    getRoom($_POST["doc_no"]);
}
//根据科别获取医师列表
function listDoctor($deptno)
{    
    $sql = "select distinct opd_sched.doc_no,doc_file.doc_name,dept_no1,dept_no2,dept_no3 from opd_sched,doc_file
                where opd_sched.doc_no=doc_file.doc_no 
                and opd_sched.rec_status = 'A'  and opd_sched.orgid='$_SESSION[coid]' and opd_sched.orgid=doc_file.orgid 
                and to_date(OPD_DATE, 'yyyymmdd')=to_date('".$_POST[opd_date]."','dd/mm/yyyy')  
                and dept_no1='$deptno' 
                and opd_sched.time_shift = '".$_POST["time_shift"]."'";
    $stmt = ociparse(connected_resource(), $sql);
    ociexecute($stmt,OCI_DEFAULT);
    $doctor_nrows = OCIFetchStatement($stmt,$doctor_rows);
    OCIFreeStatement($stmt);
    $json = "[";
    if($doctor_nrows !=0){
        for($i = 0;$i < $doctor_nrows;$i++){
            $json .= "{no:\"{$doctor_rows['DOC_NO'][$i]}\",name:\"{$doctor_rows['DOC_NAME'][$i]}\"},";
        }
        $json = substr($json,0,strlen($json)-1);    
    }
   $json .= "]";
   print $json;

}
//根据获取诊室列表
function getRoom($docno)
{    
    
    $v_date=date("ymd");
    $query ="SELECT ROOM_NO,
    (SELECT DESC_1 FROM CODE_DTL T WHERE T.ITEM_CODE=ROOM_NO AND T.ITEM_TYPE='0114' and orgid='$_SESSION[coid]' ) ROOM_NAME 
    FROM OPD_SCHED 
    WHERE opd_sched.rec_status = 'A'  and opd_sched.orgid='$_SESSION[coid]' 
     and to_date(OPD_DATE, 'yyyymmdd')=to_date('".$_POST[opd_date]."','dd/mm/yyyy')  
     AND DEPT_NO1='$_POST[dept_no]' and doc_no='$docno'
     and opd_sched.time_shift = '".$_POST["time_shift"]."'"; 
    
    $stmt = ociparse(connected_resource(), $query);
    ociexecute($stmt,OCI_DEFAULT);
    $room_nrows = OCIFetchStatement($stmt,$room_rows);
    OCIFreeStatement($stmt);
    
    $json = "[";
 
        for($i = 0;$i < $room_nrows;$i++){
            $json .= "{no:\"{$room_rows['ROOM_NO'][$i]}\",name:\"{$room_rows['ROOM_NAME'][$i]}\"},";
        }
        $json = substr($json,0,strlen($json)-1);    
 
   $json .= "]";
   print $json;
    }

acquire_resource();
?>
版权声明:程序员胖胖胖虎阿 发表于 2022年11月21日 上午7:24。
转载请注明:【Vegas原创】PHP+jquery实现select的三级联动 | 胖虎的工具箱-编程导航

相关文章

暂无评论

暂无评论...