home.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479
  1. <template>
  2. <view class="content">
  3. <block v-if='PageCur=="msg"'>
  4. <!-- #ifdef MP-WEIXIN -->
  5. <u-navbar :is-back="false" title="消息" :background="{ background: '#F6F7F8' }" title-color="#404133" :border-bottom="false" z-index="1001">
  6. <view class="slot-wrap">
  7. <text class = 'tip_text cuIcon-back' @click='back' ></text>
  8. </view>
  9. <view class="slot-wrap" slot="right">
  10. <u-icon name="plus-circle" size="34" @click="showSelect"></u-icon>
  11. </view>
  12. </u-navbar>
  13. <!-- #endif -->
  14. <selectInput :list="selectList" :list-key="'name'" :show.sync="selectShow" @on-select="checkSelect" @close="closeSelect" />
  15. <searchInput :searchType="1"/>
  16. <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">
  17. <chatItem @linkTo="linkTochat" :value="item" :index="index" :voiceIcon="true"></chatItem>
  18. </u-swipe-action>
  19. </block>
  20. <block v-if='PageCur=="contract"'>
  21. <!-- #ifdef MP-WEIXIN -->
  22. <u-navbar :is-back="false" title="通讯录" :background="{ background: '#F6F7F8' }" title-color="#404133" :border-bottom="false" z-index="1001">
  23. <view class="slot-wrap">
  24. <text class = 'tip_text cuIcon-back' @click='back'></text>
  25. </view>
  26. </u-navbar>
  27. <!-- #endif -->
  28. <searchInput :searchType="2"/>
  29. <addressBook :list="firendItem" :scrollTop="scrollTop" :isShowMenu="true" @linkTo="linkToCard"></addressBook>
  30. </block>
  31. <block v-if='PageCur=="find"'>
  32. <!-- #ifdef MP-WEIXIN -->
  33. <u-navbar :is-back="false" title="发现" :background="{ background: '#F6F7F8' }" title-color="#404133" :border-bottom="false" z-index="1001">
  34. <view class="slot-wrap">
  35. <text class = 'tip_text cuIcon-back' @click='back' ></text>
  36. </view>
  37. </u-navbar>
  38. <!-- #endif -->
  39. <u-cell-group>
  40. <u-cell-item title="粮友圈" :title-style="{marginLeft:'30rpx',fontWeight:'800'}" @tap="linkToMoment">
  41. <u-icon slot="icon" name="moments" color="#409eff" size="40"></u-icon>
  42. </u-cell-item>
  43. </u-cell-group>
  44. <view style="height: 10rpx;"></view>
  45. <u-cell-group>
  46. <u-cell-item title="扫一扫" :title-style="{marginLeft:'30rpx',fontWeight:'800'}" @tap="linkToScan">
  47. <u-icon slot="icon" name="scan" color="#409eff" size="40"></u-icon>
  48. </u-cell-item>
  49. </u-cell-group>
  50. <view style="height: 10rpx;"></view>
  51. <view class="" v-for="(item,index) in linkItem" :key="index">
  52. <u-cell-group>
  53. <u-cell-item :title="item.title" :title-style="{marginLeft:'30rpx',fontWeight:'800'}" @tap="linkTo(item,index)">
  54. <u-icon slot="icon" :name="item.icon" :color="item.color" size="40"></u-icon>
  55. </u-cell-item>
  56. </u-cell-group>
  57. <view v-if="index!=linkItem.length" class="" style="height: 10rpx;"></view>
  58. </view>
  59. </block>
  60. <block v-if='PageCur=="my"'>
  61. <!-- #ifdef MP-WEIXIN -->
  62. <u-navbar :is-back="false" title=" " :border-bottom="false">
  63. <view class="slot-wrap">
  64. <text class = 'tip_text cuIcon-back' @click='back' ></text>
  65. </view>
  66. <view class="u-flex u-row-right" style="width: 100%;">
  67. <view class="camera u-flex u-row-center">
  68. <u-icon @tap="linkToMoment" name="camera-fill" color="#000000" size="48"></u-icon>
  69. </view>
  70. </view>
  71. </u-navbar>
  72. <!-- #endif -->
  73. <view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30" @tap="linkToPerson">
  74. <view class="u-m-r-10">
  75. <u-avatar mode="square" :src="userData.user.avatar" size="140"></u-avatar>
  76. </view>
  77. <view class="u-flex-1">
  78. <view class="u-font-18 u-p-b-20">{{userData.user.realname}}</view>
  79. <view class="u-font-14 u-tips-color">积分: {{userData.user.money}}</view>
  80. </view>
  81. <view class="u-m-l-10 u-p-10">
  82. <u-icon name="arrow-right" color="#969799" size="28"></u-icon>
  83. </view>
  84. </view>
  85. <view class="u-m-t-20">
  86. <u-cell-group>
  87. <u-cell-item @tap="linkTomy(index)" v-for="(item, index) in groupList" :key="index" :title="item.title" :title-style="{ marginLeft: '30rpx' ,fontWeight:'800'}">
  88. <u-icon slot="icon" :name="item.icon" :color="item.color" size="40"></u-icon>
  89. </u-cell-item>
  90. </u-cell-group>
  91. </view>
  92. <view class="u-m-t-20">
  93. <u-cell-group>
  94. <u-cell-item @click="linkToSetting" title="设置" :title-style="{ marginLeft: '30rpx' ,fontWeight:'800'}">
  95. <u-icon slot="icon" name="setting" color="#409eff" size="40"></u-icon>
  96. </u-cell-item>
  97. </u-cell-group>
  98. </view>
  99. </block>
  100. <view class="cu-bar tabbar bg-white shadow foot">
  101. <view :class="PageCur=='msg'?'action text-pink':'action text-gray'" @click="tabClick" data-cur="msg">
  102. <view :class="PageCur=='msg'?'cuIcon-message':'cuIcon-message'"></view> 消息
  103. </view>
  104. <view :class="PageCur=='contract'?'action text-pink':'action text-gray'" @click="tabClick" data-cur="contract">
  105. <view :class="PageCur=='contract'?'cuIcon-addressbook':'cuIcon-addressbook'"></view> 通讯录
  106. </view>
  107. <view :class="PageCur=='find'?'action text-pink':'action text-gray'" @click="tabClick" data-cur="find">
  108. <view :class="PageCur=='find'?'cuIcon-friendfill':'cuIcon-friendfill'"></view> 发现
  109. </view>
  110. <view :class="PageCur=='my'?'action text-pink':'action text-gray'" @click="tabClick" data-cur="my">
  111. <view :class="PageCur=='my'?'cuIcon-people':'cuIcon-people'"></view> 我的
  112. </view>
  113. </view>
  114. </view>
  115. </template>
  116. <script>
  117. import searchInput from '@/components/searchInput/index.vue';
  118. import selectInput from '@/components/selectInput/selectInput.vue';
  119. import chatItem from '@/components/chatItem.vue';
  120. import addressBook from '@/components/addressBook.vue';
  121. import { openFSqlite , createFSQL, selectFSQL, addFSQL } from '../../util/f.js'
  122. import {
  123. mapState
  124. } from 'vuex';
  125. export default {
  126. components: { searchInput, selectInput,chatItem, addressBook},
  127. data() {
  128. return {
  129. selectShow: false,
  130. PageCur: "msg",
  131. options: [
  132. {
  133. text: '置顶',
  134. style: {
  135. backgroundColor: '#b4b4b4',
  136. fontSize: '24rpx'
  137. }
  138. },
  139. {
  140. text: '删除',
  141. style: {
  142. backgroundColor: '#dd524d',
  143. fontSize: '24rpx'
  144. }
  145. }
  146. ],
  147. scrollTop: 0,
  148. selectList: [
  149. { id: '1', name: '添加粮友', icon: 'man-add-fill' },
  150. { id: '2', name: '扫一扫', icon: 'scan' },
  151. { id: '3', name: '收付款', icon: 'fingerprint' }
  152. ],
  153. pic:'',
  154. show:true,
  155. tar:{
  156. color:'#07A7E3',
  157. id:4
  158. },
  159. groupList: [
  160. {
  161. title: '相册',
  162. color: '#50E3C2',
  163. icon: 'photo'
  164. },
  165. {
  166. title: '表情',
  167. color: '#ff9900',
  168. icon: 'star'
  169. }
  170. ],
  171. $url:'',
  172. userInfo:[]
  173. }
  174. },
  175. watch:{
  176. pushRes: function(value){
  177. this.getChats(false)
  178. },
  179. PageCur: function(value){
  180. if(value == 'msg'){
  181. this.getChats(false)
  182. }
  183. }
  184. },
  185. mounted() {
  186. this.getChats(false)
  187. },
  188. computed: {
  189. ...mapState(['userInfo'])
  190. },
  191. onShow() {
  192. this.userInfo = uni.getStorageSync("userInfo")
  193. console.log(this.userData.user.realname,this.userInfo.nickname)
  194. // if(this.userData.user.realname == this.userInfo.nickname){
  195. // var context = this.userData.user.realname
  196. // var type = 0
  197. // this.$u.route({
  198. // url: 'pageC/chat/updateGroupInfo',
  199. // params: { context, type }
  200. // });
  201. // }
  202. this.$socket.showLoginDialog = false
  203. uni.hideLoading()
  204. if(this.PageCur=='msg'){
  205. this.getChats(false)
  206. }else if(this.PageCur=='contract'){
  207. this.getFriends(false)
  208. }else if(this.PageCur=='find'){
  209. this.querylinkItem(false)
  210. }
  211. },
  212. onPageScroll(e) {
  213. this.scrollTop = e.scrollTop;
  214. },
  215. onLoad(){
  216. uni.setTabBarItem({
  217. index: 1,
  218. pagePath:'pages/addressBook/addressBook'
  219. })
  220. },
  221. onPullDownRefresh() {
  222. if(this.PageCur=='msg'){
  223. this.getChats(true)
  224. }else if(this.PageCur=='contract'){
  225. this.getFriends(true)
  226. }else if(this.PageCur=='find'){
  227. this.querylinkItem(true)
  228. }
  229. },
  230. methods: {
  231. back(){
  232. uni.switchTab({
  233. url:'/pages/sale/information'
  234. })
  235. },
  236. tabClick: function(e) {
  237. this.PageCur = e.currentTarget.dataset.cur
  238. if(this.PageCur=='msg'){
  239. this.getChats(false)
  240. }else if(this.PageCur=='contract'){
  241. this.getFriends(false)
  242. }else if(this.PageCur=='find'){
  243. this.querylinkItem(false)
  244. }
  245. },
  246. linkTochat(item){
  247. this.$u.vuex('chatObj', item)
  248. this.$u.route({
  249. url: 'pageC/chat/chat',
  250. params: {}
  251. });
  252. },
  253. getChats(freshFlag){
  254. if(this.userData.user==undefined){
  255. return;
  256. }
  257. uni.showLoading({
  258. title: '正在加载'
  259. })
  260. this.$socket.queryChats('', this.userData.user.operId,(res) => {
  261. if (res.success) {
  262. res.chats.sort((a, b) => { return b.lastOpenTime - a.lastOpenTime });
  263. this.$u.vuex('chatItem', res.chats);
  264. }
  265. if(freshFlag){
  266. uni.stopPullDownRefresh();
  267. }
  268. uni.hideLoading()
  269. });
  270. },
  271. //打开或者关闭弹窗
  272. showSelect(){
  273. this.selectShow = !this.selectShow;
  274. },
  275. //action 点击事件
  276. click(index,index1) {
  277. if(index1==0){
  278. this.chatItem[index].isTop = true;
  279. // TODO 留空
  280. }else {
  281. this.chatItem.splice(index, 1);
  282. let obj = this.chatItem[index==this.chatItem.length?index-1:index];
  283. this.$socket.delChat(this.userData.user.operId, obj.id, (res) => {})
  284. }
  285. },
  286. //action 打开事件
  287. open(index) {
  288. this.chatItem[index].show = true;
  289. this.chatItem.map((val, idx) => {
  290. if (index != idx) this.chatItem[idx].show = false;
  291. });
  292. },
  293. //点击导航栏自定义按钮
  294. onNavigationBarButtonTap({ index }) {
  295. if (index == 0) {
  296. this.showSelect()
  297. }
  298. },
  299. //关闭弹窗
  300. closeSelect(){
  301. //小程序兼容
  302. this.selectShow = false;
  303. },
  304. getFriends (freshFlag) {
  305. uni.showLoading({
  306. title: '正在加载'
  307. })
  308. // #ifndef H5
  309. var list = [];
  310. selectFSQL(this.userData.user.operId).then(res=>{
  311. this.indexList.forEach(name=>{
  312. var members = [];
  313. res.forEach(f=>{
  314. if(f.name===name){
  315. members.push(f);
  316. }
  317. });
  318. let obj = {
  319. name: name,
  320. members: members
  321. };
  322. list.push(obj);
  323. });
  324. this.$u.vuex('firendItem', list);
  325. if(freshFlag){
  326. uni.stopPullDownRefresh();
  327. }
  328. uni.hideLoading()
  329. });
  330. // #endif
  331. // #ifndef APP-PLUS
  332. this.$socket.listGuests(this.userData.user.operId, res => {
  333. this.$u.vuex('firendItem', res.response.data)
  334. if(freshFlag){
  335. uni.stopPullDownRefresh();
  336. }
  337. uni.hideLoading()
  338. })
  339. // #endif
  340. },
  341. linkToCard({id}){
  342. console.log("linkToCard")
  343. this.$u.route({
  344. url: 'pageC/businessCard/businessCard',
  345. params:{ id: id, source: 1}
  346. });
  347. },
  348. //扫码
  349. checkSelect(index) {
  350. if (index == 0) {
  351. this.$u.route({
  352. url:"pageD/search/search",
  353. params: {searchType: 0}
  354. })
  355. }
  356. else if (index == 1) {
  357. //扫码
  358. const t = this
  359. uni.scanCode({
  360. success: function(res) {
  361. uni.vibrateLong();
  362. console.log('条码内容:' + res.result);
  363. let uId = res.result
  364. if (uId==t.userData.user.operId){
  365. uni.showToast({
  366. icon:'none',
  367. title:'不能添加自己为好友'
  368. })
  369. } else {
  370. t.$u.route({
  371. url: 'pageC/businessCard/businessCard',
  372. params:{ id: uId, source: 2}
  373. })
  374. }
  375. }
  376. });
  377. }
  378. },
  379. // 发现
  380. querylinkItem(freshFlag){
  381. this.$socket.getLinks(this.userData.user.operId, res=>{
  382. this.$u.vuex('linkItem',res.response.data)
  383. if(freshFlag){
  384. uni.stopPullDownRefresh();
  385. }
  386. });
  387. },
  388. linkToMoment(){
  389. this.$u.route({
  390. url:'pageC/firendCircle/firendCircle'
  391. })
  392. },
  393. linkToScan(){
  394. uni.scanCode({
  395. success: function(res) {
  396. uni.vibrateLong();
  397. let uId = res.result
  398. if (uId==t.userData.user.operId){
  399. uni.showToast({
  400. icon:'none',
  401. title:'暂不支持添加自己'
  402. })
  403. } else {
  404. t.$u.route({
  405. url: 'pageC/businessCard/businessCard',
  406. params:{ id: uId, source: 2}
  407. })
  408. }
  409. }
  410. });
  411. },
  412. linkTo(item, index){
  413. this.$u.route({
  414. url:'pageA/webview/webview',
  415. params:{url:item.url,name:item.title}
  416. })
  417. },
  418. // 我
  419. linkTomy(index) {
  420. const url = index == 1 ? '/pageC/my/face' : '/pageC/my/photo'
  421. this.$u.route({
  422. url: url
  423. });
  424. },
  425. linkToSetting() {
  426. this.$u.route({
  427. url: 'pageC/setings/setings'
  428. });
  429. },
  430. linkToPerson() {
  431. this.$u.route({
  432. url: 'pageC/my/person'
  433. });
  434. },
  435. previewImage() {
  436. let current = this.userData.user.avatar
  437. uni.previewImage({
  438. current,
  439. urls: [current],
  440. // #ifndef MP-WEIXIN
  441. indicator: 'number'
  442. // #endif
  443. });
  444. }
  445. },
  446. };
  447. </script>
  448. <style lang="scss" scoped>
  449. .content {
  450. height: 100%;
  451. background:#fff;
  452. }
  453. .tarbar {
  454. width: 100%;
  455. height: 96rpx;
  456. display: flex;
  457. justify-content: space-around;
  458. background-color: #FFFFFF;
  459. position: fixed;
  460. bottom: 0;
  461. z-index: 100;
  462. font-size: 26rpx;
  463. color: #999999;
  464. }
  465. .tarbar view {
  466. text-align: center;
  467. }
  468. .cuIcon-back{
  469. font-size:45rpx;
  470. margin-left:10rpx;
  471. }
  472. </style>