| // components/listItem/listItem.js | // components/listItem/listItem.js | ||||
| const app = getApp() | |||||
| const app = getApp(); | |||||
| Component({ | Component({ | ||||
| /** | /** | ||||
| * 组件的属性列表 | * 组件的属性列表 | ||||
| // 是否收藏 | // 是否收藏 | ||||
| isCollect: { | isCollect: { | ||||
| type: Boolean, | type: Boolean, | ||||
| value:false, | |||||
| value: false, | |||||
| }, | }, | ||||
| // 是否显示收藏 | // 是否显示收藏 | ||||
| isShowCollect:{ | |||||
| isShowCollect: { | |||||
| type: Boolean, | type: Boolean, | ||||
| value:false, | |||||
| value: false, | |||||
| }, | }, | ||||
| // 是否其他查看主页---用于是否显示聊一聊 | // 是否其他查看主页---用于是否显示聊一聊 | ||||
| isOther:{ | |||||
| isOther: { | |||||
| type: Boolean, | type: Boolean, | ||||
| value:true, | |||||
| value: true, | |||||
| }, | }, | ||||
| // 类名 | // 类名 | ||||
| listClass: { | listClass: { | ||||
| type: String, | type: String, | ||||
| value: "", | value: "", | ||||
| }, | }, | ||||
| customerId:{ | |||||
| type:Number, | |||||
| value:null, | |||||
| }, | |||||
| }, | }, | ||||
| /** | /** | ||||
| */ | */ | ||||
| data: { | data: { | ||||
| }, | }, | ||||
| /** | /** | ||||
| * 组件的方法列表 | * 组件的方法列表 | ||||
| */ | */ | ||||
| methods: { | methods: { | ||||
| getCustomerId() { | |||||
| return 123 | |||||
| }, | |||||
| // 进入详情 | // 进入详情 | ||||
| goDetails(e) { | goDetails(e) { | ||||
| if (this.data.listClass == 'disabled-model-view') { | if (this.data.listClass == 'disabled-model-view') { | ||||
| console.log(`点击了聊一聊`) | console.log(`点击了聊一聊`) | ||||
| let item = e.currentTarget.dataset.item; | let item = e.currentTarget.dataset.item; | ||||
| wx.navigateTo({ | wx.navigateTo({ | ||||
| url:"/pages/msgModule/wechat2/wechat2", | |||||
| url: "/pages/msgModule/wechat2/wechat2", | |||||
| success: function (res) { | success: function (res) { | ||||
| // 通过eventChannel向被打开页面传送数据 | // 通过eventChannel向被打开页面传送数据 | ||||
| res.eventChannel.emit('customerid', { customerid:item.customerId,businessCommunicationDemandId:item.businessCommunicationDemandId,chatHeads:item.chatHeads }) | |||||
| res.eventChannel.emit('customerid', { customerid: item.customerId, businessCommunicationDemandId: item.businessCommunicationDemandId, chatHeads: item.chatHeads }) | |||||
| } | } | ||||
| }) | }) | ||||
| }, | }, |
| <image class="collect-img" src="/images/home/not-collect.png" wx:else /> | <image class="collect-img" src="/images/home/not-collect.png" wx:else /> | ||||
| 收藏 | 收藏 | ||||
| </view> | </view> | ||||
| <view class="fr list-foot-text-chat" wx:if="{{ pageStatus != 'myRelease' && isOther }}" bindtap="goToChat" data-item="{{ item }}"> | |||||
| <view class="fr list-foot-text-chat" wx:if="{{ pageStatus != 'myRelease' && isOther && customerId != item.customerId }}" bindtap="goToChat" data-item="{{ item }}"> | |||||
| <image class="chat-img" src="/images/home/chat-icon.png" /> | <image class="chat-img" src="/images/home/chat-icon.png" /> | ||||
| 聊一聊 | 聊一聊 | ||||
| </view> | </view> |
| </view> | </view> | ||||
| <view wx:else> | <view wx:else> | ||||
| <view class="list-view" wx:for="{{ listData }}" wx:key="*this"> | <view class="list-view" wx:for="{{ listData }}" wx:key="*this"> | ||||
| <listItem item="{{ item }}" bind:getItem="goDetails" pageStatus="homepage" isOther="{{ isOther }}"/> | |||||
| <listItem item="{{ item }}" bind:getItem="goDetails" pageStatus="homepage" isOther="{{ isOther }}" /> | |||||
| </view> | </view> | ||||
| <view class="text-center" wx:if="{{ itemLoading }}"> | <view class="text-center" wx:if="{{ itemLoading }}"> | ||||
| <van-loading size="24px">加载中...</van-loading> | <van-loading size="24px">加载中...</van-loading> |
| // 是否加载数据,true加载,false不加载 | // 是否加载数据,true加载,false不加载 | ||||
| onRefresh: true, | onRefresh: true, | ||||
| currentIndex: 0, | currentIndex: 0, | ||||
| // 当前登录器用户登录ID | |||||
| userCustomerId: null, | |||||
| }, | }, | ||||
| /** | /** | ||||
| onLoad(option) { | onLoad(option) { | ||||
| }, | }, | ||||
| onShow() { | onShow() { | ||||
| const businessCommunicationCustomer = wx.getStorageSync('businessCommunicationCustomer') || null; | |||||
| if (businessCommunicationCustomer) { | |||||
| this.setData({ | |||||
| userCustomerId:businessCommunicationCustomer.customerId | |||||
| }) | |||||
| } | |||||
| const listDetail = wx.getStorageSync('listDetail') || null; | const listDetail = wx.getStorageSync('listDetail') || null; | ||||
| this.setData({ | this.setData({ | ||||
| currentData: listDetail, | currentData: listDetail, |
| </view> | </view> | ||||
| <view wx:else> | <view wx:else> | ||||
| <view class="list-view"> | <view class="list-view"> | ||||
| <listItem | |||||
| item="{{ currentData }}" | |||||
| pageStatus="detatil" | |||||
| isCollect="{{ isCollect }}" | |||||
| isShowCollect="{{ customerId != currentData.customerId }}" | |||||
| bind:changeCollect="changeCollect" /> | |||||
| <listItem item="{{ currentData }}" pageStatus="detatil" isCollect="{{ isCollect }}" isShowCollect="{{ customerId != currentData.customerId }}" bind:changeCollect="changeCollect" customerId="{{ userCustomerId }}" /> | |||||
| </view> | </view> | ||||
| <view class="view-interested">你可能感兴趣的需求</view> | <view class="view-interested">你可能感兴趣的需求</view> | ||||
| <view class="not-data" wx:if="{{ listData.length < 1 }}"> | <view class="not-data" wx:if="{{ listData.length < 1 }}"> | ||||
| </view> | </view> | ||||
| <view wx:else> | <view wx:else> | ||||
| <view class="list-view" wx:for="{{ listData }}" wx:key="*this"> | <view class="list-view" wx:for="{{ listData }}" wx:key="*this"> | ||||
| <listItem item="{{ item }}" bind:getItem="goDetails" /> | |||||
| <listItem item="{{ item }}" bind:getItem="goDetails" customerId="{{ userCustomerId }}" /> | |||||
| </view> | </view> | ||||
| <view class="text-center" wx:if="{{ itemLoading }}"> | <view class="text-center" wx:if="{{ itemLoading }}"> | ||||
| <van-loading size="24px">加载中...</van-loading> | <van-loading size="24px">加载中...</van-loading> |
| attentionTypeIds: "", | attentionTypeIds: "", | ||||
| // 用来判断关注显示按钮 | // 用来判断关注显示按钮 | ||||
| paramIsInterest:0, | paramIsInterest:0, | ||||
| customerId:null, | |||||
| }, | }, | ||||
| onLoad() { | onLoad() { | ||||
| }, | }, | ||||
| const businessCommunicationCustomer = wx.getStorageSync('businessCommunicationCustomer') || null; | const businessCommunicationCustomer = wx.getStorageSync('businessCommunicationCustomer') || null; | ||||
| if (businessCommunicationCustomer) { | if (businessCommunicationCustomer) { | ||||
| this.setData({ | this.setData({ | ||||
| attentionTypeIds: businessCommunicationCustomer.attentionTypeIds.split(',') | |||||
| attentionTypeIds: businessCommunicationCustomer.attentionTypeIds.split(','), | |||||
| customerId:businessCommunicationCustomer.customerId | |||||
| }) | }) | ||||
| } | } | ||||
| }, | }, |
| </view> | </view> | ||||
| <view class="view-interested" wx:if="{{ paramIsInterest == 1 }}">为您推荐以下内容</view> | <view class="view-interested" wx:if="{{ paramIsInterest == 1 }}">为您推荐以下内容</view> | ||||
| <view class="list-view" wx:for="{{ listData }}" wx:key="*this"> | <view class="list-view" wx:for="{{ listData }}" wx:key="*this"> | ||||
| <listItem item="{{ item }}" bind:getItem="goDetails" /> | |||||
| <listItem item="{{ item }}" bind:getItem="goDetails" customerId="{{ customerId }}"/> | |||||
| </view> | </view> | ||||
| <view class="text-center" wx:if="{{ itemLoading }}"> | <view class="text-center" wx:if="{{ itemLoading }}"> | ||||
| <van-loading size="24px">加载中...</van-loading> | <van-loading size="24px">加载中...</van-loading> |
| * 生命周期函数--监听页面加载 | * 生命周期函数--监听页面加载 | ||||
| */ | */ | ||||
| onLoad() { | onLoad() { | ||||
| this.getMsgData(); | |||||
| }, | |||||
| onShow(){ | |||||
| // this.getMsgData(); | |||||
| this.initData(); | |||||
| }, | }, | ||||
| closeTopShow() { | closeTopShow() { | ||||
| this.setData({ | this.setData({ | ||||
| } | } | ||||
| }) | }) | ||||
| }, | }, | ||||
| initData(){ | |||||
| this.setData({ | |||||
| pageLoading: true, | |||||
| page:1, | |||||
| size: 10, | |||||
| msgData: [], | |||||
| }) | |||||
| this.getMsgData(); | |||||
| }, | |||||
| getMsgData() { | getMsgData() { | ||||
| let { page, size } = this.data; | let { page, size } = this.data; | ||||
| $request.get('/businessCommunicationDemand/getChatRecordTable.action', { page, size }).then(res => { | $request.get('/businessCommunicationDemand/getChatRecordTable.action', { page, size }).then(res => { |
| // 历史记录当前页 | // 历史记录当前页 | ||||
| pageNo: 1, | pageNo: 1, | ||||
| // 当前产品ID | // 当前产品ID | ||||
| businessCommunicationDemandId:null, | |||||
| businessCommunicationDemandId: null, | |||||
| }, | }, | ||||
| /** | /** | ||||
| onLoad: function (options) { | onLoad: function (options) { | ||||
| const eventChannel = this.getOpenerEventChannel() | const eventChannel = this.getOpenerEventChannel() | ||||
| // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据 | // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据 | ||||
| eventChannel.on('customerid', data => { | eventChannel.on('customerid', data => { | ||||
| this.setData({ | this.setData({ | ||||
| sendMemberId: data.customerid, | sendMemberId: data.customerid, | ||||
| businessCommunicationDemandId:data.businessCommunicationDemandId, | |||||
| receivebaseInfo:{ | |||||
| avatar:data.chatHeads | |||||
| businessCommunicationDemandId: data.businessCommunicationDemandId, | |||||
| receivebaseInfo: { | |||||
| avatar: data.chatHeads | |||||
| } | } | ||||
| }) | }) | ||||
| // 获取历史记录 | // 获取历史记录 | ||||
| this.getHistory() | |||||
| this.getHistory(); | |||||
| }) | }) | ||||
| let customerId = app.globalData.customerId; | let customerId = app.globalData.customerId; | ||||
| let sendAvatar = app.globalData.businessCommunicationCustomer.chatHeads; | let sendAvatar = app.globalData.businessCommunicationCustomer.chatHeads; | ||||
| let _data = JSON.parse(res.data); | let _data = JSON.parse(res.data); | ||||
| _data.chatRecord = JSON.parse(_data.chatRecord); | _data.chatRecord = JSON.parse(_data.chatRecord); | ||||
| let msgData = {}; | let msgData = {}; | ||||
| if(_data.chatRecord.sender != _this.data.receiveMemberId){ | |||||
| if (_data.chatRecord.sender != _this.data.receiveMemberId) { | |||||
| msgData.type = 1; | msgData.type = 1; | ||||
| }else{ | |||||
| } else { | |||||
| msgData.type = 0; | msgData.type = 0; | ||||
| } | } | ||||
| msgData.message = _data.chatRecord.content; | msgData.message = _data.chatRecord.content; | ||||
| // 获取历史记录 | // 获取历史记录 | ||||
| getHistory() { | getHistory() { | ||||
| var { sendMemberId,businessCommunicationDemandId } = this.data; | |||||
| let url = ""; | |||||
| if(businessCommunicationDemandId){ | |||||
| url = '/businessCommunicationDemand/getChatRecordById/' + businessCommunicationDemandId + '/' + sendMemberId + '.action' | |||||
| }else{ | |||||
| url = '/businessCommunicationDemand/getChatRecordById/' + sendMemberId + '.action' | |||||
| } | |||||
| $request.get(url).then(res => { | |||||
| console.log(`------------聊一聊获取历史记录-----------------`) | |||||
| console.log(res); | |||||
| console.log(`------------聊一聊获取历史记录-----------------`) | |||||
| var { sendMemberId, businessCommunicationDemandId } = this.data; | |||||
| $request.get('/businessCommunicationDemand/getChatRecordById/' + sendMemberId + '.action').then(res => { | |||||
| if (res.status == 0) { | if (res.status == 0) { | ||||
| var historyList = [...res.data.chatRecordList, ...this.data.historyList] | var historyList = [...res.data.chatRecordList, ...this.data.historyList] | ||||
| if (historyList && historyList.length > 0) { | if (historyList && historyList.length > 0) { | ||||
| }) | }) | ||||
| console.log(this.data.historyList, '历史记录数据') | console.log(this.data.historyList, '历史记录数据') | ||||
| } | } | ||||
| // 如果产品ID存在 | |||||
| console.log(businessCommunicationDemandId, '产品ID是否存在') | |||||
| if (businessCommunicationDemandId) { | |||||
| // this.data.historyList | |||||
| if(historyList.length > 0){ | |||||
| for (let index = historyList.length - 1; index >= 0; index--) { | |||||
| const element = historyList[index]; | |||||
| if (element.messageType == 1) { | |||||
| if (element.transactionId == businessCommunicationDemandId) { | |||||
| break; | |||||
| } else { | |||||
| this.sendmsgApi("", 1); | |||||
| } | |||||
| } | |||||
| } | |||||
| }else{ | |||||
| this.sendmsgApi("", 1); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| }).catch(err => { | }).catch(err => { | ||||
| console.log(err) | console.log(err) | ||||
| send: function () { | send: function () { | ||||
| var _this = this; | var _this = this; | ||||
| if (_this.data.input) { | if (_this.data.input) { | ||||
| let { sendMemberId ,receiveMemberId ,businessCommunicationDemandId} = _this.data; | |||||
| let params = { | |||||
| sender: receiveMemberId, // 发件人Id | |||||
| addressee: sendMemberId, // 收件人Id | |||||
| transactionId: businessCommunicationDemandId, // 产品ID | |||||
| content: _this.data.input | |||||
| }; | |||||
| $request.post('/businessCommunicationDemand/addChatRecord.action',params).then(res => { | |||||
| console.log(`------------聊一聊保存记录-----------------`) | |||||
| console.log(res); | |||||
| console.log(`------------聊一聊保存记录-----------------`) | |||||
| }).catch(err => { | |||||
| console.log(err) | |||||
| }) | |||||
| // wx.sendSocketMessage({ | |||||
| // data: _this.data.input, | |||||
| // success: (res) => { | |||||
| // }, | |||||
| // fail: (err) => { | |||||
| // console.log('sendSocketMessage', '失败') | |||||
| // } | |||||
| // }) | |||||
| var list = []; | |||||
| list = this.data.newsList; | |||||
| var temp = { 'message': _this.data.input, 'date': utils.formatTime(new Date()), type: 0 }; | |||||
| list.push(temp); | |||||
| this.setData({ | |||||
| newsList: list, | |||||
| input: null | |||||
| }) | |||||
| this.scrollBottom() | |||||
| // 表情选择隐藏 | |||||
| this.setData({ | |||||
| emotionVisible: false, | |||||
| }) | |||||
| this.sendmsgApi(_this.data.input, 0); | |||||
| } | } | ||||
| }, | |||||
| sendmsgApi(content, msgType) { | |||||
| let { sendMemberId, receiveMemberId, businessCommunicationDemandId } = this.data; | |||||
| let transactionId = businessCommunicationDemandId; | |||||
| if (!businessCommunicationDemandId) { | |||||
| transactionId = this.data.historyList[this.data.historyList.length - 1].transactionId; | |||||
| } | |||||
| let params = { | |||||
| sender: receiveMemberId, // 发件人Id | |||||
| addressee: sendMemberId, // 收件人Id | |||||
| transactionId, // 产品ID | |||||
| content, | |||||
| messageType: msgType, | |||||
| }; | |||||
| $request.post('/businessCommunicationDemand/addChatRecord.action', params).then(res => { | |||||
| console.log(`------------聊一聊保存记录-----------------`) | |||||
| console.log(res); | |||||
| console.log(`------------聊一聊保存记录-----------------`) | |||||
| }).catch(err => { | |||||
| console.log(err) | |||||
| }) | |||||
| // wx.sendSocketMessage({ | |||||
| // data: _this.data.input, | |||||
| // success: (res) => { | |||||
| // }, | |||||
| // fail: (err) => { | |||||
| // console.log('sendSocketMessage', '失败') | |||||
| // } | |||||
| // }) | |||||
| var list = []; | |||||
| list = this.data.newsList; | |||||
| var temp = { 'message': this.data.input, 'date': utils.formatTime(new Date()), type: 0 }; | |||||
| list.push(temp); | |||||
| this.setData({ | |||||
| newsList: list, | |||||
| input: null | |||||
| }) | |||||
| // this.bottom() | |||||
| this.scrollBottom() | |||||
| // 表情选择隐藏 | |||||
| this.setData({ | |||||
| emotionVisible: false, | |||||
| }) | |||||
| const client = wx.getSystemInfoSync().windowHeight // 获取当前窗口的高度 | const client = wx.getSystemInfoSync().windowHeight // 获取当前窗口的高度 | ||||
| console.log(client, 'shurugaodu') | |||||
| console.log(client, '当前消息高度') | |||||
| }, | }, | ||||
| bindChange: function (res) { | bindChange: function (res) { | ||||
| this.setData({ | this.setData({ | ||||
| input = input + connectemoji[e.currentTarget.dataset.index]; | input = input + connectemoji[e.currentTarget.dataset.index]; | ||||
| } else { | } else { | ||||
| input = connectemoji[e.currentTarget.dataset.index] | input = connectemoji[e.currentTarget.dataset.index] | ||||
| } | |||||
| } | |||||
| console.log(input, '输入框额值') | console.log(input, '输入框额值') | ||||
| this.setData({ | this.setData({ | ||||
| input | input |
| </view> | </view> | ||||
| <view wx:else> | <view wx:else> | ||||
| <view class="list-view " wx:for="{{ listData }}" wx:key="*this"> | <view class="list-view " wx:for="{{ listData }}" wx:key="*this"> | ||||
| <listItem item="{{ item }}" pageStatus="myCollect" bind:getItem="goDetails" listClass="{{ item.isDeleted > 0 || item.state < 0 ? 'disabled-model-view' : '' }}" /> | |||||
| <listItem item="{{ item }}" pageStatus="myCollect" bind:getItem="goDetails" listClass="{{ item.isDeleted > 0 || item.state < 0 ? 'disabled-model-view' : '' }}" customerId="{{ customerId }}"/> | |||||
| <image class="disabled-model-img" src="/images/home/isDelete-icon.png" wx:if="{{ item.isDeleted > 0 }}"/> | <image class="disabled-model-img" src="/images/home/isDelete-icon.png" wx:if="{{ item.isDeleted > 0 }}"/> | ||||
| <image class="disabled-model-img" src="/images/home/isState-0-icon.png" wx:if="{{ item.isDeleted == 0 && item.state < 0}}"/> | <image class="disabled-model-img" src="/images/home/isState-0-icon.png" wx:if="{{ item.isDeleted == 0 && item.state < 0}}"/> | ||||
| <view class="del-collect-view" bindtap="delCollect" data-id="{{ item.businessCommunicationDemandId }}"> | <view class="del-collect-view" bindtap="delCollect" data-id="{{ item.businessCommunicationDemandId }}"> |
| if (code == 'my-release') { | if (code == 'my-release') { | ||||
| url = "/pages/myModule/components/myRelease/myRelease"; | url = "/pages/myModule/components/myRelease/myRelease"; | ||||
| } | } | ||||
| // 前往发布的需求 | |||||
| if (code == 'my-release') { | |||||
| url = "/pages/myModule/components/myRelease/myRelease"; | |||||
| // 前往收藏的需求 | |||||
| if (code == 'my-collect') { | |||||
| url = "/pages/myModule/components/myCollect/myCollect"; | |||||
| } | } | ||||
| // 前往关注的类型 | // 前往关注的类型 | ||||
| if (code == 'my-attention') { | if (code == 'my-attention') { |