index.vue 6.3 KB

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