补齐店务端改密导出员工订单
This commit is contained in:
@@ -14,6 +14,13 @@ module.exports = {
|
||||
})
|
||||
},
|
||||
|
||||
orders(userId, params) {
|
||||
return request({
|
||||
url: `/manager/employees/${userId}/orders`,
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
save(data) {
|
||||
return request({
|
||||
url: '/manager/employees',
|
||||
|
||||
@@ -1,4 +1,39 @@
|
||||
const request = require('../utils/request')
|
||||
const { ADMIN_API_BASE_URL, REQUEST_TIMEOUT } = require('../utils/config')
|
||||
|
||||
function buildDownloadUrl(params) {
|
||||
const query = Object.keys(params || {})
|
||||
.filter(key => params[key] !== undefined && params[key] !== null && params[key] !== '')
|
||||
.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`)
|
||||
.join('&')
|
||||
return `${ADMIN_API_BASE_URL}/export${query ? `?${query}` : ''}`
|
||||
}
|
||||
|
||||
function downloadFile(url, params) {
|
||||
const header = request.buildSignatureHeaders({
|
||||
url: '/export',
|
||||
requestUrl: url,
|
||||
method: 'GET',
|
||||
params
|
||||
})
|
||||
return new Promise((resolve, reject) => {
|
||||
wx.downloadFile({
|
||||
url,
|
||||
header,
|
||||
timeout: REQUEST_TIMEOUT,
|
||||
success(response) {
|
||||
if (response.statusCode >= 200 && response.statusCode < 300 && response.tempFilePath) {
|
||||
resolve(response.tempFilePath)
|
||||
return
|
||||
}
|
||||
reject(new Error(`导出 Excel 下载失败:HTTP ${response.statusCode}`))
|
||||
},
|
||||
fail(error) {
|
||||
reject(new Error(`导出 Excel 下载失败:${error.errMsg || '网络异常'}`))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
settings() {
|
||||
@@ -35,5 +70,10 @@ module.exports = {
|
||||
url: '/export',
|
||||
params
|
||||
})
|
||||
},
|
||||
|
||||
downloadExport(params) {
|
||||
const url = buildDownloadUrl(params)
|
||||
return downloadFile(url, params)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,5 +20,16 @@ module.exports = {
|
||||
},
|
||||
data
|
||||
})
|
||||
},
|
||||
|
||||
updatePassword(data) {
|
||||
return request({
|
||||
url: '/user/password',
|
||||
method: 'PUT',
|
||||
params: {
|
||||
__baseUrl: API_DOMAIN
|
||||
},
|
||||
data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,84 @@
|
||||
const dateUtil = require('../../utils/date')
|
||||
const employeesApi = require('../../api/employees')
|
||||
|
||||
function shortDate(value) {
|
||||
return String(value || '').slice(0, 10) || '-'
|
||||
}
|
||||
|
||||
function timeRange(item) {
|
||||
const start = String(item.startTime || '').slice(11, 16)
|
||||
const end = String(item.endTime || '').slice(11, 16)
|
||||
if (!start && !end) return '-'
|
||||
return `${start || '-'}-${end || '-'}`
|
||||
}
|
||||
|
||||
function orderAmount(item) {
|
||||
const value = item.amount !== undefined && item.amount !== null ? item.amount : item.manualProductPrice
|
||||
if (value === undefined || value === null || value === '') return '0'
|
||||
const amount = Number(value)
|
||||
if (Number.isNaN(amount)) return String(value)
|
||||
return amount.toFixed(2).replace(/\.00$/, '')
|
||||
}
|
||||
|
||||
function toOrderRow(item, index) {
|
||||
return {
|
||||
id: item.orderItemId || index,
|
||||
date: item.date || shortDate(item.startTime),
|
||||
project: item.productTitle || '预约作品',
|
||||
customer: item.customerName || '到店客户',
|
||||
artist: item.artistName || '未分配',
|
||||
time: timeRange(item),
|
||||
status: item.statusText || '-',
|
||||
amount: orderAmount(item)
|
||||
}
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
orders: [
|
||||
{ id: 1, date: '2026-06-01', project: '纯色美甲', customer: '王女士', amount: 168 },
|
||||
{ id: 2, date: '2026-05-31', project: '猫眼延长', customer: '陈女士', amount: 268 },
|
||||
{ id: 3, date: '2026-05-30', project: '手部护理', customer: '林女士', amount: 98 }
|
||||
]
|
||||
id: '',
|
||||
startDate: dateUtil.formatDate(dateUtil.startOfMonth(new Date())),
|
||||
endDate: dateUtil.formatDate(new Date()),
|
||||
orders: [],
|
||||
loading: false,
|
||||
loadError: ''
|
||||
},
|
||||
|
||||
onLoad(options) {
|
||||
this.setData({ id: options.id || '' })
|
||||
this.loadOrders()
|
||||
},
|
||||
|
||||
onStartDate(event) {
|
||||
this.setData({ startDate: event.detail.value }, () => this.loadOrders())
|
||||
},
|
||||
|
||||
onEndDate(event) {
|
||||
this.setData({ endDate: event.detail.value }, () => this.loadOrders())
|
||||
},
|
||||
|
||||
async loadOrders() {
|
||||
if (!this.data.id) {
|
||||
this.setData({ orders: [], loadError: '员工ID不能为空' })
|
||||
return
|
||||
}
|
||||
this.setData({ loading: true, loadError: '' })
|
||||
try {
|
||||
const list = await employeesApi.orders(this.data.id, {
|
||||
startDate: this.data.startDate,
|
||||
endDate: this.data.endDate
|
||||
})
|
||||
this.setData({
|
||||
orders: (Array.isArray(list) ? list : []).map(toOrderRow)
|
||||
})
|
||||
} catch (error) {
|
||||
this.setData({
|
||||
orders: [],
|
||||
loadError: error.message || '员工订单加载失败'
|
||||
})
|
||||
} finally {
|
||||
this.setData({ loading: false })
|
||||
}
|
||||
},
|
||||
|
||||
back() { wx.navigateBack() }
|
||||
})
|
||||
|
||||
@@ -1,9 +1,17 @@
|
||||
<view class="page no-tab">
|
||||
<view class="list">
|
||||
<view class="card form-card">
|
||||
<view class="field"><text class="field-label">开始日期</text><picker mode="date" value="{{startDate}}" bindchange="onStartDate"><view class="field-value">{{startDate}}</view></picker></view>
|
||||
<view class="field"><text class="field-label">结束日期</text><picker mode="date" value="{{endDate}}" bindchange="onEndDate"><view class="field-value">{{endDate}}</view></picker></view>
|
||||
</view>
|
||||
<view wx:if="{{loading}}" class="empty card">订单加载中...</view>
|
||||
<view wx:elif="{{loadError}}" class="empty card error">{{loadError}}</view>
|
||||
<view wx:elif="{{orders.length === 0}}" class="empty card">当前日期范围内没有订单</view>
|
||||
<view wx:else class="list">
|
||||
<view wx:for="{{orders}}" wx:key="id" class="card list-card order-row">
|
||||
<view>
|
||||
<text class="order-title">{{item.project}}</text>
|
||||
<text class="muted">{{item.date}} · {{item.customer}}</text>
|
||||
<text class="order-meta">{{item.artist}} · {{item.time}} · {{item.status}}</text>
|
||||
</view>
|
||||
<text class="amount">¥{{item.amount}}</text>
|
||||
</view>
|
||||
|
||||
@@ -15,3 +15,10 @@
|
||||
color: #6f8f83;
|
||||
font-weight: 900;
|
||||
}
|
||||
|
||||
.order-meta {
|
||||
display: block;
|
||||
margin-top: 6rpx;
|
||||
color: #8b8680;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ const dateUtil = require('../../utils/date')
|
||||
const planningApi = require('../../api/planning')
|
||||
const customersApi = require('../../api/customers')
|
||||
const employeesApi = require('../../api/employees')
|
||||
const shopApi = require('../../api/shop')
|
||||
|
||||
const PREVIEW_SIZE = 10
|
||||
|
||||
@@ -40,7 +41,8 @@ Page({
|
||||
previewColumns: [],
|
||||
previewRows: [],
|
||||
previewLoading: false,
|
||||
previewError: ''
|
||||
previewError: '',
|
||||
exporting: false
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -131,7 +133,31 @@ Page({
|
||||
})
|
||||
},
|
||||
|
||||
exportExcel() { wx.showToast({ title: '导出任务已创建', icon: 'none' }) },
|
||||
async exportExcel() {
|
||||
if (this.data.exporting) {
|
||||
return
|
||||
}
|
||||
this.setData({ exporting: true })
|
||||
try {
|
||||
const filePath = await shopApi.downloadExport({
|
||||
type: this.data.type,
|
||||
startDate: this.data.startDate,
|
||||
endDate: this.data.endDate
|
||||
})
|
||||
wx.openDocument({
|
||||
filePath,
|
||||
fileType: 'xlsx',
|
||||
showMenu: true,
|
||||
fail(error) {
|
||||
wx.showToast({ title: error.errMsg || 'Excel 打开失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || 'Excel 导出失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ exporting: false })
|
||||
}
|
||||
},
|
||||
|
||||
back() { wx.navigateBack() }
|
||||
})
|
||||
|
||||
@@ -42,5 +42,5 @@
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
<view class="fixed-bottom"><button class="primary-btn" bindtap="exportExcel">导出 Excel</button></view>
|
||||
<view class="fixed-bottom"><button class="primary-btn" loading="{{exporting}}" disabled="{{exporting}}" bindtap="exportExcel">导出 Excel</button></view>
|
||||
</view>
|
||||
|
||||
@@ -1,12 +1,48 @@
|
||||
const userApi = require('../../api/user')
|
||||
|
||||
function clearSessionAndGoLogin() {
|
||||
const app = getApp()
|
||||
if (app && typeof app.clearSession === 'function') {
|
||||
app.clearSession()
|
||||
}
|
||||
wx.reLaunch({ url: '/pages/login/index' })
|
||||
}
|
||||
|
||||
Page({
|
||||
data: { form: { oldPassword: '', newPassword: '', confirmPassword: '' } },
|
||||
data: {
|
||||
form: { oldPassword: '', newPassword: '', confirmPassword: '' },
|
||||
saving: false
|
||||
},
|
||||
onInput(event) { this.setData({ [`form.${event.currentTarget.dataset.field}`]: event.detail.value }) },
|
||||
save() {
|
||||
async save() {
|
||||
if (this.data.saving) {
|
||||
return
|
||||
}
|
||||
if (!this.data.form.oldPassword) {
|
||||
wx.showToast({ title: '请填写原密码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (!this.data.form.newPassword || !this.data.form.confirmPassword) {
|
||||
wx.showToast({ title: '请填写新密码', icon: 'none' })
|
||||
return
|
||||
}
|
||||
if (this.data.form.newPassword !== this.data.form.confirmPassword) {
|
||||
wx.showToast({ title: '两次密码不一致', icon: 'none' })
|
||||
return
|
||||
}
|
||||
wx.showToast({ title: '已提交' })
|
||||
this.setData({ saving: true })
|
||||
try {
|
||||
await userApi.updatePassword({
|
||||
oldPassword: this.data.form.oldPassword,
|
||||
password: this.data.form.newPassword
|
||||
})
|
||||
wx.showToast({ title: '密码已修改', icon: 'success' })
|
||||
setTimeout(clearSessionAndGoLogin, 600)
|
||||
} catch (error) {
|
||||
wx.showToast({ title: error.message || '密码修改失败', icon: 'none' })
|
||||
} finally {
|
||||
this.setData({ saving: false })
|
||||
}
|
||||
},
|
||||
back() { wx.navigateBack() }
|
||||
})
|
||||
|
||||
@@ -4,5 +4,5 @@
|
||||
<view class="field"><text class="field-label">新密码</text><input password value="{{form.newPassword}}" data-field="newPassword" bindinput="onInput" /></view>
|
||||
<view class="field"><text class="field-label">确认密码</text><input password value="{{form.confirmPassword}}" data-field="confirmPassword" bindinput="onInput" /></view>
|
||||
</view>
|
||||
<view class="fixed-bottom"><button class="primary-btn" bindtap="save">保存密码</button></view>
|
||||
<view class="fixed-bottom"><button class="primary-btn" loading="{{saving}}" disabled="{{saving}}" bindtap="save">保存密码</button></view>
|
||||
</view>
|
||||
|
||||
Reference in New Issue
Block a user