window.onload = function() {
mui.plusReady(function() {
var str = plus.storage.getItem('user');
var user = JSON.parse(str);
var token = user.Data.Token;
//调用相册
//mui('body').on('tap', '#headImage', function(e) {
// var imghtml = '';
// imghtml += '
';
// mui('#photos')[0].innerHTML = imghtml;
//});
//输入框为空
mui(document.body).on('tap', 'textarea', function() {
mui('textarea')[0].innerHTML = "";
mui('textarea')[0].style.color = 'black'
});
//调用相册函数
function galleryImgs() {
// 从相册中选择图片
mui.plusReady(function() {
plus.gallery.pick(function(e) {
var imghtml = '';
imghtml += '
';
mui('#photos')[0].innerHTML = imghtml;
}, function(e) {
mui.toast("取消选择图片");
}, {
filter: "image",
multiple: true,
maximum: 1,
system: false,
onmaxed: function() {
plus.nativeUI.alert('最多只能选择1张图片');
}
});
readFile(this)
})
};
//点击发布
mui('body').on('tap', '.fb', function() {
if(mui('#article')[0].innerHTML != '请填写动态内容') {
if(mui('.img')[0] != undefined) {
var image = new Image();
image.src = mui('.img')[0].src;
var img = image.src;
var im = img.substring(23, img.length)
var postDatas = {
"": im
}
mui.ajax("http://www.bosshand.cn/api/Customer/Base64StringToImage", {
data: postDatas,
dataType: 'json',
type: "post",
headers: {
authorization: token
},
success: function(resp) {
if(resp.Code == 200) {
var url = resp.Data;
var details = mui('#article')[0].value;
var postData = {
Name: "",
Description: "",
BgImg: "", //背景图片,
Remark: "",
Thumbnail: "", //缩略图,
Type: "",
Icon: "", //图标,
IsShow: 2, //是否首页显示(1是 2否),
TemplateCode: 0, //模版,
TemplateType: 2, //1-企业日志发布,2-商圈动态,3-点赞,4-评论
Content: details,
Atlas: url, //图集,
Advertising: "", //广告位,
}
mui.ajax("http://www.bosshand.cn/api/Customer/CompanyLogAddUpdate", {
data: postData,
dataType: 'json',
type: "post",
timeout: 10000, //超时时间设置为10秒;
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
authorization: token
},
success: function(resp) {
if(resp.Code == 200) {
mui.toast('发布成功');
var wobj = plus.webview.getWebviewById("communicate.html");
mui.fire(wobj, 'reload', {});
setTimeout(function() {
mui.back()
}, 500);
}
}
});
}
}
});
} else {
var details = mui('#article')[0].value;
var postData = {
Name: "",
Description: "",
BgImg: "", //背景图片,
Remark: "",
Thumbnail: "", //缩略图,
Type: "",
Icon: "", //图标,
IsShow: 2, //是否首页显示(1是 2否),
TemplateCode: 0, //模版,
TemplateType: 2, //1-企业日志发布,2-商圈动态,3-点赞,4-评论
Content: details,
Atlas: "", //图集,
Advertising: "", //广告位,
}
mui.ajax("http://www.bosshand.cn/api/Customer/CompanyLogAddUpdate", {
data: postData,
dataType: 'json',
type: "post",
timeout: 10000, //超时时间设置为10秒;
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
authorization: token
},
success: function(resp) {
if(resp.Code == 200) {
mui.toast('发布成功');
var wobj = plus.webview.getWebviewById("communicate.html");
mui.fire(wobj, 'reload', {});
setTimeout(function() {
mui.back()
}, 500);
}
}
});
}
} else {
mui.toast('请输入内容')
}
});
//图片转换为base64函数
// function getBaseImage(img) {
// var canvas = document.createElement("canvas");
// var width = img.width;
// var height = img.height;
// canvas.width = width; /*设置新的图片的宽度*/
// canvas.height = height; /*设置新的图片的长度*/
// var ctx = canvas.getContext("2d");
// ctx.drawImage(img, 0, 0, width, height); /*绘图*/
// var dataURL = canvas.toDataURL("image/png", 0.8);
// return dataURL.replace("data:image/png;base64,", "");
// }
// function loadImg() {
// //获取文件
// var file = $(".addBorder")[0].files[0];
//
// //创建读取文件的对象
// var reader = new FileReader();
//
// //创建文件读取相关的变量
// var imgFile;
//
// //为文件读取成功设置事件
// reader.onload = function(e) {
// alert('文件读取完成');
// imgFile = e.target.result;
//// $("#imgContent").attr('src', imgFile);
// };
// //正式读取文件
// reader.readAsDataURL(file);
// }
})
}
function readFile(img) {
// var file = obj.files[0];
var file = img.files[0];
var reader = new FileReader();
reader.readAsDataURL(file);
var imgFile;
reader.onload = function(e) {
var imghtml = "";
imghtml += '
';
mui('#photos')[0].innerHTML = imghtml;
// console.log(JSON.stringify(this.result))
}
}