yysj.js 7.92 KB
$(function () {
var Date = undefined;
var appuintText = undefined;
var bustime = undefined;

// 国有房屋无业点击选中记录
var busIndex = undefined;
// 机构id
var jgid = undefined;
  getAppointmentDay();
  layui.use("element", function () {
    let element = layui.element; //导航的hover效果、二级菜单等功能,需要依赖element模块
    //监听导航点击
    element.on("nav(demo)", function (elem) {
      layer.msg(elem.text());
    });
  });

  function a(i) {
    Date = data.dateList[i].jyjh;
    bookingDate = data.dateList[i].bookingDate;
    bustime = data.dateList[i].week;
    getAppointmentPeriodAndBusiness()
    $(".swiper-slide")
      .eq(i)
      .addClass("active1")
      .siblings()
      .removeClass("active1");
  }
  var swiper = new Swiper(".swiper-container", {
    slidesPerView: 5,
    spaceBetween: 20,
    slidesPerGroup: 1,
    observer: true,
    observeParents: true,
    on: {
      click: function (swiper) {
        var index = swiper["clickedIndex"];
        a(index);
      },
    },
    loopFillGroupWithBlank: true,
    navigation: {
      nextEl: ".swiper-button-next",
      prevEl: ".swiper-button-prev",
    },
  });
  function handle() {
    layui.use("layer", function () {
      layer.open({
        type: 1,
        title: "请确认以下信息",
        shadeClose: false,
        area: ["500px", "320px"],
        scrollbar: false,
        skin: "confimInfo",
        content:
        '<div class="infoContent">' +
        "<ul>" +
        "<li><span>姓名</span>:" + getCookie().username +"</li>" +
        "<li><span>身份证号</span>:"+getCookie().zjhm+"</li>" +
        "<li><span>联系电话</span>:"+getCookie().phone +"</li>" +
        "</ul>" +
        '<div class="listItem"><h3>大厅名称:</h3>' +
        hallname +
        "</div>" +
        '<div class="listItem"><h3>预约业务:</h3>' +
        appuintText +
        "</div>" +
        '<div class="listItem"><h3>预约时间:</h3>' +
        Date +
        "&nbsp;&nbsp;" +
        bustime +
        "</div>" +
        '<div class="confimButton"><button type="button" class="layui-btn cancel layui-btn-primary">取消</button><button type="button" class="layui-btn confim layui-btn-normal">确定</button></div>' +
        "</div>",
      });
    });
  }
  function detailHandle(){
    layui.use("layer", function () {
      layer.open({
        type: 1,
        title: "请确认以下信息",
        shadeClose: false,
        area: ["500px", "320px"],
        scrollbar: false,
        skin: "confimInfo",
        content:'123',
      });
    });
  }
  // 业务选择
  $(document).on("click", ".business_item ul .item_appoint ", function (e) {
    console.log(5555)
    jgid = GetRequest();
    appuintText = $(this).find("h3").text();
    periodRulesId = $(this).data('id')
    console.log('aaa',periodRulesId)
    checkAppointment()
    handle();
  });
  $(document).on("click", ".cancel", function () {
    layer.closeAll();
  });
  $(document).on("click", ".confim", function () {
      if(flag){
        var paramsobj = {}
        paramsobj.jgid = GetRequest()
        paramsobj.periodRulesId = periodRulesId
        paramsobj.userid = getCookie().userid
        makeAppointment(paramsobj)
      }
  });
});
function GetRequest() {
  var url = location.search; //获取url中"?"符后的字串
  var theRequest = new Object();
  if (url.indexOf("?") != -1) {
    var str = url.substr(1);
    strs = str.split("?");
    for (var i = 0; i < strs.length; i++) {
      theRequest[strs[i].split("=")[0]] = decodeURIComponent(
        strs[i].split("=")[1]
      );
    }
  }
  return theRequest.jgid;
}
function getAppointmentDay() {
  $.ajax({
    type: "get", //提交方式
    url: portal.api_url + "/portal/appointmentmh/getAppointmentDay", //路径
    data: {
      jgid: GetRequest(),
    },
    dataType: "json",
    success: function (result) {
      //返回数据根据结果进行相应的处理
      if (result.code == 200 && result.data != null) {
        data.dateList = result.data.listTime;
        layui.use("laytpl", function () {
          laytpl = layui.laytpl;
          var getTpl = document.getElementById("date").innerHTML,
            view = document.getElementById("swiperDate");
          laytpl(getTpl).render(data, function (html) {
            view.innerHTML = html;
          });
        });
      }
    },
  });
}
// 根据办事大厅机构ID、日期、用户ID,查询可预约的业务 GET
function getAppointmentPeriodAndBusiness() {
  $.ajax({
    type: "get", //提交方式
    url:
      portal.api_url + "/portal/appointmentmh/getAppointmentPeriodAndBusiness", //
    data: {
      jgid: GetRequest(),
      userid: getCookie().userid,
      bookingDate: bookingDate,
    },
    dataType: "json",
    //数据,这里使用的是Json格式进行传输
    success: function (result) {
      //返回数据根据结果进行相应的处理
      if (result.code == 200 && result.data != null) {
        console.log(result.data)
        data.busList = result.data.appointmentPeriodBusinessList
        // console.log(2222,data.busList)
        // if(result.data.choosePeriodRulesId!==null){
        //   if(2){
        //     // for循环找到对应的id 打开,其余都设置为禁用
        //   }
        // }else if(result.data.choosePeriodRulesId ==null){
        //   // step 1: 如果等于0
        //   for(var i =0;i<result.data.appointmentPeriodBusinessList.length;i++){
        //     for(var j=0;j<result.data.appointmentPeriodBusinessList[i].orgBusinessList.length; j++){
        //       if(result.data.appointmentPeriodBusinessList[i].orgBusinessList[j].residueNumber ==0){
        //         result.data.appointmentPeriodBusinessList[i].orgBusinessList[j].disabled = true
        //       }
        //     }
        //   }
        //   data.busList = result.data.appointmentPeriodBusinessList
        //   console.log(11111, data.busList)
        // }
        if(data.busList.length >0){
          data.busList.forEach((item,index)=>{
            hallname = item.orgBusinessList[0].jgName
          })
        }
        layui.use("laytpl", function () {
          laytpl = layui.laytpl;
          var getTpl1 = document.getElementById("business_item").innerHTML,
            view1 = document.getElementById("business_list");
          laytpl(getTpl1).render(data, function (html) {
            view1.innerHTML = html;
          });
        });
      }
    },
  });
}
// 根据办事大厅机构ID、用户ID检查用户是否可预约抢号
function checkAppointment(){
  $.ajax({
    type: "get", //提交方式
    async:false,
    url:
      portal.api_url + "/portal/appointmentmh/checkAppointment",
    data: {
      jgid: GetRequest(),
      userid: getCookie().userid,
    },
    dataType: "json",
    //数据,这里使用的是Json格式进行传输
    success: function (result) {
      //返回数据根据结果进行相应的处理
      if (result.code == 200) {
        return  flag = result.data
      }else if(result.code ==210){
        return layer.msg( result.message)
      }
    },
  });
}
// 用户预约抢号  POST 
function makeAppointment(data){
  $.ajax({
    type: "post",  //提交方式  
    async:false,
    url: portal.api_url + "/portal/appointmentmh/makeAppointment",//路径  
    headers:{//***关键******
      'Content-Type': 'application/json;charset=UTF-8',
    },
    dataType: "json",
    data:JSON.stringify(data),//***关键******
    success: function (result) {//返回数据根据结果进行相应的处理
       if(result.code ==200 && result.data!==null){
          appointmentId = result.data
          window.location.href = "./yyjg.html?appointmentId="+ appointmentId
       } 
    }
  });
}

var bookingDate = undefined;
var flag = undefined;
var msg = undefined;
var hallname = undefined;
var periodRulesId = undefined
var appointmentId = undefined
var periodRulesId = undefined
var data = {
  dateList: [],
  busList: [
    {
      startTime: "",
      endTime: "",
      orgBusinessList: [],
    },
  ],
};