添加开发者发货功能

This commit is contained in:
Dev
2026-09-30 14:56:56 +08:00
parent f13a5e682a
commit bc17810445
14 changed files with 768 additions and 4 deletions
@@ -0,0 +1,299 @@
// pages/demand/deliver/index.js
import { demandOperate } from '../../../services/demand/fetchDemand';
Page({
/**
* 页面的初始数据
*/
data: {
demandId: 0,
remark: '',
// 开发完成凭证截图(软件成品展示图等)
imageFiles: [],
imageMax: 9,
imageSizeLimit: {
size: 20, unit: 'MB', message: '图片大小不超过 {sizeLimit} MB'
},
// 交付附件(源码或软件成品文件)
attachFiles: [],
attachMax: 5,
attachConfig: {
count: 5,
},
attachSizeLimit: {
size: 20, unit: 'MB', message: '附件大小不超过 {sizeLimit} MB'
},
gridConfig: {
column: 4,
width: 160,
height: 160,
},
},
/**
* 生命周期函数--监听页面加载
*/
onLoad(options) {
const demandId = options?.demandId;
this.setData({ demandId });
},
// 备注变更
onRemarkChange(e) {
this.setData({ remark: e.detail.value });
},
// 凭证截图选择成功
handleSuccessImage(e) {
const files = e.detail?.files || [];
const { imageFiles, imageMax } = this.data;
const remain = imageMax - imageFiles.length;
const accepted = files.slice(0, remain);
if (files.length > remain) {
wx.showToast({
title: `最多上传${imageMax}张截图`,
icon: 'none'
});
}
if (!accepted.length) {
return;
}
this.setData({
imageFiles: [...imageFiles, ...accepted]
});
this.uploadFiles(accepted, 'image');
},
// 移除凭证截图
handleRemoveImage(e) {
const { index } = e.detail;
const { imageFiles } = this.data;
imageFiles.splice(index, 1);
this.setData({ imageFiles });
},
// 交付附件选择成功
handleSuccessAttach(e) {
const files = e.detail?.files || [];
const { attachFiles, attachMax } = this.data;
const remain = attachMax - attachFiles.length;
const accepted = files.slice(0, remain);
if (files.length > remain) {
wx.showToast({
title: `最多上传${attachMax}个附件`,
icon: 'none'
});
}
if (!accepted.length) {
return;
}
const list = [...attachFiles, ...accepted];
this.setData({
attachFiles: list,
attachConfig: { count: attachMax - list.length }
});
this.uploadFiles(accepted, 'attach');
},
// 移除交付附件
handleRemoveAttach(e) {
const { index } = e.currentTarget.dataset;
const { attachFiles, attachMax } = this.data;
attachFiles.splice(index, 1);
this.setData({
attachFiles,
attachConfig: { count: attachMax - attachFiles.length }
});
},
// 上传文件到服务器
uploadFiles(files, type) {
files.forEach((file, index) => {
if (file.status === 'done') {
return;
}
wx.uploadFile({
url: wx.$api.UploadFile,
filePath: file.url,
name: 'file',
formData: {
'name': file.name,
'type': file.type
},
header: {
'Accept': 'application/json',
'token': wx.getStorageSync('token')
},
success: (res) => {
if (res.statusCode == 413) {
wx.showToast({
title: '文件大小超出限制',
icon: 'none'
});
this.removeFileByUrl(file.url, type);
return;
}
let response = {};
try {
response = JSON.parse(res.data);
} catch (err) {
response = {};
}
if (response.code === 1 && response.data && response.data.length > 0) {
this.updateFile(type, {
...file,
fullUrl: response.data[0].url,
status: 'done'
});
if (index === files.length - 1) {
wx.showToast({
title: '上传成功',
icon: 'success'
});
}
} else {
wx.showToast({
title: response.msg || '上传失败',
icon: 'none'
});
this.removeFileByUrl(file.url, type);
}
},
fail: () => {
wx.showToast({
title: '上传失败',
icon: 'none'
});
this.removeFileByUrl(file.url, type);
}
});
});
},
// 上传完成后回写
updateFile(type, newFile) {
if (type === 'image') {
const { imageFiles } = this.data;
const idx = imageFiles.findIndex(item => item.url === newFile.url);
if (idx === -1) {
return;
}
const list = [...imageFiles];
list[idx] = newFile;
this.setData({ imageFiles: list });
} else {
const { attachFiles, attachMax } = this.data;
const idx = attachFiles.findIndex(item => item.url === newFile.url);
if (idx === -1) {
return;
}
const list = [...attachFiles];
list[idx] = newFile;
this.setData({
attachFiles: list,
attachConfig: { count: attachMax - list.length }
});
}
},
// 上传失败时移除
removeFileByUrl(url, type) {
if (type === 'image') {
this.setData({
imageFiles: this.data.imageFiles.filter(item => item.url !== url)
});
} else {
const { attachFiles, attachMax } = this.data;
const list = attachFiles.filter(item => item.url !== url);
this.setData({
attachFiles: list,
attachConfig: { count: attachMax - list.length }
});
}
},
// 表单验证
validateForm() {
const { imageFiles, attachFiles } = this.data;
if (!imageFiles.length) {
wx.showToast({
title: '请上传开发完成的凭证截图',
icon: 'none'
});
return false;
}
if (!attachFiles.length) {
wx.showToast({
title: '请上传源码或软件附件',
icon: 'none'
});
return false;
}
if (imageFiles.some(item => item.status !== 'done') || attachFiles.some(item => item.status !== 'done')) {
wx.showToast({
title: '文件上传中,请稍候',
icon: 'none'
});
return false;
}
return true;
},
// 提交发货
onSubmit() {
if (!this.validateForm()) {
return;
}
wx.showLoading({
title: '提交中...'
});
const { demandId, imageFiles, attachFiles, remark } = this.data;
// 只提交服务端地址与文件名,避免提交本地临时路径
const params = {
demandId,
opType: 'deliverGoods',
images: imageFiles.map(file => ({
url: file.fullUrl || file.url,
name: file.name || ''
})),
files: attachFiles.map(file => ({
url: file.fullUrl || file.url,
name: file.name
})),
remark
};
demandOperate(params).then(
(res) => {
console.log(res);
wx.hideLoading();
if (res.code == 1) {
wx.showModal({
title: '提示',
showCancel: false,
content: '发货成功,等待客户确认收货',
success: (res2) => {
if (res2.confirm) {
//返回上一页(需求详情)并刷新
wx.$util.backAndRefresh();
console.log('用户点击确定');
}
}
});
} else {
wx.showToast({
title: res.msg || '发货失败',
icon: 'none'
});
}
},
() => {
//接口异常处理
wx.hideLoading();
wx.showToast({
title: '操作失败',
icon: 'none'
});
},
);
}
})
@@ -0,0 +1,8 @@
{
"navigationBarTitleText": "发货",
"usingComponents": {
"t-upload": "tdesign-miniprogram/upload/upload",
"t-tag": "tdesign-miniprogram/tag/tag",
"t-textarea": "tdesign-miniprogram/textarea/textarea"
}
}
@@ -0,0 +1,81 @@
<!--pages/demand/deliver/index.wxml-->
<view class="page-content">
<!-- 开发完成凭证截图 -->
<view class="form-card">
<view class="form-card__head">
<text class="form-card__title">开发完成凭证截图</text>
<text class="form-card__require">*</text>
<text class="form-card__extra">最多 {{imageMax}} 张</text>
</view>
<view class="form-card__desc">上传软件成品展示图等开发完成凭证,供客户核对</view>
<t-upload
media-type="{{['image']}}"
files="{{imageFiles}}"
gridConfig="{{gridConfig}}"
max="{{imageMax}}"
size-limit="{{imageSizeLimit}}"
bind:success="handleSuccessImage"
bind:remove="handleRemoveImage"
/>
</view>
<!-- 交付附件 -->
<view class="form-card">
<view class="form-card__head">
<text class="form-card__title">交付附件(源码或软件成品)</text>
<text class="form-card__require">*</text>
<text class="form-card__extra">{{attachFiles.length}}/{{attachMax}}</text>
</view>
<view class="form-card__desc">上传源码或软件成品文件,客户确认收货后可下载,从聊天记录选择文件</view>
<view class="attach-list" wx:if="{{attachFiles.length}}">
<t-tag
wx:for="{{attachFiles}}"
wx:for-index="index"
wx:key="index"
class="file-tag-margin"
max-width="{{220}}"
size="medium"
variant="light"
data-index="{{index}}"
bind:close="handleRemoveAttach"
closable
>{{item.name}}</t-tag>
</view>
<t-upload
wx:if="{{attachFiles.length < attachMax}}"
files="{{[]}}"
gridConfig="{{gridConfig}}"
config="{{attachConfig}}"
size-limit="{{attachSizeLimit}}"
source="messageFile"
bind:success="handleSuccessAttach"
/>
</view>
<!-- 发货备注 -->
<view class="form-card">
<view class="form-card__head">
<text class="form-card__title">发货备注</text>
<text class="form-card__extra">选填</text>
</view>
<t-textarea
autosize="{{ { maxHeight: 120, minHeight: 50 } }}"
disableDefaultPadding="{{true}}"
placeholder="填写交付说明,如软件安装方式、源码目录结构、注意事项等"
value="{{remark}}"
bindchange="onRemarkChange"
maxlength="255"
/>
</view>
</view>
<!-- 底部提交栏 -->
<view class="wx-pay-cover">
<view class="wx-pay">
<view class="submit-btn {{(imageFiles.length && attachFiles.length) ? '' : 'btn-gray'}}" bindtap="onSubmit">
确认发货
</view>
</view>
</view>
@@ -0,0 +1,103 @@
/* pages/demand/deliver/index.wxss */
.page-content {
padding: 24rpx 24rpx calc(112rpx + env(safe-area-inset-bottom) + 24rpx);
box-sizing: border-box;
}
/* ================= 分组卡片 ================= */
.form-card {
background: var(--bg-card);
border-radius: var(--radius-lg);
padding: 32rpx;
margin-bottom: 24rpx;
box-shadow: var(--shadow-card);
}
.form-card__head {
display: flex;
align-items: baseline;
margin-bottom: 16rpx;
}
.form-card__title {
font-size: 30rpx;
font-weight: 600;
line-height: 44rpx;
color: var(--text-primary);
}
.form-card__require {
margin-left: 4rpx;
font-size: 28rpx;
line-height: 44rpx;
color: var(--error);
}
.form-card__extra {
margin-left: auto;
font-size: 22rpx;
line-height: 40rpx;
color: var(--text-tertiary);
}
.form-card__desc {
margin-bottom: 24rpx;
font-size: 24rpx;
line-height: 36rpx;
color: var(--text-tertiary);
}
/* ================= 附件标签 ================= */
.attach-list {
display: flex;
flex-wrap: wrap;
}
.file-tag-margin {
margin: 8rpx 16rpx 8rpx 0;
}
/* ================= 底部提交栏 ================= */
.wx-pay-cover {
position: fixed;
left: 0;
bottom: 0;
right: 0;
z-index: 10;
background: var(--bg-card);
height: 112rpx;
padding-bottom: env(safe-area-inset-bottom);
box-shadow: 0 -4rpx 20rpx rgba(29, 33, 41, 0.05);
}
.wx-pay-cover .wx-pay {
width: 100%;
height: 100rpx;
box-sizing: border-box;
padding: 0rpx 32rpx;
display: flex;
justify-content: center;
align-items: center;
}
.wx-pay-cover .wx-pay .submit-btn {
height: 80rpx;
width: 50%;
border-radius: 40rpx;
background: var(--brand-gradient);
box-shadow: var(--shadow-brand);
color: #ffffff;
line-height: 80rpx;
font-weight: 500;
font-size: 28rpx;
text-align: center;
}
.wx-pay-cover .wx-pay .submit-btn:active {
opacity: 0.88;
}
.wx-pay-cover .wx-pay .btn-gray {
background: var(--text-disabled);
box-shadow: none;
}