123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470 |
- const app = getApp();
- import {
- ApiModel
- } from "../../utils/api";
- const _Http = new ApiModel();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- iosX: false,
- sendText: "", //输入框内容
- headerTitle: "对话框",
- socketMsgQueue: [],
- lineCount: 1, //输入框行数
- toView: 'item0',
- keyboardHeight: 0, //键盘高度
- functionToChoose: "", //功能选项
- memePopup: false, //表情弹出
- pageNumber: 1,
- pageTotal: 1,
- triggered: false, //下拉状态
- unreadCount: 0, //对方发送未读信息
- joinHands: false, //是否显示合作按钮
- ownerid: 0, //供需id
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- //app.initSocket(); 链接websocket 用于测试
- const that = this;
- this.setData({
- timdialogid: options.id,
- userid: wx.getStorageSync('userData').userid
- });
- //详情
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "system.im.imdialog.imdialog",
- "method": "query_imdialogMain",
- "content": {
- "timdialogid": options.id
- }
- }).then(res => {
- console.log("详情", res)
- let title = res.data[0].fimdialogname.split('-'),
- headerTitle = (title[0] == res.data[0].fname) ? title[1] : title[0],
- joinHands = false;
- if (res.data[0].ownerid != 0) {
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "customer.supplyanddemand.supplyanddemand",
- "method": "updatesupplyanddemandstatus",
- "content": {
- "tsupplyanddemandid": res.data[0].ownerid,
- "fstatus": "对接中",
- "timdialogid": res.data[0].timdialogid
- }
- }).then(res => {
- console.log("对接中", res)
- })
- if (res.data[0].fimuserid != wx.getStorageSync('userData').userid) {
- joinHands = true;
- }
- }
- this.setData({
- headerTitle,
- joinHands,
- ownerid: res.data[0].ownerid,
- initiator: res.data[0].fimuserid
- })
- })
- //群历史信息
- this.query_imdialogMessage();
- let iosX = (getApp().globalData.safeAreaBottom == 0) ? false : true;
- this.setData({
- iosX
- })
- //获取表情包
- this.getMeme()
- },
- /* 确认合作 */
- confirmTheCooperation() {
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "customer.supplyanddemand.supplyanddemand",
- "method": "updatesupplyanddemandstatus",
- "content": {
- "tsupplyanddemandid": this.data.ownerid,
- "fstatus": "已解决",
- "tenterprise_userid": this.data.initiator
- }
- }).then(res => {
- console.log("确认合作", res)
- })
- },
- /* 拒绝合作 */
- refuseToCooperate() {
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "customer.supplyanddemand.supplyanddemand",
- "method": "updatesupplyanddemandstatus",
- "content": {
- "tsupplyanddemandid": this.data.ownerid,
- "fstatus": "待对接",
- "timdialogid": this.data.timdialogid
- }
- }).then(res => {
- console.log("拒绝合作", res)
- })
- },
- //历史信息查询
- query_imdialogMessage() {
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "system.im.imdialog.imdialog",
- "method": "query_imdialogMessage",
- "content": {
- "pageNumber": this.data.pageNumber,
- "pageSize": 20,
- "timdialogid": this.data.timdialogid
- }
- }, false).then(res => {
- if (res.msg != '成功') return wx.showToast({
- title: res.data,
- icon: "none"
- })
- if (res.pageNumber != 1) {
- let list = res.data;
- list = list.reverse();
- list = list.concat(this.data.socketMsgQueue);
- this.setData({
- socketMsgQueue: list,
- toView: `item${res.data.length - 1}`,
- triggered: false
- })
- } else {
- let list = res.data;
- list = list.reverse();
- this.setData({
- socketMsgQueue: list,
- toView: `item${res.data.length - 1}`,
- pageTotal: res.pageTotal
- })
- setTimeout(() => {
- this.setData({
- toView: 'bottom'
- })
- }, 500)
- }
- })
- },
- scrolltoupper() {
- if (this.data.pageNumber < this.data.pageTotal) {
- this.setData({
- pageNumber: this.data.pageNumber + 1,
- triggered: true
- })
- this.query_imdialogMessage();
- } else {
- this.setData({
- triggered: true
- })
- }
- },
- //键盘弹出高度
- keyboardheightchange(e) {
- let {
- height
- } = e.detail;
- if (this.data.iosX && height > 150) height = height - 17;
- this.setData({
- keyboardHeight: height
- })
- },
- /* 输入框数据绑定 */
- sendInput(e) {
- this.setData({
- sendText: e.detail.value
- })
- },
- /* 发送信息 */
- sendMsg(type, data) {
- const content = this.data.sendText.trim(),
- that = this;
- if (type === 'file') {
- console.log("发送", data)
- app.globalData.SocketTask.send({
- data: JSON.stringify({
- "classname": "message.message",
- "method": "sendFileMessage",
- "content": {
- "timdialogid": this.data.timdialogid,
- "tattachmentid": data[0].tattachmentid
- }
- }),
- success(res) {}
- })
- } else {
- if (content == '') return;
- app.globalData.SocketTask.send({
- data: JSON.stringify({
- "classname": "message.message",
- "method": "sendTextMessage",
- "content": {
- "timdialogid": that.data.timdialogid,
- "fmessage": content
- }
- }),
- success(res) {
- that.setData({
- sendText: ''
- })
- }
- })
- }
- },
- sendMeme(e) {
- const {
- item
- } = e.currentTarget.dataset;
- let data = [];
- data.push(item);
- this.sendMsg('file', data)
- },
- //功能选择
- selectionFunction(e) {
- const {
- name
- } = e.target.dataset,
- that = this;
- if (name == undefined || name == "") return;
- if (name == '表情') {
- let keyboardHeight = (this.data.iosX == true) ? 220 : 200;
- this.setData({
- keyboardHeight,
- memePopup: true
- })
- that.toBotton()
- let time1 = setInterval(() => {
- this.setData({
- keyboardHeight
- })
- if (this.data.keyboardHeight == keyboardHeight && this.data.memePopup) clearInterval(time1);
- }, 100);
- } else if (name == '图片') {
- this.endMemePopup()
- wx.chooseMedia({
- count: 1,
- mediaType: ['image'],
- sourceType: ['album', 'camera'],
- maxDuration: 30,
- camera: 'back',
- success(res) {
- let data = {
- file: res.tempFiles[0].tempFilePath
- };
- that.afterRead(data)
- }
- })
- } else if (name == '历史') {
- wx.navigateTo({
- url: './history?id=' + that.data.timdialogid,
- })
- }
- },
- textareaFocus() {
- this.setData({
- memePopup: false, //表情弹出
- })
- this.toBotton()
- },
- //关闭表情
- endMemePopup(e) {
- this.setData({
- keyboardHeight: 0, //键盘高度
- memePopup: false, //表情弹出
- })
- },
- /* 文本域行数变化 */
- linechange(e) {
- console.log(e)
- const {
- lineCount
- } = e.detail;
- if (lineCount == this.data.lineCount) return;
- this.setData({
- lineCount
- })
- },
- //获取表情包
- getMeme() {
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "system.system.docManage",
- "method": "queryDoc",
- "content": {
- "getdatafromdbanyway": true,
- "ownertable": "system",
- "ownerid": 0
- }
- }, false).then(res => {
- if (res.msg != '成功') return setTimeout(() => {
- this.getMeme();
- }, 3000);
- this.setData({
- memeList: res.data
- })
- })
- },
- afterRead({
- file
- }) {
- var that = this
- var index = file.lastIndexOf(".");
- var ext = file.substr(index + 1);
- var timestamp = Date.parse(new Date());
- wx.getFileSystemManager().readFile({
- filePath: file,
- // encoding:'utf-8',
- success: result => {
- //返回临时文件路径
- const fileData = result.data
- wx.request({
- url: 'https://www.buwanjia.com/bwj/rest/webclientrest/', //仅为示例,并非真实的接口地址
- data: {
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "system.system.docManage",
- "method": "getFileName",
- "content": {
- "filename": 'wx' + timestamp,
- "filetype": ext,
- "ownertable": "timdialog",
- "ownerid": that.data.timdialogid,
- "ftype": "default",
- "HttpMethod": 'put'
- }
- },
- method: 'post',
- header: {
- 'content-type': 'application/json' // 默认值
- },
- success(res) {
- console.log(res)
- that.uploadFile(res, fileData)
- }
- })
- },
- fail: console.error
- })
- },
- uploadFile(res, data) {
- var that = this
- wx.request({
- url: res.data.data.obsuploadurl,
- method: "PUT",
- data: data,
- header: {
- 'content-type': 'application/octet-stream' // 默认值
- },
- success() {
- wx.request({
- url: 'https://www.buwanjia.com/bwj/rest/webclientrest/', //仅为示例,并非真实的接口地址
- data: {
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "system.system.docManage",
- "method": "uploadSuccess",
- "content": {
- "obsfilename": res.data.data.obsfilename
- }
- },
- method: 'post',
- header: {
- 'content-type': 'application/json' // 默认值
- },
- success(res) {
- let file = res.data.data;
- console.log(res)
- that.sendMsg('file', file)
- }
- })
- }
- })
- },
- toBotton() {
- this.setData({
- toView: 'bottom'
- })
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- var that = this
- app.globalData.callback = function (res) {
- //res 接收websocket onMessage事件返回的数据
- let objs = JSON.parse(res.data),
- unreadCount = that.data.unreadCount; /* triggered */
- that.data.socketMsgQueue.push(objs)
- console.log("发送消息", objs)
- that.setData({
- socketMsgQueue: that.data.socketMsgQueue
- })
- that.toBotton()
- /* if (wx.getStorageSync('userData').userid == objs.message.sendfrom.userid) {
- } else {
- that.setData({
- socketMsgQueue: that.data.socketMsgQueue
- })
- } */
- /* ,
- toView: `item${that.data.socketMsgQueue.length - 1}` */
- }
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- //重置未读信息
- _Http.basic({
- "accesstoken": wx.getStorageSync('userData').token,
- "classname": "system.im.imdialog.imdialog",
- "method": "restUnReadMsgCount",
- "content": {
- "timdialogid": this.data.timdialogid
- }
- }).then(res => {
- console.log(res)
- })
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- }
- })
|