You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
215 lines
4.4 KiB
215 lines
4.4 KiB
// pages/secondhand/publish.js
|
|
const toast = require('../../utils/toast.js')
|
|
Page({
|
|
data: {
|
|
images: [],
|
|
category: '',
|
|
title: '',
|
|
price: '',
|
|
condition: '',
|
|
description: '',
|
|
tradeMethod: '',
|
|
contact: ''
|
|
},
|
|
|
|
onLoad: function (options) {
|
|
// 初始化页面
|
|
},
|
|
|
|
// 选择图片
|
|
chooseImage: function () {
|
|
const that = this;
|
|
wx.chooseImage({
|
|
count: 6 - that.data.images.length,
|
|
sizeType: ['compressed'],
|
|
sourceType: ['album', 'camera'],
|
|
success: function (res) {
|
|
// 更新图片数组
|
|
that.setData({
|
|
images: [...that.data.images, ...res.tempFilePaths]
|
|
});
|
|
}
|
|
});
|
|
},
|
|
|
|
// 预览图片
|
|
previewImage: function (e) {
|
|
const index = e.currentTarget.dataset.index;
|
|
wx.previewImage({
|
|
current: this.data.images[index],
|
|
urls: this.data.images
|
|
});
|
|
},
|
|
|
|
// 删除图片
|
|
deleteImage: function (e) {
|
|
const index = e.currentTarget.dataset.index;
|
|
const images = this.data.images;
|
|
images.splice(index, 1);
|
|
this.setData({
|
|
images: images
|
|
});
|
|
},
|
|
|
|
// 选择分类
|
|
selectCategory: function (e) {
|
|
this.setData({
|
|
category: e.currentTarget.dataset.category
|
|
});
|
|
},
|
|
|
|
// 输入标题
|
|
inputTitle: function (e) {
|
|
this.setData({
|
|
title: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 输入价格
|
|
inputPrice: function (e) {
|
|
this.setData({
|
|
price: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 选择新旧程度
|
|
selectCondition: function (e) {
|
|
this.setData({
|
|
condition: e.currentTarget.dataset.condition
|
|
});
|
|
},
|
|
|
|
// 输入描述
|
|
inputDescription: function (e) {
|
|
this.setData({
|
|
description: e.detail.value
|
|
});
|
|
},
|
|
|
|
// 选择交易方式
|
|
selectTradeMethod: function (e) {
|
|
this.setData({
|
|
tradeMethod: e.currentTarget.dataset.method
|
|
});
|
|
},
|
|
|
|
// 输入联系方式
|
|
inputContact: function (e) {
|
|
this.setData({
|
|
contact: e.detail.value
|
|
});
|
|
},
|
|
//雷雨田2025.8.30添加
|
|
handleSubmit() {
|
|
if (!this.data.title) {
|
|
wx.showToast({ title: '标题不能为空', icon: 'none' })
|
|
return
|
|
}
|
|
if (!this.data.desc) {
|
|
wx.showToast({ title: '描述不能为空', icon: 'none' })
|
|
return
|
|
}
|
|
// 校验通过 -> 调用 showSuccess
|
|
wx.showToast({ title: '发布成功', icon: 'success' })
|
|
},
|
|
|
|
// 校验表单
|
|
validateForm: function () {
|
|
if (this.data.images.length === 0) {
|
|
wx.showToast({
|
|
title: '请至少上传一张商品图片',
|
|
icon: 'none'
|
|
});
|
|
return false;
|
|
}
|
|
if (!this.data.category) {
|
|
wx.showToast({
|
|
title: '请选择商品分类',
|
|
icon: 'none'
|
|
});
|
|
return false;
|
|
}
|
|
if (!this.data.title) {
|
|
wx.showToast({
|
|
title: '请输入商品名称',
|
|
icon: 'none'
|
|
});
|
|
return false;
|
|
}
|
|
if (!this.data.price) {
|
|
wx.showToast({
|
|
title: '请输入商品价格',
|
|
icon: 'none'
|
|
});
|
|
return false;
|
|
}
|
|
if (!this.data.condition) {
|
|
wx.showToast({
|
|
title: '请选择商品新旧程度',
|
|
icon: 'none'
|
|
});
|
|
return false;
|
|
}
|
|
if (!this.data.description) {
|
|
wx.showToast({
|
|
title: '请输入商品描述',
|
|
icon: 'none'
|
|
});
|
|
return false;
|
|
}
|
|
if (!this.data.tradeMethod) {
|
|
wx.showToast({
|
|
title: '请选择交易方式',
|
|
icon: 'none'
|
|
});
|
|
return false;
|
|
}
|
|
if (!this.data.contact) {
|
|
wx.showToast({
|
|
title: '请输入联系方式',
|
|
icon: 'none'
|
|
});
|
|
return false;
|
|
}
|
|
return true;
|
|
},
|
|
|
|
// 提交发布
|
|
submitPublish: function () {
|
|
if (!this.validateForm()) return;
|
|
|
|
// 这里应该调用发布商品的接口
|
|
wx.showLoading({
|
|
title: '发布中...'
|
|
});
|
|
|
|
// 模拟上传过程
|
|
setTimeout(() => {
|
|
wx.hideLoading();
|
|
wx.showToast({
|
|
title: '发布成功',
|
|
icon: 'success',
|
|
duration: 2000,
|
|
success: () => {
|
|
// 延迟返回,让用户看到成功提示
|
|
setTimeout(() => {
|
|
wx.navigateBack();
|
|
}, 1500);
|
|
}
|
|
});
|
|
}, 2000);
|
|
},
|
|
|
|
// 取消发布
|
|
cancelPublish: function () {
|
|
wx.showModal({
|
|
title: '确认取消',
|
|
content: '确定要放弃发布吗?已填写的内容将不会保存。',
|
|
success: (res) => {
|
|
if (res.confirm) {
|
|
wx.navigateBack();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
})
|