feat: harden phase one workflows
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
const { createSecondGoods } = require('../../api/secondGoodsApi')
|
||||
const { setField } = require('../../utils/request')
|
||||
const { setField, uploadFile } = require('../../utils/request')
|
||||
|
||||
Page({
|
||||
data: {
|
||||
submitting: false,
|
||||
imageText: '',
|
||||
uploading: false,
|
||||
form: {
|
||||
title: '',
|
||||
priceCent: 0,
|
||||
@@ -28,14 +28,43 @@ Page({
|
||||
this.setData({ 'form.tradeMethod': event.detail.value })
|
||||
},
|
||||
|
||||
onImageInput(event) {
|
||||
const imageText = event.detail.value
|
||||
this.setData({
|
||||
imageText,
|
||||
'form.imageUrls': imageText ? imageText.split(',').map((item) => item.trim()).filter(Boolean) : []
|
||||
chooseImages() {
|
||||
if (this.data.uploading) {
|
||||
return
|
||||
}
|
||||
wx.chooseMedia({
|
||||
count: Math.max(1, 6 - this.data.form.imageUrls.length),
|
||||
mediaType: ['image'],
|
||||
sourceType: ['album', 'camera'],
|
||||
success: (result) => {
|
||||
const files = result.tempFiles || []
|
||||
this.uploadImages(files.map((item) => item.tempFilePath))
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
uploadImages(filePaths) {
|
||||
if (!filePaths.length) {
|
||||
return
|
||||
}
|
||||
this.setData({ uploading: true })
|
||||
Promise.all(filePaths.map((filePath) => uploadFile(filePath)))
|
||||
.then((results) => {
|
||||
const urls = results.map((item) => item.url).filter(Boolean)
|
||||
this.setData({
|
||||
'form.imageUrls': this.data.form.imageUrls.concat(urls).slice(0, 6)
|
||||
})
|
||||
})
|
||||
.catch((error) => wx.showToast({ title: error.message, icon: 'none' }))
|
||||
.finally(() => this.setData({ uploading: false }))
|
||||
},
|
||||
|
||||
removeImage(event) {
|
||||
const index = Number(event.currentTarget.dataset.index)
|
||||
const next = this.data.form.imageUrls.filter((item, itemIndex) => itemIndex !== index)
|
||||
this.setData({ 'form.imageUrls': next })
|
||||
},
|
||||
|
||||
submit() {
|
||||
if (this.data.submitting) {
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user