index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <swiper class="swiper" circular :indicator-dots="true" indicator-color="#FFFFFF"
  5. indicator-active-color="#007AFF" :autoplay="true" :interval="3000" :duration="1000">
  6. <swiper-item class="list" v-for="(item,index) in advertList" :key="index">
  7. <image class="image" :src="item.image&&item.image.length>0?item.image[0].url:''" mode=""></image>
  8. </swiper-item>
  9. </swiper>
  10. </view>
  11. <view class="two" v-if="user.role!='Patient'">
  12. <uni-collapse accordion>
  13. <uni-collapse-item title="群组" :thumb="config.group_url[0].url">
  14. <view class="content" v-if="groupList.length>0">
  15. <view class="two_1">
  16. <input type="text" v-model="searchgroup.name" @input="toInputGroup" placeholder="搜索">
  17. </view>
  18. <view class="list" v-for="(item, index) in groupList" :key="index">
  19. <uni-list-chat :title="item.name||''"
  20. :avatar="item.doctor.icon[0].url||config.logo_url[0].url" :time="item.doctor.name||''"
  21. link="navigateTo" @click="toInfo(item,'group')">
  22. </uni-list-chat>
  23. </view>
  24. </view>
  25. </uni-collapse-item>
  26. <uni-collapse-item title="好友" :thumb="config.friend_url[0].url" :open="true">
  27. <view class="content" v-if="friendList.length>0">
  28. <view class="two_1">
  29. <input type="text" v-model="searchfriend.name" @input="toInputFriend" placeholder="搜索">
  30. </view>
  31. <view class="list" v-for="(item, index) in friendList" :key="index"
  32. @tap="toInfo(item,'friend')">
  33. <uni-list-chat v-if="item.notRead==0" :title="item.patientName||''"
  34. :avatar="item.patientIcon||config.user_url[0].url" :note="item.content||''"
  35. :time="item.time||''" link="navigateTo" @click="toInfo(item,'friend')">
  36. </uni-list-chat>
  37. <uni-list-chat v-else :title="item.patientName||''"
  38. :avatar="item.patientIcon||config.user_url[0].url" :note="item.content||''"
  39. :time="item.time||''" badge-positon="left" :badge-text="item.notRead||''"
  40. link="navigateTo" @click="toInfo(item,'friend')">
  41. </uni-list-chat>
  42. </view>
  43. </view>
  44. </uni-collapse-item>
  45. </uni-collapse>
  46. </view>
  47. <view class="two" v-else>
  48. <view class="content" v-if="groupList.length>0">
  49. <view class="two_1">
  50. <input type="text" v-model="searchgroup.name" @input="toInputGroup" placeholder="搜索">
  51. </view>
  52. <view class="list" v-for="(item, index) in groupList" :key="index">
  53. <uni-list-chat :title="item.name" :avatar="item.doctor.icon[0].url||config.logo_url[0].url"
  54. :time="item.doctor.name" link="navigateTo" @click="toInfo(item,'group')">
  55. </uni-list-chat>
  56. <!-- <uni-list-chat v-if="item.notRead==0" :title="item.name"
  57. :avatar="item.doctor.icon[0].url||config.logo_url[0].url" :time="item.doctor.name"
  58. link="navigateTo" @click="toInfo(item,'group')">
  59. </uni-list-chat>
  60. <uni-list-chat v-else :title="item.name" :avatar="item.doctor.icon[0].url||config.logo_url[0].url"
  61. :time="item.doctor.name" link="navigateTo" badge-positon="left" :badge-text="item.notRead"
  62. @click="toInfo(item,'group')">
  63. </uni-list-chat> -->
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </template>
  69. <script>
  70. export default {
  71. data() {
  72. return {
  73. user: {},
  74. config: {},
  75. searchgroup: {},
  76. searchfriend: {},
  77. // 广告
  78. advertList: [],
  79. // 群组
  80. groupList: [],
  81. // 好友
  82. friendList: [{
  83. id: '1'
  84. }]
  85. }
  86. },
  87. onShow: async function() {
  88. const that = this;
  89. await that.searchToken();
  90. await that.searchConfig();
  91. await that.search();
  92. },
  93. onPullDownRefresh: async function() {
  94. const that = this;
  95. await that.search();
  96. uni.stopPullDownRefresh();
  97. },
  98. methods: {
  99. // 用户信息
  100. searchToken() {
  101. const that = this;
  102. try {
  103. const res = uni.getStorageSync('token');
  104. if (res) {
  105. const user = that.$jwt(res);
  106. that.$set(that, `user`, user);
  107. }
  108. } catch (e) {}
  109. },
  110. searchConfig() {
  111. const that = this;
  112. try {
  113. const res = uni.getStorageSync('config');
  114. if (res) that.$set(that, `config`, res);
  115. } catch (e) {}
  116. },
  117. // 查询
  118. async search() {
  119. const that = this;
  120. let res;
  121. // 广告
  122. res = await that.$api(`/adv`, 'GET', {
  123. is_use: '0'
  124. })
  125. if (res.errcode == '0') {
  126. that.$set(that, `advertList`, res.data)
  127. } else {
  128. uni.showToast({
  129. title: res.errmsg,
  130. icon: 'none'
  131. });
  132. }
  133. let info = {}
  134. if (that.user.role == 'Doctor') info.doctor = that.user._id
  135. else if (that.user.role == 'Nurse') info.doctor = that.user.doctor
  136. else info.patients = that.user._id
  137. // 群组
  138. res = await that.$api(`/group`, 'GET', {
  139. ...info,
  140. ...that.searchgroup
  141. })
  142. if (res.errcode == '0') {
  143. that.$set(that, `groupList`, res.data)
  144. } else {
  145. uni.showToast({
  146. title: res.errmsg,
  147. icon: 'none'
  148. });
  149. }
  150. // 好友
  151. res = await that.$api(`/chat/lcl`, 'GET', {
  152. ...info,
  153. ...that.searchfriend
  154. })
  155. if (res.errcode == '0') {
  156. // 处理显示数据
  157. for (let val of res.data) {
  158. if (val.type == 'image') val.content = '[图片]'
  159. if (val.type == 'record') val.content = '[语音]'
  160. if (val.patientIcon.length > 0) val.patientIcon = val.patientIcon[0].url
  161. val.time = that.formatDate(val.time)
  162. }
  163. that.$set(that, `friendList`, res.data)
  164. } else {
  165. uni.showToast({
  166. title: res.errmsg,
  167. icon: 'none'
  168. });
  169. }
  170. },
  171. // 群组输入框
  172. toInputGroup(e) {
  173. const that = this;
  174. if (that.searchgroup.name) that.$set(that.searchgroup, `name`, e.detail.value)
  175. else that.$set(that, `searchgroup`, {})
  176. that.search();
  177. },
  178. // 好友输入框
  179. toInputFriend(e) {
  180. const that = this;
  181. if (that.searchfriend.name) that.$set(that.searchfriend, `name`, e.detail.value)
  182. else that.$set(that, `searchfriend`, {})
  183. that.search();
  184. },
  185. // 处理时间
  186. formatDate(value) {
  187. if (typeof(value) == 'undefined') {
  188. return ''
  189. } else {
  190. let date = new Date(value)
  191. let now = new Date()
  192. let y = date.getFullYear()
  193. let MM = date.getMonth() + 1
  194. MM = MM < 10 ? ('0' + MM) : MM
  195. let d = date.getDate()
  196. d = d < 10 ? ('0' + d) : d
  197. let h = date.getHours()
  198. h = h < 10 ? ('0' + h) : h
  199. let m = date.getMinutes()
  200. m = m < 10 ? ('0' + m) : m
  201. let s = date.getSeconds()
  202. s = s < 10 ? ('0' + s) : s
  203. if (now.getDate() - d == 1 && now - date < 172800000) {
  204. return '昨天' + h + ':' + m
  205. } else if (now - date < 86400000) {
  206. return h + ':' + m
  207. } else if (now - date >= 86400000 && now - date < 31536000000) {
  208. return MM + '-' + d + ' ' + h + ':' + m
  209. } else if (now - date >= 31536000000) {
  210. return y + '-' + MM + '-' + d + ' ' + h + ':' + m
  211. }
  212. }
  213. },
  214. // 详情
  215. toInfo(item, type) {
  216. if (type == 'group') {
  217. uni.navigateTo({
  218. url: `/pagesHome/group/index?id=${item.id||item._id}&title=${item.name}`
  219. })
  220. } else {
  221. uni.navigateTo({
  222. url: `/pagesHome/friend/index?patientId=${item.patient}&doctorId=${item.doctor}&groupId=${item.group}&title=${item.patientName}`
  223. })
  224. }
  225. },
  226. }
  227. }
  228. </script>
  229. <style lang="scss" scoped>
  230. .main {
  231. .one {
  232. padding: 0 0 2vw 0;
  233. .swiper {
  234. height: 70vw;
  235. .list {
  236. .image {
  237. width: 100%;
  238. height: 100%;
  239. }
  240. }
  241. }
  242. }
  243. .two {
  244. .content {
  245. .two_1 {
  246. display: flex;
  247. justify-content: center;
  248. align-items: center;
  249. padding: 2vw;
  250. background-color: var(--f3CColor);
  251. input {
  252. width: 100%;
  253. padding: 2vw;
  254. background-color: var(--mainColor);
  255. font-size: var(--font14Size);
  256. border-radius: 5px;
  257. }
  258. }
  259. }
  260. }
  261. }
  262. </style>