ts_aimz/pages/shop/betrayGoodsDetail/betrayGoodsDetail.js
2025-06-16 15:04:57 +08:00

438 lines
13 KiB
JavaScript

// pages/shop/publishCopyright/publishCopyright.js
import Shop from '../../../net/api/shop'
import {
sImgPrefix
} from '../../../net/mainUrl'
const Cache = require('../../../utils/storage')
var docFix = ['doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', 'pdf'];
var imgFix = ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'svg', 'ico', 'tiff', 'tif'];
// 工具函数:检查文件类型
function getFileExtension(filename) {
if (!filename || typeof filename !== 'string') return '';
var lastDot = filename.lastIndexOf('.');
return lastDot === -1 ? '' : filename.substring(lastDot + 1).toLowerCase();
}
function isImageFile(filename) {
return imgFix.indexOf(getFileExtension(filename)) !== -1;
}
function isDocumentFile(filename) {
return docFix.indexOf(getFileExtension(filename)) !== -1;
}
Page({
/**
* 页面的初始数据
*/
data: {
msgHint: '',
msgType: 'info',
msgShow: false,
showType: false,
goodsId: '',
goods: null,
typeNameList: [],
cardTypeName: '',
cityName: '',
leaderType: '',
needRefresh: false,
orderId: '',
order: null,
curTab: 0,
loadingState: 'loading',
pageData: {
page: 1,
rows: 10,
orderId: ''
},
isLoadMore: false,
hasMore: true,
listRefreshTrig: false,
replenlishList: [], //补充资料
kind: 'buy', //用来标识 buy买家 sell卖家
files: [],
downloadProgress: 0,
downloading: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '详情',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#FFFFFF', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
const orderId = options.orderId
const kind = options.kind
if (orderId && orderId != '') {
this.setData({
orderId: orderId,
kind: kind,
'pageData.orderId': orderId
})
this.doGetOrderDetail()
} else {
this.setData({
msgHint: '数据有误,请稍后重试',
msgType: 'error',
msgShow: true
})
setTimeout(() => {
wx.navigateBack()
}, 1500);
}
},
onShow() {
if (this.data.needRefresh) {
this.setData({
needRefresh: false
})
this.upPageNeedRefresh()
this.doGetOrderDetail()
this.doRefreshList()
}
},
//显示补充详情
doShowReplishDetail(e) {
const item = e.currentTarget.dataset.item
console.log(item)
if (this.data.kind == 'buy' && item.buyId == '') {
this.setData({
msgHint: '请补充内容',
msgType: 'error',
msgShow: true
})
return
}
if (this.data.kind == 'sell' && item.sellId == '') {
this.setData({
msgHint: '请补充内容',
msgType: 'error',
msgShow: true
})
return
}
wx.navigateTo({
url: '/pages/shop/replenishDetail/replenishDetail?id=' + item.correctionId + '&kind=' + this.data.kind,
})
},
bindChangeTab(e) {
const tabIndex = e.currentTarget.dataset.value
this.setData({
curTab: tabIndex
})
if (this.data.curTab == 2) {
//加载补充资料
this.doRefreshList()
}
},
//加载补充资料
doRefreshList() {
this.setData({
loadingState: 'loading',
listRefreshTrig: true,
replenlishList: [],
isLoadMore: false,
hasMore: true,
'pageData.page': 1
})
this.doGetReplenish(true)
},
//加载更多
doLoadMore() {
const _self = this
if (_self.data.isLoadMore || !_self.data.hasMore) {
return
}
//判断是否有更多
_self.setData({
isLoadMore: true,
'pageData.page': ++_self.data.pageData.page
})
_self.doGetReplenish(false)
},
//获取补充资料
doGetReplenish(isRefresh) {
const _self = this
Shop.doGetReplenishList(_self.data.kind, _self.data.pageData)
.then(res => {
console.log(res)
var status = 'success'
status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
_self.setData({
loadingState: isRefresh ? status : '',
replenlishList: _self.data.replenlishList.concat(res.rows),
isLoadMore: false,
listRefreshTrig: false,
hasMore: _self.data.replenlishList.length < res.total
})
})
.catch(err => {
console.log(err)
_self.setData({
loadingState: 'error',
isLoadMore: false,
hasMore: true,
listRefreshTrig: false
})
})
},
//获取订单详情
doGetOrderDetail() {
wx.showLoading({
title: '加载中...',
})
const _self = this
Shop.doGetOrderDetail(_self.data.orderId)
.then(res => {
wx.hideLoading()
console.log('订单详情', res)
res.goodsDTO.goodsPhoto = sImgPrefix + res.goodsDTO.goodsPhoto
_self.setData({
order: res
})
if (res.orderStatus == '过户已完成' && res.producePhoto != '') {
_self.doGetFileInfo(res.producePhoto)
}
})
.catch(err => {
wx.hideLoading()
_self.setData({
msgHint: err.msg ? err.msg : '网络错误,请稍后重试',
msgType: 'error',
msgShow: true
})
setTimeout(() => {
wx.navigateBack()
}, 1800);
})
},
// 添加baseUrl
addPrefix: function (list) {
return list.map(function (item) {
item.netUrl = sImgPrefix + item.fileId;
return item;
});
},
//获取文件详情
doGetFileInfo(ids) {
var that = this;
var data = {
ids: ids
};
wx.showLoading({
title: '加载中...'
});
Shop.doGetFileInfos(data)
.then(function (res) {
wx.hideLoading();
if (res && res !== null) {
const list = that.addPrefix(res)
that.setData({
files: list
})
}
})
.catch(function (err) {
wx.hideLoading();
that.showMessage(err.msg || '获取证书详情失败,请稍后重试', 'error');
});
},
showMessage: function (msg, type) {
this.setData({
msgHint: msg,
msgType: type || 'info',
msgShow: true
});
},
doPreImg(e) {
wx.previewImage({
urls: [e.currentTarget.dataset.value],
})
},
backPageRefresh() {
let pages = getCurrentPages();
let beforePage = pages[pages.length - 2];
beforePage.setData({
needRefresh: true
})
wx.navigateBack()
},
//取消订单
doCancelOrder() {
wx.showModal({
title: '提示',
content: '您确定要取消该订单吗?',
complete: (res) => {
if (res.confirm) {
this.goCancelOrder()
}
}
})
},
goCancelOrder() {
wx.showLoading({
title: '取消中...',
})
const _self = this
Shop.doCancelOrder(_self.data.orderId)
.then(res => {
wx.hideLoading()
_self.setData({
msgHint: '取消成功',
msgType: 'success',
msgShow: true
})
_self.upPageNeedRefresh()
_self.doGetOrderDetail()
})
.catch(err => {
wx.hideLoading()
_self.setData({
msgHint: err.msg ? err.msg : '网络错误,请稍后重试',
msgType: 'error',
msgShow: true
})
})
},
upPageNeedRefresh() {
let pages = getCurrentPages();
let beforePage = pages[pages.length - 2];
beforePage.setData({
needRefresh: true
})
},
//付款
async doPayOrder() {
try {
const _self = this
wx.showLoading({
title: '付款中...',
});
await Shop.doConfirmOrder(_self.data.orderId);
wx.hideLoading();
this.setData({
msgHint: '购买成功',
msgType: 'success',
msgShow: true
});
setTimeout(() => {
_self.upPageNeedRefresh()
_self.doGetOrderDetail()
}, 1500);
} catch (err) {
wx.hideLoading();
this.setData({
msgHint: err.msg ? err.msg : '网络错误,请稍后重试',
msgType: 'error',
msgShow: true
});
}
},
//填报受让人信息
bindFill() {
wx.navigateTo({
url: '/pages/shop/saveAssigneeInfo/saveAssigneeInfo?orderId=' + this.data.orderId,
})
},
//补充材料
goReplenish(e) {
const item = e.currentTarget.dataset.value
wx.navigateTo({
url: '/pages/shop/reportReplenish/reportReplenish?id=' + item.correctionId,
})
},
doPreImg: function (e) {
var url = e.currentTarget.dataset.value;
wx.previewImage({
urls: [url]
});
},
// 下载文件
doDownloadFile: function (e) {
var item = e.currentTarget.dataset.item;
// 判断是否是图片
if (isImageFile(item.fileName)) {
wx.previewImage({
urls: [item.netUrl]
});
} else {
// 判断是否支持打开
if (isDocumentFile(item.fileName)) {
// 去下载文件
this.goDownloadFile(item);
} else {
this.showMessage('该文件无法在小程序中打开,请前往电脑端查看', 'info');
}
}
},
goDownloadFile: function (item) {
var that = this;
that.setData({
downloadProgress: 0,
downloading: true
});
var token = Cache.get('token');
var header = {};
if (token) {
header.Auth = 'Bearer ' + token;
}
var downloadTask = wx.downloadFile({
url: item.netUrl,
header: header,
success: function (res) {
that.setData({
downloadProgress: 0,
downloading: false
});
if (res.statusCode === 200) {
wx.getFileSystemManager().saveFile({
tempFilePath: res.tempFilePath,
filePath: wx.env.USER_DATA_PATH + '/' + item.fileName,
success: function (res) {
wx.openDocument({
filePath: res.savedFilePath,
showMenu: true
});
},
fail: function (err) {
console.error('文件保存失败', err);
that.showMessage('很抱歉,文件下载出现问题。建议您稍作等待,之后再尝试下载。', 'error');
}
});
} else {
that.showMessage('很抱歉,文件下载出现问题。建议您稍作等待,之后再尝试下载。', 'error');
}
},
fail: function (err) {
console.log('下载失败', err);
that.showMessage('很抱歉,文件下载出现问题。建议您稍作等待,之后再尝试下载。', 'error');
}
});
downloadTask.onProgressUpdate(function (res) {
that.setData({
downloadProgress: res.progress
});
});
},
})