card_list.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. }
  85. },
  86. onShow(){
  87. _hook.routeTabBarHook();
  88. },
  89. onLoad(option) {
  90. let _this = this,
  91. friend_list = _data.localData('friend_list'),
  92. send_data = { list_id: option.list_id,friend: 1 };
  93. _this.list_id = option.list_id;
  94. /** 这里初始化好友列表 */
  95. if(!friend_list){
  96. send_data.friend = 1;
  97. }
  98. _get.getFriendList(send_data,(data) => {
  99. let data_list = _data.localData('friend_list');
  100. let len = data_list.length || Object.keys(data_list).length;
  101. console.log(data_list)
  102. for(let i in data_list ){
  103. for(let k = 0,o = data_list[i].data,l = o.length;k < l;k ++){
  104. o[k].other = false;
  105. }
  106. _this.list_data.push(data_list[i]);
  107. }
  108. });
  109. let winHeight = uni.getSystemInfoSync().windowHeight;
  110. _this.itemHeight = winHeight / 26;
  111. _this.winHeight = winHeight;
  112. },
  113. computed: {
  114. staticPhoto(){
  115. return _data.staticPhoto();
  116. },
  117. imgRan(){
  118. return Math.random();
  119. },
  120. },
  121. methods: {
  122. imageError(e){
  123. console.log("图片加载失败!",e.detail);
  124. let index = e.currentTarget.dataset.index
  125. console.log(e.currentTarget.dataset.index)
  126. //替换index对应的图片
  127. console.log(this.list[index].photo_path)
  128. this.list[index].photo_path = '/default_photo_path.png';
  129. },
  130. change(user_id){
  131. if(user_id){
  132. let i = this.add_user_ids.indexOf(user_id);
  133. if(i > -1){
  134. this.add_user_ids.splice(i,1);
  135. this.list_data
  136. }else{
  137. this.add_user_ids.push(user_id);
  138. }
  139. }
  140. },
  141. isKey(key,index){
  142. return key + '' + index;
  143. },
  144. touchStart(e) {
  145. this.touchmove = true;
  146. let pageY = e.touches[0].pageY;
  147. let index = Math.floor((pageY - this.titleHeight) / this.itemHeight);
  148. let item = this.list_data[index];
  149. if (item) {
  150. this.scrollViewId = item.letter;
  151. this.touchmoveIndex = index;
  152. }
  153. },
  154. touchMove(e) {
  155. let pageY = e.touches[0].pageY;
  156. let index = Math.floor((pageY - this.titleHeight) / this.itemHeight);
  157. let item = this.list_data[index];
  158. if (item) {
  159. this.scrollViewId = item.letter;
  160. this.touchmoveIndex = index;
  161. }
  162. },
  163. touchEnd() {
  164. this.touchmove = false;
  165. //this.touchmoveIndex = -1;
  166. },
  167. touchCancel() {
  168. this.touchmove = false;
  169. //this.touchmoveIndex = -1;
  170. },
  171. },
  172. watch: {
  173. },
  174. onNavigationBarButtonTap(e) {
  175. let _this = this;
  176. if(_this.add_user_ids.length){
  177. let path = '/im/message/sendCard';
  178. _get.sendCard({ users: JSON.stringify(_this.add_user_ids),list_id: _this.list_id},function () {
  179. uni.redirectTo({
  180. url: '../message?list_id=' + _this.list_id,
  181. });
  182. })
  183. }else{
  184. uni.redirectTo({
  185. url: '../message?list_id=' + _this.list_id,
  186. });
  187. }
  188. }
  189. }
  190. </script>
  191. <style>
  192. .page .content{
  193. display: flex;
  194. flex-direction:row;
  195. }
  196. .page {
  197. /*display: flex;*/
  198. /*flex-direction:row;*/
  199. background-color: white;
  200. }
  201. .scrollList {
  202. flex: 1;
  203. height: 100vh;
  204. margin-top: 20upx;
  205. width: 100%;
  206. }
  207. .uni-indexed-list-bar {
  208. width: 40upx;
  209. height: 100vh;
  210. background-color: white;
  211. display: flex;
  212. flex-direction: column;
  213. z-index: 20;
  214. }
  215. .uni-list-cell-divider{
  216. background-color: #e5e5e5;
  217. padding: 4upx 18px !important;
  218. }
  219. .uni-indexed-list-bar.active {
  220. /* background-color: rgb(200, 200, 200); */
  221. }
  222. .uni-list-cell-pd{
  223. padding: 0 12px !important;
  224. }
  225. .uni-media-list{
  226. padding: 4px 8px !important;
  227. }
  228. .uni-indexed-list-text {
  229. font-size: 22upx;
  230. text-align: center;
  231. }
  232. .uni-indexed-list-bar.active .uni-indexed-list-text {
  233. color: #333;
  234. }
  235. .uni-indexed-list-text.active,
  236. .uni-indexed-list-bar.active .uni-indexed-list-text.active {
  237. color: #02b300;
  238. }
  239. .uni-indexed-list-alert {
  240. position: absolute;
  241. z-index: 20;
  242. width: 160upx;
  243. height: 160upx;
  244. left: 50%;
  245. top: 50%;
  246. margin-left: -80upx;
  247. margin-top: -80upx;
  248. border-radius: 80upx;
  249. text-align: center;
  250. line-height: 160upx;
  251. font-size: 70upx;
  252. color: #fff;
  253. background-color: rgba(0, 0, 0, 0.5);
  254. }
  255. .header {
  256. display: flex;
  257. flex-direction: row;
  258. padding: 10px 15px;
  259. align-items: center;
  260. }
  261. .input-view {
  262. display: flex;
  263. align-items: center;
  264. flex-direction: row;
  265. background-color: #e7e7e7;
  266. height: 30px;
  267. border-radius: 5px;
  268. padding: 0 10px;
  269. flex: 1;
  270. }
  271. .input {
  272. flex: 1;
  273. padding: 0 5px;
  274. height: 24px;
  275. line-height: 24px;
  276. font-size: 16px;
  277. }
  278. .uni-list-cell-navigate {
  279. padding: 0;
  280. }
  281. .uni-media-list-body {
  282. height: auto;
  283. }
  284. </style>