home.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <template>
  2. <view class="content">
  3. <!-- #ifdef MP-WEIXIN -->
  4. <u-navbar :is-back="false" title="消息" :background="{ background: '#F6F7F8' }" title-color="#404133" :border-bottom="false" z-index="1001">
  5. <view class="slot-wrap" slot="right">
  6. <u-icon name="plus-circle" size="34" @click="showSelect"></u-icon>
  7. </view>
  8. </u-navbar>
  9. <!-- #endif -->
  10. <selectInput :list="selectList" :list-key="'name'" :show.sync="selectShow" @on-select="checkSelect" @close="closeSelect" />
  11. <searchInput :searchType="1"/>
  12. <u-swipe-action style="margin-right: 1px;" :show="item.show" v-for="(item, index) in chatItem" :index="index" btn-width="160" :key="item.id" @click="click" @open="open" :options="options">
  13. <chatItem @linkTo="linkTo" :value="item" :index="index" :voiceIcon="true"></chatItem>
  14. </u-swipe-action>
  15. <tarBer :totarBer='tar'></tarBer>
  16. </view>
  17. </template>
  18. <script>
  19. import tarBer from '@/components/tarber.vue'
  20. import searchInput from '@/components/searchInput/index.vue';
  21. import selectInput from '@/components/selectInput/selectInput.vue';
  22. import chatItem from '@/components/chatItem.vue';
  23. export default {
  24. components: { searchInput, selectInput,chatItem ,tarBar },
  25. data() {
  26. return {
  27. selectShow: false,
  28. options: [
  29. {
  30. text: '置顶',
  31. style: {
  32. backgroundColor: '#b4b4b4',
  33. fontSize: '24rpx'
  34. }
  35. },
  36. {
  37. text: '删除',
  38. style: {
  39. backgroundColor: '#dd524d',
  40. fontSize: '24rpx'
  41. }
  42. }
  43. ],
  44. tar:{
  45. color:'#07A7E3',
  46. id:1
  47. },//向子组件发送的值
  48. selectList: [
  49. { id: '1', name: '添加朋友', icon: 'man-add-fill' },
  50. { id: '2', name: '扫一扫', icon: 'scan' },
  51. { id: '3', name: '收付款', icon: 'fingerprint' }
  52. ]
  53. };
  54. },
  55. watch:{
  56. pushRes: function(value){
  57. this.getChats(false)
  58. }
  59. },
  60. mounted() {
  61. this.getChats(false)
  62. },
  63. onShow() {
  64. },
  65. onLoad(){
  66. },
  67. onPullDownRefresh() {
  68. this.getChats(true)
  69. },
  70. methods: {
  71. linkTo(item){
  72. this.$u.vuex('chatObj', item)
  73. this.$u.route({
  74. url: 'pages/chat/chat',
  75. params: {}
  76. });
  77. },
  78. getChats(freshFlag){
  79. if(this.userData.user==undefined){
  80. return;
  81. }
  82. this.$socket.queryChats('', this.userData.user.operId,(res) => {
  83. if (res.success) {
  84. res.chats.sort((a, b) => { return b.lastOpenTime - a.lastOpenTime });
  85. this.$u.vuex('chatItem', res.chats);
  86. }
  87. if(freshFlag){
  88. uni.stopPullDownRefresh();
  89. }
  90. });
  91. },
  92. //打开或者关闭弹窗
  93. showSelect(){
  94. this.selectShow = !this.selectShow;
  95. },
  96. //action 点击事件
  97. click(index,index1) {
  98. if(index1==0){
  99. this.chatItem[index].isTop = true;
  100. // TODO 留空
  101. }else {
  102. this.chatItem.splice(index, 1);
  103. let obj = this.chatItem[index==this.chatItem.length?index-1:index];
  104. this.$socket.delChat(this.userData.user.operId, obj.id, (res) => {})
  105. }
  106. },
  107. //action 打开事件
  108. open(index) {
  109. this.chatItem[index].show = true;
  110. this.chatItem.map((val, idx) => {
  111. if (index != idx) this.chatItem[idx].show = false;
  112. });
  113. },
  114. //点击导航栏自定义按钮
  115. onNavigationBarButtonTap({ index }) {
  116. if (index == 0) {
  117. this.showSelect()
  118. }
  119. },
  120. //关闭弹窗
  121. closeSelect(){
  122. //小程序兼容
  123. this.selectShow = false;
  124. },
  125. //扫码
  126. checkSelect(index) {
  127. if (index == 0) {
  128. this.$u.route({
  129. url:"pages/search/search",
  130. params: {searchType: 0}
  131. })
  132. }
  133. else if (index == 1) {
  134. //扫码
  135. const t = this
  136. uni.scanCode({
  137. success: function(res) {
  138. uni.vibrateLong();
  139. // console.log('条码内容:' + res.result);
  140. let uId = res.result
  141. if (uId==t.userData.user.operId){
  142. uni.showToast({
  143. icon:'none',
  144. title:'不能添加自己为好友'
  145. })
  146. } else {
  147. t.$u.route({
  148. url: 'pages/businessCard/businessCard',
  149. params:{ id: uId, source: 2}
  150. })
  151. }
  152. }
  153. });
  154. }
  155. },
  156. },
  157. };
  158. </script>