home.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537
  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. <u-modal v-model="isShowAlert" :title-style="{fontSize: '18px',fontWeight:'500'}"
  114. :content-style="{fontSize: '14px',fontWeight:'400'}" confirm-color='#22C572' confirm-text='确定' title='提示'
  115. :showCancelButton='false' :content="content" @confirm="alertBtn" @cancel="cancelClick"></u-modal>
  116. </view>
  117. </template>
  118. <script>
  119. import searchInput from '@/components/searchInput/index.vue';
  120. import selectInput from '@/components/selectInput/selectInput.vue';
  121. import chatItem from '@/components/chatItem.vue';
  122. import addressBook from '@/components/addressBook.vue';
  123. import { openFSqlite , createFSQL, selectFSQL, addFSQL } from '../../util/f.js'
  124. import {
  125. mapState
  126. } from 'vuex';
  127. export default {
  128. components: { searchInput, selectInput,chatItem, addressBook},
  129. data() {
  130. return {
  131. isShowAlert: false,
  132. content: '您尚未登录,是否立即登录?',
  133. selectShow: false,
  134. PageCur: "msg",
  135. options: [
  136. {
  137. text: '置顶',
  138. style: {
  139. backgroundColor: '#b4b4b4',
  140. fontSize: '24rpx'
  141. }
  142. },
  143. {
  144. text: '删除',
  145. style: {
  146. backgroundColor: '#dd524d',
  147. fontSize: '24rpx'
  148. }
  149. }
  150. ],
  151. scrollTop: 0,
  152. selectList: [
  153. { id: '1', name: '添加粮友', icon: 'man-add-fill' },
  154. { id: '2', name: '扫一扫', icon: 'scan' },
  155. { id: '3', name: '收付款', icon: 'fingerprint' }
  156. ],
  157. pic:'',
  158. show:true,
  159. tar:{
  160. color:'#07A7E3',
  161. id:4
  162. },
  163. groupList: [
  164. {
  165. title: '相册',
  166. color: '#50E3C2',
  167. icon: 'photo'
  168. },
  169. {
  170. title: '表情',
  171. color: '#ff9900',
  172. icon: 'star'
  173. }
  174. ],
  175. $url:'',
  176. userInfo:[],
  177. isShowFlag:false
  178. }
  179. },
  180. watch:{
  181. pushRes: function(value){
  182. this.getChats(false)
  183. },
  184. PageCur: function(value){
  185. if(value == 'msg'){
  186. this.getChats(false)
  187. }
  188. }
  189. },
  190. mounted() {
  191. this.getChats(false)
  192. },
  193. computed: {
  194. ...mapState(['hasLogin', 'userInfo'])
  195. },
  196. onReady() {
  197. uni.setNavigationBarTitle({
  198. title: '新的标题'
  199. });
  200. },
  201. onShow() {
  202. uni.hideTabBar()
  203. this.userInfo = uni.getStorageSync("userInfo")
  204. console.log(this.userData.user.realname,this.userInfo.nickname)
  205. // if(this.userData.user.realname == this.userInfo.nickname){
  206. // var context = this.userData.user.realname
  207. // var type = 0
  208. // this.$u.route({
  209. // url: 'pageC/chat/updateGroupInfo',
  210. // params: { context, type }
  211. // });
  212. // }
  213. this.$socket.showLoginDialog = false
  214. uni.hideLoading()
  215. if(this.PageCur=='msg'){
  216. this.getChats(false)
  217. }else if(this.PageCur=='contract'){
  218. this.getFriends(false)
  219. }else if(this.PageCur=='find'){
  220. this.querylinkItem(false)
  221. }
  222. },
  223. onPageScroll(e) {
  224. this.scrollTop = e.scrollTop;
  225. },
  226. onLoad(){
  227. if (!this.hasLogin) {
  228. this.isShowAlert = true;
  229. // uni.showModal({
  230. // title: '提示',
  231. // content: '您尚未登录,是否立即登录?',
  232. // showCancel: true,
  233. // confirmText: '登录',
  234. // success: (e) => {
  235. // if (e.confirm) {
  236. // uni.navigateTo({
  237. // url: '/pages/public/login'
  238. // })
  239. // }
  240. // else{
  241. // uni.switchTab({
  242. // url: '/pages/sale/information'
  243. // });
  244. // }
  245. // },
  246. // fail: () => {},
  247. // complete: () => {}
  248. // })
  249. }
  250. else{
  251. uni.hideTabBar()
  252. }
  253. },
  254. onPullDownRefresh() {
  255. if(this.PageCur=='msg'){
  256. this.getChats(true)
  257. }else if(this.PageCur=='contract'){
  258. this.getFriends(true)
  259. }else if(this.PageCur=='find'){
  260. this.querylinkItem(true)
  261. }
  262. },
  263. methods: {
  264. alertBtn() {
  265. uni.navigateTo({
  266. url: '/pages/public/login'
  267. })
  268. },
  269. cancelClick() {
  270. this.isShowAlert = false
  271. },
  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. const that = this
  285. that.$api.request('user', 'test', failres => {
  286. that.$api.msg(failres.errmsg)
  287. uni.hideLoading()
  288. }).then(res => {
  289. console.log("res === ",res)
  290. if(res.data){
  291. that.isShowFlag = true
  292. }
  293. this.querylinkItem(false)
  294. uni.hideLoading()
  295. })
  296. }
  297. },
  298. linkTochat(item){
  299. this.$u.vuex('chatObj', item)
  300. this.$u.route({
  301. url: 'pageC/chat/chat',
  302. params: {}
  303. });
  304. },
  305. getChats(freshFlag){
  306. if(this.userData.user==undefined){
  307. return;
  308. }
  309. // uni.showLoading({
  310. // title: '正在加载'
  311. // })
  312. this.$socket.queryChats('', this.userData.user.operId,(res) => {
  313. if (res.success) {
  314. res.chats.sort((a, b) => { return b.lastOpenTime - a.lastOpenTime });
  315. this.$u.vuex('chatItem', res.chats);
  316. }
  317. if(freshFlag){
  318. uni.stopPullDownRefresh();
  319. }
  320. uni.hideLoading()
  321. });
  322. },
  323. //打开或者关闭弹窗
  324. showSelect(){
  325. this.selectShow = !this.selectShow;
  326. },
  327. //action 点击事件
  328. click(index,index1) {
  329. if(index1==0){
  330. this.chatItem[index].isTop = true;
  331. // TODO 留空
  332. }else {
  333. this.chatItem.splice(index, 1);
  334. let obj = this.chatItem[index==this.chatItem.length?index-1:index];
  335. this.$socket.delChat(this.userData.user.operId, obj.id, (res) => {})
  336. }
  337. },
  338. //action 打开事件
  339. open(index) {
  340. this.chatItem[index].show = true;
  341. this.chatItem.map((val, idx) => {
  342. if (index != idx) this.chatItem[idx].show = false;
  343. });
  344. },
  345. //点击导航栏自定义按钮
  346. onNavigationBarButtonTap({ index }) {
  347. if (index == 0) {
  348. this.showSelect()
  349. }
  350. },
  351. //关闭弹窗
  352. closeSelect(){
  353. //小程序兼容
  354. this.selectShow = false;
  355. },
  356. getFriends (freshFlag) {
  357. // uni.showLoading({
  358. // title: '正在加载'
  359. // })
  360. // #ifndef H5
  361. var list = [];
  362. selectFSQL(this.userData.user.operId).then(res=>{
  363. this.indexList.forEach(name=>{
  364. var members = [];
  365. res.forEach(f=>{
  366. if(f.name===name){
  367. members.push(f);
  368. }
  369. });
  370. let obj = {
  371. name: name,
  372. members: members
  373. };
  374. list.push(obj);
  375. });
  376. this.$u.vuex('firendItem', list);
  377. if(freshFlag){
  378. uni.stopPullDownRefresh();
  379. }
  380. uni.hideLoading()
  381. });
  382. // #endif
  383. // #ifndef APP-PLUS
  384. this.$socket.listGuests(this.userData.user.operId, res => {
  385. this.$u.vuex('firendItem', res.response.data)
  386. if(freshFlag){
  387. uni.stopPullDownRefresh();
  388. }
  389. uni.hideLoading()
  390. })
  391. // #endif
  392. },
  393. linkToCard({id}){
  394. console.log("linkToCard")
  395. this.$u.route({
  396. url: 'pageC/businessCard/businessCard',
  397. params:{ id: id, source: 1}
  398. });
  399. },
  400. //扫码
  401. checkSelect(index) {
  402. if (index == 0) {
  403. this.$u.route({
  404. url:"pageD/search/search",
  405. params: {searchType: 0}
  406. })
  407. }
  408. else if (index == 1) {
  409. //扫码
  410. const t = this
  411. uni.scanCode({
  412. success: function(res) {
  413. uni.vibrateLong();
  414. console.log('条码内容:' + res.result);
  415. let uId = res.result
  416. if (uId==t.userData.user.operId){
  417. uni.showToast({
  418. icon:'none',
  419. title:'不能添加自己为好友'
  420. })
  421. } else {
  422. t.$u.route({
  423. url: 'pageC/businessCard/businessCard',
  424. params:{ id: uId, source: 2}
  425. })
  426. }
  427. }
  428. });
  429. }
  430. },
  431. // 发现
  432. querylinkItem(freshFlag){
  433. this.$socket.getLinks(this.userData.user.operId, res=>{
  434. this.$u.vuex('linkItem',res.response.data)
  435. if(freshFlag){
  436. uni.stopPullDownRefresh();
  437. }
  438. });
  439. },
  440. linkToMoment(){
  441. this.$u.route({
  442. url:'pageC/firendCircle/firendCircle'
  443. })
  444. },
  445. linkToScan(){
  446. uni.scanCode({
  447. success: function(res) {
  448. uni.vibrateLong();
  449. let uId = res.result
  450. if (uId==t.userData.user.operId){
  451. uni.showToast({
  452. icon:'none',
  453. title:'暂不支持添加自己'
  454. })
  455. } else {
  456. t.$u.route({
  457. url: 'pageC/businessCard/businessCard',
  458. params:{ id: uId, source: 2}
  459. })
  460. }
  461. }
  462. });
  463. },
  464. linkTo(item, index){
  465. this.$u.route({
  466. url:'pageA/webview/webview',
  467. params:{url:item.url,name:item.title}
  468. })
  469. },
  470. // 我
  471. linkTomy(index) {
  472. const url = index == 1 ? '/pageC/my/face' : '/pageC/my/photo'
  473. this.$u.route({
  474. url: url
  475. });
  476. },
  477. linkToSetting() {
  478. this.$u.route({
  479. url: 'pageC/setings/setings'
  480. });
  481. },
  482. linkToPerson() {
  483. this.$u.route({
  484. url: 'pageC/my/person'
  485. });
  486. },
  487. previewImage() {
  488. let current = this.userData.user.avatar
  489. uni.previewImage({
  490. current,
  491. urls: [current],
  492. // #ifndef MP-WEIXIN
  493. indicator: 'number'
  494. // #endif
  495. });
  496. }
  497. },
  498. };
  499. </script>
  500. <style lang="scss" scoped>
  501. .status_bar{
  502. height: var(--status-bar-height);
  503. width: 100%;
  504. }
  505. .content {
  506. height: 100%;
  507. background:#fff;
  508. }
  509. .tarbar {
  510. width: 100%;
  511. height: 96rpx;
  512. display: flex;
  513. justify-content: space-around;
  514. background-color: #FFFFFF;
  515. position: fixed;
  516. bottom: 0;
  517. z-index: 100;
  518. font-size: 26rpx;
  519. color: #999999;
  520. }
  521. .tarbar view {
  522. text-align: center;
  523. }
  524. .cuIcon-back{
  525. font-size:45rpx;
  526. margin-left:10rpx;
  527. }
  528. </style>