yysj.js 10.8 KB
var bustime = undefined;
$(function () {
  var Date = undefined;
  var appuintText = 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",
    },
  });
  $(document).on("click", ".cancel", function () {
    layer.closeAll();
  });
  $(document).on("click", ".confim", function () {
    var paramsobj = {}
    paramsobj.jgid = GetQueryString("jgid");
    paramsobj.periodRulesId = periodRulesId
    paramsobj.userid = getCookie().userid
    makeAppointment(paramsobj)
  });
});
$(document).on('click','#canlebutton',function(){
  console.log(2323)
  var obj = {}
  obj.appointmentId = cancleId,
  obj.userid = getCookie().userid
  obj.jgid = GetQueryString("jgid"),
  obj.periodRulesId = choosePeriodRulesId,
  cancleAppointment(obj)
})
//获取当前页面预约日期
function getAppointmentDay() {
  $.ajax({
    type: "get", //提交方式
    url: portal.api_url + "/portal/appointmentmh/getAppointmentDay", //路径
    data: {
      jgid: GetQueryString("jgid"),
    },
    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: GetQueryString("jgid"),
      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;
        choosePeriodRulesId = result.data.choosePeriodRulesId     
        cancleId = result.data.appointmentId     
        RenderBusinessList(result.data);
        if (data.busList.length > 0) {
          data.busList.forEach((item, index) => {
            hallname = item.orgBusinessList[0].jgName
          })
        }
      }
    },
  });
}
var bookingDate = undefined;
var flag = undefined;
var msg = undefined;
var hallname = undefined;
var periodRulesId = undefined
var choosePeriodRulesId = undefined
var appointmentId = undefined
var cancleId = undefined
var data = {
  dateList: [],
  busList: [
    {
      startTime: "",
      endTime: "",
      orgBusinessList: [],
    },
  ],
};

//渲染业务信息列表
function RenderBusinessList(data) {
  //获取业务列表DIV容器ID
  let businessDiv = $("#business_list");
  //是否存在预约记录(默认为否)
  let existRecord = false;
  if (data.choosePeriodRulesId != null && data.choosePeriodRulesId != "") {
    existRecord = true;
  }
  let businessContent = "";
  $.each(data.appointmentPeriodBusinessList, function (index, item) {
    businessContent += '<div class="business_item">';
    businessContent += '<div class="item_time"><span>上午</span> <span>' + item.startTime + '</span><span>-</span><span>' + item.endTime + '</span></div>';
    businessContent += '<ul>';
    $.each(item.orgBusinessList, function (childIndex, childItem) {
      //存在预约记录
      if (existRecord) {
        if (data.choosePeriodRulesId == childItem.periodRulesId) {
          businessContent += '<li class="isAppoint" style="border: 1px solid red ;" data-id="' + childItem.periodRulesId + '">';
          businessContent += '<h3>' + childItem.shortName + '</h3>';
          businessContent += '<input type="button" value="查看详情" id="' + data.appointmentId + '" dataName="' + childItem.shortName + '"  onclick="getAppointmentDetail(this.id)"/>';
        }
        else {
          businessContent += '<li class="isAppoint">';
          businessContent += '<h3>' + childItem.shortName + '</h3>';
        }
        businessContent += '<p style="color:#5FB878">(剩' + childItem.residueNumber + '票)</p></li>';
      } else {
        businessContent += '<li class="isAppoint" data-id="' + childItem.periodRulesId + '">';
        businessContent += '<h3>' + childItem.shortName + '</h3>';
        if (childItem.residueNumber > 0) {
          businessContent += '<input type="button" value="立即预约" id="' + childItem.periodRulesId + '" dataName="' + childItem.shortName + '"  onclick="handle(this.id)"/>';
        }
        businessContent += '<p style="color:#5FB878">(剩' + childItem.residueNumber + '票)</p></li>';
      }

    });
    businessContent += '</ul>';
    businessContent += '</div>';

  });
  businessDiv.html(businessContent);
}

// 根据办事大厅机构ID、用户ID检查用户是否存在预约限制
function checkAppointment() {
  let msg;
  $.ajax({
    type: "get", //提交方式
    async: false,
    url:
      portal.api_url + "/portal/appointmentmh/checkAppointment",
    data: {
      jgid: GetQueryString("jgid"),
      userid: getCookie().userid,
    },
    dataType: "json",
    //数据,这里使用的是Json格式进行传输
    success: function (result) {
      //返回数据根据结果进行相应的处理
      if (result.code == 210) {
        msg = result.message;
      }
    },
  });
  return msg;
}

function handle(id) {
  periodRulesId = id
  let msg = checkAppointment();
  if (msg != undefined) {
    //layer.msg('hello'); 
    return;
  };
  var input = $("#" + id);
  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>' +
        input.attr("dataName") +
        "</div>" +
        '<div class="listItem"><h3>预约时间:</h3>' +
        yysj +
        "&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>",
    });
  });
}

// 用户预约抢号  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
      }
    }
  });
}
// 用户取消预约
function cancleAppointment(data) {
  $.ajax({
    type: "post",  //提交方式  
    url: portal.api_url + "/portal/appointmentmh/cancleAppointment",//路径  
    headers: {//***关键******
      'Content-Type': 'application/json;charset=UTF-8',
    },
    dataType: "json",
    data: JSON.stringify(data),//***关键******
    success: function (result) {//返回数据根据结果进行相应的处理
      if (result.code == 200 && result.data !== null) {
        console.log('取消预约成功')
        // a(i)
        // appointmentId = result.data
        // window.location.href = "./yyjg.html?appointmentId=" + appointmentId
      }
    }
  });
}
// GET 根据预约信息标识码appointmentId查看预约详情
function getAppointmentDetail(id){
  $.ajax({
    type: "get", //提交方式
    url:
      portal.api_url + "/portal/appointmentmh/getAppointmentDetail",
    data: {
      appointmentId: id,
    },
    dataType: "json",
    //数据,这里使用的是Json格式进行传输
    success: function (result) {
      //返回数据根据结果进行相应的处理
      if (result.code == 200) {
        appointmentDetail(result.data);
      } 
      else{
        alert(result.message);
      }
    },
  });
}


//预约详情
function appointmentDetail(data) {
  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>:" + data.username + "</li>" +
        "<li><span>身份证号</span>:" + data.zjhm + "</li>" +
        "<li><span>联系电话</span>:" + data.phone + "</li>" +
        "</ul>" +
        '<div class="listItem"><h3>预约编号:</h3>' +
        data.reservationNumber +
        "</div>" +
        '<div class="listItem"><h3>预约业务:</h3>' +
        data.hbShortname  +
        "</div>" +
        '<div class="listItem"><h3>预约时间:</h3>' +
        data.bookingDate.substr(0,4) + '年'+data.bookingDate.substr(4,2) + '月' + data.bookingDate.substr(6,2) + '日'+data.startTime + '至'+data.endTime +
        "</div>" +
        '<div class="confimButton"><button type="button" class="layui-btn cancel layui-btn-primary" id="canlebutton">取消预约</button></div>' +
        "</div>",
    });
  });
}