home.vue 13 KB

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