添加开发者发货功能

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
+1
View File
@@ -35,6 +35,7 @@
"pages/demand/list/index",
"pages/demand/detail/index",
"pages/demand/contract/index",
"pages/demand/deliver/index",
"pages/demand/agreement/index",
"pages/usercenter/balance/index"
],
@@ -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;
}
+19 -1
View File
@@ -11,7 +11,7 @@ Page({
needDays: '',
remark: '',
actualAccount: 0,
activeValues: [0, 1, 2, 3],
activeValues: [0, 1, 2, 3, 4],
demandInfo: null
},
@@ -103,6 +103,24 @@ Page({
urls: images
});
},
//交付凭证截图预览
onDeliveryImagePreview(e) {
const { images, index } = e.currentTarget.dataset;
const urls = (images || []).map(item => item.url);
if (!urls.length) {
return;
}
wx.previewImage({
current: urls[index],
urls
});
},
//去发货(交付开发成果)
deliverGoods() {
wx.navigateTo({
url: `/pages/demand/deliver/index?demandId=${this.data.id}`,
});
},
//参与竞标
submitBidding() {
const { id, quotedPrice, needDays, remark } = this.data;
@@ -53,6 +53,33 @@
<t-input label="{{opType=='quote' ? '我的优势' : 'Ta的优势'}}" placeholder="{{opType=='quote' ? '请填写您的优势技能' : '优势技能'}}" disabled="{{opType=='quote' && !demandInfo.myBidding ? false : true}}" value="{{opType=='quote' ? demandInfo.myBidding.remark : demandInfo.winBidding.remark}}" data-field="remark" bindchange="onInputChange" />
</view>
</t-collapse-panel>
<!-- 交付内容:开发者发货后展示,客户确认收货前可查看 -->
<block wx:if="{{_calc.getDelivery(demandInfo)}}">
<t-collapse-panel header="交付内容" value="{{4}}" expandIcon>
<view class="delivery-section">
<view class="delivery-title">开发完成凭证截图</view>
<view class="delivery-images">
<image wx:for="{{_calc.getDelivery(demandInfo).images}}" wx:key="index" class="delivery-image" src="{{item.url}}" mode="aspectFill" data-index="{{index}}" data-images="{{_calc.getDelivery(demandInfo).images}}" bindtap="onDeliveryImagePreview" />
</view>
<view class="delivery-title">交付附件</view>
<view class="file-list">
<view class="file-item" wx:for="{{_calc.getDelivery(demandInfo).files}}" wx:key="index">
<view class="file-item__name">
<t-tag max-width="420rpx" variant="light">{{item.name}}</t-tag>
</view>
<view class="file-item__ops">
<button class="mini-btn" type="default" size="mini" data-url="{{item.url}}" bindtap="fileUrlCopy">复制</button>
<button class="mini-btn mini-btn--primary" size="mini" data-url="{{item.url}}" bindtap="fileView">预览</button>
</view>
</view>
</view>
<block wx:if="{{_calc.getDelivery(demandInfo).remark}}">
<view class="delivery-title">发货备注</view>
<view class="delivery-remark">{{_calc.getDelivery(demandInfo).remark}}</view>
</block>
</view>
</t-collapse-panel>
</block>
</t-collapse>
@@ -73,6 +100,10 @@
<t-button theme="light" size="large" data-status="0" bind:tap="completeWork">完成失败</t-button>
<t-button theme="danger" size="large" data-status="1" bind:tap="completeWork" block>工作完成</t-button>
</view>
<view class="button-layout-flex" wx:elif="{{_calc.canDeliverGoods(demandInfo)}}">
<t-button theme="danger" size="large" bind:tap="deliverGoods" block>去发货</t-button>
</view>
<t-button wx:elif="{{_calc.isDelivered(demandInfo)}}" theme="light" size="large" disabled block>已发货(等待客户确认收货)</t-button>
</block>
</view>
<!-- 需求方 -->
@@ -64,6 +64,36 @@ var canConfirmReceipt = function (demandInfo) {
demandInfo.accept_status == 2;
}
// 获取交付内容(订单发货表,后端 detail 接口挂载的 delivery 字段,未发货返回 null)
var getDelivery = function (demandInfo) {
if (!demandInfo) {
return null;
}
return demandInfo.delivery || null;
}
// 开发者待发货:需求待收货(客户已付尾款)、自己中标且尚未交付
var canDeliverGoods = function (demandInfo) {
if (!demandInfo) return false;
return demandInfo.status == 5 &&
demandInfo.isMyWin &&
demandInfo.winBidding &&
demandInfo.winBidding.bidding_status == 2 &&
demandInfo.winBidding.process_status == 2 &&
!getDelivery(demandInfo);
}
// 开发者已发货、等待客户确认收货
var isDelivered = function (demandInfo) {
if (!demandInfo) return false;
return demandInfo.status == 5 &&
demandInfo.isMyWin &&
demandInfo.winBidding &&
demandInfo.winBidding.bidding_status == 2 &&
demandInfo.winBidding.process_status == 2 &&
!!getDelivery(demandInfo);
}
// 数值拼接单位,空值时不显示单位
var withUnit = function (value, unit) {
if (value === undefined || value === null || value === '') {
@@ -81,5 +111,8 @@ module.exports = {
canCompleteWork: canCompleteWork,
canAcceptPassed: canAcceptPassed,
canConfirmReceipt: canConfirmReceipt,
getDelivery: getDelivery,
canDeliverGoods: canDeliverGoods,
isDelivered: isDelivered,
withUnit: withUnit,
};
@@ -68,6 +68,40 @@ page {
color: var(--text-tertiary);
}
/* 交付内容 */
.delivery-section {
padding-bottom: 8rpx;
}
.delivery-title {
margin: 16rpx 0 12rpx;
font-size: 26rpx;
font-weight: 500;
color: var(--text-primary);
}
.delivery-images {
display: flex;
flex-wrap: wrap;
margin-right: -16rpx;
}
.delivery-image {
width: 160rpx;
height: 160rpx;
margin: 0 16rpx 16rpx 0;
border-radius: var(--radius-md, 12rpx);
background: var(--bg-grey);
}
.delivery-remark {
font-size: 26rpx;
line-height: 40rpx;
color: var(--text-tertiary);
white-space: pre-wrap;
word-break: break-all;
}
.button-submit {
margin: 32rpx;
}