home.vue 14 KB

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