index_list.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <template>
  2. <view class="page">
  3. <uni-search-bar placeholder="搜索" :show="false" @confirm="search"></uni-search-bar>
  4. <view class="content">
  5. <scroll-view class="scrollList" scroll-y :scroll-into-view="scrollViewId" :style="{height:winHeight + 'px'}">
  6. <view class="uni-list">
  7. <block v-for="(list, key) in list_data" :key="key">
  8. <view class="uni-list-cell-divider" :id="list.letter">
  9. {{list.letter}}
  10. </view>
  11. <view class="uni-list-cell"
  12. hover-class="none"
  13. v-for="(item,index) of list.data"
  14. :class="list.data.length -1 == index ? 'uni-list-cell-last' : ''"
  15. :key="isKey(key,index)"
  16. >
  17. <checkbox-group @change="change(item.user_id + '')" >
  18. <label class="uni-list-cell uni-list-cell-pd">
  19. <view>
  20. <checkbox color="#02b300"
  21. :checked="item.other"
  22. :disabled="item.other"
  23. :value="item.user_id + ''"
  24. />
  25. </view>
  26. <view class="uni-media-list">
  27. <view class="uni-media-list-logo">
  28. <image :data-index="index" :src="staticPhoto + item.photo" :lazy-load="true" style="border-radius: 10px;" @error="imageError" />
  29. </view>
  30. <view class="uni-media-list-body">
  31. <view class="uni-list-cell-navigate">{{item.name}}</view>
  32. </view>
  33. </view>
  34. </label>
  35. </checkbox-group>
  36. </view>
  37. </block>
  38. </view>
  39. </scroll-view>
  40. <view class="uni-indexed-list-bar" :class="touchmove ? 'active' : ''"
  41. @touchstart="touchStart"
  42. @touchmove.stop.prevent="touchMove"
  43. @touchend="touchEnd"
  44. @touchcancel="touchCancel"
  45. :style="{height:winHeight + 'px'}">
  46. <text v-for="(list,key) in list_data" :key="key" class="uni-indexed-list-text" :class="touchmoveIndex == key ? 'active' : ''"
  47. :style="{height:itemHeight + 'px',lineHeight:itemHeight + 'px'}">
  48. {{list.letter}}
  49. </text>
  50. </view>
  51. <view class="uni-indexed-list-alert" v-if="touchmove">
  52. {{list_data[touchmoveIndex].letter}}
  53. </view>
  54. </view>
  55. </view>
  56. </template>
  57. <script>
  58. import uniIcon from '../../components/uni-ui/uni-icon/uni-icon.vue';
  59. import uniList from '../../components/uni-ui/uni-list/uni-list.vue';
  60. import uniListItem from '../../components/uni-ui/uni-list-item/uni-list-item.vue';
  61. import _get from '../../common/_get';
  62. import _hook from '../../common/_hook';
  63. import _data from '../../common/_data';
  64. import uniSearchBar from '@/components/mehaotian-search/mehaotian-search.vue'
  65. export default {
  66. components: {
  67. uniIcon,
  68. uniList,
  69. uniListItem,
  70. uniSearchBar
  71. },
  72. data() {
  73. return {
  74. list_data: [],
  75. title: 'grid',
  76. touchmove: false,
  77. touchmoveIndex: -1,
  78. itemHeight: 0,
  79. winHeight: 0,
  80. scrollViewId: "A",
  81. titleHeight: 0,
  82. list_id: 0,
  83. add_user_ids: [],
  84. loading:false,
  85. }
  86. },
  87. onShow(){
  88. _hook.routeTabBarHook();
  89. },
  90. onLoad(option) {
  91. let _this = this,
  92. friend_list = _data.localData('friend_list'),
  93. send_data = { list_id: option.list_id,friend: 1 };
  94. _this.list_id = option.list_id;
  95. /** 这里初始化好友列表 */
  96. if(!friend_list){
  97. send_data.friend = 1;
  98. }
  99. _get.getFriendList(send_data,(data) => {
  100. let data_list = _data.localData('friend_list');
  101. let len = data_list.length || Object.keys(data_list).length;
  102. console.log(data_list)
  103. for(let i in data_list ){
  104. for(let k = 0,o = data_list[i].data,l = o.length;k < l;k ++){
  105. o[k].other = data.member.indexOf(o[k].user_id) > -1 ? true : false;
  106. }
  107. _this.list_data.push(data_list[i]);
  108. }
  109. });
  110. let winHeight = uni.getSystemInfoSync().windowHeight;
  111. _this.itemHeight = winHeight / 26;
  112. _this.winHeight = winHeight;
  113. },
  114. computed: {
  115. staticPhoto(){
  116. return _data.staticPhoto();
  117. },
  118. imgRan(){
  119. return Math.random();
  120. },
  121. },
  122. methods: {
  123. imageError(e){
  124. console.log("图片加载失败!",e.detail);
  125. let index = e.currentTarget.dataset.index
  126. console.log(e.currentTarget.dataset.index)
  127. //替换index对应的图片
  128. console.log(this.list[index].photo_path)
  129. this.list[index].photo_path = '/default_photo_path.png';
  130. },
  131. change(user_id){
  132. if(user_id){
  133. let i = this.add_user_ids.indexOf(user_id);
  134. if(i > -1){
  135. this.add_user_ids.splice(i,1);
  136. this.list_data
  137. }else{
  138. this.add_user_ids.push(user_id);
  139. }
  140. }
  141. },
  142. isKey(key,index){
  143. return key + '' + index;
  144. },
  145. touchStart(e) {
  146. this.touchmove = true;
  147. let pageY = e.touches[0].pageY;
  148. let index = Math.floor((pageY - this.titleHeight) / this.itemHeight);
  149. let item = this.list_data[index];
  150. if (item) {
  151. this.scrollViewId = item.letter;
  152. this.touchmoveIndex = index;
  153. }
  154. },
  155. touchMove(e) {
  156. let pageY = e.touches[0].pageY;
  157. let index = Math.floor((pageY - this.titleHeight) / this.itemHeight);
  158. let item = this.list_data[index];
  159. if (item) {
  160. this.scrollViewId = item.letter;
  161. this.touchmoveIndex = index;
  162. }
  163. },
  164. touchEnd() {
  165. this.touchmove = false;
  166. //this.touchmoveIndex = -1;
  167. },
  168. touchCancel() {
  169. this.touchmove = false;
  170. //this.touchmoveIndex = -1;
  171. },
  172. confirm(){
  173. },
  174. search(){
  175. }
  176. },
  177. watch: {
  178. },
  179. onNavigationBarButtonTap(e) {
  180. if(this.loading){
  181. uni.showToast({
  182. icon:'none',
  183. title:'loading'
  184. })
  185. return
  186. }
  187. this.loading = true
  188. let _this = this;
  189. if(_this.add_user_ids.length){
  190. let path = _this.list_id != '0' ? '/im/message/addChat' : '/im/message/addGroup';
  191. _this.$httpSend({
  192. path: path,
  193. data: { users: JSON.stringify(_this.add_user_ids),list_id: _this.list_id, },
  194. success_action: true,
  195. success(res) {
  196. uni.showToast({
  197. title: res.msg,
  198. duration: 1000,
  199. complete:()=>{
  200. setTimeout(()=>{
  201. this.loading = false
  202. if(_this.list_id != '0'){
  203. uni.redirectTo({
  204. url: '../chat/message?list_id=' + _this.list_id,
  205. });
  206. }else{
  207. uni.switchTab({
  208. url: '../chat/index',
  209. });
  210. }
  211. },1500)
  212. }
  213. });
  214. },
  215. fail:()=>{
  216. this.loading = false
  217. }
  218. });
  219. }else{
  220. if(_this.list_id != '0'){
  221. this.loading = false
  222. uni.redirectTo({
  223. url: '../chat/message?list_id=' + _this.list_id,
  224. });
  225. }else{
  226. uni.showToast({
  227. icon:'none',
  228. title: '未创建',
  229. complete: () => {
  230. this.loading = false
  231. // setTimeout(()=>{
  232. // uni.switchTab({
  233. // url: '../chat/index',
  234. // });
  235. // },1500)
  236. }
  237. });
  238. }
  239. }
  240. }
  241. }
  242. </script>
  243. <style>
  244. .page .content{
  245. display: flex;
  246. flex-direction:row;
  247. }
  248. .page {
  249. /*display: flex;*/
  250. /*flex-direction:row;*/
  251. background-color: white;
  252. }
  253. .scrollList {
  254. flex: 1;
  255. height: 100vh;
  256. margin-top: 20upx;
  257. width: 100%;
  258. }
  259. .uni-indexed-list-bar {
  260. width: 40upx;
  261. height: 100vh;
  262. background-color: white;
  263. display: flex;
  264. flex-direction: column;
  265. z-index: 20;
  266. }
  267. .uni-list-cell-divider{
  268. background-color: #fff;
  269. padding: 4upx 18px !important;
  270. }
  271. .uni-indexed-list-bar.active {
  272. /* background-color: rgb(200, 200, 200); */
  273. }
  274. .uni-list-cell-pd{
  275. padding: 0 12px !important;
  276. }
  277. .uni-media-list{
  278. padding: 4px 8px !important;
  279. }
  280. .uni-indexed-list-text {
  281. font-size: 22upx;
  282. text-align: center;
  283. }
  284. .uni-indexed-list-bar.active .uni-indexed-list-text {
  285. color: #333;
  286. }
  287. .uni-indexed-list-text.active,
  288. .uni-indexed-list-bar.active .uni-indexed-list-text.active {
  289. color: #02b300;
  290. }
  291. .uni-indexed-list-alert {
  292. position: absolute;
  293. z-index: 20;
  294. width: 160upx;
  295. height: 160upx;
  296. left: 50%;
  297. top: 50%;
  298. margin-left: -80upx;
  299. margin-top: -80upx;
  300. border-radius: 80upx;
  301. text-align: center;
  302. line-height: 160upx;
  303. font-size: 70upx;
  304. color: #fff;
  305. background-color: rgba(0, 0, 0, 0.5);
  306. }
  307. .header {
  308. display: flex;
  309. flex-direction: row;
  310. padding: 10px 15px;
  311. align-items: center;
  312. }
  313. .input-view {
  314. display: flex;
  315. align-items: center;
  316. flex-direction: row;
  317. background-color: #e7e7e7;
  318. height: 30px;
  319. border-radius: 5px;
  320. padding: 0 10px;
  321. flex: 1;
  322. }
  323. .input {
  324. flex: 1;
  325. padding: 0 5px;
  326. height: 24px;
  327. line-height: 24px;
  328. font-size: 16px;
  329. }
  330. .uni-list-cell-navigate {
  331. padding: 0;
  332. }
  333. .uni-media-list-body {
  334. height: auto;
  335. }
  336. </style>