123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346 |
- $(function(){
- //填充下拉框
- querySignType();
- /* 复选框兼容 */
- $(document).on("click", ".input-group-pack > input[type=checkbox]", function() {
- var $cpChk = $(this).parent();
- if ($(this).attr("checked") == "checked") {
- $cpChk.removeClass("checked");
- $(this).removeAttr("checked");
- } else {
- $cpChk.addClass("checked");
- $(this).attr("checked", true);
- }
- });
- //弹窗
- $('.broadcast-icon').on('click',function(){
- $('.broadcast-shadow-panel').removeClass('c-hide');
- });
- $('.win-cancle').on('click',function(){
- $('.broadcast-shadow-panel').addClass('c-hide');
- });
-
- //从后台那边获取签名等信息
- var params = {};
- params.pageUrl = server + "wx/html/zxwz/html/teachers-consult-commit.html";
- $.ajax(server + "weixin/getSign", {
- data: params,
- dataType: "json",
- type: "post",
- success: function(res){
- if (res.status == 200) {
- var t = res.data.timestamp;
- var noncestr = res.data.noncestr;
- var signature = res.data.signature;
- wx.config({
- // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
- appId: appId, // 必填,公众号的唯一标识
- timestamp: t, // 必填,生成签名的时间戳
- nonceStr: noncestr, // 必填,生成签名的随机串
- signature: signature,// 必填,签名,见附录1
- jsApiList: [
- 'chooseImage',
- 'uploadImage'
- ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
- });
- }
- else{
- dialog({
- title:'提示',
- skin:"ui-dialog ax-popup pror",
- content:"获取微信签名失败",
- ok: function (){}
- }).showModal();
- window.location.href = "online-consulting.html";
- }
- }
- });
- //提交咨询
- $("#commit").click(function() {
- var data = {};
- data.when = $("#txtWhen").val();
- data.type = Number($("#txtTypeCode").val());
- if($("#txtContent").val() == null)
- data.symptoms = "";
- else
- data.symptoms = utf16toEntities($("#txtContent").val().replace(/\s+/g,""));
- data.voice = "";
- if (validate(data)) {
- //验证通过执行
- dd.showModal();
- var images = getImages();
- if(images.length == 0){
- doSubmit(data);
- }
- else{
- uploadImage(data);
- }
- }
- });
- });
- //查询签约类别
- function querySignType(){
- d.show();
- sendPost('patient/sign_status', {}, 'json', 'post', querySignTypeFailed, querySignTypeSuccess);
- }
- function querySignTypeFailed(res) {
- d.close();
- if (res && res.msg) {
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:'获取签约类别失败'}).show();
- }
- }
- function querySignTypeSuccess(res) {
- if (res.status == 200) {
- var arr_key=[];
- var arr_value=[];
- var sign = Number(res.data);
- if(sign == 1){
- arr_key=[1];
- arr_value=['三师团队'];
- }
- else if(sign == 2){
- arr_key=[2];
- arr_value=['家庭医生'];
- }
- else if(sign == 3){
- arr_key=[1,2];
- arr_value=['三师团队', '家庭医生'];
- }
- else{
- arr_key=[];
- arr_value=[];
- }
- //签约类型
- var option1 = {
- theme: 'ios',
- lang: 'zh',
- formatValue: function(d) {
- return d.join(',');
- },
- customWheels: true,
- wheels: [
- [{
- keys: arr_key,
- values: arr_value
- }]
- ],
- onSelect: function(valueText, inst) {
- var dd = eval("[" + valueText + "]");
- $('#txtTypeCode').val(dd[0].keys);
- $('#txtTypeName').val(dd[0].values);
- $('#lbl_doctor').html(getSignDoctor(res,dd[0].keys));
- }
- };
- $('#txtTypeName').mobiscroll(option1);
- $('#txtTypeCode').val(option1.wheels[0][0].keys[0]);
- $('#txtTypeName').val(option1.wheels[0][0].values[0]);
- $('#lbl_doctor').html(getSignDoctor(res,option1.wheels[0][0].keys[0]));
- //选择发病时间
- $('li.ill-time').mobiscroll({
- theme: 'ios',
- lang: 'zh',
- formatValue: function(d) {
- return d.join(',');
- },
- customWheels: true,
- wheels: [
- [{
- keys: ['0', '1', '2', '3', '4', '5'],
- values: ['最近24小时', '最近一周', '最近三个月', '最近一年', '一年以上', '不清楚']
- }]
- ],
- onSelect: function(valueText, inst) {
- var dd = eval("[" + valueText + "]");
- $('input[data-time=illTime]').val(dd[0].values);
- }
- });
- d.close();
- } else {
- querySignTypeFailed(res);
- }
- }
- //获取医生信息
- function getSignDoctor(data,type){
- var doctor_name = "";
- var doctor_type = "";
- switch(Number(type))
- {
- case 1:
- doctor_type = data.teamDoctors;
- break;
- case 2:
- doctor_type = data.familyDoctors;
- break;
- default:
- break;
- }
- for(var i=0; i < doctor_type.length; i++){
- doctor_name += doctor_type[i] + ",";
- }
- if(doctor_name.length > 0){
- doctor_name = doctor_name.substring(0, doctor_name.length-1);
- }
- return doctor_name;
- }
- //验证信息
- function validate(data) {
- if (data.type == '') {
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请选择签约类别'}).show();
- return false;
- }
- if (data.when == '') {
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请选择发病时间'}).show();
- return false;
- }
- if (data.symptoms.length < 10) {
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请至少用10个字描述您的症状'}).show();
- return false;
- }
- if (data.symptoms.length > 500) {
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请在500字以内完成您的症状描述'}).show();
- return false;
- }
- if(!$(".input-group-pack > input[type=checkbox]").attr("checked")){
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:'请勾选"我已阅读咨询说明"'}).show();
- return false;
- }
- return true;
- }
- var serverId = "";
- function chooseImage(){
- wx.chooseImage({
- count: 9-getImages().length,
- success: function (res) {
- for (var i in res.localIds) {
- appendFile(res.localIds[i]);
- }
- }
- });
- }
- function uploadImage(data){
- var images = getImages();
- if (images.length == 0) {
- return;
- }
- var i = 0, length = images.length;
- serverId = "";
- function upload() {
- wx.uploadImage({
- localId: images[i],
- isShowProgressTips: 0,
- success: function (res) {
- i++;
- if(serverId.length == 0){
- serverId = res.serverId;
- }
- else{
- serverId =serverId + "," + res.serverId;
- }
- if (i < length) {
- upload();
- }
- if(i == images.length){
- doSubmit(data);
- }
- },
- fail: function (res) {
- alert(JSON.stringify(res));
- }
- });
- }
- upload();
- }
- // 添加文件
- function appendFile(p) {
- var amount = getImages().length;
- if (amount >= 8) {
- $("#add_img_li").hide();
- }
- if(amount < 9){
- var $li = $('<li>' + ' <img src="' + p + '" data-src="' + p + '" onclick="viewImg(this)">' + ' <a href="javascript:;" class="del-img" onclick="delImg(this)"><i class="iconfont icon-laji"></i></a>' + '</li>');
- var $add_img_li = $("#add_img_li");
- $add_img_li.before($li);
- $("#image_tips").text(getImages().length + "/9");
- }
- }
- //获取需要上传的图片
- function getImages() {
- var images = [];
- $("#img_ul").find("img").each(function() {
- var imgSrc = $(this).attr("data-src");
- images.push(imgSrc);
- });
- return images;
- }
- //查看图片
- function viewImg(dom) {
- var $img = $(dom);
- var thissrc = $img.attr("data-src");
- var mWid = $(window).width();
- var mHei = $(window).height();
- var nHtml = '<div class="delimgpop"><div class="del-img-box"><div class="del-img-con"><img class="del-pop-img" src="' + thissrc + '" style="max-width:' + mWid + 'px; max-height:' + mHei + 'px;"></div></div></div>';
- $("body").append(nHtml);
- $(".delimgpop").click(function() {
- $(this).remove()
- });
- };
- //删除图片
- function delImg(dom) {
- var $li = $(dom).parent();
- $li.remove();
- $("#image_tips").text(getImages().length + "/9");
- var amount = getImages().length;
- if(amount <= 8){
- $("#add_img_li").show();
- }
- return;
- }
- //微信sdk配置出错
- wx.error(function (res) {
- alert("wx.error:" + res.errMsg);
- });
- //提交咨询
- function doSubmit(data) {
- data.mediaIds = serverId;
- sendPost('patient/consult/add', data, 'json', 'post', submitFailed, submitSuccess);
- }
- function submitFailed(res) {
- dd.close();
- if (res && res.msg) {
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:res.msg}).show();
- } else {
- dialog({contentType:'tipsbox', skin:'bk-popup' , content:'提交失败'}).show();
- }
- }
- function submitSuccess(res) {
- if (res.status == 200) {
- dd.close();
- window.location.href = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + appId + "&redirect_uri=http%3a%2f%2f" + weixinUrl + "%2f" + urlName + "%2fwx%2fhtml%2fzxwz%2fhtml%2fteachers-consulting-list.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect";
- //window.location.href = "vedio-consulting-commit-success.html?type=2";
- } else {
- submitFailed(res);
- }
- }
- //function voicePop(n) {
- // $(".win-broadcast,.win-broadcast-mb").show();
- // $("#voice-finish").click(function() {
- // $("#voice" + n).show();
- // $(".win-broadcast,.win-broadcast-mb").hide();
- // });
- //}
- //
- //function voicePopClose() {
- // $(".win-broadcast,.win-broadcast-mb").hide();
- //}
|