index.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <view class="home-content">
  3. <Index v-if="current===0" key="home-index" ref='homeIndex' />
  4. <middle v-if="current===1" key="home-middle" />
  5. <my-center v-if="current===2" key="home-center" />
  6. <tab-bar :list='tabBars' :current="current" @change='changeTab' ref="tabBar" key="home-tabBars" />
  7. </view>
  8. </template>
  9. <script>
  10. import Index from '@/pages/index/index';
  11. import middle from '@/views/record/index.vue';
  12. import myCenter from "@/pages/myCenter/index";
  13. import TabBar from '@/components/TabBar/index';
  14. import tabBars from '@/config/tabBar';
  15. import config from '@/config';
  16. import {MyWebSokcet} from '@/libs/websocket';
  17. const socketBaseUrl=config.socketUrl;
  18. import {ReceivedOrder} from '@/api/doctor';
  19. export default {
  20. components:{
  21. Index,
  22. middle,
  23. myCenter,
  24. TabBar
  25. },
  26. data() {
  27. return {
  28. userType:null,
  29. tabBars:[],
  30. current:0
  31. }
  32. },
  33. created() {
  34. this.$nextTick(()=>{
  35. this.init();
  36. })
  37. },
  38. onLoad({type}) {
  39. if(type==='consult'){
  40. this.current=1;
  41. uni.setNavigationBarTitle({
  42. title:'记录'
  43. })
  44. this.$forceUpdate();
  45. }
  46. },
  47. methods: {
  48. init(){
  49. let accountInfo=uni.getStorageSync('accountInfo');
  50. this.userType=accountInfo.userType;
  51. if(accountInfo.userType===1){//医生
  52. let tabBarList=tabBars.filter((item)=>{
  53. return item.permissions.indexOf("doctor")>-1;
  54. })
  55. this.tabBars=tabBarList;
  56. this.initSocket();
  57. }else{
  58. let tabBarList=tabBars.filter((item)=>{
  59. return item.permissions.indexOf("patient")>-1;
  60. })
  61. this.tabBars=tabBarList;
  62. }
  63. },
  64. changeTab(index){
  65. this.current=index;
  66. },
  67. initSocket(){//启动接单监听
  68. let accountInfo=uni.getStorageSync('accountInfo');
  69. let doctorId=accountInfo.id;
  70. let socketUrl=`${socketBaseUrl}/${doctorId}`;
  71. MyWebSokcet.sokcet(
  72. socketUrl,
  73. this.onReceive,
  74. this.onErrorEvent,
  75. this.onErrorSucceed
  76. )
  77. },
  78. onReceive(receivedata){
  79. let self=this;
  80. if(receivedata.indexOf('seekId')<0){
  81. return ;
  82. }
  83. var info=JSON.parse(receivedata);
  84. let patientName=info.patientName;
  85. let seekId=info.seekId;
  86. console.log({
  87. seekId,patientName,msg:'接单'
  88. })
  89. uni.showModal({
  90. title: '提示',
  91. content:`你收到了${patientName}的一条咨询,是否接受?`,
  92. success: function (res) {
  93. if (res.confirm) {
  94. let accountInfo=uni.getStorageSync('accountInfo');
  95. let doctorId=accountInfo.id;
  96. ReceivedOrder(seekId,doctorId).then((res)=>{
  97. if(res.code===0){
  98. uni.showToast({
  99. title:'已接单',
  100. complete() {
  101. if(self.current===0){
  102. self.$refs.homeIndex.reload('doctor');
  103. }
  104. }
  105. })
  106. }
  107. })
  108. } else if (res.cancel) {
  109. uni.showToast({
  110. title:'已放弃'
  111. })
  112. }
  113. }
  114. });
  115. },
  116. onErrorEvent(res){
  117. console.log('onErrorEvent------------'+JSON.stringify(res))
  118. },
  119. onErrorSucceed(res){
  120. console.log('onErrorSucceed-------------'+JSON.stringify(res))
  121. }
  122. }
  123. }
  124. </script>
  125. <style lang="scss" scoped>
  126. .home-content{
  127. padding-bottom: 120upx;
  128. }
  129. </style>