add.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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/img/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. <view v-if="item2.isDisable">
  20. <image class="select" src="/static/chat/check-no.png" mode="widthFix"></image>
  21. </view>
  22. <view v-else>
  23. <image class="select" v-if="!item2.select" src="/static/chat/check.png" mode="widthFix"></image>
  24. <image class="select" v-else src="/static/chat/check-btn.png" mode="widthFix"></image>
  25. </view>
  26. <image style="border-radius: 50%;" :src="item2.avatar == '' ? '/static/chat/user-avatar.png' : item2.avatar" mode="aspectFill"></image>
  27. <view class="info fx-h fx-ac">
  28. <rich-text class="title" :nodes="getRanValue(item2.remark || item2.nickname)"></rich-text>
  29. </view>
  30. </view>
  31. </view>
  32. <view class="foot-value">{{count}}个朋友</view>
  33. </view>
  34. </scroll-view>
  35. <view class="SideMenu" >
  36. <view @tap="tapOpenLetter(item.letter)" v-for="(item, index) in letter"> {{item.letter}} </view>
  37. </view>
  38. <view class="choice" v-if="isChoice">{{choice}}</view>
  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 image{width: 40px;height: 40px;}
  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: 20px;height: 20px;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. noData : [],
  86. count : 0,
  87. keyword : "",
  88. isChoice : false,
  89. choice : "",
  90. toView:"",
  91. barheight : 0,
  92. groupId : 0
  93. }
  94. },
  95. onLoad(options) {
  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. this.groupId = options.groupId;
  105. this.noData = JSON.parse(decodeURIComponent(options.notData));
  106. },
  107. methods: {
  108. ...mapMutations(['checkUserLogin','setSys']),
  109. /**
  110. *
  111. */
  112. initView:function(){
  113. this
  114. .request
  115. .get("FriendIndex")
  116. .then(res=>{
  117. if(res.code == 200) {
  118. for(var i in res.data){
  119. res.data[i].select = false;
  120. res.data[i].isDisable = false;
  121. for(var j in this.noData) {
  122. if(this.noData[j] == res.data[i].f_uid) {
  123. res.data[i].isDisable = true;
  124. }
  125. }
  126. }
  127. this.dataAr = res.data;
  128. this.letterView();
  129. } else {
  130. this.utils.showModal(res.msg);
  131. }
  132. });
  133. },
  134. /**
  135. * 检索关键词
  136. */
  137. tapKeyWord:function(ev){
  138. this.keyword = ev.detail.value;
  139. this.letterView();
  140. },
  141. //字母
  142. letterView:function(){
  143. var tAr = {};
  144. for(var i in LetterList) {
  145. var letter = LetterList[i];
  146. for(var j in this.dataAr) {
  147. var jAr = this.dataAr[j];
  148. if(jAr.letter == letter && (jAr.nickname.indexOf(this.keyword) >= 0 || jAr.remark.indexOf(this.keyword) >= 0 )) {
  149. if(tAr[letter] != null) {
  150. tAr[letter].data.push(jAr);
  151. } else {
  152. tAr[letter] = {'letter':letter,'data':[jAr]};
  153. }
  154. }
  155. }
  156. }
  157. var count = 0;
  158. var nAr = [];
  159. for(var j in tAr) {
  160. nAr.push(tAr[j]);
  161. count += tAr[j].data.length;
  162. }
  163. this.letter = nAr;
  164. this.count = count;
  165. },
  166. tapSelect:function(index,index2){
  167. if(this.letter[index].data[index2].isDisable)return;
  168. var bool = this.letter[index].data[index2].select;
  169. this.$set(this.letter[index].data[index2],'select',!bool);
  170. },
  171. inAr:function(){
  172. var count = 0;
  173. for(var i in this.letter) {
  174. for(var j in this.letter[i].data) {
  175. if(this.letter[i].data[j].select) {
  176. count += 1;
  177. }
  178. }
  179. }
  180. return count > 0 ? ("(" + count+ ")") : "";
  181. },
  182. /**
  183. * 遍历字符串
  184. */
  185. getRanValue:function(str) {
  186. let value = str;
  187. if (value.indexOf(this.keyword)!==-1) {
  188. let reg = new RegExp(this.keyword, 'gi')
  189. return value.replace(reg, `<font style="color:#2fbec0">${this.keyword}</font>`)
  190. } else {
  191. return value
  192. }
  193. },
  194. /**
  195. * 打开字母
  196. */
  197. tapOpenLetter:function(item){
  198. this.isChoice = true;
  199. this.choice = item;
  200. setTimeout(()=>{this.isChoice = false;},500);
  201. this.toView = "letter_" + item;
  202. },
  203. /**
  204. * 打开
  205. * @param {Object} ev
  206. */
  207. tapOpen: function(ev) {
  208. let url = ev.currentTarget.dataset.url;
  209. this.utils.navigateTo(url);
  210. },
  211. /**
  212. * 提交创建
  213. */
  214. tapSubmit:function(){
  215. var idsAr = [];
  216. for(var i in this.letter) {
  217. for(var j in this.letter[i].data) {
  218. if(this.letter[i].data[j].select) {
  219. idsAr.push(this.letter[i].data[j].f_uid);
  220. }
  221. }
  222. }
  223. if(idsAr.length < 0) {
  224. return this.utils.Tip("请选择添加的人");
  225. }
  226. uni.showLoading({ title:"提交中.." });
  227. this
  228. .request
  229. .post("GroupAdd",{groupId:this.groupId,usercodes:idsAr.join(",")})
  230. .then(res=>{
  231. uni.hideLoading();
  232. if(res.code == 200) {
  233. this.utils.Tip("操作成功");
  234. setTimeout(()=>{uni.navigateBack();},200);
  235. } else {
  236. uni.showModal({title: '系统提示',content: res.msg,showCancel: false});
  237. }
  238. })
  239. .catch(err=>{
  240. console.log(err);
  241. uni.hideLoading();
  242. uni.showModal({title: '系统提示',content: '加载失败,返回在尝试',showCancel: false});
  243. });
  244. }
  245. }
  246. }
  247. </script>
  248. <style>
  249. .app{width: 100vw;height: 100vh;}
  250. /* #ifdef H5 */
  251. .app{height: calc(100vh - 95px);}
  252. /* #endif */
  253. .app-run .text{font-size: 24px;font-weight: bold;color: #737373;}
  254. .choice {
  255. width: 110rpx;
  256. height: 110rpx;
  257. position: fixed;
  258. top: 40%;
  259. left: 50%;
  260. transform: translate(-50%,-50%);
  261. background: rgba(0,0,0,0.3);
  262. color: #fff;
  263. border-radius: 20rpx;
  264. text-align: center;
  265. line-height: 110rpx;
  266. font-size: 45rpx;
  267. z-index: 2;
  268. }
  269. </style>