* 返回顶部
*/
backTop: function() {
this.stickyFlag = false, wx.pageScrollTo({
scrollTop: 0,
duration: 500
});
},
//跳转
goLink: function(event) {
let url = event.currentTarget.dataset.link;
url && wx.navigateTo({ url })
},
//复制
copy: function () {
var that = this;
wx.setClipboardData({
data: that.data.goodsList[0].code,
success() {
wx.showToast({
title: '复制成功',
icon: 'success',
duration: 1000
})
}
})
},
/**
* 拨打电话
*/
callTelphone: function (e) {
var that = this;
var phoneNumber = e.currentTarget.dataset.phone;
if (phoneNumber) {
this.isCalling || (this.isCalling = true, wx.makePhoneCall({
phoneNumber: phoneNumber,
complete: function () {
that.isCalling = false;
}
}));
}
},
/**
* 搜索栏高度
*/
getScrollViewHeight: function () {
var that = this;
wx.createSelectorQuery().select(".search-bar").boundingClientRect(function (res) {
res.height && that.setData({
scrollViewHeight: wx.getSystemInfoSync().windowHeight - res.height
});
}).exec();
},
//图片上传
headsculpture: function (e) {
var that = this;
wx.chooseImage({
count: 1, //最多可以选择的图片总数
sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success: function (res) {
// 返回选定照片的本地文件路径列表,tempFilePath可以作为img标签的src属性显示图片
var tempFilePaths = res.tempFilePaths;
//启动上传等待中...
wx.showToast({
title: '正在上传...',
icon: 'loading',
mask: true,
duration: 2000,
})
wx.uploadFile({
url: '', //地址
filePath: tempFilePaths[0],
name: 'uploadfile_ant',
formData: {},
header: {
"Content-Type": "multipart/form-data"
},
success: function (res) {
var data = JSON.parse(res.data);
//服务器返回格式: { "Catalog": "testFolder", "FileName": "1.jpg", "Url": "https://test.com/1.jpg" }
console.log(data);
},
fail: function (res) {
wx.hideToast();
wx.showModal({
title: '错误提示',
content: '上传图片失败',
showCancel: false,
success: function (res) {}
})
}
});
}
});
},
//时间转换
getDateStr: function (seconds) {
var date = new Date(seconds)
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours();
var minute = date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes();
var second = date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
var currentTime = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
console.log(currentTime)
},
//返回上一页刷新
if (pages.length > 1) {
//上一个页面实例对象
var prePage = pages[pages.length - 2];
//关键在这里
prePage.onLoad()
setTimeout(function () {
wx.navigateBack({
delta: 1,
})
}, 2000)
}