Commit c0e7b452 by 施宇

11

parent c3026ab2
Showing with 1758 additions and 829 deletions
const WebIM = require("utils/WebIM")["default"];
let msgStorage = require("components/chat/msgstorage");
let msgType = require("components/chat/msgtype");
let disp = require("utils/broadcast");
function calcUnReadSpot(message) {
let myName = wx.getStorageSync("myUsername");
let allMembers = wx.getStorageSync("member") || []; //好友
let count = allMembers.reduce(function (result, curMember, idx) {
let chatMsgs = wx.getStorageSync(curMember.toLowerCase() + myName.toLowerCase()) || [];
return result + chatMsgs.length;
}, 0);
getApp().globalData.unReadMessageNum = count;
disp.fire("em.xmpp.unreadspot", message);
}
function onMessageError(err) {
if (err.type === "error") {
wx.showToast({
title: err.errorText
});
return false;
}
return true;
}
function addMember(id) {
let member = wx.getStorageSync("member") || [];
let index = member.indexOf(id);
if (index == -1) {
member.push(id)
}
wx.setStorage({
key: "member",
data: member
});
}
// let msgStorage = require("components/chat/msgstorage");
// let msgType = require("components/chat/msgtype");
// let disp = require("utils/broadcast");
let chat = require('utils/chat.js');
import { getData } from './utils/util.js';
import { apis } from './utils/api.js';
// function calcUnReadSpot(message) {
// let myName = wx.getStorageSync("myUsername");
// let allMembers = wx.getStorageSync("member") || []; //好友
// let count = allMembers.reduce(function (result, curMember, idx) {
// let chatMsgs = wx.getStorageSync(curMember.toLowerCase() + myName.toLowerCase()) || [];
// return result + chatMsgs.length;
// }, 0);
// getApp().globalData.unReadMessageNum = count;
// disp.fire("em.xmpp.unreadspot", message);
// }
// function onMessageError(err) {
// if (err.type === "error") {
// wx.showToast({
// title: err.errorText
// });
// return false;
// }
// return true;
// }
// function addMember(id) {
// let member = wx.getStorageSync("member") || [];
// let index = member.indexOf(id);
// if (index == -1) {
// member.push(id)
// }
// wx.setStorage({
// key: "member",
// data: member
// });
// }
App({
globalData: {
unReadMessageNum: 0,
token:wx.getStorageSync('access_token'),
isIPX: false //是否为iphone X
isIPX: false, //是否为iphone X
customerNum:"18664936975",
customerName:"IC业务助手"
},
conn: {
closed: false,
curOpenOpt: {},
open(opt) {
// /* wx.showLoading({
// title: '正在初始化客户端...',
// mask: true
// }) */
this.curOpenOpt = opt;
WebIM.conn.open(opt);
this.closed = false;
},
reopen() {
if (this.closed) {
WebIM.conn.open(this.curOpenOpt);
this.closed = false;
}
// conn: {
// closed: false,
// curOpenOpt: {},
// open(opt) {
// // /* wx.showLoading({
// // title: '正在初始化客户端...',
// // mask: true
// // }) */
// this.curOpenOpt = opt;
// WebIM.conn.open(opt);
// this.closed = false;
// },
// reopen() {
// if (this.closed) {
// WebIM.conn.open(this.curOpenOpt);
// this.closed = false;
// }
// }
// },
getImUser: chat.getImUser,
addChatMember: function (id) {
let token = wx.getStorageSync('access_token') || ''
let member = wx.getStorageSync("member") || [];
let index = member.indexOf(id);
if (index == -1) {
member.push(id)
}
wx.setStorage({
key: "member",
data: member
});
getData(apis.addrecord, 'GET', {
"token": token,
"user_id": id
}, function (res) {
if (res.errcode === 0) {
} else {
console.log('添加聊天成员失败')
}
}, false);
},
onLaunch() {
let me = this;
......@@ -68,9 +96,9 @@ App({
success(res) {
if(res.data){
// wx.switchTab({
// url: '/pages/tab/home/home'
// });
wx.switchTab({
url: '/pages/tab/home/home'
});
}
}
......@@ -82,74 +110,74 @@ App({
success(res) {
if (res.authSetting['scope.userInfo']) {
// 已经授权
// wx.switchTab({
// url: '/pages/tab/home/home'
// })
wx.switchTab({
url: '/pages/tab/home/home'
})
}
}
})
wx.setStorage({
key: "myUsername",
data: '18271408717'
});
this.conn.open({
apiUrl: WebIM.config.apiURL,
user: '18271408717',
pwd: '123456',
appKey: WebIM.config.appkey
});
WebIM.conn.listen({
onOpened(message) {
},
onReconnect() {
wx.showToast({
title: "重连中...",
duration: 2000
});
},
onSocketConnected() {
/* wx.showToast({
title: "socket连接成功",
duration: 2000
}); */
},
onClosed() {
wx.showToast({
title: "网络已断开",
icon: 'none',
duration: 2000
});
me.conn.closed = true;
WebIM.conn.close();
},
onCmdMessage(message) {
},
onTextMessage(message) {
addMember(message.from)
if (message) {
if (onMessageError(message)) {
msgStorage.saveReceiveMsg(message, msgType.TEXT);
}
calcUnReadSpot(message);
}
},
onPictureMessage(message) {
},
// 各种异常
onError(error) {
console.log(error)
},
});
this.getImUser()
// wx.setStorage({
// key: "myUsername",
// data: '7a2765fc7caa5e512a6d1270bcf98bf0'
// });
// this.conn.open({
// apiUrl: WebIM.config.apiURL,
// user: '7a2765fc7caa5e512a6d1270bcf98bf0',
// pwd: 'ic_55028838',
// appKey: WebIM.config.appkey
// });
chat.webimListen();
// WebIM.conn.listen({
// onOpened(message) {
// },
// onReconnect() {
// wx.showToast({
// title: "重连中...",
// duration: 2000
// });
// },
// onSocketConnected() {
// /* wx.showToast({
// title: "socket连接成功",
// duration: 2000
// }); */
// },
// onClosed() {
// wx.showToast({
// title: "网络已断开",
// icon: 'none',
// duration: 2000
// });
// me.conn.closed = true;
// WebIM.conn.close();
// },
// onCmdMessage(message) {
// },
// onTextMessage(message) {
// chat.addMember(message.from)
// if (message) {
// if (chat.onMessageError(message)) {
// msgStorage.saveReceiveMsg(message, msgType.TEXT);
// }
// chat.calcUnReadSpot(message);
// }
// },
// onPictureMessage(message) {
// },
// // 各种异常
// onError(error) {
// console.log(error)
// },
// });
this.checkIsIPhoneX();
},
checkIsIPhoneX: function () {
......
......@@ -29,8 +29,11 @@ Component({
},
saveSendMsg(evt){
msgStorage.saveMsg(evt.detail.msg, evt.detail.type);
this.data.__comps__.inputbar.cancelEmoji();
msgStorage.saveMsg(evt.detail.msg, evt.detail.type);
if(evt.detail.type !== 'cmd'){
this.data.__comps__.inputbar.cancelEmoji();
}
}
},
......@@ -40,6 +43,7 @@ Component({
ready(){
this.data.__comps__.inputbar = this.selectComponent("#chat-inputbar");
this.data.__comps__.msglist = this.selectComponent("#chat-msglist");
},
moved(){},
detached(){
......
......@@ -16,20 +16,8 @@ Component({
},
methods: {
openCamera(){
var me = this;
wx.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
sourceType: ["camera"],
success(res){
me.upLoadImage(res);
}
});
},
sendImage(){
var me = this;
let me = this;
wx.chooseImage({
count: 1,
sizeType: ["original", "compressed"],
......@@ -49,23 +37,23 @@ Component({
},
upLoadImage(res){
var me = this;
var tempFilePaths = res.tempFilePaths;
var token = WebIM.conn.context.accessToken
let me = this;
let tempFilePaths = res.tempFilePaths;
let token = WebIM.conn.context.accessToken
wx.getImageInfo({
src: res.tempFilePaths[0],
success(res){
var allowType = {
let allowType = {
jpg: true,
gif: true,
png: true,
bmp: true
};
var str = WebIM.config.appkey.split("#");
var width = res.width;
var height = res.height;
var index = res.path.lastIndexOf(".");
var filetype = (~index && res.path.slice(index + 1)) || "";
let str = WebIM.config.appkey.split("#");
let width = res.width;
let height = res.height;
let index = res.path.lastIndexOf(".");
let filetype = (~index && res.path.slice(index + 1)) || "";
if(filetype.toLowerCase() in allowType){
wx.uploadFile({
url: "https://a1.easemob.com/" + str[0] + "/" + str[1] + "/chatfiles",
......@@ -76,11 +64,11 @@ Component({
Authorization: "Bearer " + token
},
success(res){
var data = res.data;
var dataObj = JSON.parse(data);
var id = WebIM.conn.getUniqueId(); // 生成本地消息 id
var msg = new WebIM.message(msgType.IMAGE, id);
var file = {
let data = res.data;
let dataObj = JSON.parse(data);
let id = WebIM.conn.getUniqueId(); // 生成本地消息 id
let msg = new WebIM.message(msgType.IMAGE, id);
let file = {
type: msgType.IMAGE,
size: {
width: width,
......@@ -90,16 +78,32 @@ Component({
filetype: filetype,
filename: tempFilePaths[0]
};
let userId = wx.getStorageSync('user_id');
let companyName = wx.getStorageSync('company_name');
let avatar = wx.getStorageSync('avatar');
msg.set({
apiUrl: WebIM.config.apiURL,
body: file,
from: me.data.username.myName,
to: me.getSendToParam(),
ext: {
id: userId,
name: companyName,
img: avatar,
touserid: me.data.username.id == userId ? me.data.username.touserid : me.data.username.id,
name1: me.data.username.name == companyName ? me.data.username.name1 : me.data.username.name,
img1: me.data.username.name == companyName ? me.data.username.img1 : me.data.username.img,
timer: WebIM.time()
},
roomType: false,
chatType: me.data.chatType,
success: function (argument) {
console.log('发送图片成功')
disp.fire('em.chat.sendSuccess', id);
}
},
fail:function(){
console.log('发送图片失败')
}
});
if(me.data.chatType == msgType.chatType.CHAT_ROOM){
msg.setGroup("groupchat");
......
......@@ -2,121 +2,174 @@ let WebIM = require("../../../../../utils/WebIM")["default"];
let msgType = require("../../../msgtype");
let disp = require("../../../../../utils/broadcast");
Component({
properties: {
username: {
type: Object,
value: {},
},
chatType: {
type: String,
value: msgType.chatType.SINGLE_CHAT,
},
},
data: {
inputMessage: "", // render input 的值
userMessage: "", // input 的实时值
},
properties: {
username: {
type: Object,
value: {},
},
chatType: {
type: String,
value: msgType.chatType.SINGLE_CHAT,
},
},
data: {
inputMessage: "", // render input 的值
userMessage: "", // input 的实时值
template: null,
},
methods: {
focus(){
this.triggerEvent("inputFocused", null, { bubbles: true });
},
methods: {
focus() {
this.triggerEvent("inputFocused", null, {
bubbles: true
});
},
blur(){
this.triggerEvent("inputBlured", null, { bubbles: true });
},
blur() {
this.triggerEvent("inputBlured", null, {
bubbles: true
});
},
// bindinput 不能打冒号!
bindMessage(e) {
this.setData({
userMessage: e.detail.value
});
},
isGroupChat(){
return this.data.chatType == msgType.chatType.CHAT_ROOM;
},
emojiAction(emoji) {
var str;
var msglen = this.data.userMessage.length - 1;
if (emoji && emoji != "[del]") {
str = this.data.userMessage + emoji;
}
this.setData({
userMessage: str,
inputMessage: str
});
},
getSendToParam(){
return this.isGroupChat() ? this.data.username.groupId : this.data.username.your;
},
sendMessage() {
let me = this;
String.prototype.trim = function () {
return this.replace(/(^\s*)|(\s*$)/g, '');
}
if (!this.data.userMessage.trim()) {
return;
}
let id = WebIM.conn.getUniqueId();
let msg = new WebIM.message(msgType.TEXT, id);
let userId = wx.getStorageSync('user_id');
let companyName = wx.getStorageSync('company_name');
let avatar = wx.getStorageSync('avatar');
msg.set({
msg: this.data.userMessage,
from: this.data.username.myName,
to: this.data.username.your,
ext: {
id: userId,
name: companyName,
img: avatar,
touserid: this.data.username.id == userId ? this.data.username.touserid : this.data.username.id,
name1: this.data.username.name == companyName ? this.data.username.name1 : this.data.username.name,
img1: this.data.username.name == companyName ? this.data.username.img1 : this.data.username.img,
timer: WebIM.time()
},
roomType: false,
chatType: this.data.chatType,
success(id, serverMsgId) {
console.log('发送消息成功')
disp.fire('em.chat.sendSuccess', id, me.data.userMessage);
},
fail(id, serverMsgId) {
console.log('发送消息失败')
}
});
WebIM.conn.send(msg.body);
this.triggerEvent(
"newTextMsg", {
msg: msg,
type: msgType.TEXT,
}, {
bubbles: true,
composed: true
}
);
//
this.setData({
userMessage: "",
inputMessage: "",
});
},
sendCmd: function () {
let me = this;
let id = WebIM.conn.getUniqueId();
let msg = new WebIM.message(msgType.CMD, id);
let userId = wx.getStorageSync('user_id');
let companyName = wx.getStorageSync('company_name');
let avatar = wx.getStorageSync('avatar');
let params = Object.assign({}, me.data.template, {
id: userId,
name: companyName,
img: avatar,
touserid: this.data.username.id == userId ? this.data.username.touserid : this.data.username.id,
name1: this.data.username.name == companyName ? this.data.username.name1 : this.data.username.name,
img1: this.data.username.name == companyName ? this.data.username.img1 : this.data.username.img,
timer: WebIM.time()
});
msg.set({
msg: 'template',
from: me.data.username.myName,
to: me.data.username.your,
action: "template",
ext: params,
success: function () {
console.log('发送模板成功')
console.log(me.data.username.your)
getApp().addChatMember(me.data.username.your)
disp.fire('em.chat.sendSuccess', id);
},
fail: function () {
console.log('发送模板失败');
}
});
console.log(msg.body)
getApp().addChatMember(me.data.username.your)
// bindinput 不能打冒号!
bindMessage(e){
this.setData({
userMessage: e.detail.value
});
},
WebIM.conn.send(msg.body);
this.triggerEvent(
"newTextMsg", {
msg: msg,
type: msgType.CMD,
}, {
bubbles: true,
composed: true
}
);
}
},
emojiAction(emoji){
var str;
var msglen = this.data.userMessage.length - 1;
if(emoji && emoji != "[del]"){
str = this.data.userMessage + emoji;
}
else if(emoji == "[del]"){
let start = this.data.userMessage.lastIndexOf("[");
let end = this.data.userMessage.lastIndexOf("]");
let len = end - start;
if(end != -1 && end == msglen && len >= 3 && len <= 4){
str = this.data.userMessage.slice(0, start);
}
else{
str = this.data.userMessage.slice(0, msglen);
}
}
this.setData({
userMessage: str,
inputMessage: str
});
},
// lifetimes
created() {
sendMessage(){
let me = this;
},
attached() {
String.prototype.trim=function()
{
return this.replace(/(^\s*)|(\s*$)/g, '');
}
if(!this.data.userMessage.trim()){
return;
}
let id = WebIM.conn.getUniqueId();
let msg = new WebIM.message(msgType.TEXT, id);
msg.set({
msg: this.data.userMessage,
from: this.data.username.myName,
to: this.getSendToParam(),
roomType: false,
chatType: this.data.chatType,
success(id, serverMsgId){
//console.log('成功了')
disp.fire('em.chat.sendSuccess', id, me.data.userMessage);
},
fail(id, serverMsgId){
console.log('失败了')
}
});
if(this.data.chatType == msgType.chatType.CHAT_ROOM){
msg.setGroup("groupchat");
}
WebIM.conn.send(msg.body);
this.triggerEvent(
"newTextMsg",
{
msg: msg,
type: msgType.TEXT,
},
{
bubbles: true,
composed: true
}
);
//
this.setData({
userMessage: "",
inputMessage: "",
});
},
},
},
moved() {
// lifetimes
created(){},
attached(){},
moved(){},
detached(){},
ready(){},
});
},
detached() { },
ready() {
let template = wx.getStorageSync('template') || '';
if (!template) {
return
} else {
this.setData({
template: template
});
wx.removeStorageSync('template');
this.sendCmd();
}
},
});
\ No newline at end of file
......@@ -7,24 +7,46 @@
<template name="img">
<image class="avatar" src="{{ item.msg.data }}" style="width:90px; height:120px; margin:2px auto;" mode="aspectFit" bind:tap="previewImage" data-url="{{ item.msg.data }}" />
</template>
<template name="cmd">
<view class="tel-view">
<image src="{{ item.ext.goodImage?item.ext.goodImage:'/res/images/imgs/defaultgood.png' }}" class="good-img"></image>
<view class="right-content">
<view class="cmd-type">{{ item.ext.type }}</view>
<view class="cmd-price">{{ item.ext.price }}</view>
<view class="cmd-com">
<view class="cmd-text">品牌:</view>
<view class="cmd-value">{{ item.ext.brand }}</view>
</view>
<view class="cmd-com">
<view class="cmd-text">数量:</view>
<view class="cmd-value">{{ item.ext.num }}</view>
</view>
<view class="cmd-com">
<view class="cmd-text">货期:</view>
<view class="cmd-value">{{ item.ext.hq }}</view>
</view>
<view class="cmd-com">
<view class="cmd-text">时间:</view>
<view class="cmd-value">{{ item.ext.time }}</view>
</view>
</view>
</view>
</template>
<!-- view 换成 scroll-view效果更好 用view是为了要stopPullDownRefresh -->
<view scroll-y="true" class="{{ view }} wrap {{isIPX?'scroll_view_X': ''}}" bind:tap="onTap" scroll-into-view="{{ toView }}">
<view class="message" wx:for="{{ chatMsg }}" wx:key="{{ item.mid }}" id="{{ item.mid }}">
<view class="{{ item.style }}">
<!-- <view class="user">
<text class="user-text">{{ item.yourname + ' ' + item.time}}</text>
</view> -->
<image class="avatar" src="../../../images/theme@2x.png" />
<view class="msg">
<image class="avatar" src="{{item.ext.img?item.ext.img:'/res/images/imgs/s.png'}}" />
<view class="msg {{item.msg.type=='cmd'?'cmd-msg':''}}">
<image class="err {{(item.style == 'self' && item.isFail) ? 'show' : 'hide'}}" src="../../../images/msgerr.png" />
<!-- <image wx:if="{{item.style == 'self'}}" src="../../../images/poprightarrow@2x.png" class="msg_poprightarrow" /> -->
<!-- <image wx:if="{{item.style == ''}}" src="../../../images/popleftarrow@2x.png" class="msg_popleftarrow" /> -->
<view wx:if="{{ item.msg.type == 'img'}}">
<template is="{{ item.msg.type }}" data="{{ item }}" />
</view>
<view wx:if="{{ item.msg.type == 'cmd'}}">
<template is="{{ item.msg.type }}" data="{{ item }}" />
</view>
<view wx:elif="{{ item.msg.type == 'txt' || item.msg.type == 'emoji' }}">
<view class="template" wx:for="{{ item.msg.data }}" wx:key="">
<template is="{{ item.type }}" data="{{ item }}" />
......
......@@ -5,98 +5,101 @@
z-index: 0;
top: 50px;
}*/
.scroll_view,
.scroll_view_change {
/*width: 100%;
.scroll_view, .scroll_view_change {
/*width: 100%;
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 150rpx;*/
margin-bottom: 174rpx;
background-color: #fff;
margin-bottom: 174rpx;
background-color: #fff;
}
.scroll_view_X,
.scroll_view_change_X{
margin-bottom: 244rpx;
.scroll_view_X, .scroll_view_change_X {
margin-bottom: 244rpx;
}
.scroll_view_change {
/*bottom: 440rpx;*/
margin-bottom: 590rpx;
/*bottom: 440rpx;*/
margin-bottom: 590rpx;
}
.message {
height: auto;
margin: 0 24rpx 30rpx;
position: relative;
height: auto;
margin: 0 24rpx 30rpx;
position: relative;
}
.time {
margin:0rpx 0 0 92rpx
margin: 0rpx 0 0 92rpx;
}
.self .time{
margin:0rpx 92rpx 0 0 ;
.self .time {
margin: 0rpx 92rpx 0 0;
}
.time .time-text {
font-size: 22rpx;
color:#ADB6BF;
color: #adb6bf;
}
.user .user-text {
margin: auto 100rpx 8rpx;
font-size: 20rpx;
color: #dcdcdc;
display: block;
margin: auto 100rpx 8rpx;
font-size: 20rpx;
color: #dcdcdc;
display: block;
}
.avatar {
width: 68rpx;
height: 68rpx;
/* margin-left:24rpx; */
border-radius: 8rpx;
float: left;
width: 68rpx;
height: 68rpx;
/* margin-left:24rpx; */
border-radius: 8rpx;
float: left;
margin: 0 24rpx 0 0;
}
.msg {
display: inline-block;
padding: 14rpx 24rpx;
max-width: calc(85% - 80rpx);
/* min-height: 40rpx; */
font-size: 24rpx;
text-align: left;
word-break: break-all;
background-color: #DFECFC;
border-radius:8rpx;
position: relative;
display: inline-block;
padding: 14rpx 24rpx;
max-width: calc(85% - 80rpx);
/* min-height: 40rpx; */
font-size: 24rpx;
text-align: left;
word-break: break-all;
background-color: #dfecfc;
border-radius: 8rpx;
position: relative;
color: #515559;
}
.cmd-msg {
padding: 0;
background-color: #f5f9fc !important;
}
.msg .msg_poprightarrow {
position: absolute;
right: -10rpx;
height: 18rpx;
width: 18rpx;
margin-top: -10rpx;
position: absolute;
right: -10rpx;
height: 18rpx;
width: 18rpx;
margin-top: -10rpx;
}
.msg .msg_popleftarrow{
position:absolute;
left: -14rpx;
height: 18rpx;
width: 18rpx;
margin-top: -10rpx;
.msg .msg_popleftarrow {
position: absolute;
left: -14rpx;
height: 18rpx;
width: 18rpx;
margin-top: -10rpx;
}
.msg .msg-text {
line-height: 40rpx;
font-size: 26rpx;
margin: 0;
line-height: 40rpx;
font-size: 26rpx;
margin: 0;
}
/*.msg:before {
......@@ -109,42 +112,95 @@
}*/
.self {
text-align: right;
text-align: right;
}
.self .avatar {
float: right;
margin: 0 0 0 24rpx;
float: right;
margin: 0 0 0 24rpx;
}
.user {
position: relative;
bottom: -30rpx;
position: relative;
bottom: -30rpx;
}
.self .msg {
background-color: #FCF2DF;
background-color: #fcf2df;
}
.self .msg:before {
right: inherit;
left: 100%;
border-right-color: transparent;
border-left-color: #b2e281;
right: inherit;
left: 100%;
border-right-color: transparent;
border-left-color: #b2e281;
}
.template {
display: inline;
display: inline;
}
.err{
width: 32rpx;
height: 32rpx;
position: absolute;
left: -40rpx;
.err {
width: 32rpx;
height: 32rpx;
position: absolute;
left: -40rpx;
}
.hide {
display: none;
}
.show {
display: block;
}
.good-img {
height: 100rpx;
width: 100rpx;
position: absolute;
left:24rpx;
top:24rpx;
border-radius: 8rpx;
}
.tel-view {
font-size: 26rpx;
border: 1px solid #e6ecf2;
position: relative;
padding:24rpx 24rpx 24rpx 145rpx;
}
.cmd-type {
color: #515559;
font-size: 32rpx;
font-weight: 600;
}
.cmd-price {
font-size: 28rpx;
color: #ea1717;
font-weight: 600;
margin-top: 6rpx;
}
.cmd-text {
color: #8a9299;
position: absolute;
width: 78rpx;
left:0;
}
.cmd-value {
color: #515559;
}
.hide{
display: none;
.cmd-com::after{
display: block;
content:"";
clear: both;
}
.show{
display: block;
.cmd-com{
margin-top:10rpx;
position: relative;
padding-left:78rpx;
}
let WebIM = require("../../utils/WebIM")["default"];
let msgType = require("msgtype");
module.exports = function(sendableMsg, type, myName){
module.exports = function (sendableMsg, type, myName) {
var time = WebIM.time();
var renderableMsg = {
info: {
......@@ -10,41 +10,35 @@ module.exports = function(sendableMsg, type, myName){
},
username: sendableMsg.body.from == myName ? sendableMsg.body.to : sendableMsg.body.from,
yourname: sendableMsg.body.from,
name:sendableMsg.body.from == myName ? sendableMsg.body.ext.name1: sendableMsg.body.ext.name,
img: sendableMsg.body.from == myName ? sendableMsg.body.ext.img1: sendableMsg.body.ext.img,
msg: {
type: type,
url: sendableMsg.body.body.url,
data: getMsgData(sendableMsg, type),
},
ext:sendableMsg.body.ext,
style: sendableMsg.body.from == myName ? "self" : "",
time: time,
mid: sendableMsg.type + sendableMsg.id,
chatType: sendableMsg.body.chatType
};
if(type == msgType.IMAGE){
if (type == msgType.IMAGE) {
renderableMsg.msg.size = {
width: sendableMsg.body.body.size.width,
height: sendableMsg.body.body.size.height,
};
}else if (type == msgType.AUDIO) {
renderableMsg.msg.length = sendableMsg.body.length;
}else if (type == msgType.FILE){
renderableMsg.msg.data = [{data: "[当前不支持此格式消息展示]", type: "txt"}];
renderableMsg.msg.type = 'txt';
}
return renderableMsg;
function getMsgData(sendableMsg, type){
if(type == msgType.TEXT){
function getMsgData(sendableMsg, type) {
if (type == msgType.TEXT) {
return WebIM.parseEmoji(sendableMsg.value.replace(/\n/mg, ""));
}
else if(type == msgType.EMOJI){
} else if (type == msgType.EMOJI) {
return sendableMsg.value;
}
else if(type == msgType.IMAGE || type == msgType.VIDEO || type == msgType.AUDIO){
} else if (type == msgType.IMAGE) {
return sendableMsg.body.body.url;
} else if (type == msgType.FILE) {
return sendableMsg.body.body.msg
}
return "";
}
};
};
\ No newline at end of file
......@@ -2,10 +2,9 @@ let Disp = require("../../utils/Dispatcher");
let msgPackager = require("msgpackager");
let msgType = require("msgtype");
let msgStorage = new Disp();
let disp = require("../../utils/broadcast");
msgStorage.saveReceiveMsg = function(receiveMsg, type){
msgStorage.saveReceiveMsg = function (receiveMsg, type) {
let sendableMsg;
if(type == msgType.IMAGE){
if (type == msgType.IMAGE) {
sendableMsg = {
id: receiveMsg.id,
type: type,
......@@ -16,7 +15,6 @@ msgStorage.saveReceiveMsg = function(receiveMsg, type){
type: receiveMsg.type,
ext: receiveMsg.ext,
chatType: receiveMsg.type,
toJid: "",
body: {
type: type,
url: receiveMsg.url,
......@@ -29,8 +27,7 @@ msgStorage.saveReceiveMsg = function(receiveMsg, type){
},
},
};
}
else if(type == msgType.TEXT || type == msgType.EMOJI){
} else if (type == msgType.TEXT || type == msgType.EMOJI || type == msgType.CMD) {
sendableMsg = {
id: receiveMsg.id,
type: type,
......@@ -41,7 +38,6 @@ msgStorage.saveReceiveMsg = function(receiveMsg, type){
type: receiveMsg.type,
ext: receiveMsg.ext,
chatType: receiveMsg.type,
toJid: "",
body: {
type: type,
msg: receiveMsg.data,
......@@ -49,123 +45,32 @@ msgStorage.saveReceiveMsg = function(receiveMsg, type){
},
value: receiveMsg.data
};
}
else if (type == msgType.FILE) {
sendableMsg = {
id: receiveMsg.id,
type: type,
body: {
id: receiveMsg.id,
length: receiveMsg.file_length,
from: receiveMsg.from,
to: receiveMsg.to,
type: receiveMsg.type,
ext: receiveMsg.ext,
chatType: receiveMsg.type,
toJid: "",
body: {
type: type,
url: receiveMsg.url,
filename: receiveMsg.filename,
msg: "当前不支持此格式消息展示",
},
},
value: receiveMsg.data
};
}
else if(type == msgType.AUDIO){
sendableMsg = {
id: receiveMsg.id,
type: type,
accessToken: receiveMsg.token || receiveMsg.accessToken,
body: {
id: receiveMsg.id,
length: receiveMsg.length,
from: receiveMsg.from,
to: receiveMsg.to,
type: receiveMsg.type,
ext: receiveMsg.ext,
chatType: type,
toJid: "",
body: {
type: type,
url: receiveMsg.url,
filename: receiveMsg.filename,
filetype: receiveMsg.filetype,
from: receiveMsg.from,
to: receiveMsg.to
},
},
};
}
else{
} else {
return;
}
this.saveMsg(sendableMsg, type, receiveMsg);
this.saveMsg(sendableMsg, type);
};
msgStorage.saveMsg = function(sendableMsg, type, receiveMsg){
//console.log('sendableMsgsendableMsg', sendableMsg)
msgStorage.saveMsg = function (sendableMsg, type) {
let me = this;
let myName = wx.getStorageSync("myUsername");
let sessionKey;
// 仅用作群聊收消息,发消息没有 receiveMsg
if(receiveMsg && receiveMsg.type == "groupchat"){
sessionKey = receiveMsg.to + myName;
}
// 群聊发 & 单发 & 单收
else{
sessionKey = sendableMsg.body.from == myName
? sendableMsg.body.to + myName
: sendableMsg.body.from + myName;
}
sessionKey = sendableMsg.body.from == myName ?
sendableMsg.body.to + myName :
sendableMsg.body.from + myName;
let curChatMsg = wx.getStorageSync(sessionKey) || [];
let renderableMsg = msgPackager(sendableMsg, type, myName);
if(type == msgType.AUDIO) {
renderableMsg.msg.length = sendableMsg.body.length;
renderableMsg.msg.token = sendableMsg.accessToken;
}
curChatMsg.push(renderableMsg);
//console.log('renderableMsgrenderableMsg', renderableMsg)
if(type == msgType.AUDIO){
renderableMsg.msg.token = sendableMsg.accessToken;
//如果是音频则请求服务器转码
// wx.downloadFile({
// url: sendableMsg.body.body.url,
// header: {
// "X-Requested-With": "XMLHttpRequest",
// Accept: "audio/mp3",
// Authorization: "Bearer " + sendableMsg.accessToken
// },
// success(res){
// // wx.playVoice({
// // filePath: res.tempFilePath
// // });
// renderableMsg.msg.url = res.tempFilePath;
// save();
// },
// fail(e){
// console.log("downloadFile failed", e);
// }
// });
}
// else{
// save();
// }
save();
function save(){
function save() {
wx.setStorage({
key: sessionKey,
data: curChatMsg,
success(){
if (type == msgType.AUDIO || type == msgType.VIDEO) {
disp.fire('em.chat.audio.fileLoaded');
}
success() {
me.fire("newChatMsg", renderableMsg, type, curChatMsg, sessionKey);
}
});
}
};
module.exports = msgStorage;
module.exports = msgStorage;
\ No newline at end of file
......@@ -6,6 +6,7 @@ module.exports = {
AUDIO: "audio",
EMOJI: "emoji",
FILE: "chat",
CMD:'cmd',
//
chatType: {
SINGLE_CHAT: "singleChat",
......
let startX = 0
Component({
/**
* 组件的初始数据
*/
data: {
translateX: 0
},
/**
* 组件的方法列表
*/
methods: {
deleteItem: function (e) {
this.setData({
translateX: 0
})
this.triggerEvent('deleteChatItem', {}, {bubbles: true})
},
/**
* 滑动删除事件-滑动开始
*/
touchStartHandler: function(e) {
startX = e.touches[0].pageX
},
/**
* 滑动删除事件-滑动
*/
touchMoveHandler: function(e) {
let pageX = e.touches[0].pageX
let moveX = pageX - startX
if(Math.abs(moveX) < 80) {
return
}
// e.target.style.WebkitTransform = `translateX(${moveX}px)`
if (moveX > 0) { // 右滑 隐藏删除
if (Math.abs(this.data.translateX) == 0) {
return
} else {
this.setData({
translateX: 0
})
}
} else { // 左滑 显示删除
if (Math.abs(this.data.translateX) >= 160) {
return
} else {
this.setData({
translateX: -160
})
}
}
}
}
})
\ No newline at end of file
{
"component": true,
"usingComponents": {}
}
\ No newline at end of file
<view class='swipedelete-wrapper' bindtouchmove='touchMoveHandler' bindtouchstart='touchStartHandler' style="transform:translateX({{translateX}}rpx)">
<slot></slot>
<view class='swipedelete-btn' bindtap='deleteItem'>删除</view>
</view>
\ No newline at end of file
.swipedelete-wrapper {
transition: all .4s ease;
position: relative;
}
.swipedelete-btn {
/* position:absolute;
top:0;
right:-180rpx;
text-align:center;
background: #f00;
color:#fff;
width:160rpx;
height:100%;
display:flex;
justify-content:center;
align-items:center;*/
position:absolute;
right: -160rpx;
top:0;
background-color:#D0021B;
width:160rpx;
height:100%;
text-align:center;
color: #fff;
display:flex;
align-items:center;
justify-content:center;
}
\ No newline at end of file
......@@ -12,8 +12,9 @@ Page({
onLoad(options) {
let username = JSON.parse(options.username);
this.setData({ username: username });
console.log(username)
wx.setNavigationBarTitle({
title: username.your
title: username.title
});
},
......
// pages/detail/good/index.js
import { getData } from '../../../utils/util.js';
import { getData, changeTime } from '../../../utils/util.js';
import { apis } from '../../../utils/api.js';
Page({
......@@ -9,26 +9,33 @@ Page({
data: {
info: null,
editOrShow:-1,//1编辑 2在线沟通
goodId:"",
type:"",
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
let goodId = options.goodId || '';
let type = options.type||'';
this.getData(goodId,type)
this.setData({
goodId: options.goodId || '',
type: options.type || ''
})
},
getData: function (goodId, type) {
getData: function () {
let me = this;
let token = wx.getStorageSync('access_token');
let url = "";
let goodId = me.data.goodId;
let type = me.data.type;
if (type == 1) {
url = apis.goodsInfo;
} else if (type == 2) {
url = apis.goodsSearch;
} else {
return;
}
getData(url, 'get', {
"goods_id/eq": goodId,
......@@ -70,6 +77,47 @@ Page({
}
}, true)
},
editGood:function(){
wx.navigateTo({
url: "/pages/form/good/index?goodId="+this.data.goodId,
})
},
sendTemplate:function(){
let data = this.data.info;
let my = wx.getStorageSync("myUsername");
let companyName = wx.getStorageSync("company_name");
let userId = wx.getStorageSync("user_id");
let avatar = wx.getStorageSync("avatar");
let obj = {
userId: data.im_username,
type: data.goods_name,
price: data.currency == 1 ? '¥' + data.price : '$' + data.price,
brand: data.brand_name,
fz: data.encap,
num: data.stock + '',
hq: data.delivery_time,
time: changeTime(data.add_time * 1000),
goodImage: data.goods_images,
userName: data.company_name,
targetId: data.user_id,
userImg: data.avatar,
};
let queryObj = {
myName: my,
your: data.im_username,
name: data.company_name,
name1: companyName,
id: userId,
touserid: data.user_id,
title: data.company_name,
img: data.avatar,
img1: avatar
};
wx.setStorageSync('template', obj);
wx.navigateTo({
url: "/pages/detail/chat/index?username=" + JSON.stringify(queryObj)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
......@@ -81,7 +129,7 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.getData()
},
/**
......
......@@ -64,15 +64,15 @@
<text class="c-com">{{dateUtil.dateFormat(info.update_time*1000)}}</text>
</view>
</view>
<cover-image class="right" src="{{info.goods_images?info.goods_images:'/res/images/imgs/iclogo.png'}}"></cover-image>
<image class="right" src="{{info.goods_images?info.goods_images:'/res/images/imgs/defaultgood.png'}}"></image>
</view>
</view>
</view>
<view class="zxgt btn-com btn-com-y" wx:if="{{editOrShow==2}}">
<view class="zxgt btn-com btn-com-y" wx:if="{{editOrShow==2}}" bindtap="sendTemplate">
<text class="icon iconfont iconiconxiantiaoshouji11"></text>
<text class="gt-t">在线沟通</text>
</view>
<view class="zxgt btn-com btn-com-b" wx:if="{{editOrShow==1}}">
<view class="zxgt btn-com btn-com-b" wx:if="{{editOrShow==1}}" bindtap="editGood">
<text class="gt-t">编辑商品</text>
</view>
</view>
\ No newline at end of file
// pages/detail/xj/index.js
import { getData } from '../../../utils/util.js';
import { getData, changeTime } from '../../../utils/util.js';
import { apis } from '../../../utils/api.js';
Page({
/**
* 页面的初始数据
*/
data: {
info: null
info: null,
topInfo:"",
},
/**
......@@ -16,12 +18,29 @@ Page({
onLoad: function (options) {
let inquiryItemsId = options.inquiryItemsId || '';
let offerId = options.offerId || '';
this.getData(inquiryItemsId, offerId)
// this.getData(inquiryItemsId, offerId)
this.getTopInfo(inquiryItemsId,offerId)
},
getData: function (inquiryItemsId, offerId) {
getTopInfo: function (inquiryItemsId, offerId) {
let me = this;
let token = wx.getStorageSync('access_token');
getData(apis.inquiryInfo, 'get', { "inquiry_items_id/eq": inquiryItemsId, token: token }, function (res) {
if (res.errcode == 0) {
me.setData({
topInfo: res.inquiry_list[inquiryItemsId]
});
console.log(me.data.topInfo)
me.getData(inquiryItemsId, offerId,token)
} else if (res.errcode == 105001) {
me.setData({
topInfo: ""
})
}
}, true)
},
getData: function (inquiryItemsId, offerId, token) {
let me = this;
getData(apis.inquiryMyOffer, 'get', {
"offer_id/eq": offerId,
"inquiry_items_id/eq": inquiryItemsId,
......@@ -43,8 +62,51 @@ Page({
info: {}
})
}
}, true)
}, false)
},
sendTemplate:function(){
let data = this.data.info;
let my = wx.getStorageSync("myUsername");
let companyName = wx.getStorageSync("company_name");
let userId = wx.getStorageSync("user_id");
let avatar = wx.getStorageSync("avatar");
let img = "";
if(this.data.topInfo){
img = this.data.topInfo.goods_images||''
}else{
img = ""
}
let obj = {
userId: data.im_username,
type: data.goods_name,
price: data.currency == 1?'¥'+data.price:'$'+data.price,
brand: data.brand_name,
fz: data.encap,
num: data.number+'',
hq: data.delivery_time,
time: changeTime(data.add_time*1000),
goodImage: img,
userName: data.company_name,
targetId: data.user_id,
userImg: data.avatar,
};
let queryObj = {
myName: my,
your: data.im_username,
name: data.company_name,
name1: companyName,
id: userId,
touserid: data.user_id,
title: data.company_name,
img: data.avatar,
img1: avatar
};
wx.setStorageSync('template', obj);
wx.navigateTo({
url: "/pages/detail/chat/index?username=" + JSON.stringify(queryObj)
})
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
......
......@@ -72,7 +72,7 @@
</view>
</view>
<view class="zxgt btn-com btn-com-y" wx:if="{{info}}">
<view class="zxgt btn-com btn-com-y" wx:if="{{info}}" bindtap="sendTemplate">
<text class="icon iconfont iconiconxiantiaoshouji11"></text>
<text class="gt-t">在线沟通</text>
</view>
......
// pages/form/bj/index.js
import { getData, tips } from '../../../utils/util.js';
import { apis } from '../../../utils/api.js';
Page({
/**
* 页面的初始数据
*/
data: {
isShowSwitch:false,
inquiryItemsId: "",
offerId: "",
type: "",
isShowSwitch: false,
isShowTime: false,
currency: 1,
isClick: true
},
formSubmit: function (e) {
let obj = e.detail.value;
if (!obj.goods_name) {
tips('请填写型号');
return
} else if (!obj.brand_name) {
tips('请填写品牌');
return
} else if (!obj.number) {
tips('请填写数量');
return
} else if (!obj.price) {
tips('请填写价格');
return
} else {
if (obj.hq == 2) {//期货
if (!obj.day) {
tips('请填写货期');
return
}
}
}
this.postData(obj);
},
postData: function (obj) {
let me = this;
let token = wx.getStorageSync('access_token');
let url;
obj.hq == 1 ? obj.delivery_time = '现货' : obj.delivery_time = obj.day + '天';
obj.currency = this.data.currency;
obj.token = token;
if (me.data.type == 1) {
obj.inquiry_items_id = me.data.inquiryItemsId;
url = apis.offeradd;
} else {
obj.offer_id = me.data.offerId;
url = apis.offercontinue;
}
delete obj.day;
delete obj.hq;
if (me.data.isClick) {
me.setData({
isClick: false
})
getData(url, 'get', obj, function (res) {
if (res.errcode == 0) {
tips('提交成功')
// wx.showToast({
// title: '提交成功',
// icon: 'none',
// duration: 2000,
// success: function () {
// wx.navigateBack()
// }
// })
me.setData({
isClick: true
});
} else {
tips('提交失败')
me.setData({
isClick: true
})
}
}, true)
}
},
radioChange(e) {
let val = e.detail.value;
this.setData({
isShowTime: val == 1 ? false : true
})
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
console.log(options)
this.setData({
inquiryItemsId: options.inquiryItemsId || "",
offerId: options.offerId || "",
type: options.type || ""
})
},
/**
......@@ -63,10 +154,16 @@ Page({
onShareAppMessage: function () {
},
switchPrice:function(){
this.setData({
isShowSwitch:!this.data.isShowSwitch
})
changePrice: function (e) {
let type = e.target.dataset.pricetype;
this.setData({
currency: type,
isShowSwitch: false
})
},
switchPrice: function () {
this.setData({
isShowSwitch: !this.data.isShowSwitch
})
}
})
\ No newline at end of file
......@@ -7,70 +7,72 @@
</view>
<text class="icon iconfont iconiconxiantiaoshouji13 close-icon"></text>
</view>
<view class="form-item row verCenter">
<text class="form-item-title">*型号</text>
<view class="form-item-right">
<input placeholder="请输入产品型号(必填)" placeholder-class="placeholderClass" type="text"></input>
</view>
</view>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*品牌</text>
<view class="form-item-right">
<input placeholder="请输入品牌(必填)" placeholder-class="placeholderClass" type="text"></input>
<form bindsubmit="formSubmit">
<view class="form-item row verCenter">
<text class="form-item-title">*型号</text>
<view class="form-item-right">
<input placeholder="请输入产品型号(必填)" placeholder-class="placeholderClass" type="text" name="goods_name"></input>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title"> 封装</text>
<view class="form-item-right">
<input placeholder="请输入封装" placeholder-class="placeholderClass" type="text"></input>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*品牌</text>
<view class="form-item-right">
<input placeholder="请输入品牌(必填)" placeholder-class="placeholderClass" type="text" name="brand_name"></input>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*数量</text>
<view class="form-item-right">
<input placeholder="请输入数量(必填)" placeholder-class="placeholderClass" type="number"></input>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title"> 封装</text>
<view class="form-item-right">
<input placeholder="请输入封装" placeholder-class="placeholderClass" type="text" name="encap"></input>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top bj-item">
<text class="form-item-title">*报价</text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入单价" placeholder-class="placeholderClass" type="number"></input>
<view class="price-type" bindtap="switchPrice">
<text class="price-value">RMB</text>
<text class="icon iconfont iconbianzu1"></text>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*数量</text>
<view class="form-item-right">
<input placeholder="请输入数量(必填)" placeholder-class="placeholderClass" type="number" name="number"></input>
</view>
</view>
<view class="price-ul {{isShowSwitch?'show':''}}">
<view class="price-li active">RMB</view>
<view class="price-li px-hr-top">USD</view>
<view class="form-item row verCenter px-hr-top bj-item">
<text class="form-item-title">*报价</text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入单价" placeholder-class="placeholderClass" type="number" name="price"></input>
<view class="price-type" bindtap="switchPrice">
<text class="price-value">{{currency == 1?'RMB':'USD'}}</text>
<text class="icon iconfont iconbianzu1"></text>
</view>
</view>
<view class="price-ul {{isShowSwitch?'show':''}}">
<view class="price-li {{currency == 1?'active':''}}" data-pricetype="1" bindtap="changePrice">RMB</view>
<view class="price-li px-hr-top {{currency == 2?'active':''}}" data-pricetype="2" bindtap="changePrice">USD</view>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top qx-item">
<text class="form-item-title">*货期</text>
<view class="form-item-right">
<radio-group>
<label>
<radio value="1"/>现货
</label>
<label>
<radio value="2"/>期货
</label>
</radio-group>
<view class="form-item row verCenter px-hr-top qx-item">
<text class="form-item-title">*货期</text>
<view class="form-item-right">
<radio-group name="hq" bindchange="radioChange">
<label>
<radio value="1" checked/>现货
</label>
<label>
<radio value="2" />期货
</label>
</radio-group>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*时间</text>
<view class="form-item-right">
<input placeholder="请输入货期时间(天)" placeholder-class="placeholderClass" type="text"></input>
<view class="form-item row verCenter px-hr-top" hidden="{{!isShowTime}}">
<text class="form-item-title">*时间</text>
<view class="form-item-right">
<input placeholder="请输入货期时间(天)" placeholder-class="placeholderClass" type="text" name="day"></input>
</view>
</view>
</view>
<view class="form-hr"></view>
<view class="form-item row px-hr-bottom">
<text class="form-item-title">备注</text>
<view class="form-item-right">
<textarea placeholder="请输入备注" placeholder-class="placeholderClass" maxlength="-1" />
<view class="form-hr"></view>
<view class="form-item row px-hr-bottom">
<text class="form-item-title">备注</text>
<view class="form-item-right">
<textarea placeholder="请输入备注" placeholder-class="placeholderClass" maxlength="-1" name="remark"/>
</view>
</view>
</view>
<view class="btn-com btn-com-b hf-btn">回复报价</view>
<button class="btn-com btn-com-b hf-btn" form-type="submit">回复报价</button>
</form>
</view>
\ No newline at end of file
// pages/form/good/index.js
import { getData, chooseImg, tips } from '../../../utils/util.js';
import { apis } from '../../../utils/api.js';
Page({
/**
* 页面的初始数据
*/
data: {
isShowSwitch: false
isShowSwitch: false,
isShowTime: false,
imgUrl: null,
currency: 1,
isClick: true,
goodsName: "",
brandName: "",
encap: "",
stock: "",
price: "",
day: "",
goodId: "",
hq:"1"
},
......@@ -13,9 +27,152 @@ Page({
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.setData({
goodId: options.goodId || "",
});
if (this.data.goodId) {
wx.setNavigationBarTitle({
title: '编辑商品'
})
this.getGoodData();
} else {
wx.setNavigationBarTitle({
title: '新增商品'
})
}
},
getGoodData: function () {
let me = this;
let token = wx.getStorageSync('access_token');
let goodId = me.data.goodId;
getData(apis.goodsInfo, 'get', {
"goods_id/eq": goodId,
"token": token,
}, function (res) {
if (res.errcode == 0) {
if (res.total == 0) {
return
} else {
let infoObj = res.goods_list[me.data.goodId]
me.renderForm(infoObj)
}
} else {
tips('获取商品详情失败');
}
}, true)
},
renderForm: function (infoObj) {
this.setData({
goodsName:infoObj.goods_name,
brandName: infoObj.brand_name,
encap: infoObj.encap,
stock: infoObj.stock,
price: infoObj.price,
currency: infoObj.currency,
imgUrl:infoObj.goods_images
});
if(infoObj.delivery_time !== '现货'){
let day = infoObj.delivery_time.replace('天','');
console.log(day)
this.setData({
isShowTime:2,
hq:2,
day:day
});
}
},
formSubmit: function (e) {
let obj = e.detail.value;
if (!obj.goods_name) {
tips('请填写型号');
return
} else if (!obj.brand_name) {
tips('请填写品牌');
return
} else if (!obj.stock) {
tips('请填写库存');
return
} else if (!obj.price) {
tips('请填写价格');
return
} else {
if (obj.hq == 2) {//期货
if (!obj.day) {
tips('请填写货期');
return
}
}
}
this.postData(obj);
},
postData: function (obj) {
let me = this;
let token = wx.getStorageSync('access_token');
let url = "";
obj.hq == 1 ? obj.delivery_time = '现货' : obj.delivery_time = obj.day + '天';
obj.currency = this.data.currency;
obj.goods_images = this.data.imgUrl || '';
obj.token = token;
if (me.data.goodId) {
obj.goods_id = me.data.goodId;
url = apis.goodsSave
} else {
url = apis.goodsAdd;
}
delete obj.day;
delete obj.hq;
if (me.data.isClick) {
me.setData({
isClick: false
})
getData(url, 'get', obj, function (res) {
if (res.errcode == 0) {
tips('操作成功')
me.setData({
isClick: true
});
setTimeout(() => {
wx.navigateBack()
}, 1000)
} else {
tips('操作失败')
me.setData({
isClick: true
})
}
}, true)
}
},
radioChange(e) {
let val = e.detail.value;
this.setData({
isShowTime: val == 1 ? false : true,
hq:val
})
},
uploadImg: function () {
let me = this;
chooseImg(apis.ossupload, 1, function (url) {
me.setData({
imgUrl: url
})
})
},
deleteImg: function () {
this.setData({
imgUrl: null
})
},
deleteGood:function(){
},
/**
* 生命周期函数--监听页面初次渲染完成
*/
......@@ -64,6 +221,13 @@ Page({
onShareAppMessage: function () {
},
changePrice: function (e) {
let type = e.target.dataset.pricetype;
this.setData({
currency: type,
isShowSwitch: false
})
},
switchPrice: function () {
this.setData({
isShowSwitch: !this.data.isShowSwitch
......
{
"usingComponents": {},
"navigationBarTitleText": "新增商品"
"navigationBarTitleText": ""
}
\ No newline at end of file
......@@ -8,66 +8,79 @@
<text class="icon iconfont iconiconxiantiaoshouji13 close-icon"></text>
</view>
<view class="upload-view column verCenter">
<view class="upload column verCenter rowCenter">
<view class="upload column verCenter rowCenter" bindtap="uploadImg" wx:if="{{!imgUrl}}">
<text class="icon iconfont iconiconxiantiaoshouji15"></text>
<text class="upload-text">上传图片</text>
</view>
<view class="hasImg" wx:else>
<cover-image src="{{imgUrl}}"></cover-image>
<text class="icon iconfont iconiconxiantiaoshouji7 deleteImg" bindtap="deleteImg"></text>
</view>
<view class="text">据说上传图片更容易被采纳报价</view>
</view>
<view class="form-item row verCenter">
<text class="form-item-title">*型号</text>
<view class="form-item-right">
<input placeholder="请输入产品型号(必填)" placeholder-class="placeholderClass"></input>
<form bindsubmit="formSubmit">
<view class="form-item row verCenter">
<text class="form-item-title">*型号</text>
<view class="form-item-right">
<input placeholder="请输入产品型号(必填)" placeholder-class="placeholderClass" value="{{goodsName}}" type="text" name="goods_name"></input>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*品牌</text>
<view class="form-item-right">
<input placeholder="请输入品牌(必填)" placeholder-class="placeholderClass"></input>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*品牌</text>
<view class="form-item-right">
<input placeholder="请输入品牌(必填)" placeholder-class="placeholderClass" type="text" name="brand_name" value="{{brandName}}"></input>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title"> 封装</text>
<view class="form-item-right">
<input placeholder="请输入封装" placeholder-class="placeholderClass"></input>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title"> 封装</text>
<view class="form-item-right">
<input placeholder="请输入封装" placeholder-class="placeholderClass" type="text" name="encap" value="{{encap}}"></input>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*库存</text>
<view class="form-item-right">
<input placeholder="请输入库存数量(必填)" placeholder-class="placeholderClass"></input>
<view class="form-item row verCenter px-hr-top">
<text class="form-item-title">*库存</text>
<view class="form-item-right">
<input placeholder="请输入库存数量(必填)" placeholder-class="placeholderClass" type="number" name="stock" value="{{stock}}"></input>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top bj-item">
<text class="form-item-title">*报价</text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入单价" placeholder-class="placeholderClass"></input>
<view class="price-type" bindtap="switchPrice">
<text class="price-value">RMB</text>
<text class="icon iconfont iconbianzu1"></text>
<view class="form-item row verCenter px-hr-top bj-item">
<text class="form-item-title">*报价</text>
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入单价" placeholder-class="placeholderClass" type="number" name="price" value="{{price}}"></input>
<view class="price-type" bindtap="switchPrice">
<text class="price-value">{{currency == 1?'RMB':'USD'}}</text>
<text class="icon iconfont iconbianzu1"></text>
</view>
</view>
<view class="price-ul {{isShowSwitch?'show':''}}">
<view class="price-li {{currency == 1?'active':''}}" data-pricetype="1" bindtap="changePrice">RMB</view>
<view class="price-li px-hr-top {{currency == 2?'active':''}}" data-pricetype="2" bindtap="changePrice">USD</view>
</view>
</view>
<view class="price-ul {{isShowSwitch?'show':''}}">
<view class="price-li active">RMB</view>
<view class="price-li px-hr-top">USD</view>
<view class="form-item row verCenter px-hr-top qx-item px-hr-bottom">
<text class="form-item-title">*货期</text>
<view class="form-item-right">
<radio-group name="hq" bindchange="radioChange">
<label>
<radio value="1" checked="{{hq == 1}}"/>现货
</label>
<label>
<radio value="2" checked="{{hq == 2}}"/>期货
</label>
</radio-group>
</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top qx-item px-hr-bottom">
<text class="form-item-title">*货期</text>
<view class="form-item-right">
<radio-group>
<label>
<radio value="1" checked/>现货
</label>
<label>
<radio value="2" checked/>期货
</label>
</radio-group>
<view class="form-item row verCenter px-hr-bottom" hidden="{{!isShowTime}}">
<text class="form-item-title">*时间</text>
<view class="form-item-right">
<input placeholder="请输入货期时间(天)" placeholder-class="placeholderClass" type="text" name="day" value="{{day}}"></input>
</view>
</view>
</view>
<view class="btn-com btn-com-b hf-btn">
<text class="icon iconfont iconiconxiantiaoshouji15"></text>
<text>新增商品</text>
</view>
<!-- <button class="btn-com btn-com-b hf-btn " form-type="submit" style="margin-bottom:{{'goodId'&&'32rpx'}}"> -->
<!-- <text class="icon iconfont iconiconxiantiaoshouji15"></text> -->
<button class="btn-com btn-com-b hf-btn " form-type="submit">
<text>保存</text>
</button>
<!-- <button class="btn-com delete-btn" wx:if="{{goodId}}" bindtap="deleteGood">删除商品</button> -->
</form>
</view>
\ No newline at end of file
// pages/form/xj/index.js
import { getData, chooseImg } from '../../../utils/util.js';
import { getData, chooseImg, tips } from '../../../utils/util.js';
import { apis } from '../../../utils/api.js';
Page({
......@@ -9,28 +9,81 @@ Page({
data: {
isShowSwitch: false,
isShowTime: false,
imgUrl:null,
imgUrl: null,
currency: 1,
isClick: true
},
formSubmit: function (e) {
console.log(e)
let obj = e.detail.value;
if (!obj.goods_name) {
tips('请填写型号');
return
} else if (!obj.brand_name) {
tips('请填写品牌');
return
} else if (!obj.number) {
tips('请填写数量');
return
} else if (!obj.price) {
tips('请填写价格');
return
} else {
if (obj.hq == 2) {//期货
if (!obj.day) {
tips('请填写货期');
return
}
}
}
this.postData(obj);
},
postData: function (obj) {
let me = this;
let token = wx.getStorageSync('access_token');
obj.hq == 1 ? obj.delivery_time = '现货' : obj.delivery_time = obj.day + '天';
obj.currency = this.data.currency;
obj.goods_images = this.data.imgUrl || '';
obj.token = token;
delete obj.day;
delete obj.hq;
if (me.data.isClick) {
me.setData({
isClick: false
})
getData(apis.inquiryadd, 'get', obj, function (res) {
if (res.errcode == 0) {
tips('发布成功')
me.setData({
isClick: true
})
} else {
tips('发布失败')
me.setData({
isClick: true
})
}
}, true)
}
},
radioChange(e) {
let val = e.detail.value;
this.setData({
isShowTime: val == 1?false:true
isShowTime: val == 1 ? false : true
})
},
uploadImg:function(){
uploadImg: function () {
let me = this;
chooseImg(apis.ossupload, 1, function(url){
chooseImg(apis.ossupload, 1, function (url) {
me.setData({
imgUrl:url
imgUrl: url
})
})
},
deleteImg:function(){
deleteImg: function () {
this.setData({
imgUrl: null
})
......@@ -90,8 +143,14 @@ Page({
onShareAppMessage: function () {
},
changePrice: function (e) {
let type = e.target.dataset.pricetype;
this.setData({
currency: type,
isShowSwitch: false
})
},
switchPrice: function () {
this.setData({
isShowSwitch: !this.data.isShowSwitch
})
......
......@@ -48,14 +48,14 @@
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入单价" placeholder-class="placeholderClass" type="number" name="price"></input>
<view class="price-type" bindtap="switchPrice">
<text class="price-value">RMB</text>
<text class="price-value">{{currency == 1?'RMB':'USD'}}</text>
<text class="icon iconfont iconbianzu1"></text>
</view>
</view>
<view class="price-ul {{isShowSwitch?'show':''}}">
<view class="price-li active">RMB</view>
<view class="price-li px-hr-top">USD</view>
<view class="price-li {{currency == 1?'active':''}}" data-pricetype="1" bindtap="changePrice">RMB</view>
<view class="price-li px-hr-top {{currency == 2?'active':''}}" data-pricetype="2" bindtap="changePrice">USD</view>
</view>
</view>
<view class="form-item row verCenter px-hr-top qx-item">
......@@ -71,7 +71,7 @@
</radio-group>
</view>
</view>
<view class="form-item row verCenter px-hr-top" wx:if="{{isShowTime}}">
<view class="form-item row verCenter px-hr-top" hidden="{{!isShowTime}}">
<text class="form-item-title">*时间</text>
<view class="form-item-right">
<input placeholder="请输入货期时间(天)" placeholder-class="placeholderClass" type="text" name="day"></input>
......
......@@ -9,7 +9,9 @@ Page({
data: {
priceList: null,
topInfo: null,
total: 0
total: 0,
inquiryItemsId: "",
offerId:""
},
/**
......@@ -18,11 +20,15 @@ Page({
onLoad: function (options) {
let inquiryItemsId = options.inquiryItemsId || '';
let offerId = options.offerId || '';
this.getTopInfo(inquiryItemsId);
this.getList(inquiryItemsId, offerId)
this.setData({
inquiryItemsId: inquiryItemsId,
offerId: offerId
});
},
getTopInfo: function (id) {
getTopInfo: function () {
let me = this;
let id = me.data.inquiryItemsId;
getData(apis.inquirySearch, 'get', { "inquiry_items_id/eq": id }, function (res) {
if (res.errcode === 0) {
me.setData({
......@@ -35,8 +41,10 @@ Page({
}
}, false)
},
getList: function (inquiryItemsId, offerId) {
getList: function () {
let me = this;
let inquiryItemsId = me.data.inquiryItemsId;
let offerId = me.data.offerId;
let token = wx.getStorageSync('access_token');
let params = { token: token };
if (offerId) {
......@@ -53,8 +61,8 @@ Page({
})
} else {
let arr = res.data[0].items || [];
for (let i = 0; i < arr.length;i++){
arr[i].company_name = res.data[0].company_name||''
for (let i = 0; i < arr.length; i++) {
arr[i].company_name = res.data[0].company_name || ''
}
me.setData({
priceList: arr,
......@@ -81,7 +89,14 @@ Page({
* 生命周期函数--监听页面显示
*/
onShow: function () {
this.setData({
priceList: null,
topInfo: null,
total: 0,
})
this.getTopInfo();
this.getList()
},
/**
......@@ -126,9 +141,17 @@ Page({
duration: 2000
});
} else {
wx.navigateTo({
url: "/pages/form/bj/index",
})
if (this.data.total == 0) {
wx.navigateTo({
url: "/pages/form/bj/index?type=1&inquiryItemsId=" + this.data.inquiryItemsId,
})
} else {
let offerId = this.data.priceList[0].offer_id || ''
wx.navigateTo({
url: "/pages/form/bj/index?type=2&offerId=" + offerId,
})
}
}
}
......
......@@ -50,7 +50,7 @@
<text class="c-com">{{topInfo.remark||'--'}}</text>
</view>
</view>
<cover-image class="right" src="{{topInfo.goods_images?topInfo.goods_images:'/res/images/imgs/iclogo.png'}}"></cover-image>
<image class="right" src="{{topInfo.goods_images?topInfo.goods_images:'/res/images/imgs/defaultgood.png'}}"></image>
</view>
</view>
......@@ -65,7 +65,7 @@
</view>
<view class="bj-list">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata">
<cover-image src="/res/images/imgs/noxb.png" class="img"></cover-image>
<image src="/res/images/imgs/noxb.png" class="img"></image>
<!-- <view class="h3 bold">暂无报价信息</view> -->
</view>
<priceItem price-list="{{priceList}}" wx:if="{{priceList&&priceList.length!==0}}" price-type="4"></priceItem>
......
......@@ -16,7 +16,7 @@
</view>
<view class="qd-content">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata">
<cover-image src="/res/images/imgs/noxb.png" class="img"></cover-image>
<image src="/res/images/imgs/noxb.png" class="img"></image>
<view class="h3 bold">暂无询报价信息</view>
<view class="p">您还可以发布询价。</view>
<view class="fb_btn btn-com btn-com-b" bindtap="toXj">
......
......@@ -42,7 +42,7 @@
<text class="c-com">{{topInfo.remark||'--'}}</text>
</view>
</view>
<cover-image class="right" src="{{topInfo.goods_images?topInfo.goods_images:'/res/images/imgs/iclogo.png'}}"></cover-image>
<image class="right" src="{{topInfo.goods_images?topInfo.goods_images:'/res/images/imgs/defaultgood.png'}}"></image>
</view>
</view>
</view>
......@@ -57,7 +57,7 @@
</view>
<view class="bj-list">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata">
<cover-image src="/res/images/imgs/noxb.png" class="img"></cover-image>
<image src="/res/images/imgs/noxb.png" class="img"></image>
<view class="h3 bold">暂无报价信息</view>
</view>
<priceItem price-list="{{priceList}}" wx:if="{{priceList&&priceList.length!==0}}" price-type="3" xb="2"></priceItem>
......
......@@ -2,7 +2,7 @@
<view class='head column verCenter'>
<view class="head-logo column">
<view class='logo'>
<cover-image src="/res/images/imgs/iclogo.png" class="img"></cover-image>
<image src="/res/images/imgs/iclogo.png" class="img"></image>
</view>
<text class="t1">IC业务助手</text>
<text class='t2'>让询报价更轻松、便捷</text>
......
......@@ -49,7 +49,7 @@
</block>
<block wx:else>
<view class="view column rowCenter verCenter">
<cover-image src="/res/images/imgs/test.jpg " class="img"></cover-image>
<image src="/res/images/imgs/test.jpg " class="img"></image>
<text class="icon iconfont iconiconxiantiaoshouji7"></text>
</view>
</block>
......
......@@ -11,7 +11,7 @@
<view class="content">
<text class="time">更新时间:2019-05-10</text>
<view class="status row verCenter rowCenter">
<cover-image src="/res/images/imgs/test.jpg " class="img"></cover-image>
<image src="/res/images/imgs/test.jpg " class="img"></image>
<text class=c"></text>
</view>
<view class="error">
......
......@@ -26,7 +26,7 @@
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入图形验证码" placeholder-class="placeholderClass" name='captcha' data-type="3" bindinput='bindinputFn'></input>
<view class='code-img'>
<cover-image src="{{captchaUrl}}" class="img" bindtap='refreshVerification'></cover-image>
<image src="{{captchaUrl}}" class="img" bindtap='refreshVerification'></image>
</view>
</view>
</view>
......@@ -58,7 +58,7 @@
<block wx:elif="{{type === 3}}">
<view class="success column rowCenter verCenter">
<cover-image src="/res/images/imgs/scu.png" class="img"></cover-image>
<image src="/res/images/imgs/scu.png" class="img"></image>
<text class="t1">恭喜您,密码找回成功</text>
<text class="t2">请保管好您的账户信息。</text>
</view>
......
......@@ -2,7 +2,7 @@
<view class='head column verCenter'>
<view class="head-logo column">
<view class='logo'>
<cover-image src="/res/images/imgs/iclogo.png" class="img"></cover-image>
<image src="/res/images/imgs/iclogo.png" class="img"></image>
</view>
<text class="t1">IC业务助手</text>
<text class='t2'>让询报价更轻松、便捷</text>
......
......@@ -38,7 +38,7 @@
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入图形验证码" placeholder-class="placeholderClass" name='captcha' data-type="3" bindinput='bindinputFn'></input>
<view class='code-img'>
<cover-image src="{{captchaUrl}}" class="img" bindtap='refreshVerification'></cover-image>
<image src="{{captchaUrl}}" class="img" bindtap='refreshVerification'></image>
</view>
</view>
</view>
......
<view class="success column rowCenter verCenter">
<cover-image src="/res/images/imgs/success.png" class="img"></cover-image>
<image src="/res/images/imgs/success.png" class="img"></image>
<text class="tit">恭喜您,注册成功</text>
<navigator url="/pages/person/login/index" class="btn">资质认证</navigator>
<view class="txt">
......
......@@ -22,7 +22,7 @@
<view class="form-item-right row verCenter bothSide">
<input placeholder="请输入图形验证码" placeholder-class="placeholderClass" name='captcha' data-type="3" bindinput='bindinputFn'></input>
<view class='code-img'>
<cover-image src="{{captchaUrl}}" class="img" bindtap='refreshVerification'></cover-image>
<image src="{{captchaUrl}}" class="img" bindtap='refreshVerification'></image>
</view>
</view>
</view>
......
......@@ -16,7 +16,7 @@
</view>
<view class="searchresult-content">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata">
<cover-image src="/res/images/imgs/nodata.png" class="img"></cover-image>
<image src="/res/images/imgs/nodata.png" class="img"></image>
<view class="h3 bold">未搜索到相关信息</view>
<view class="p">
<text wx:if="{{tabIndex == 2}}">您还可以发布询价。</text>
......
......@@ -105,7 +105,7 @@ Page({
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh: function () {
console.log(111)
},
/**
......
......@@ -2,5 +2,6 @@
"usingComponents": {
"priceItem": "/components/priceItem/priceItem"
},
"navigationBarTitleText": "商品管理"
"navigationBarTitleText": "商品管理",
"enablePullDownRefresh":true
}
\ No newline at end of file
......@@ -17,7 +17,7 @@
</view>
<view class="good-content">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata">
<cover-image src="/res/images/imgs/nodata.png" class="img"></cover-image>
<image src="/res/images/imgs/nodata.png" class="img"></image>
<view class="h3 bold">未搜索到相关信息</view>
<view class="p">您还可以发布询价。</view>
<view class="btn-com btn-com-b add-good-btn" bindtap="fbGood">
......
......@@ -61,7 +61,6 @@ Page({
let interVal = setInterval(() => {
let translateY = me.data.translateY;
if (translateY + allHeight == 0) {
console.log('到底啦');
// clearInterval(interVal);
// let arr = me.data.xjList.concat();
// let arr1 = arr.splice(arrLen-2,arrLen);
......
......@@ -7,19 +7,19 @@
<view class="home-content">
<view class="home-function bothSide row">
<view class="function-item column verCenter" bindtap="toXj">
<cover-image src="/res/images/icons/home-s-1.png" class="img"></cover-image>
<image src="/res/images/icons/home-s-1.png" class="img"></image>
<text class="text">发布询价</text>
</view>
<view class="function-item column verCenter" bindtap="toQd">
<cover-image src="/res/images/icons/home-s-2.png" class="img"></cover-image>
<image src="/res/images/icons/home-s-2.png" class="img"></image>
<text class="text">抢单专区</text>
</view>
<view class="function-item column verCenter" bindtap="fbGood">
<cover-image src="/res/images/icons/home-s-3.png" class="img"></cover-image>
<image src="/res/images/icons/home-s-3.png" class="img"></image>
<text class="text">发布商品</text>
</view>
<view class="function-item column verCenter">
<cover-image src="/res/images/icons/home-s-4.png" class="img"></cover-image>
<image src="/res/images/icons/home-s-4.png" class="img"></image>
<text class="text">积分兑换</text>
</view>
</view>
......@@ -61,7 +61,7 @@
</view>
<view class="price-content">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata">
<cover-image src="/res/images/imgs/noxb.png" class="img" style="width:500rpx;"></cover-image>
<image src="/res/images/imgs/noxb.png" class="img" style="width:500rpx;"></image>
<view class="h3 bold">暂无询报价信息</view>
<view class="p" style="color:#61A0F2;padding-top:20rpx;">您还可以发布询价。</view>
</view>
......
<view class="mine" hover-class="none" hover-stop-propagation="false">
<view class="head row verCenter">
<view class="pic">
<cover-image class="im" src="{{userInfo.avatar ? userInfo.avatar:'/res/images/imgs/default.png'}}"></cover-image>
<image class="im" src="{{userInfo.avatar ? userInfo.avatar:'/res/images/imgs/default.png'}}"></image>
</view>
<view class="text">
<text class="t1">{{userInfo.company_name}}</text>
......@@ -91,7 +91,7 @@
<!-- 签到弹出层 -->
<view wx:if="{{isShow}}" class="layer-mask column verCenter rowCenter" hover-class="none" hover-stop-propagation="false">
<view class="layer column verCenter rowCenter">
<cover-image class="im" src="/res/images/imgs/star.png"></cover-image>
<image class="im" src="/res/images/imgs/star.png"></image>
<text class="t1">恭喜您获得</text>
<view class="txt">
<text class="t2">666</text>
......
......@@ -9,6 +9,8 @@ Page({
data: {
unReadSpotNum: 0,
arr: [],
userId:"",
customer:{}
},
/**
......@@ -18,7 +20,6 @@ Page({
let me = this;
//监听未读消息数
disp.on("em.xmpp.unreadspot", function (message) {
console.log(111)
me.setData({
arr: me.getChatList(),
unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
......@@ -50,24 +51,32 @@ Page({
array.sort((a, b) => {
return b.dateTimeNum - a.dateTimeNum
})
console.log(array)
return array;
},
into_singleChatRoom: function (detail) {
var my = wx.getStorageSync("myUsername");
console.log(detail)
var nameList = {
myName: my,
your: detail.username
your: detail.username,
name:detail.ext.name,
name1:detail.ext.name1,
id:detail.ext.id,
touserid:detail.ext.touserid,
title: detail.name,
img:detail.ext.img,
img1:detail.ext.img1
};
console.log(JSON.stringify(nameList))
wx.navigateTo({
url: "/pages/detail/chat/index?username=" + JSON.stringify(nameList)
});
},
into_chatRoom: function (event) {
let detail = event.currentTarget.dataset.item;
this.into_singleChatRoom(detail)
this.into_singleChatRoom(detail)
},
/**
* 生命周期函数--监听页面初次渲染完成
......@@ -81,8 +90,39 @@ Page({
*/
onShow: function () {
let my = wx.getStorageSync("myUsername");
let companyName = wx.getStorageSync("company_name")||'';
let userId = wx.getStorageSync("user_id") || '';
let avatar = wx.getStorageSync("avatar") || '';
let customerKey = 'rendered_' + getApp().globalData.customerNum + my
let customer = wx.getStorageSync(customerKey) || '';
if(customer){
this.setData({
customer:customer[customer.length-1]
})
console.log(this.data.customer)
}else{
this.setData({
customer: {
username: getApp().globalData.customerNum,
ext:{
name: getApp().globalData.customerName,
name1: companyName,
id: userId,
touserid: '',
img: '',
img1: avatar
},
name: getApp().globalData.customerName,
}
})
}
this.setData({
arr: this.getChatList(),
userId:wx.getStorageSync('user_id'),
unReadSpotNum: getApp().globalData.unReadMessageNum > 99 ? '99+' : getApp().globalData.unReadMessageNum,
});
},
......
{
"usingComponents": {},
"usingComponents": {
"swipe-delete": "../../../components/swipedelete/swipedelete"
},
"navigationBarTitleText": "消息"
}
\ No newline at end of file
<!--pages/tab/message/message.wxml-->
<view class="message-view">
<view class="nodata" wx:if="{{arr.length == 0}}">
<cover-image src="/res/images/imgs/nomessage.png" class="img"></cover-image>
<scroll-view scroll-y="true" class="message-view">
<!-- <view class="nodata" wx:if="{{arr.length == 0}}">
<image src="/res/images/imgs/nomessage.png" class="img"></image>
<view class="h3 bold">暂无询价消息</view>
</view>
<view class="message-content" wx:else>
</view> -->
<view class="message-content">
<view class="tip row bothSide verCenter">
<view class="tip-left">
<text class="icon iconfont iconiconxiantiaoshouji12 tip-icon"></text>
......@@ -13,19 +13,42 @@
<text class="icon iconfont iconiconxiantiaoshouji13 close-icon"></text>
</view>
<view class="message-list">
<view class="message-item px-hr-bottom row verCenter bothSide nowrap" wx:for="{{ arr }}" wx:key="index" catchtap="into_chatRoom" data-item="{{ item }}">
<view class="message-l row verCenter ellipsis">
<cover-image src="/res/images/imgs/iclogo.png" class="message-avar"></cover-image>
<view catchtap="into_chatRoom" data-item="{{customer}}">
<view class="message-item px-hr-bottom row bothSide nowrap">
<view class="message-l row ellipsis">
<image src="/res/images/imgs/timg.jpg" class="message-avar"></image>
<view class="message-l-view ellipsis">
<view class="message-c bold ellipsis">IC助手客服</view>
<view class="message-t ellipsis" wx:if="{{ customer.msg.data[0].data }}">{{ customer.msg.data[0].data }}</view>
<view class="message-t ellipsis" wx:if="{{customer.msg.type == 'img' }}">[图片]</view>
<view class="message-t ellipsis" wx:if="{{customer.msg.type == 'cmd' }}">{{customer.ext.type}} {{customer.ext.price}}</view>
</view>
</view>
<view class="message-r">
<view class="message-r-t">{{customer.time}}</view>
<view class="message-r-n" wx:if="{{ customer.unReadCount > 0 || customer.unReadCount == '99+' }}">{{ customer.unReadCount }}</view>
</view>
</view>
</view>
<view wx:for="{{ arr }}" wx:key="index" catchtap="into_chatRoom" data-item="{{ item }}">
<swipe-delete>
<view class="message-item px-hr-bottom row bothSide nowrap">
<view class="message-l row ellipsis">
<image src="{{item.img?item.img:'/res/images/imgs/s.png'}}" class="message-avar"></image>
<view class="message-l-view ellipsis">
<view class="message-c bold ellipsis">{{ item.username }}</view>
<view class="message-t ellipsis">{{ item.msg.data[0].data }}</view>
<view class="message-c bold ellipsis">{{ item.name||'--' }}</view>
<view class="message-t ellipsis" wx:if="{{ item.msg.data[0].data }}">{{ item.msg.data[0].data }}</view>
<view class="message-t ellipsis" wx:if="{{item.msg.type == 'img' }}">[图片]</view>
<view class="message-t ellipsis" wx:if="{{item.msg.type == 'cmd' }}">{{item.ext.type}} {{item.ext.price}}</view>
</view>
</view>
<view class="message-r">
<view class="message-r-t">{{item.time}}</view>
<view class="message-r-n" wx:if="{{ item.unReadCount > 0 || item.unReadCount == '99+' }}">{{ item.unReadCount }}</view>
</view>
</view>
</view>
</swipe-delete>
</view>
</view>
</view>
</view>
\ No newline at end of file
</scroll-view>
\ No newline at end of file
/* pages/tab/message/message.wxss */
page{
overflow: hidden
}
.message-view{
/* overflow: hidden; */
position: fixed;
top:0;
bottom:0;
left:0;
right:0;
overflow: hidden;
}
.tip {
......
......@@ -12,7 +12,7 @@
</view>
<view class="price-content">
<view wx:if="{{priceList&&priceList.length==0}}" class="nodata">
<cover-image src="/res/images/imgs/noxb.png" class="img"></cover-image>
<image src="/res/images/imgs/noxb.png" class="img"></image>
<view class="h3 bold">暂无询报价信息</view>
<view class="p">您还可以发布询价。</view>
<view class="fb_btn btn-com btn-com-b" bindtap="toXj">
......
......@@ -48,12 +48,13 @@
"list": []
},
"miniprogram": {
"current": 11,
"current": 7,
"list": [
{
"id": -1,
"name": "pages/form/xj/index",
"pathName": "pages/form/xj/index",
"query": "",
"scene": null
},
{
......@@ -83,6 +84,27 @@
"pathName": "pages/person/certification/certificationmanage/index",
"query": "",
"scene": null
},
{
"id": 5,
"name": "pages/form/bj/index",
"pathName": "pages/form/bj/index",
"query": "type=2&offerId=156386287503289",
"scene": null
},
{
"id": 6,
"name": "pages/form/good/index",
"pathName": "pages/form/good/index",
"query": "goodId=156454347576866",
"scene": null
},
{
"id": 7,
"name": "pages/detail/chat/index",
"pathName": "pages/detail/chat/index",
"query": "username={\"myName\":\"7a2765fc7caa5e512a6d1270bcf98bf0\",\"your\":\"06b6a13c7ae849be08c98ceeefd6ee7f\",\"name\":\"sy\",\"name1\":\"11\",\"id\":\"53\",\"touserid\":\"54\",\"title\":\"11\",\"img\":\"http://img.icsales.com/test/images/icsales/201907/18/ee8b86dc8cac0e5df402a72d77a1b75e.png\",\"img1\":\"http://img.icsales.com/test/images/icsales/201907/18/767111a5b24e07d950506ea9452ff57c.jpg\"}",
"scene": null
}
]
}
......
......@@ -97,7 +97,7 @@ textarea {
right: 24rpx;
background-color: #fff;
box-shadow: 2px 2px 5px #ddd;
z-index: 2;
z-index: 3;
border-radius: 2rpx;
display: none;
}
......@@ -154,10 +154,24 @@ textarea {
width:100%;
}
.deleteImg{
font-size:48rpx !important;
color:#EA1717;
font-size:30rpx !important;
color:#fff;
position: absolute;
top:0;
right:0;
transform: translate(30%,-30%)
transform: translate(30%,-30%);
background-color: #EA1717;
height:44rpx;
width:44rpx;
text-align: center;
line-height: 44rpx;
border-radius: 50%;
}
.delete-btn{
margin-bottom:60rpx;
border:2rpx solid #D8DFE6;
background-color: #fff;
color:#686E73;
box-sizing: border-box;
}
......@@ -110,12 +110,14 @@ WebIM.parseEmoji = function (msg) {
return objList;
};
WebIM.time = function () {
WebIM.time = function (str) {
var date = new Date();
var Hours = date.getHours();
var Minutes = date.getMinutes();
var Seconds = date.getSeconds();
var time = date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate() + " "
var Month = date.getMonth() + 1;
var Day = date.getDate() ;
var time = date.getFullYear() + "-" + (Month < 10 ? "0" + Month : Month) + "-" + (Day < 10 ? "0" + Day : Day) + " "
+ (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds);
return time;
};
......@@ -123,41 +125,41 @@ WebIM.time = function () {
WebIM.Emoji = {
path: "../../../../../images/faces/",
map: {
"[):]": "ee_1.png",
"[:D]": "ee_2.png",
"[;)]": "ee_3.png",
"[:-o]": "ee_4.png",
"[:p]": "ee_5.png",
"[(H)]": "ee_6.png",
"[:@]": "ee_7.png",
"[:s]": "ee_8.png",
"[:$]": "ee_9.png",
"[:(]": "ee_10.png",
"[:'(]": "ee_11.png",
"[<o)]": "ee_12.png",
"[(a)]": "ee_13.png",
"[8o|]": "ee_14.png",
"[8-|]": "ee_15.png",
"[+o(]": "ee_16.png",
"[|-)]": "ee_17.png",
"[:|]": "ee_18.png",
"[*-)]": "ee_19.png",
"[:-#]": "ee_20.png",
"[^o)]": "ee_21.png",
"[:-*]": "ee_22.png",
"[8-)]": "ee_23.png",
"[(|)]": "ee_24.png",
"[(u)]": "ee_25.png",
"[(S)]": "ee_26.png",
"[(*)]": "ee_27.png",
"[(#)]": "ee_28.png",
"[(R)]": "ee_29.png",
"[({)]": "ee_30.png",
"[(})]": "ee_31.png",
"[(k)]": "ee_32.png",
"[(F)]": "ee_33.png",
"[(W)]": "ee_34.png",
"[(D)]": "ee_35.png"
'[):]': 'ee_1.png',
'[:D]': 'ee_2.png',
'[;)]': 'ee_3.png',
'[:-o]': 'ee_4.png',
'[:p]': 'ee_5.png',
'[(H)]': 'ee_6.png',
'[:@]': 'ee_7.png',
'[:s]': 'ee_8.png',
'[:$]': 'ee_9.png',
'[:(]': 'ee_10.png',
'[:"(]': 'ee_11.png',
'[:|]': 'ee_12.png',
'[(a)]': 'ee_13.png',
'[8o|]': 'ee_14.png',
'[8-|]': 'ee_15.png',
'[+o(]': 'ee_16.png',
'[o)]': 'ee_17.png',
'[|-)]': 'ee_18.png',
'[*-)]': 'ee_19.png',
'[:-#]': 'ee_20.png',
'[:-*]': 'ee_21.png',
'[^o)]': 'ee_22.png',
'[8-)]': 'ee_23.png',
'[(|)]': 'ee_24.png',
'[(u)]': 'ee_25.png',
'[(S)]': 'ee_26.png',
'[(*)]': 'ee_27.png',
'[(#)]': 'ee_28.png',
'[(R)]': 'ee_29.png',
'[({)]': 'ee_30.png',
'[(})]': 'ee_31.png',
'[(k)]': 'ee_32.png',
'[(F)]': 'ee_33.png',
'[(W)]': 'ee_34.png',
'[(D)]': 'ee_35.png'
}
};
......@@ -165,49 +167,49 @@ WebIM.EmojiObj = {
// 相对 emoji.js 路径
path: "../../../../../images/faces/",
map1: {
"[):]": "ee_1.png",
"[:D]": "ee_2.png",
"[;)]": "ee_3.png",
"[:-o]": "ee_4.png",
"[:p]": "ee_5.png",
"[(H)]": "ee_6.png",
"[:@]": "ee_7.png"
'[):]': 'ee_1.png',
'[:D]': 'ee_2.png',
'[;)]': 'ee_3.png',
'[:-o]': 'ee_4.png',
'[:p]': 'ee_5.png',
'[(H)]': 'ee_6.png',
'[:@]': 'ee_7.png'
},
map2: {
"[:s]": "ee_8.png",
"[:$]": "ee_9.png",
"[:(]": "ee_10.png",
"[:'(]": "ee_11.png",
"[<o)]": "ee_12.png",
"[(a)]": "ee_13.png",
"[8o|]": "ee_14.png"
'[:s]': 'ee_8.png',
'[:$]': 'ee_9.png',
'[:(]': 'ee_10.png',
'[:"(]': 'ee_11.png',
'[:|]': 'ee_12.png',
'[(a)]': 'ee_13.png',
'[8o|]': 'ee_14.png'
},
map3: {
"[8-|]": "ee_15.png",
"[+o(]": "ee_16.png",
"[|-)]": "ee_17.png",
"[:|]": "ee_18.png",
"[*-)]": "ee_19.png",
"[:-#]": "ee_20.png",
"[^o)]": "ee_21.png",
'[8-|]': 'ee_15.png',
'[+o(]': 'ee_16.png',
'[o)]': 'ee_17.png',
'[|-)]': 'ee_18.png',
'[*-)]': 'ee_19.png',
'[:-#]': 'ee_20.png',
'[:-*]': 'ee_21.png'
},
map4: {
"[:-*]": "ee_22.png",
"[8-)]": "ee_23.png",
"[(|)]": "ee_24.png",
"[(u)]": "ee_25.png",
"[(S)]": "ee_26.png",
"[(*)]": "ee_27.png",
"[(#)]": "ee_28.png"
'[^o)]': 'ee_22.png',
'[8-)]': 'ee_23.png',
'[(|)]': 'ee_24.png',
'[(u)]': 'ee_25.png',
'[(S)]': 'ee_26.png',
'[(*)]': 'ee_27.png',
'[(#)]': 'ee_28.png'
},
map5: {
"[(R)]": "ee_29.png",
"[({)]": "ee_30.png",
"[(})]": "ee_31.png",
"[(k)]": "ee_32.png",
"[(F)]": "ee_33.png",
"[(W)]": "ee_34.png",
"[(D)]": "ee_35.png"
'[(R)]': 'ee_29.png',
'[({)]': 'ee_30.png',
'[(})]': 'ee_31.png',
'[(k)]': 'ee_32.png',
'[(F)]': 'ee_33.png',
'[(W)]': 'ee_34.png',
'[(D)]': 'ee_35.png'
}
};
......
......@@ -183,7 +183,15 @@ const apis = {
/**
* 标记会员通知(已读)
*/
userMarkmsg: user_url + '/user/markmsg'
userMarkmsg: user_url + '/user/markmsg',
/**
* 环信通讯记录添加
*/
addrecord: user_url + '/im/add/record',
/**
* 环信通讯记录列表(最多显示30条最新的聊天记录)
*/
listrecord: user_url + '/im/list/record',
}
......
import { getData } from '../utils/util.js';
import { apis } from '../utils/api.js';
const WebIM = require("./WebIM")["default"];
let msgStorage = require("../components/chat/msgstorage");
let msgType = require("../components/chat/msgtype");
let disp = require("./broadcast");
let conn = {
closed: false,
curOpenOpt: {},
open(opt) {
/* wx.showLoading({
title: '正在初始化客户端...',
mask: true
}) */
this.curOpenOpt = opt;
WebIM.conn.open(opt);
this.closed = false;
},
reopen() {
if (this.closed) {
WebIM.conn.open(this.curOpenOpt);
this.closed = false;
}
}
};
const calcUnReadSpot = (message) => {
let myName = wx.getStorageSync("myUsername");
let allMembers = wx.getStorageSync("member") || []; //好友
let count = allMembers.reduce(function (result, curMember, idx) {
let chatMsgs = wx.getStorageSync(curMember.toLowerCase() + myName.toLowerCase()) || [];
return result + chatMsgs.length;
}, 0);
getApp().globalData.unReadMessageNum = count;
disp.fire("em.xmpp.unreadspot", message);
}
const onMessageError = (err) => {
if (err.type === "error") {
wx.showToast({
title: err.errorText
});
return false;
}
return true;
}
const getImUser = () => {
let me = this;
let token = wx.getStorageSync('access_token') || ''
getData(apis.authme, 'get', {
"token": token,
}, function (res) {
if (res.err_code == 0) {
wx.setStorageSync('user_id', res.data.user_id+'');
wx.setStorageSync('avatar', res.data.avatar);
wx.setStorageSync('company_name', res.data.company_name);
wx.setStorageSync("myUsername", res.data.im_username);
conn.open({
apiUrl: WebIM.config.apiURL,
user: res.data.im_username,
pwd: res.data.im_password,
appKey: WebIM.config.appkey
})
} else {
console.log('获取环信账号失败')
}
}, false)
};
const webimListen = () => {
WebIM.conn.listen({
onOpened(message) {
},
onReconnect() {
wx.showToast({
title: "重连中...",
duration: 2000
});
},
onSocketConnected() {
/* wx.showToast({
title: "socket连接成功",
duration: 2000
}); */
},
onClosed() {
wx.showToast({
title: "网络已断开",
icon: 'none',
duration: 2000
});
me.conn.closed = true;
WebIM.conn.close();
},
onCmdMessage(message) {
getApp().addChatMember(message.from)
if (message) {
if (onMessageError(message)) {
msgStorage.saveReceiveMsg(message, msgType.CMD);
}
calcUnReadSpot(message);
}
},
onTextMessage(message) {
if (message) {
if (onMessageError(message)) {
msgStorage.saveReceiveMsg(message, msgType.TEXT);
// console.log(111)
}
calcUnReadSpot(message);
}
},
onEmojiMessage(message) {
console.log("onEmojiMessage", message);
if (message) {
if (onMessageError(message)) {
msgStorage.saveReceiveMsg(message, msgType.EMOJI);
}
calcUnReadSpot(message);
}
},
onPictureMessage(message) {
console.log("onPictureMessage", message);
if (message) {
if (onMessageError(message)) {
msgStorage.saveReceiveMsg(message, msgType.IMAGE);
}
calcUnReadSpot(message);
}
},
// 各种异常
onError(error) {
console.log(error)
},
});
};
module.exports = {
// calcUnReadSpot: calcUnReadSpot,
// onMessageError: onMessageError,
webimListen: webimListen,
conn: conn,
getImUser: getImUser
}
\ No newline at end of file
//数据请求(get,post)
const getData = (url, type, param, callBack, loading, isheader) => {
wx.showNavigationBarLoading();
var token, header;
//获取token
token = wx.getStorageSync('access_token');
//参数字段追加来源字段
var params = Object.assign({}, param, {
source: 1
});
//是否启用loading加载效果
if (loading) {
wx.showLoading();
}
//是否启用请求头token
if (isheader) {
header = {
"Content-Type": "applciation/json",
"Authorization": 'Bearer ' + token
}
} else {
header = {
"Content-Type": "applciation/json"
}
}
wx.request({
url: url,
data: params,
header: header,
method: type,
success: (res) => {
//处理token失效的情况
if (res.data.hasOwnProperty('data')) {
if (res.data.data.err_code === 501 || res.data.data.errcode === 501) {
wx.navigateTo({
url: '/pages/person/login/index'
});
} else {
typeof callBack == "function" && callBack(res.data, "");
}
} else {
typeof callBack == "function" && callBack(res.data, "");
}
wx.hideNavigationBarLoading();
wx.showNavigationBarLoading();
var token, header;
//获取token
token = wx.getStorageSync('access_token');
//参数字段追加来源字段
var params = Object.assign({}, param, {
source: 1
});
//是否启用loading加载效果
if (loading) {
wx.showLoading();
}
//是否启用请求头token
if (isheader) {
header = {
"Content-Type": "applciation/json",
"Authorization": 'Bearer ' + token
}
} else {
header = {
"Content-Type": "applciation/json"
}
}
wx.request({
url: url,
data: params,
header: header,
method: type,
success: (res) => {
//处理token失效的情况
if (res.data.hasOwnProperty('data')) {
if (res.data.data.err_code === 501 || res.data.data.errcode === 501) {
wx.navigateTo({
url: '/pages/person/login/index'
});
} else {
typeof callBack == "function" && callBack(res.data, "");
}
} else {
typeof callBack == "function" && callBack(res.data, "");
}
wx.hideNavigationBarLoading();
if (loading) {
wx.hideLoading();
}
},
fail: (err) => {
},
fail: (err) => {
typeof callBack == "function" && callBack(null, err.errMsg);
typeof callBack == "function" && callBack(null, err.errMsg);
console.log(err);
console.log(err);
wx.hideNavigationBarLoading();
wx.hideNavigationBarLoading();
if (loading) {
wx.hideLoading();
}
}
})
}
})
};
//上传文件
const uploadFile = (url,paths,callBack) => {
const uploadFile = (url, paths, callBack) => {
wx.showLoading({
title: '上传中',
mask:true
mask: true
})
for (var i = 0; i < paths.length; i++) {
wx.uploadFile({
for (var i = 0; i < paths.length; i++) {
wx.uploadFile({
url: url,
filePath: paths[i],
name: 'upload',
formData: { token: wx.getStorageSync('access_token'), source: 2},
filePath: paths[i],
name: 'upload',
formData: { token: wx.getStorageSync('access_token'), source: 2 },
header: {
"Content-Type": "multipart/form-data"
},
success: (res) => {
},
success: (res) => {
var data = JSON.parse(res.data);
if (data.errcode == 103200) {
wx.showToast({
......@@ -97,42 +97,62 @@ const uploadFile = (url,paths,callBack) => {
duration: 2000
});
callBack(data.data[0])
} else {
} else {
wx.showToast({
title: '上传失败',
icon: 'none',
duration: 2000
});
}
},
fail: (e) => {
}
},
fail: (e) => {
console.log(e)
wx.showToast({
title: '上传失败',
icon: 'none',
duration: 2000
});
},
complete: () => {
wx.hideLoading();
}
})
}
},
complete: () => {
wx.hideLoading();
}
})
}
};
const chooseImg = (url,num, callback) => {
wx.chooseImage({
count: num,
const chooseImg = (url, num, callback) => {
wx.chooseImage({
count: num,
sizeType: ['original', 'compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
uploadFile(url,res.tempFilePaths, (rtn) => {
success: (res) => {
uploadFile(url, res.tempFilePaths, (rtn) => {
callback(rtn)
})
}
})
})
}
})
};
const tips = (text) => {
wx.showToast({
title: text,
icon: 'none',
duration: 2000
});
}
const changeTime = (str) => {
var date = new Date(str);
var Hours = date.getHours();
var Minutes = date.getMinutes();
var Seconds = date.getSeconds();
var Month = date.getMonth() + 1;
var Day = date.getDate();
var time = date.getFullYear() + "-" + (Month < 10 ? "0" + Month : Month) + "-" + (Day < 10 ? "0" + Day : Day) + " "
+ (Hours < 10 ? "0" + Hours : Hours) + ":" + (Minutes < 10 ? "0" + Minutes : Minutes) + ":" + (Seconds < 10 ? "0" + Seconds : Seconds);
return time;
};
module.exports = {
getData: getData,
chooseImg: chooseImg
getData: getData,
chooseImg: chooseImg,
tips: tips,
changeTime: changeTime
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment