index.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. <template>
  2. <view class="main">
  3. <view class="one">
  4. <input type="text" v-model="searchInfo.name" @input="toInput" placeholder="搜索姓名">
  5. </view>
  6. <view class="two">
  7. <scroll-view scroll-y="true" class="scroll-view" @scrolltolower="toPage" @scroll="toScroll">
  8. <view class="list-scroll-view">
  9. <view class="list" v-for="(item, index) in list" :key="index" @tap="toChat(item)">
  10. <view class="list_1">
  11. <view class="left">
  12. <image class="image"
  13. :src="item.icon&&item.icon.length>0?item.icon[0].url:config.user_url[0].url">
  14. </image>
  15. </view>
  16. <view class="right">
  17. <view class="name textOne">{{item.name||'暂无'}}</view>
  18. </view>
  19. </view>
  20. <view class="bottom">
  21. <button class="warning" size="mini" type="warn" @tap.stop="toView(item)">用户详情</button>
  22. <button class="danger" size="mini" type="warn" @tap.stop="toExit(item)">退出群聊</button>
  23. </view>
  24. </view>
  25. <view class="is_bottom" v-if="is_bottom">
  26. <text>{{config.bottom_title||'到底了!'}}</text>
  27. </view>
  28. </view>
  29. </scroll-view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. export default {
  35. data() {
  36. return {
  37. id: '',
  38. config: {},
  39. user: {},
  40. groupInfo: {},
  41. patientsList: [],
  42. list: [],
  43. total: 0,
  44. skip: 0,
  45. limit: 6,
  46. page: 0,
  47. // 数据是否触底
  48. is_bottom: false,
  49. scrollTop: 0,
  50. }
  51. },
  52. onLoad: async function(e) {
  53. const that = this;
  54. that.$set(that, `id`, e && e.id || '');
  55. that.searchToken();
  56. that.searchConfig();
  57. },
  58. onShow: async function() {
  59. const that = this;
  60. that.clearPage();
  61. await that.search();
  62. },
  63. onPullDownRefresh: async function() {
  64. const that = this;
  65. that.clearPage();
  66. await that.search();
  67. uni.stopPullDownRefresh();
  68. },
  69. methods: {
  70. // 用户信息
  71. searchToken() {
  72. const that = this;
  73. try {
  74. const res = uni.getStorageSync('token');
  75. if (res) {
  76. const user = that.$jwt(res);
  77. that.$set(that, `user`, user);
  78. }
  79. } catch (e) {}
  80. },
  81. searchConfig() {
  82. const that = this;
  83. try {
  84. const res = uni.getStorageSync('config');
  85. if (res) that.$set(that, `config`, res);
  86. } catch (e) {}
  87. },
  88. async search() {
  89. const that = this;
  90. if (that.id) {
  91. // 群详情
  92. const arr = await that.$api(`/group/${that.id}`, 'GET', {})
  93. if (arr.errcode == '0') {
  94. that.$set(that, `groupInfo`, arr.data)
  95. that.$set(that, `patientsList`, arr.data.patients)
  96. } else {
  97. uni.showToast({
  98. title: arr.errmsg,
  99. icon: 'none'
  100. });
  101. }
  102. // 群成员
  103. let info = {
  104. skip: that.skip,
  105. limit: that.limit,
  106. groupId: that.id
  107. }
  108. const res = await that.$api(`/group/getPaitentList`, 'GET', {
  109. ...info,
  110. ...that.searchInfo
  111. })
  112. if (res.errcode == '0') {
  113. let list = [...that.list, ...res.data];
  114. that.$set(that, `list`, list)
  115. that.$set(that, `total`, res.total)
  116. } else {
  117. uni.showToast({
  118. title: res.errmsg,
  119. icon: 'none'
  120. });
  121. }
  122. }
  123. },
  124. // 输入框
  125. toInput(e) {
  126. const that = this;
  127. if (that.searchInfo.name) that.$set(that.searchInfo, `name`, e.detail.value)
  128. else that.$set(that, `searchInfo`, {})
  129. that.clearPage();
  130. that.search();
  131. },
  132. // 聊天
  133. toChat(item) {
  134. const that = this;
  135. if (that.user.role == 'Doctor') {
  136. uni.navigateTo({
  137. url: `/pagesHome/friend/index?patientId=${item._id}&doctorId=${that.user._id}&groupId=${that.id}&title=${item.name}`
  138. })
  139. } else {
  140. uni.navigateTo({
  141. url: `/pagesHome/friend/index?patientId=${item._id}&doctorId=${that.user.doctor}&groupId=${that.id}&title=${item.name}`
  142. })
  143. }
  144. },
  145. // 查看用户详情
  146. toView(item) {
  147. uni.navigateTo({
  148. url: `/pagesMy/person/detail?id=${item.id||item._id}`
  149. })
  150. },
  151. // 退出群里
  152. toExit(item) {
  153. const that = this;
  154. uni.showModal({
  155. title: '提示',
  156. content: `您确定将${item.name}用户退出群聊吗?`,
  157. success: async function(res) {
  158. if (res.confirm) {
  159. that.groupInfo.patients = taht.patientsList.filter(i => i != item._id)
  160. const res = await that.$api(`/group/${item._id||item.id}`, 'POST', that.groupInfo)
  161. if (res.errcode == 0) {
  162. that.clearPage();
  163. that.search();
  164. } else {
  165. uni.showToast({
  166. title: res.errmsg,
  167. icon: 'none'
  168. })
  169. }
  170. }
  171. }
  172. });
  173. },
  174. // 分页
  175. toPage(e) {
  176. const that = this;
  177. let list = that.list;
  178. let limit = that.limit;
  179. if (that.total > list.length) {
  180. uni.showLoading({
  181. title: '加载中',
  182. mask: true
  183. })
  184. let page = that.page + 1;
  185. that.$set(that, `page`, page)
  186. let skip = page * limit;
  187. that.$set(that, `skip`, skip)
  188. that.search();
  189. uni.hideLoading();
  190. } else that.$set(that, `is_bottom`, true)
  191. },
  192. toScroll(e) {
  193. const that = this;
  194. let up = that.scrollTop;
  195. that.$set(that, `scrollTop`, e.detail.scrollTop);
  196. let num = Math.sign(up - e.detail.scrollTop);
  197. if (num == 1) that.$set(that, `is_bottom`, false);
  198. },
  199. // 清空列表
  200. clearPage() {
  201. const that = this;
  202. that.$set(that, `list`, [])
  203. that.$set(that, `skip`, 0)
  204. that.$set(that, `limit`, 6)
  205. that.$set(that, `page`, 0)
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. .main {
  212. display: flex;
  213. flex-direction: column;
  214. width: 100vw;
  215. height: 100vh;
  216. .one {
  217. display: flex;
  218. justify-content: center;
  219. align-items: center;
  220. padding: 2vw;
  221. input {
  222. width: 100%;
  223. padding: 2vw;
  224. background-color: var(--f1Color);
  225. font-size: var(--font14Size);
  226. border-radius: 5px;
  227. }
  228. }
  229. .two {
  230. position: relative;
  231. flex-grow: 1;
  232. background-color: var(--f9Color);
  233. margin: 2vw 0 0 0;
  234. .list {
  235. background-color: var(--mainColor);
  236. border: 1px solid var(--f5Color);
  237. padding: 2vw;
  238. margin: 2vw 2vw 0 2vw;
  239. border-radius: 5px;
  240. .list_1 {
  241. display: flex;
  242. .left {
  243. width: 15vw;
  244. .image {
  245. width: 15vw;
  246. height: 15vw;
  247. border-radius: 1vw;
  248. }
  249. }
  250. .right {
  251. width: 75vw;
  252. margin: 0 0 0 2vw;
  253. .name {
  254. font-size: var(--font14Size);
  255. }
  256. .other {
  257. padding: 2px 0 0 0;
  258. font-size: var(--font12Size);
  259. color: var(--f85Color);
  260. }
  261. }
  262. }
  263. .bottom {
  264. margin: 2vw 0 0 0;
  265. text-align: center;
  266. .warning {
  267. background: var(--f3CColor);
  268. }
  269. .danger {
  270. background: var(--fF0Color);
  271. }
  272. button {
  273. margin: 0 1vw 0 0;
  274. }
  275. }
  276. }
  277. }
  278. }
  279. .scroll-view {
  280. position: absolute;
  281. top: 0;
  282. left: 0;
  283. right: 0;
  284. bottom: 0;
  285. .list-scroll-view {
  286. display: flex;
  287. flex-direction: column;
  288. }
  289. }
  290. .is_bottom {
  291. width: 100%;
  292. text-align: center;
  293. text {
  294. padding: 2vw 0;
  295. display: inline-block;
  296. color: var(--f85Color);
  297. font-size: var(--font14Size);
  298. }
  299. }
  300. </style>