home.vue 14 KB

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