home.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  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 v-if="isShowFlag">
  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. isShowFlag:false
  202. }
  203. },
  204. watch:{
  205. pushRes: function(value){
  206. this.getChats(false)
  207. },
  208. PageCur: function(value){
  209. if(value == 'msg'){
  210. this.getChats(false)
  211. }
  212. }
  213. },
  214. mounted() {
  215. this.getChats(false)
  216. },
  217. computed: {
  218. ...mapState(['hasLogin', 'userInfo'])
  219. },
  220. onShow() {
  221. uni.hideTabBar()
  222. this.userInfo = uni.getStorageSync("userInfo")
  223. console.log(this.userData.user.realname,this.userInfo.nickname)
  224. // if(this.userData.user.realname == this.userInfo.nickname){
  225. // var context = this.userData.user.realname
  226. // var type = 0
  227. // this.$u.route({
  228. // url: 'pageC/chat/updateGroupInfo',
  229. // params: { context, type }
  230. // });
  231. // }
  232. this.$socket.showLoginDialog = false
  233. uni.hideLoading()
  234. if(this.PageCur=='msg'){
  235. this.getChats(false)
  236. }else if(this.PageCur=='contract'){
  237. this.getFriends(false)
  238. }else if(this.PageCur=='find'){
  239. this.querylinkItem(false)
  240. }
  241. },
  242. onPageScroll(e) {
  243. this.scrollTop = e.scrollTop;
  244. },
  245. onLoad(){
  246. if (!this.hasLogin) {
  247. uni.showModal({
  248. title: '登录提示',
  249. content: '您尚未登录,是否立即登录?',
  250. showCancel: true,
  251. confirmText: '登录',
  252. success: (e) => {
  253. if (e.confirm) {
  254. uni.navigateTo({
  255. url: '/pages/public/login'
  256. })
  257. }
  258. else{
  259. uni.switchTab({
  260. url: '/pages/sale/information'
  261. });
  262. }
  263. },
  264. fail: () => {},
  265. complete: () => {}
  266. })
  267. }
  268. else{
  269. uni.hideTabBar()
  270. }
  271. },
  272. onPullDownRefresh() {
  273. if(this.PageCur=='msg'){
  274. this.getChats(true)
  275. }else if(this.PageCur=='contract'){
  276. this.getFriends(true)
  277. }else if(this.PageCur=='find'){
  278. this.querylinkItem(true)
  279. }
  280. },
  281. methods: {
  282. back(){
  283. uni.switchTab({
  284. url:'/pages/sale/information'
  285. })
  286. },
  287. tabClick: function(e) {
  288. this.PageCur = e.currentTarget.dataset.cur
  289. if(this.PageCur=='msg'){
  290. this.getChats(false)
  291. }else if(this.PageCur=='contract'){
  292. this.getFriends(false)
  293. }else if(this.PageCur=='find'){
  294. const that = this
  295. that.$api.request('user', 'test', failres => {
  296. that.$api.msg(failres.errmsg)
  297. uni.hideLoading()
  298. }).then(res => {
  299. console.log("res === ",res)
  300. if(res.data){
  301. that.isShowFlag = true
  302. }
  303. this.querylinkItem(false)
  304. uni.hideLoading()
  305. })
  306. }
  307. },
  308. linkTochat(item){
  309. this.$u.vuex('chatObj', item)
  310. this.$u.route({
  311. url: 'pageC/chat/chat',
  312. params: {}
  313. });
  314. },
  315. getChats(freshFlag){
  316. if(this.userData.user==undefined){
  317. return;
  318. }
  319. // uni.showLoading({
  320. // title: '正在加载'
  321. // })
  322. this.$socket.queryChats('', this.userData.user.operId,(res) => {
  323. if (res.success) {
  324. res.chats.sort((a, b) => { return b.lastOpenTime - a.lastOpenTime });
  325. this.$u.vuex('chatItem', res.chats);
  326. }
  327. if(freshFlag){
  328. uni.stopPullDownRefresh();
  329. }
  330. uni.hideLoading()
  331. });
  332. },
  333. //打开或者关闭弹窗
  334. showSelect(){
  335. this.selectShow = !this.selectShow;
  336. },
  337. //action 点击事件
  338. click(index,index1) {
  339. if(index1==0){
  340. this.chatItem[index].isTop = true;
  341. // TODO 留空
  342. }else {
  343. this.chatItem.splice(index, 1);
  344. let obj = this.chatItem[index==this.chatItem.length?index-1:index];
  345. this.$socket.delChat(this.userData.user.operId, obj.id, (res) => {})
  346. }
  347. },
  348. //action 打开事件
  349. open(index) {
  350. this.chatItem[index].show = true;
  351. this.chatItem.map((val, idx) => {
  352. if (index != idx) this.chatItem[idx].show = false;
  353. });
  354. },
  355. //点击导航栏自定义按钮
  356. onNavigationBarButtonTap({ index }) {
  357. if (index == 0) {
  358. this.showSelect()
  359. }
  360. },
  361. //关闭弹窗
  362. closeSelect(){
  363. //小程序兼容
  364. this.selectShow = false;
  365. },
  366. getFriends (freshFlag) {
  367. // uni.showLoading({
  368. // title: '正在加载'
  369. // })
  370. // #ifndef H5
  371. var list = [];
  372. selectFSQL(this.userData.user.operId).then(res=>{
  373. this.indexList.forEach(name=>{
  374. var members = [];
  375. res.forEach(f=>{
  376. if(f.name===name){
  377. members.push(f);
  378. }
  379. });
  380. let obj = {
  381. name: name,
  382. members: members
  383. };
  384. list.push(obj);
  385. });
  386. this.$u.vuex('firendItem', list);
  387. if(freshFlag){
  388. uni.stopPullDownRefresh();
  389. }
  390. uni.hideLoading()
  391. });
  392. // #endif
  393. // #ifndef APP-PLUS
  394. this.$socket.listGuests(this.userData.user.operId, res => {
  395. this.$u.vuex('firendItem', res.response.data)
  396. if(freshFlag){
  397. uni.stopPullDownRefresh();
  398. }
  399. uni.hideLoading()
  400. })
  401. // #endif
  402. },
  403. linkToCard({id}){
  404. console.log("linkToCard")
  405. this.$u.route({
  406. url: 'pageC/businessCard/businessCard',
  407. params:{ id: id, source: 1}
  408. });
  409. },
  410. //扫码
  411. checkSelect(index) {
  412. if (index == 0) {
  413. this.$u.route({
  414. url:"pageD/search/search",
  415. params: {searchType: 0}
  416. })
  417. }
  418. else if (index == 1) {
  419. //扫码
  420. const t = this
  421. uni.scanCode({
  422. success: function(res) {
  423. uni.vibrateLong();
  424. console.log('条码内容:' + res.result);
  425. let uId = res.result
  426. if (uId==t.userData.user.operId){
  427. uni.showToast({
  428. icon:'none',
  429. title:'不能添加自己为好友'
  430. })
  431. } else {
  432. t.$u.route({
  433. url: 'pageC/businessCard/businessCard',
  434. params:{ id: uId, source: 2}
  435. })
  436. }
  437. }
  438. });
  439. }
  440. },
  441. // 发现
  442. querylinkItem(freshFlag){
  443. this.$socket.getLinks(this.userData.user.operId, res=>{
  444. this.$u.vuex('linkItem',res.response.data)
  445. if(freshFlag){
  446. uni.stopPullDownRefresh();
  447. }
  448. });
  449. },
  450. linkToMoment(){
  451. this.$u.route({
  452. url:'pageC/firendCircle/firendCircle'
  453. })
  454. },
  455. linkToScan(){
  456. uni.scanCode({
  457. success: function(res) {
  458. uni.vibrateLong();
  459. let uId = res.result
  460. if (uId==t.userData.user.operId){
  461. uni.showToast({
  462. icon:'none',
  463. title:'暂不支持添加自己'
  464. })
  465. } else {
  466. t.$u.route({
  467. url: 'pageC/businessCard/businessCard',
  468. params:{ id: uId, source: 2}
  469. })
  470. }
  471. }
  472. });
  473. },
  474. linkTo(item, index){
  475. this.$u.route({
  476. url:'pageA/webview/webview',
  477. params:{url:item.url,name:item.title}
  478. })
  479. },
  480. // 我
  481. linkTomy(index) {
  482. const url = index == 1 ? '/pageC/my/face' : '/pageC/my/photo'
  483. this.$u.route({
  484. url: url
  485. });
  486. },
  487. linkToSetting() {
  488. this.$u.route({
  489. url: 'pageC/setings/setings'
  490. });
  491. },
  492. linkToPerson() {
  493. this.$u.route({
  494. url: 'pageC/my/person'
  495. });
  496. },
  497. previewImage() {
  498. let current = this.userData.user.avatar
  499. uni.previewImage({
  500. current,
  501. urls: [current],
  502. // #ifndef MP-WEIXIN
  503. indicator: 'number'
  504. // #endif
  505. });
  506. }
  507. },
  508. };
  509. </script>
  510. <style lang="scss" scoped>
  511. .status_bar{
  512. height: var(--status-bar-height);
  513. width: 100%;
  514. }
  515. .content {
  516. height: 100%;
  517. background:#fff;
  518. }
  519. .tarbar {
  520. width: 100%;
  521. height: 96rpx;
  522. display: flex;
  523. justify-content: space-around;
  524. background-color: #FFFFFF;
  525. position: fixed;
  526. bottom: 0;
  527. z-index: 100;
  528. font-size: 26rpx;
  529. color: #999999;
  530. }
  531. .tarbar view {
  532. text-align: center;
  533. }
  534. .cuIcon-back{
  535. font-size:45rpx;
  536. margin-left:10rpx;
  537. }
  538. </style>