ts_aimz/pages/shop/sellGoods/sellGoods.js
2025-06-11 11:22:53 +08:00

244 lines
6.8 KiB
JavaScript

// pages/shop/sellGoods/sellGoods.js
import Shop from '../../../net/api/shop'
import {
sImgPrefix
} from '../../../net/mainUrl'
const app = getApp()
Page({
data: {
pageData: {
page: 1,
rows: 10,
keywords: '',
keywords: '',
goodsLeaderType: '',
goodsGetTime: '',
goodsDevelop: '',
goodsType: ''
},
keywords: '',
priceStart: '',
priceEnd: '',
isLoadMore: false,
hasMore: true,
listLoading: 'loading',
listRefreshTrig: false,
goodsList: [],
imgPrefix: sImgPrefix,
localAssets: app.globalData.localAssets,
imgAssets: app.globalData.imgAssetsUrl,
typeList: [],
selType: '',
ownerList: [{
dataName: '自然人',
dataId: '1'
}, {
dataName: '法人',
dataId: '2'
}, {
dataName: '非法人组织或其他',
dataId: '3'
}],
selOwner: '',
msgType: 'info',
msgHint: '',
msgShow: false,
isScrolling: false,
scrollTimer: null,
needRefresh: false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
wx.setNavigationBarTitle({
title: '我要卖',
})
wx.setNavigationBarColor({
frontColor: '#000000', // 必写项,字体颜色仅支持#ffffff和#000000
backgroundColor: '#FFFFFF', // 传递的颜色值,仅支持十六进制颜色
animation: { // 可选项
duration: 500,
timingFunc: 'easeIn'
}
})
this.doGetDic()
this.doRefreshList()
},
onShow() {
if (this.data.needRefresh) {
this.setData({
needRefresh: false
})
this.doRefreshList()
}
},
inputKeywords(e) {
this.setData({
keywords: e.detail.value
})
},
doSearch() {
this.doRefreshList()
},
//滑动监听
onScrollListener(e) {
if (this.data.scrollTimer) {
clearTimeout(this.data.scrollTimer);
}
if (!this.data.isScrolling) {
this.setData({
isScrolling: true
});
}
const timer = setTimeout(() => {
this.setData({
isScrolling: false
});
}, 300);
this.setData({
scrollTimer: timer
});
},
bindChooseType(e) {
wx.pageScrollTo({
scrollTop: 0
})
setTimeout(() => {
const item = e.currentTarget.dataset.item;
let newSelType = this.data.selType;
// 先转数组,处理空字符串情况
const typeArr = newSelType ? newSelType.split(',') : [];
if (typeArr.includes(item.dataId)) {
// 删除
const index = typeArr.indexOf(item.dataId);
typeArr.splice(index, 1);
} else {
// 添加
typeArr.push(item.dataId);
}
// 转回字符串,自动处理空数组(转成空字符串)
newSelType = typeArr.join(',');
this.setData({
selType: newSelType
});
console.log('选择分类:', this.data.selType);
this.doRefreshList();
}, 500);
},
bindChooseOwner(e) {
const item = e.currentTarget.dataset.item
this.setData({
selOwner: this.data.selOwner == item.dataId ? '' : item.dataId
})
this.doRefreshList()
},
doGetDic() {
wx.showLoading({
title: '加载中...',
})
const that = this
Shop.doGetGoodsDic('0b00884a-f7a2-425f-93e5-599fbaad4bde')
.then(res => {
wx.hideLoading()
that.setData({
typeList: res
})
})
.catch(err => {
wx.hideLoading()
})
},
//刷新
doRefreshList() {
const _self = this
this.setData({
goodsList: [],
isLoadMore: false,
hasMore: true,
listRefreshTrig: true,
'pageData.page': 1,
'pageData.keywords': _self.data.keywords,
'pageData.priceOrder': _self.data.selOwner,
'pageData.priceRangeStart': _self.data.priceStart,
'pageData.priceRangeEnd': _self.data.priceEnd,
'pageData.goodsType': _self.data.selType,
})
_self.getIndexList(true)
},
//加载更多
doLoadMore() {
const _self = this
if (_self.data.isLoadMore || !_self.data.hasMore) {
return
}
//判断是否有更多
_self.setData({
isLoadMore: true,
'pageData.page': ++_self.data.pageData.page
})
_self.getIndexList(false)
},
//获取列表
getIndexList(isRefresh) {
const _self = this
_self.setData({
listLoading: isRefresh ? 'loading' : ''
})
Shop.doGetMineSellGoods(_self.data.pageData)
.then(res => {
console.log(res)
var status = 'success'
status = res.rows && res.rows.length > 0 ? 'success' : 'empty'
const list = _self.addPrefixToPreviewImgs(res.rows)
_self.setData({
listLoading: isRefresh ? status : '',
goodsList: _self.data.goodsList.concat(list),
listRefreshTrig: false,
isLoadMore: false,
})
_self.setData({
hasMore: _self.data.goodsList.length < res.total
})
})
.catch(err => {
console.log(err)
_self.setData({
listLoading: 'error',
listRefreshTrig: false,
isLoadMore: false,
hasMore: true
})
})
},
//为数据中图片添加前缀
addPrefixToPreviewImgs(data) {
const prefix = this.data.imgPrefix;
return data.map(item => {
if (item.goodsPhoto && item.goodsPhoto != '') {
item.preImg = prefix + item.goodsPhoto
}
return item;
});
},
//详情
doDetail(e) {
const id = e.currentTarget.dataset.value
wx.navigateTo({
url: '/pages/shop/sellGoodsDetail/sellGoodsDetail?id=' + id,
animation: 'fade'
})
},
//去创建软著商品
doCreateGoods() {
wx.navigateTo({
url: '/pages/shop/publishCopyright/publishCopyright',
})
}
})