123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535 |
- mui.ready(function() {
-
- var oconsultTitle = document.getElementById("consultTitle");
- var ochatName = document.getElementById("chatName");
-
- var oconfirmBtn = document.getElementById("confirmBtn");
- var oassessBtn = document.getElementById("assessBtn");
- var oassessed = document.getElementById("assessed");
- var omy_starContainer = document.getElementById("my_starContainer");
-
- var othat_weiassess = document.getElementById("that_weiassess");
- var owaying = document.getElementById("waying");
- var othat_assessed = document.getElementById("that_assessed");
- var oconstarContainer = document.getElementById("consult_starContainer");
-
-
- var omsg_list = document.getElementById("msg-list");
- var omsg_text = document.getElementById("msg-text");
- var omsg_type = document.getElementById("msg-type");
- var ochatFooter = document.getElementById("chatFooter");
-
- function getHeadInfo(manFlag,consultId){
- var myData;
- if(manFlag == 'myNeed'){
-
- mui.ajax(baseUrl+'/ajax/consult/qacon',{
- data:{"consultId":consultId,"readStatus":"1"},
- dataType:'json',
- type:'get',
- success:function(data){
- myData = data.data;
- ochatName.innerHTML = myData["professor"]["name"];
- var consultTitle = '关于'+myData["consultTitle"]+"的咨询";
- oconsultTitle.innerHTML = consultTitle;
-
- if(myData["consultStatus"] == 0){
- oconfirmBtn.style.display = 'block';
- ochatFooter.style.display = 'block';
- }else {
- if(myData["assessStatus"] == 0){
- oassessBtn.style.display = 'block';
- }else {
- oassessed.style.display = 'block';
-
- console.log("我的需求已评价")
- var starCount = myData["assessStar"];
- for(var i=0;i<starCount;i++){
- if(i < starCount){
- nth(omy_starContainer,'.star',i+1)
- .removeClass('icon-favor')
- .addClass("icon-favorfill");
- }
- }
-
- }
- }
-
- },
- error:function(xhr,type,errorThrown){
-
- }
- });
-
- }else if(manFlag == 'consult'){
- mui.ajax(baseUrl+'/ajax/consult/qapro',{
- data:{"consultId":consultId,"readStatus":"1"},
- dataType:'json',
- type:'get',
- success:function(data){
- myData = data.data;
- ochatName.innerHTML = myData["professor"]["name"];
- var consultTitle = '回复:关于'+myData["consultTitle"]+"的咨询";
- oconsultTitle.innerHTML = consultTitle;
-
- if(myData["consultStatus"] == 0){
- owaying.style.display = 'block';
- ochatFooter.style.display = 'block';
- }else {
- if(myData["assessStatus"] == 0){
- othat_weiassess.style.display = 'block';
- }else{
- othat_assessed.style.display = 'block';
-
- var starItem = [];
- var starCount = myData["assessStar"];
- for(var i = 0;i < starCount;i++){
- if(i < starCount){
-
- starItem[i].setAttribute('class','icon-favorfill');
- oconstarContainer.childNodes[i].className = 'icon-favorfill';
- oconstarContainer.childNodes[i].removeClassName = 'mui-icon iconfont icon-favor star';
- console.log(oconstarContainer.childNodes[i].className)*/
-
-
- }
- }
- }
- }
-
- },
- error:function(xhr,type,errorThrown){
-
- }
- });
-
- };
- };
-
-
- function saveChatFun(consultId,userid){
- var tidingsContant = omsg_text.innerHTML
- console.log(tidingsContant);
- mui.ajax(baseUrl +'/ajax/tidings',{
- data:{
- "consultId":consultId,
- "sendId":userid,
- "tidingsContant":tidingsContant
- },
- dataType:'json',
- type:'post',
- success:function(data){
- console.log(data);
- },
- error:function(xhr,type,errorThrown){
-
- }
- });
- }
-
-
-
- var MIN_SOUND_TIME = 800;
- mui.init({
- gestureConfig: {
- tap: true,
- doubletap: true,
- longtap: true,
- swipe: true,
- drag: true,
- hold: true,
- release: true
- }
- });
- template.config('escape', false);
-
- mui.plusReady(function() {
-
- var userid = plus.storage.getItem('userid');
- var self = plus.webview.currentWebview();
- var consultId = self.consultId;
- var consultantId = self.consultantId;
- console.log(consultId);
- console.log('userid'+userid);
- console.log('consultantId'+consultantId);
- if(userid == consultantId){
-
- var manFlag = 'myNeed';
- getHeadInfo(manFlag,consultId);
- }else {
-
- var manFlag = 'consult';
- getHeadInfo(manFlag,consultId);
- }
-
-
- plus.webview.currentWebview().setStyle({
- softinputMode: "adjustResize"
- });
- var showKeyboard = function() {
- if (mui.os.ios) {
- var webView = plus.webview.currentWebview().nativeInstanceObject();
- webView.plusCallMethod({
- "setKeyboardDisplayRequiresUserAction": false
- });
- } else {
- var Context = plus.android.importClass("android.content.Context");
- var InputMethodManager = plus.android.importClass("android.view.inputmethod.InputMethodManager");
- var main = plus.android.runtimeMainActivity();
- var imm = main.getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
-
- imm.showSoftInput(main.getWindow().getDecorView(), InputMethodManager.SHOW_IMPLICIT);
-
- }
- };
-
- var record = [{
- sender: 'zs',
- type: 'text',
- content: 'Hi,我是 科袖 小管家!'
- }];
-
- mui.ajax(baseUrl+'/ajax/tidings/qacon',{
- data:{
- "consultId":consultId
- },
- dataType:'json',
- type:'get',
- success:function(data){
- var myData = data.data;
- for(var i = 0; i < myData.length; i++ ){
- if(data.data[i]['professor']['id'] == userid){
- record.push({
- sender: 'self',
- type: 'text',
- content: data.data[i]["tidingsContant"]
- });
- }else{
- record.push({
- sender: 'zs',
- type: 'text',
- content: data.data[i]["tidingsContant"]
- });
- }
- }
- bindMsgList();
- },
- error:function(xhr,type,errorThrown){
-
- }
- });
-
-
-
- var ui = {
- body: document.querySelector('body'),
- footer: document.querySelector('footer'),
- footerRight: document.querySelector('.footer-right'),
- footerLeft: document.querySelector('.footer-left'),
- btnMsgType: document.querySelector('#msg-type'),
- boxMsgText: document.querySelector('#msg-text'),
- boxMsgSound: document.querySelector('#msg-sound'),
- btnMsgImage: document.querySelector('#msg-image'),
- areaMsgList: document.querySelector('#msg-list'),
- boxSoundAlert: document.querySelector('#sound-alert'),
- h: document.querySelector('#h'),
- content: document.querySelector('.mui-content')
- };
- ui.h.style.width = ui.boxMsgText.offsetWidth+'px';
-
- var footerPadding = ui.footer.offsetHeight - ui.boxMsgText.offsetHeight;
- var msgItemTap = function(msgItem, event) {
- var msgType = msgItem.getAttribute('msg-type');
- var msgContent = msgItem.getAttribute('msg-content')
- if (msgType == 'sound') {
- player = plus.audio.createPlayer(msgContent);
- var playState = msgItem.querySelector('.play-state');
- playState.innerText = '正在播放...';
- player.play(function() {
- playState.innerText = '点击播放';
- }, function(e) {
- playState.innerText = '点击播放';
- });
- }
- };
- var imageViewer = new mui.ImageViewer('.msg-content-image', {
- dbl: false
- });
- var bindMsgList = function() {
-
-
- template: 'msg-template',
- element: 'msg-list',
- model: record
- });*/
- ui.areaMsgList.innerHTML = template('msg-template', {
- "record": record
- });
- var msgItems = ui.areaMsgList.querySelectorAll('.msg-item');
- [].forEach.call(msgItems, function(item, index) {
- item.addEventListener('tap', function(event) {
- msgItemTap(item, event);
- }, false);
- });
- imageViewer.findAllImage();
- ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
- };
- bindMsgList();
- window.addEventListener('resize', function() {
- ui.areaMsgList.scrollTop = ui.areaMsgList.scrollHeight + ui.areaMsgList.offsetHeight;
- }, false);
- var send = function(msg) {
- record.push(msg);
- bindMsgList();
- toRobot(msg.content);
- };
- var toRobot = function(info) {
- var apiUrl = baseUrl+"/ajax/tidings";
-
- mui.ajax(apiUrl,{
- data:{
- "tidingsContant":ui.boxMsgText.value,
- "senderId":userid,
- "consultId":consultId
- },
- dataType:'json',
- type:'post',
- success:function(data){
- console.log('消息成功'+data.data);
-
- },
- error:function(xhr,type,errorThrown){
-
- }
- });
-
- };
- function msgTextFocus() {
- ui.boxMsgText.focus();
- setTimeout(function() {
- ui.boxMsgText.focus();
- }, 150);
- }
-
- ui.footerRight.addEventListener('touchstart', function(event) {
- if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
- msgTextFocus();
- event.preventDefault();
- }
- });
-
- ui.footerRight.addEventListener('touchmove', function(event) {
- if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
- msgTextFocus();
- event.preventDefault();
- }
- });
-
-
-
-
-
-
-
-
-
-
-
-
- ui.footerRight.addEventListener('release', function(event) {
- if (ui.btnMsgType.classList.contains('mui-icon-paperplane')) {
-
- ui.boxMsgText.focus();
- setTimeout(function() {
- ui.boxMsgText.focus();
- }, 150);
-
- send({
- sender: 'self',
- type: 'text',
- content: ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '<br/>')
- });
- ui.boxMsgText.value = '';
- mui.trigger(ui.boxMsgText, 'input', null);
- } else if (ui.btnMsgType.classList.contains('mui-icon-mic')) {
- ui.btnMsgType.classList.add('mui-icon-compose');
- ui.btnMsgType.classList.remove('mui-icon-mic');
- ui.boxMsgText.style.display = 'none';
- ui.boxMsgSound.style.display = 'block';
- ui.boxMsgText.blur();
- document.body.focus();
- } else if (ui.btnMsgType.classList.contains('mui-icon-compose')) {
- ui.btnMsgType.classList.add('mui-icon-mic');
- ui.btnMsgType.classList.remove('mui-icon-compose');
- ui.boxMsgSound.style.display = 'none';
- ui.boxMsgText.style.display = 'block';
-
-
- ui.boxMsgText.focus();
- setTimeout(function() {
- ui.boxMsgText.focus();
- }, 150);
- }
- }, false);
- ui.footerLeft.addEventListener('tap', function(event) {
- var btnArray = [{
- title: "拍照"
- }, {
- title: "从相册选择"
- }];
- plus.nativeUI.actionSheet({
- title: "选择照片",
- cancel: "取消",
- buttons: btnArray
- }, function(e) {
- var index = e.index;
- switch (index) {
- case 0:
- break;
- case 1:
- var cmr = plus.camera.getCamera();
- cmr.captureImage(function(path) {
- send({
- sender: 'self',
- type: 'image',
- content: "file://" + plus.io.convertLocalFileSystemURL(path)
- });
- }, function(err) {});
- break;
- case 2:
- plus.gallery.pick(function(path) {
- send({
- sender: 'self',
- type: 'image',
- content: path
- });
- }, function(err) {}, null);
- break;
- }
- });
- }, false);
- var setSoundAlertVisable=function(show){
- if(show){
- ui.boxSoundAlert.style.display = 'block';
- ui.boxSoundAlert.style.opacity = 1;
- }else{
- ui.boxSoundAlert.style.opacity = 0;
-
- setTimeout(function(){
- ui.boxSoundAlert.style.display = 'none';
- },200);
- }
- };
- var recordCancel = false;
- var recorder = null;
- var audio_tips = document.getElementById("audio_tips");
- var startTimestamp = null;
- var stopTimestamp = null;
- var stopTimer = null;
- ui.boxMsgSound.addEventListener('hold', function(event) {
- recordCancel = false;
- if(stopTimer)clearTimeout(stopTimer);
- audio_tips.innerHTML = "手指上划,取消发送";
- ui.boxSoundAlert.classList.remove('rprogress-sigh');
- setSoundAlertVisable(true);
- recorder = plus.audio.getRecorder();
- if (recorder == null) {
- plus.nativeUI.toast("不能获取录音对象");
- return;
- }
- startTimestamp = (new Date()).getTime();
- recorder.record({
- filename: "_doc/audio/"
- }, function(path) {
- if (recordCancel) return;
- send({
- sender: 'self',
- type: 'sound',
- content: path
- });
- }, function(e) {
- plus.nativeUI.toast("录音时出现异常: " + e.message);
- });
- }, false);
- ui.body.addEventListener('drag', function(event) {
-
- if (Math.abs(event.detail.deltaY) > 50) {
- if (!recordCancel) {
- recordCancel = true;
- if (!audio_tips.classList.contains("cancel")) {
- audio_tips.classList.add("cancel");
- }
- audio_tips.innerHTML = "松开手指,取消发送";
- }
- } else {
- if (recordCancel) {
- recordCancel = false;
- if (audio_tips.classList.contains("cancel")) {
- audio_tips.classList.remove("cancel");
- }
- audio_tips.innerHTML = "手指上划,取消发送";
- }
- }
- }, false);
- ui.boxMsgSound.addEventListener('release', function(event) {
-
- if (audio_tips.classList.contains("cancel")) {
- audio_tips.classList.remove("cancel");
- audio_tips.innerHTML = "手指上划,取消发送";
- }
-
- stopTimestamp = (new Date()).getTime();
- if (stopTimestamp - startTimestamp < MIN_SOUND_TIME) {
- audio_tips.innerHTML = "录音时间太短";
- ui.boxSoundAlert.classList.add('rprogress-sigh');
- recordCancel = true;
- stopTimer=setTimeout(function(){
- setSoundAlertVisable(false);
- },800);
- }else{
- setSoundAlertVisable(false);
- }
- recorder.stop();
- }, false);
- ui.boxMsgSound.addEventListener("touchstart", function(e) {
-
- e.preventDefault();
- });
- ui.boxMsgText.addEventListener('input', function(event) {
- ui.btnMsgType.classList[ui.boxMsgText.value == '' ? 'remove' : 'add']('mui-icon-paperplane');
- ui.btnMsgType.setAttribute("for", ui.boxMsgText.value == '' ? '' : 'msg-text');
- ui.h.innerText = ui.boxMsgText.value.replace(new RegExp('\n', 'gm'), '\n-') || '-';
- ui.footer.style.height = (ui.h.offsetHeight + footerPadding) + 'px';
- ui.content.style.paddingBottom = ui.footer.style.height;
-
- });
- ui.boxMsgText.addEventListener('tap', function(event) {
- ui.boxMsgText.focus();
- setTimeout(function() {
- ui.boxMsgText.focus();
- }, 0);
- }, false);
- });
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- })
|