作者 杨育虎

转诊待答语音调试

@@ -13,6 +13,7 @@ use app\user\model\InquiryModel; @@ -13,6 +13,7 @@ use app\user\model\InquiryModel;
13 use app\user\model\TransferModel; 13 use app\user\model\TransferModel;
14 use app\user\model\UserModel; 14 use app\user\model\UserModel;
15 use cmf\controller\WeChatBaseController; 15 use cmf\controller\WeChatBaseController;
  16 +use EasyWeChat\Foundation\Application;
16 use think\Db; 17 use think\Db;
17 18
18 class ExpertController extends WeChatBaseController 19 class ExpertController extends WeChatBaseController
@@ -97,6 +98,26 @@ class ExpertController extends WeChatBaseController @@ -97,6 +98,26 @@ class ExpertController extends WeChatBaseController
97 98
98 99
99 public function inquiryDetail(){ 100 public function inquiryDetail(){
  101 + $config=config('wechat_config');
  102 + $Wechat=new Application($config);
  103 + $js = $Wechat->js;
  104 + $api[]='startRecord';
  105 + $api[]='stopRecord';
  106 + $api[]='onVoiceRecordEnd';
  107 + $api[]='playVoice';
  108 + $api[]='pauseVoice';
  109 + $api[]='stopVoice';
  110 + $api[]='onVoicePlayEnd';
  111 + $api[]='uploadVoice';
  112 + $api[]='downloadVoice';
  113 + $api[]='chooseImage';
  114 + $api[]='previewImage';
  115 + $api[]='uploadImage';
  116 + $api[]='downloadImage';
  117 + $api[]='translateVoice';
  118 + $sdk=$js->config($api, true);
  119 + $this->assign('sdk',$sdk);
  120 +
100 $id=$this->request->param('id',0,'intval'); 121 $id=$this->request->param('id',0,'intval');
101 $model=new InquiryModel(); 122 $model=new InquiryModel();
102 $info=$model->getInfo($id); 123 $info=$model->getInfo($id);
@@ -105,6 +126,26 @@ class ExpertController extends WeChatBaseController @@ -105,6 +126,26 @@ class ExpertController extends WeChatBaseController
105 } 126 }
106 127
107 public function transferDetail(){ 128 public function transferDetail(){
  129 + $config=config('wechat_config');
  130 + $Wechat=new Application($config);
  131 + $js = $Wechat->js;
  132 + $api[]='startRecord';
  133 + $api[]='stopRecord';
  134 + $api[]='onVoiceRecordEnd';
  135 + $api[]='playVoice';
  136 + $api[]='pauseVoice';
  137 + $api[]='stopVoice';
  138 + $api[]='onVoicePlayEnd';
  139 + $api[]='uploadVoice';
  140 + $api[]='downloadVoice';
  141 + $api[]='chooseImage';
  142 + $api[]='previewImage';
  143 + $api[]='uploadImage';
  144 + $api[]='downloadImage';
  145 + $api[]='translateVoice';
  146 + $sdk=$js->config($api, true);
  147 + $this->assign('sdk',$sdk);
  148 +
108 $id=$this->request->param('id',0,'intval'); 149 $id=$this->request->param('id',0,'intval');
109 $model=new TransferModel(); 150 $model=new TransferModel();
110 $info=$model->getInfo($id); 151 $info=$model->getInfo($id);
@@ -115,12 +115,14 @@ @@ -115,12 +115,14 @@
115 </div> 115 </div>
116 </div> 116 </div>
117 </div> 117 </div>
118 - <div class="tab_content_box">  
119 - <div class="tab_info title_info" id="is_have_question" data-id="1">  
120 - <text class="tab_title">若您对转诊信息不明确,请点击发起提问</text>  
121 - <text class="iconfont icon-icon02 add_problem"></text> 118 + <empty name="info.reply">
  119 + <div class="tab_content_box">
  120 + <div class="tab_info title_info" id="is_have_question" data-id="1">
  121 + <text class="tab_title">若您对转诊信息不明确,请点击发起提问</text>
  122 + <text class="iconfont icon-icon02 add_problem"></text>
  123 + </div>
122 </div> 124 </div>
123 - </div> 125 + </empty>
124 126
125 <!--提问内容部分--> 127 <!--提问内容部分-->
126 <div class="tab_content_box info_item question_yes"> 128 <div class="tab_content_box info_item question_yes">
@@ -138,7 +140,7 @@ @@ -138,7 +140,7 @@
138 <div class="voice_box voice_third"> 140 <div class="voice_box voice_third">
139 <div class="voice_item"> 141 <div class="voice_item">
140 <text class="iconfont icon-luyin voice_icon"></text> 142 <text class="iconfont icon-luyin voice_icon"></text>
141 - <text class="voice_font luyin">点击图标可播放 时长:10</text> 143 + <text class="voice_font luyin">点击图标可播放 时长:<span class="timeLength">0</span></text>
142 </div> 144 </div>
143 <div class="voice_btn_box"> 145 <div class="voice_btn_box">
144 <text class="iconfont icon-quxiao cancle_voice"></text> 146 <text class="iconfont icon-quxiao cancle_voice"></text>
@@ -162,26 +164,26 @@ @@ -162,26 +164,26 @@
162 <div class="tab_content_box info_item question_no"> 164 <div class="tab_content_box info_item question_no">
163 <div class="tab_info inquiry_content title"> 165 <div class="tab_info inquiry_content title">
164 <text>转诊意见</text> 166 <text>转诊意见</text>
165 - <text class="iconfont icon-huatong voice_btn"></text> 167 + <text class="iconfont icon-huatong voice_btn voice_btn2"></text>
166 <text class="iconfont icon-tianxie"></text> 168 <text class="iconfont icon-tianxie"></text>
167 </div> 169 </div>
168 <div class="textarea_content"> 170 <div class="textarea_content">
169 - <textarea class="area" type="text" placeholder="请输入" maxlength="1000"></textarea> 171 + <textarea class="area textarea2" type="text" placeholder="请输入" maxlength="1000"></textarea>
170 <p class="text_num num_box"><span class="text-count">0</span>/1000</p> 172 <p class="text_num num_box"><span class="text-count">0</span>/1000</p>
171 </div> 173 </div>
172 - <div class="voice_module agree_box" video-id="1">  
173 - <div class="voice_list" voiceitemid="1"> 174 + <div id="voice_module2" class="voice_module agree_box" video-id="2">
  175 + <div class="voice_list" voiceitemid="2">
174 <div class="voice_box voice_third"> 176 <div class="voice_box voice_third">
175 <div class="voice_item"> 177 <div class="voice_item">
176 <text class="iconfont icon-luyin voice_icon"></text> 178 <text class="iconfont icon-luyin voice_icon"></text>
177 - <text class="voice_font luyin">点击图标可播放 时长:10</text> 179 + <text class="voice_font luyin">点击图标可播放 时长:<span class="timeLength">0</span></text>
178 </div> 180 </div>
179 <div class="voice_btn_box"> 181 <div class="voice_btn_box">
180 <text class="iconfont icon-quxiao cancle_voice"></text> 182 <text class="iconfont icon-quxiao cancle_voice"></text>
181 <text class="iconfont icon-tianjia add_voice"></text> 183 <text class="iconfont icon-tianjia add_voice"></text>
182 </div> 184 </div>
183 </div> 185 </div>
184 - <div class="voice_box voice_first" voiceid="1"> 186 + <div class="voice_box voice_first" voiceid="2">
185 <div class="voice_item"> 187 <div class="voice_item">
186 <text class="iconfont icon-huatong mike voice_icon"></text> 188 <text class="iconfont icon-huatong mike voice_icon"></text>
187 <text class="voice_font huatong">点击图标开始语音语音最长60秒</text> 189 <text class="voice_font huatong">点击图标开始语音语音最长60秒</text>
@@ -334,9 +336,10 @@ @@ -334,9 +336,10 @@
334 <script src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script> 336 <script src="__TMPL__/public/assets/js/jquery-2.1.0.js"></script>
335 <script src="__TMPL__/public/assets/js/weui.js"></script> 337 <script src="__TMPL__/public/assets/js/weui.js"></script>
336 <script src="__TMPL__/public/assets/js/myweui.js"></script> 338 <script src="__TMPL__/public/assets/js/myweui.js"></script>
  339 +<script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
337 <!--<script src="__TMPL__/public/assets/js/referral.js"></script>--> 340 <!--<script src="__TMPL__/public/assets/js/referral.js"></script>-->
338 <script> 341 <script>
339 - 342 + wx.config({$sdk});
340 //文本框显示字数 343 //文本框显示字数
341 $(".area").on("input propertychange", function () { 344 $(".area").on("input propertychange", function () {
342 345
@@ -350,99 +353,11 @@ @@ -350,99 +353,11 @@
350 $(this).siblings(".text_num").children('.text-count').text(count); 353 $(this).siblings(".text_num").children('.text-count').text(count);
351 }); 354 });
352 355
353 - // 疾病分类下拉  
354 - $('.inquiry_type').click(function () {  
355 - weui.picker([  
356 - {label: '一类', value: 0},  
357 - {label: '二类', value: 1}  
358 - ], {  
359 - onChange: function (res) {  
360 - console.log(res)  
361 - },  
362 - onConfirm: function (res) {  
363 - $('.inquiry_value').val(res[0].label)  
364 - }  
365 - }  
366 - )  
367 - })  
368 - // 疾病分类下拉  
369 - $('.expert').click(function () {  
370 - weui.picker([  
371 - {label: '王医生', value: 0},  
372 - {label: '刘易斯', value: 1}  
373 - ], {  
374 - onChange: function (res) {  
375 - console.log(res)  
376 - },  
377 - onConfirm: function (res) {  
378 - $('.expert_value').val(res[0].label)  
379 - }  
380 - }  
381 - )  
382 - })  
383 - // 性别分类  
384 - $('.sex_type').click(function () {  
385 - weui.picker([  
386 - {label: '男', value: 0},  
387 - {label: '女', value: 1}  
388 - ], {  
389 - onChange: function (res) {  
390 - console.log(res)  
391 - },  
392 - onConfirm: function (res) {  
393 - $('.sex_value').val(res[0].label)  
394 - }  
395 - }  
396 - )  
397 - })  
398 - // 性别分类  
399 - $('.unit_type').click(function () {  
400 - weui.picker([  
401 - {label: '国企', value: 0},  
402 - {label: '私企', value: 1}  
403 - ], {  
404 - onChange: function (res) {  
405 - console.log(res)  
406 - },  
407 - onConfirm: function (res) {  
408 - $('.unit_value').val(res[0].label)  
409 - }  
410 - }  
411 - )  
412 - })  
413 - //就诊时间  
414 - $('#showDatePicker').on('click', function () {  
415 - weui.datePicker({  
416 - start: 2019,  
417 - end: new Date().getFullYear(),  
418 - onChange: function (result) {  
419 - console.log(result);  
420 - },  
421 - onConfirm: function (result) {  
422 - console.log(result[0].label+' - '+result[1].label+' - '+result[2].label)  
423 - $('.time_value').val(result[0].value+' - '+result[1].value+' - '+result[2].value)  
424 - }  
425 - });  
426 - });  
427 -  
428 -  
429 -  
430 - //语音模块  
431 - // $('.icon-tianxie').hide()  
432 - // $('.voice_first').hide()  
433 - // $('.voice_second').hide()  
434 - $('.voice_third').hide()  
435 - $('.icon_cancle').hide()  
436 - // $('.voice_module').hide()  
437 -  
438 - var title_id = ''  
439 -  
440 //点击 356 //点击
441 $('.info_item').on('click','.title',function () { 357 $('.info_item').on('click','.title',function () {
442 $(this).parent().toggleClass('voice') 358 $(this).parent().toggleClass('voice')
443 }) 359 })
444 360
445 -  
446 //点击正在播放按钮 361 //点击正在播放按钮
447 $('.icon-luying_ongoing').click(function () { 362 $('.icon-luying_ongoing').click(function () {
448 var videolist = $(".voice_module"); 363 var videolist = $(".voice_module");
@@ -456,10 +371,10 @@ @@ -456,10 +371,10 @@
456 } 371 }
457 }) 372 })
458 373
459 -  
460 - var times = "";//倒计时总秒数量  
461 - var time = "";  
462 - 374 + //倒计时
  375 + var times = "60";//倒计时总秒数量
  376 + var time="";
  377 + var timeLength=0;
463 function countDown(times) { 378 function countDown(times) {
464 var timer = null; 379 var timer = null;
465 timer = setInterval(function () { 380 timer = setInterval(function () {
@@ -481,9 +396,10 @@ @@ -481,9 +396,10 @@
481 $('#hour_show').html('<text id="h"></text>' + hour + ':'); 396 $('#hour_show').html('<text id="h"></text>' + hour + ':');
482 $('#minute_show').html('<text></text>' + minute + ':'); 397 $('#minute_show').html('<text></text>' + minute + ':');
483 $('#second_show').html('<text></text>' + second + ''); 398 $('#second_show').html('<text></text>' + second + '');
  399 + $('#second_test').html('<text></text>' + second + '');
484 400
485 // 401 //
486 - console.log(day + "天:" + hour + "小时:" + minute + "分钟:" + second + "秒"); 402 + // console.log(day + "天:" + hour + "小时:" + minute + "分钟:" + second + "秒");
487 times--; 403 times--;
488 404
489 }, 1000); 405 }, 1000);
@@ -494,31 +410,32 @@ @@ -494,31 +410,32 @@
494 $('.pause').click(function () { 410 $('.pause').click(function () {
495 // timer(intDiff); 411 // timer(intDiff);
496 clearInterval(timer); 412 clearInterval(timer);
497 - localStorage.setItem("times", times) 413 + localStorage.setItem("times",times)
498 }) 414 })
499 $('.stop').click(function () { 415 $('.stop').click(function () {
500 clearInterval(timer); 416 clearInterval(timer);
501 - times = 0; 417 + times=0;
502 }) 418 })
503 $('.stopping').click(function () { 419 $('.stopping').click(function () {
504 clearInterval(timer); 420 clearInterval(timer);
  421 + timeLength=60-times;
  422 + console.log('录音时长:'+timeLength);
505 localStorage.clear() 423 localStorage.clear()
506 }) 424 })
507 } 425 }
508 -  
509 $('.start').click(function () { 426 $('.start').click(function () {
510 - time = localStorage.getItem("times")  
511 - if (time == null) { 427 + time=localStorage.getItem("times")
  428 + if(time==null){
512 times = parseInt(60) 429 times = parseInt(60)
513 - } else {  
514 - times = time; 430 + }else{
  431 + times=time;
515 } 432 }
516 console.log(time) 433 console.log(time)
  434 + // myTimer(intDiff);
517 countDown(times); 435 countDown(times);
518 - localStorage.setItem("times", times) 436 + localStorage.setItem("times",times)
519 }) 437 })
520 438
521 -  
522 //添加一条新语音 439 //添加一条新语音
523 var num = 1; 440 var num = 1;
524 $('.voice_module').on('click', '.add_voice', function () { 441 $('.voice_module').on('click', '.add_voice', function () {
@@ -561,6 +478,9 @@ @@ -561,6 +478,9 @@
561 ' </div>\n' + 478 ' </div>\n' +
562 ' </div>\n' + 479 ' </div>\n' +
563 '</div>' 480 '</div>'
  481 +
  482 +
  483 + // parent.append($('.voice_list').html());
564 parent.append(html) 484 parent.append(html)
565 485
566 }) 486 })
@@ -606,12 +526,16 @@ @@ -606,12 +526,16 @@
606 }) 526 })
607 527
608 //开始录音 528 //开始录音
  529 + var localId;
609 $('.start').click(function () { 530 $('.start').click(function () {
610 $('.start').hide() 531 $('.start').hide()
  532 + $('.stop').hide()
611 $('.play').hide() 533 $('.play').hide()
612 $('.pause').show() 534 $('.pause').show()
613 $('.stopping').show() 535 $('.stopping').show()
614 $('.next_step').hide() 536 $('.next_step').hide()
  537 + /*微信开始录音*/
  538 + wx.startRecord();
615 }) 539 })
616 540
617 //暂停 541 //暂停
@@ -619,60 +543,134 @@ @@ -619,60 +543,134 @@
619 $('.pause').hide() 543 $('.pause').hide()
620 $('.start').show() 544 $('.start').show()
621 $('.stopping').hide() 545 $('.stopping').hide()
622 - })  
623 546
624 - //播放语音  
625 - $('.voice_puse').hide()  
626 -  
627 - $('.voice_play').click(function () {  
628 - var url=$(this).data('url');  
629 - var mySound = new Audio(url);  
630 - mySound.play();  
631 - $(this).hide()  
632 - $(this).siblings('.voice_puse').show();  
633 - $('.voice_puse').click(function () {  
634 - mySound.pause();  
635 - $(this).hide()  
636 - $(this).siblings('.voice_play').show()  
637 - })  
638 }) 547 })
639 548
640 -  
641 -  
642 //停止录音 549 //停止录音
643 $('.stopping').click(function () { 550 $('.stopping').click(function () {
644 $('.next_step').show() 551 $('.next_step').show()
645 $('.stop').show() 552 $('.stop').show()
646 $('.pause').hide() 553 $('.pause').hide()
  554 + wx.stopRecord({
  555 + success: function (res) {
  556 + localId = res.localId;
  557 + }
  558 +
  559 + });
647 }) 560 })
648 561
649 //下一步 562 //下一步
650 $('.next_step').click(function () { 563 $('.next_step').click(function () {
651 $('.first').hide() 564 $('.first').hide()
652 $('.second').show() 565 $('.second').show()
  566 +
653 }) 567 })
654 568
655 //点击试听 569 //点击试听
656 $('.audition').click(function () { 570 $('.audition').click(function () {
  571 + wx.onVoicePlayEnd({
  572 + success: function (res) {
  573 + var localId = res.localId; // 返回音频的本地ID
  574 + }
  575 + });
  576 + wx.playVoice({
  577 + localId:localId //需要播放的音频的本地ID,由stopRecord接口获得
  578 + });
657 579
  580 + var videolist = $(".voice_module");
  581 + for (var i = 0; i < videolist.length; i++) {
  582 + var videoid = $(videolist[i]).attr("video-id");
  583 + if (videoid == title_id) {
  584 + $('.second').hide()
  585 + $(videolist[i]).show();
  586 + $(videolist[i]).children('.voice_list').hide()
  587 + $(videolist[i]).children('.voice_third').show();
  588 + }
  589 + }
658 }) 590 })
659 591
  592 + // 列表中点击试听
  593 + $('.voice_third').click(
  594 + function () {
  595 + var tryId=$(this).attr('try-id');
  596 + wx.playVoice({
  597 + localId:tryId
  598 + });
  599 + }
  600 + )
  601 +
  602 + //就诊时间
  603 + $('#showDatePicker').on('click', function () {
  604 + weui.datePicker({
  605 + start: 2019,
  606 + end: new Date().getFullYear(),
  607 + onChange: function (result) {
  608 + console.log(result);
  609 + },
  610 + onConfirm: function (result) {
  611 + console.log(result[0].label+' - '+result[1].label+' - '+result[2].label)
  612 + $('.time_value').val(result[0].value+' - '+result[1].value+' - '+result[2].value)
  613 + }
  614 + });
  615 + });
  616 +
  617 + //语音模块
  618 + $('.voice_third').hide()
  619 + $('.icon_cancle').hide()
  620 +
  621 + var title_id = ''
660 622
661 //我要发送 623 //我要发送
662 $('.submit_voice').click(function () { 624 $('.submit_voice').click(function () {
663 voiceBox.find('.voice_first').hide().siblings('.voice_third').show() 625 voiceBox.find('.voice_first').hide().siblings('.voice_third').show()
  626 + wx.uploadVoice({localId: localId, // 需要上传的音频的本地ID,由stopRecord接口获得
  627 + isShowProgressTips: 1, // 默认为1,显示进度提示
  628 + success: function (res) {
  629 + voiceBox.find('.voice_first').hide().siblings('.voice_third').attr('data-serverid',res.serverId);
  630 + }
  631 + });
  632 + voiceBox.find('.voice_first').hide().siblings('.voice_third').attr('data-try',localId);
  633 + voiceBox.find('.voice_first').hide().siblings('.voice_third').attr('data-time',timeLength);
  634 + voiceBox.find('.timeLength').html(timeLength);
664 $('.second').hide() 635 $('.second').hide()
  636 + })
665 637
  638 + //确认音频
  639 + $('.upload').click(function () {
  640 + var videolist = $(".voice_module");
  641 + for (var i = 0; i < videolist.length; i++) {
  642 + var videoid = $(videolist[i]).attr("video-id");
  643 + if (videoid == title_id) {
  644 + $('.second').hide()
  645 + $(videolist[i]).show();
  646 + $(videolist[i]).children('.voice_list').hide()
  647 + $(videolist[i]).children('.voice_third').show();
  648 + /*上面放上 音频id和本地地址*/
  649 + $(videolist[i]).children('.voice_third').attr('try-id',localId);
  650 + $(videolist[i]).children('.voice_third').data('data-try',localId);
  651 + $(videolist[i]).children('.voice_third').attr('id','audio'+videoid);
  652 + wx.uploadVoice({
  653 + localId: localId, // 需要上传的音频的本地ID,由stopRecord接口获得
  654 + isShowProgressTips: 1, // 默认为1,显示进度提示
  655 + success: function (res) {
  656 + var serverId = res.serverId; // 返回音频的服务器端ID
  657 + $(videolist[i]).children('.voice_third').attr('server-id',serverId);
  658 + $(videolist[i]).children('.voice_third').data('data-server',serverId);
  659 + localId='';
  660 + }
  661 + });
  662 + }
  663 + }
666 }) 664 })
667 665
668 //重新录制 666 //重新录制
669 $('.rerecord').click(function () { 667 $('.rerecord').click(function () {
  668 + $('#second_test').html(60);
670 $('.first').show() 669 $('.first').show()
671 $('.second').hide() 670 $('.second').hide()
672 $('.stop').hide() 671 $('.stop').hide()
673 $('.stopping').hide() 672 $('.stopping').hide()
674 $('.start').show() 673 $('.start').show()
675 - $('.start').show()  
676 }) 674 })
677 675
678 //上传图片 676 //上传图片
@@ -654,8 +654,6 @@ @@ -654,8 +654,6 @@
654 $(this).parents(".voice_box").remove(); 654 $(this).parents(".voice_box").remove();
655 }) 655 })
656 656
657 -  
658 -  
659 //开始录音 657 //开始录音
660 var localId; 658 var localId;
661 $('.start').click(function () { 659 $('.start').click(function () {
@@ -720,7 +718,6 @@ @@ -720,7 +718,6 @@
720 } 718 }
721 }) 719 })
722 720
723 -  
724 // 列表中点击试听 721 // 列表中点击试听
725 $('.voice_third').click( 722 $('.voice_third').click(
726 function () { 723 function () {