home.vue 14 KB

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