add.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view>
  3. <view id="app-top">
  4. <uni-nav-bar statusBar backgroundColor="transparent" fixed title="创建新群聊" left-icon="left" @clickLeft="utils.navigateBack()">
  5. <view slot="right" @tap="tapSubmit">
  6. <view class="sub-btn">完成{{inAr()}}</view>
  7. </view>
  8. </uni-nav-bar>
  9. <view class="search fx-r fx-bc">
  10. <image src="/static/chat/tb-seach.png"></image>
  11. <input @input="tapKeyWord" class="fx-g1" type="text" placeholder="搜索联系人" />
  12. </view>
  13. </view>
  14. <scroll-view class="search-view" :style="'height: calc(100vh - ' + barheight + 'px);'" scroll-y :scroll-into-view="toView" scroll-with-animation='true' show-scrollbar="false" >
  15. <view class="lists">
  16. <view v-for="(item,index) in letter">
  17. <view class="letter" :id="'letter_' + item.letter">{{item.letter}}</view>
  18. <view class="item fx-r fx-bc" @tap="tapSelect(index,index2)" v-for="(item2,index2) in item.data">
  19. <image class="select" v-if="!item2.select" src="/static/chat/check.png" mode="widthFix"></image>
  20. <image class="select" v-else src="/static/chat/check-btn.png" mode="widthFix"></image>
  21. <image class="avatar" :src="item2.avatar == '' ? '/static/chat/user-avatar.png' : item2.avatar" mode="aspectFill"></image>
  22. <view class="info fx-h fx-ac">
  23. <rich-text class="title" :nodes="getRanValue(item2.remark || item2.nickname)"></rich-text>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="foot-value">{{count}}个朋友</view>
  28. </view>
  29. </scroll-view>
  30. <view class="SideMenu" >
  31. <view @tap="tapOpenLetter(item.letter)" v-for="(item, index) in letter"> {{item.letter}} </view>
  32. </view>
  33. <view class="choice" v-if="isChoice">{{choice}}</view>
  34. <u-modal :show="isShow" :showCancelButton="true" @confirm="tapSubmit2" @cancel="isShow=false" title="群名称">
  35. <view class="slot-content" style="width: 90%;">
  36. <u--input clearable placeholder="请输入创建群名" v-model="group_name" border="surround"></u--input>
  37. </view>
  38. </u-modal>
  39. </view>
  40. </template>
  41. <style lang="scss">
  42. .sub-btn{color: #fff;background:$ic-appcolor;padding: 8px;border-radius: 4px;}
  43. .search{background: #fff;border-radius: 6px;margin: 0px 10px;padding: 10px;}
  44. .search image{width: 30px;height: 30px;}
  45. .search input{font-size: 14px;}
  46. .search-view{height: calc(100% - 50px)}
  47. .search-view .lists{margin-top: 10px;}
  48. .search-view .lists .item{background: #fff;padding:0 10px;position: relative;}
  49. .search-view .lists .item:active{background: #f1f1f1;}
  50. .search-view .lists .item .avatar{width: 40px;height: 40px;border-radius: 50%;}
  51. .search-view .lists .item .info{width: calc(100% - 100px);margin-left: 10px;font-size: 14px;color:#787878;border-bottom: 1px solid #f1f1f1;height: 60px;}
  52. .search-view .lists .item .flg{background: #ff5857;width: 20px;height: 20px;border-radius: 50%;font-size: 10px;text-align: center;line-height: 20px;color: #fff;}
  53. .search-view .lists .item .select{width: 18px;height: 18px;margin-right: 8px;}
  54. .search-view .lists .item:last-child .info{border-bottom: 0;}
  55. .search-view .letter{padding: 10px;}
  56. .SideMenu {
  57. position: fixed;
  58. top: 50%;
  59. right: 0;
  60. padding: 20rpx 0rpx;
  61. width: 45rpx;
  62. transform: translate(0,-50%);
  63. z-index: 1;
  64. }
  65. .SideMenu view {
  66. height: 30rpx;
  67. display: block;
  68. padding: 4rpx 0;
  69. wdith:45rpx;
  70. color: #000;
  71. text-align: center;
  72. font-size: 22rpx;
  73. }
  74. .foot-value{height:60px;line-height: 60px;font-size: 14px;text-align: center;color:#787878;}
  75. </style>
  76. <script>
  77. import {mapState,mapMutations} from 'vuex';
  78. var LetterList = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','#'];
  79. export default {
  80. computed: mapState(['user','sysData']),
  81. data() {
  82. return {
  83. dataAr : [],
  84. letter : [],
  85. count : 0,
  86. keyword : "",
  87. isChoice : false,
  88. choice : "",
  89. toView:"",
  90. barheight : 0,
  91. isShow:false,
  92. group_name:""
  93. }
  94. },
  95. onLoad() {
  96. this.checkUserLogin({
  97. page:this,isLogin:true,fn:this.initView
  98. });
  99. this.$nextTick(() => {
  100. uni.createSelectorQuery().select("#app-top").boundingClientRect(res=>{
  101. this.barheight = res.height;
  102. }).exec();
  103. });
  104. //app-top
  105. },
  106. methods: {
  107. ...mapMutations(['checkUserLogin','setSys']),
  108. /**
  109. *
  110. */
  111. initView:function(){
  112. this
  113. .request
  114. .get("FriendIndex")
  115. .then(res=>{
  116. if(res.code == 200) {
  117. for(var i in res.data){
  118. res.data[i].select = false;
  119. }
  120. this.dataAr = res.data;
  121. this.letterView();
  122. } else {
  123. this.utils.showModal(res.msg);
  124. }
  125. });
  126. },
  127. /**
  128. * 检索关键词
  129. */
  130. tapKeyWord:function(ev){
  131. this.keyword = ev.detail.value;
  132. this.letterView();
  133. },
  134. //字母
  135. letterView:function(){
  136. var tAr = {};
  137. for(var i in LetterList) {
  138. var letter = LetterList[i];
  139. for(var j in this.dataAr) {
  140. var jAr = this.dataAr[j];
  141. if(jAr.letter == letter && (jAr.nickname.indexOf(this.keyword) >= 0 || jAr.remark.indexOf(this.keyword) >= 0 )) {
  142. if(tAr[letter] != null) {
  143. tAr[letter].data.push(jAr);
  144. } else {
  145. tAr[letter] = {'letter':letter,'data':[jAr]};
  146. }
  147. }
  148. }
  149. }
  150. var count = 0;
  151. var nAr = [];
  152. for(var j in tAr) {
  153. nAr.push(tAr[j]);
  154. count += tAr[j].data.length;
  155. }
  156. this.letter = nAr;
  157. this.count = count;
  158. },
  159. tapSelect:function(index,index2){
  160. var bool = this.letter[index].data[index2].select;
  161. this.$set(this.letter[index].data[index2],'select',!bool);
  162. },
  163. inAr:function(){
  164. var count = 0;
  165. for(var i in this.letter) {
  166. for(var j in this.letter[i].data) {
  167. if(this.letter[i].data[j].select) {
  168. count += 1;
  169. }
  170. }
  171. }
  172. return count > 0 ? ("(" + count+ ")") : "";
  173. },
  174. /**
  175. * 遍历字符串
  176. */
  177. getRanValue:function(str) {
  178. let value = str;
  179. if (value.indexOf(this.keyword)!==-1) {
  180. let reg = new RegExp(this.keyword, 'gi')
  181. return value.replace(reg, `<font style="color:#2fbec0">${this.keyword}</font>`)
  182. } else {
  183. return value
  184. }
  185. },
  186. /**
  187. * 打开字母
  188. */
  189. tapOpenLetter:function(item){
  190. this.isChoice = true;
  191. this.choice = item;
  192. setTimeout(()=>{this.isChoice = false;},500);
  193. this.toView = "letter_" + item;
  194. },
  195. /**
  196. * 打开
  197. * @param {Object} ev
  198. */
  199. tapOpen: function(ev) {
  200. let url = ev.currentTarget.dataset.url;
  201. this.utils.navigateTo(url);
  202. },
  203. /**
  204. * 提交创建
  205. */
  206. tapSubmit:function(){
  207. var idsAr = [];
  208. for(var i in this.letter) {
  209. for(var j in this.letter[i].data) {
  210. if(this.letter[i].data[j].select) {
  211. idsAr.push(this.letter[i].data[j].f_uid);
  212. }
  213. }
  214. }
  215. if(idsAr.length < 1) {
  216. return this.utils.Tip("群聊不能少于1人");
  217. }
  218. this.group_name = "";
  219. this.isShow = true;
  220. },
  221. tapSubmit2:function(){
  222. if(this.group_name == "") {
  223. return this.utils.Tip("请输入群名");
  224. }
  225. var idsAr = [];
  226. for(var i in this.letter) {
  227. for(var j in this.letter[i].data) {
  228. if(this.letter[i].data[j].select) {
  229. idsAr.push(this.letter[i].data[j].f_uid);
  230. }
  231. }
  232. }
  233. this.isShow = false;
  234. uni.showLoading({ title:"创建中" });
  235. this
  236. .request
  237. .post("GroupCreate",{usercodes:idsAr.join(","),group_name:this.group_name})
  238. .then(res=>{
  239. uni.hideLoading();
  240. if(res.code == 200) {
  241. this.utils.Tip("创建成功");
  242. setTimeout(()=>{uni.navigateBack();},200);
  243. } else {
  244. uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
  245. }
  246. })
  247. .catch(err=>{
  248. console.log(err);
  249. uni.hideLoading();
  250. uni.showModal({title: '系统提示',content: '加载失败,返回在尝试',showCancel: false});
  251. });
  252. }
  253. }
  254. }
  255. </script>
  256. <style>
  257. .app{width: 100vw;height: 100vh;}
  258. /* #ifdef H5 */
  259. .app{height: calc(100vh - 95px);}
  260. /* #endif */
  261. .app-run .text{font-size: 24px;font-weight: bold;color: #737373;}
  262. .choice {
  263. width: 110rpx;
  264. height: 110rpx;
  265. position: fixed;
  266. top: 40%;
  267. left: 50%;
  268. transform: translate(-50%,-50%);
  269. background: rgba(0,0,0,0.3);
  270. color: #fff;
  271. border-radius: 20rpx;
  272. text-align: center;
  273. line-height: 110rpx;
  274. font-size: 45rpx;
  275. z-index: 2;
  276. }
  277. </style>