2024-10-18 15:13:47 +08:00
|
|
|
|
import request from '@/utils/request';
|
2024-10-18 15:30:03 +08:00
|
|
|
|
import {
|
|
|
|
|
setStorageWithExpiry,
|
|
|
|
|
getStorageWithExpiry
|
|
|
|
|
} from '@/utils/auth'
|
2024-10-18 15:13:47 +08:00
|
|
|
|
|
2024-10-18 20:03:26 +08:00
|
|
|
|
export function getWXStatusHeight() {
|
2024-10-09 13:34:36 +08:00
|
|
|
|
// #ifdef MP-WEIXIN
|
|
|
|
|
// 获取距上
|
|
|
|
|
const barTop = wx.getSystemInfoSync().statusBarHeight
|
|
|
|
|
// 获取胶囊按钮位置信息
|
|
|
|
|
const menuButtonInfo = wx.getMenuButtonBoundingClientRect()
|
|
|
|
|
// 获取导航栏高度
|
|
|
|
|
const barHeight = menuButtonInfo.height + (menuButtonInfo.top - barTop) * 2
|
|
|
|
|
let barWidth = menuButtonInfo.width
|
|
|
|
|
console.log('menuButtonInfo', menuButtonInfo)
|
|
|
|
|
let barLeftPosition = 375 - menuButtonInfo.right + menuButtonInfo.width
|
|
|
|
|
let menuButtonLeft = menuButtonInfo.left
|
|
|
|
|
let menuButtonRight = menuButtonInfo.right
|
|
|
|
|
return {
|
|
|
|
|
barHeight,
|
|
|
|
|
barTop,
|
|
|
|
|
barWidth,
|
|
|
|
|
barLeftPosition,
|
|
|
|
|
menuButtonLeft,
|
|
|
|
|
menuButtonRight
|
|
|
|
|
}
|
|
|
|
|
// #endif
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 15:13:47 +08:00
|
|
|
|
/**
|
|
|
|
|
* 根据订单的状态获取订单的文字展示状态
|
2024-10-18 17:33:53 +08:00
|
|
|
|
* @param ticketsStatus 订单状态
|
|
|
|
|
* @param workStatus 维修工作状态
|
2024-10-18 15:13:47 +08:00
|
|
|
|
*/
|
2024-10-18 20:03:26 +08:00
|
|
|
|
export function getOrderStatusText(ticketsStatus,workStatus){
|
2024-10-18 15:13:47 +08:00
|
|
|
|
let str = "";
|
2024-10-18 17:33:53 +08:00
|
|
|
|
if("04"==ticketsStatus){
|
2024-10-18 15:13:47 +08:00
|
|
|
|
//待派工
|
|
|
|
|
str = "待派工"
|
2024-10-18 17:33:53 +08:00
|
|
|
|
}else if("05"==ticketsStatus){
|
2024-10-18 15:13:47 +08:00
|
|
|
|
//维修中
|
|
|
|
|
str = "维修中"
|
2024-10-18 17:33:53 +08:00
|
|
|
|
}else if("01"==ticketsStatus){
|
2024-10-18 15:13:47 +08:00
|
|
|
|
//待结算
|
|
|
|
|
str = "待结算"
|
2024-10-18 17:33:53 +08:00
|
|
|
|
}else if("06"==ticketsStatus){
|
2024-10-18 15:13:47 +08:00
|
|
|
|
//挂单/记账
|
|
|
|
|
str = "挂单/记账"
|
2024-10-18 17:33:53 +08:00
|
|
|
|
}else if("02"==ticketsStatus){
|
2024-10-18 15:13:47 +08:00
|
|
|
|
//已结账
|
|
|
|
|
str = "已结账"
|
2024-10-18 17:33:53 +08:00
|
|
|
|
}else if("03"==ticketsStatus){
|
2024-10-18 15:13:47 +08:00
|
|
|
|
//已作废
|
|
|
|
|
str = "已作废"
|
|
|
|
|
}
|
|
|
|
|
return str;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 查询字典可选值
|
|
|
|
|
* @param dictCode
|
|
|
|
|
*/
|
2024-10-18 20:03:26 +08:00
|
|
|
|
export function getDictByCode(dictCode){
|
2024-10-18 15:30:03 +08:00
|
|
|
|
let dictArray = getStorageWithExpiry(dictCode);
|
2024-10-19 10:55:12 +08:00
|
|
|
|
if(null==dictArray || undefined==dictArray){
|
2024-10-18 15:30:03 +08:00
|
|
|
|
request({
|
|
|
|
|
url: '/admin-api/system/dict-data/type',
|
|
|
|
|
method: 'get',
|
|
|
|
|
params:{type:dictCode}
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
console.log(res)
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
setStorageWithExpiry(dictCode,res.data,3600)
|
|
|
|
|
return res.data
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}else{
|
|
|
|
|
return dictArray
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-18 21:44:30 +08:00
|
|
|
|
/**
|
|
|
|
|
* 工单记录操作日志
|
|
|
|
|
* @param id 工单主表id
|
|
|
|
|
* @param ticketsWorkStatus 工单主表状态
|
|
|
|
|
* @param itemId 工单子表id
|
|
|
|
|
* @param itemStatus 工单子表状态
|
|
|
|
|
* @param recordType 操作类型 对应后端枚举:RecordTypeEnum
|
|
|
|
|
* @param remark 备注
|
|
|
|
|
* @param image 图片相对路径,多个英文逗号隔开
|
|
|
|
|
*/
|
|
|
|
|
export function saveTicketsRecords(id,ticketsWorkStatus,itemId,itemStatus,recordType,remark,image){
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
let dataObj = {
|
|
|
|
|
id: id,
|
|
|
|
|
ticketsWorkStatus:ticketsWorkStatus,
|
|
|
|
|
item: {id: itemId, itemStatus: itemStatus},
|
|
|
|
|
recordType: recordType,
|
|
|
|
|
remark: remark,
|
|
|
|
|
image: image
|
|
|
|
|
}
|
|
|
|
|
request({
|
|
|
|
|
url: '/admin-api/repair/tickets/updateStatus',
|
|
|
|
|
method: 'POST',
|
|
|
|
|
data:dataObj
|
|
|
|
|
}).then((res) => {
|
|
|
|
|
console.log(res)
|
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '操作成功',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
resolve(1);
|
|
|
|
|
}else{
|
|
|
|
|
uni.showToast({
|
|
|
|
|
title: '操作失败,请联系管理员',
|
|
|
|
|
icon: 'none'
|
|
|
|
|
})
|
|
|
|
|
reject(0);
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-10-18 15:30:03 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 翻译字典
|
|
|
|
|
* @param dictCode
|
|
|
|
|
*/
|
2024-10-22 18:29:31 +08:00
|
|
|
|
export async function getDictTextByCodeAndValue(dictCode, value) {
|
2024-10-18 15:30:03 +08:00
|
|
|
|
let dictArray = getStorageWithExpiry(dictCode);
|
2024-10-22 18:29:31 +08:00
|
|
|
|
if (null == dictArray || undefined == dictArray) {
|
|
|
|
|
let res = await request({
|
2024-10-19 10:55:12 +08:00
|
|
|
|
url: '/admin-api/system/dict-data/type',
|
|
|
|
|
method: 'get',
|
2024-10-22 18:29:31 +08:00
|
|
|
|
params: {type: dictCode}
|
2024-10-19 10:55:12 +08:00
|
|
|
|
})
|
2024-10-22 18:29:31 +08:00
|
|
|
|
if (res.code == 200) {
|
|
|
|
|
setStorageWithExpiry(dictCode, res.data, 3600)
|
|
|
|
|
dictArray = res.data
|
|
|
|
|
let dictObj = dictArray.find(item => item.value == value)
|
|
|
|
|
if (dictObj) {
|
|
|
|
|
return dictObj.label
|
|
|
|
|
} else {
|
|
|
|
|
return "未知数据"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
let dictObj = dictArray.find(item => item.value == value)
|
|
|
|
|
if (dictObj) {
|
2024-10-19 18:07:46 +08:00
|
|
|
|
return dictObj.label
|
2024-10-22 18:29:31 +08:00
|
|
|
|
} else {
|
2024-10-19 18:07:46 +08:00
|
|
|
|
return "未知数据"
|
|
|
|
|
}
|
2024-10-18 15:30:03 +08:00
|
|
|
|
}
|
2024-10-18 15:13:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 20:03:26 +08:00
|
|
|
|
export function formatTimestamp(timestamp) {
|
2024-10-17 18:05:11 +08:00
|
|
|
|
// 将时间戳转换为Date对象
|
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
// 获取年月日时分秒
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
const day = date.getDate().toString().padStart(2, '0');
|
|
|
|
|
const hours = date.getHours().toString().padStart(2, '0');
|
|
|
|
|
const minutes = date.getMinutes().toString().padStart(2, '0');
|
|
|
|
|
const seconds = date.getSeconds().toString().padStart(2, '0');
|
|
|
|
|
// 组合成日期时间字符串
|
|
|
|
|
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-21 18:11:30 +08:00
|
|
|
|
/**
|
|
|
|
|
* 将时间戳转换为指定格式的日期字符串
|
|
|
|
|
* @param {number} timestamp - 时间戳(毫秒)
|
|
|
|
|
* @param {string} [format='YYYY-MM-DD'] - 日期格式,默认为 'YYYY-MM-DD'
|
|
|
|
|
* @returns {string} - 格式化的日期字符串
|
|
|
|
|
*/
|
|
|
|
|
export function formatTimestampCustom(timestamp, format = 'YYYY-MM-DD') {
|
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
const day = date.getDate().toString().padStart(2, '0');
|
|
|
|
|
const hour = date.getHours().toString().padStart(2, '0');
|
|
|
|
|
const minute = date.getMinutes().toString().padStart(2, '0');
|
|
|
|
|
const second = date.getSeconds().toString().padStart(2, '0');
|
|
|
|
|
|
|
|
|
|
const replaceMap = {
|
|
|
|
|
'YYYY': year,
|
|
|
|
|
'MM': month,
|
|
|
|
|
'DD': day,
|
|
|
|
|
'HH': hour,
|
|
|
|
|
'mm': minute,
|
|
|
|
|
'ss': second
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return format.replace(/YYYY|MM|DD|HH|mm|ss/g, match => replaceMap[match]);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-18 20:03:26 +08:00
|
|
|
|
/**
|
|
|
|
|
* 组装订单对象
|
|
|
|
|
* @param order
|
|
|
|
|
*/
|
2024-10-18 20:04:30 +08:00
|
|
|
|
export function builderOrder(order) {
|
2024-10-18 20:03:26 +08:00
|
|
|
|
return {
|
2024-10-18 20:04:30 +08:00
|
|
|
|
id: order.id,
|
|
|
|
|
orderNo: order.ticketNo,
|
|
|
|
|
flag: 1,
|
|
|
|
|
ticketsStatus: order.ticketsStatus,
|
|
|
|
|
ticketsWorkStatus: order.ticketsWorkStatus,
|
|
|
|
|
flagStr: getOrderStatusText(order.ticketsStatus, order.ticketsWorkStatus),
|
|
|
|
|
carNum: order.carNo,
|
|
|
|
|
nowRepairId: order.nowRepairId,
|
|
|
|
|
carModel: order.carBrandName,
|
|
|
|
|
userName: order.userName,
|
|
|
|
|
userPhone: order.userMobile,
|
|
|
|
|
counselorName: order.adviserName,
|
2024-10-18 20:03:26 +08:00
|
|
|
|
}
|
2024-10-17 18:05:11 +08:00
|
|
|
|
}
|
2024-10-18 20:04:30 +08:00
|
|
|
|
|
|
|
|
|
export function formatDate(timestamp) {
|
2024-10-18 19:55:06 +08:00
|
|
|
|
// 将时间戳转换为Date对象
|
|
|
|
|
const date = new Date(timestamp);
|
|
|
|
|
// 获取年月日时分秒
|
|
|
|
|
const year = date.getFullYear();
|
|
|
|
|
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
|
|
|
|
const day = date.getDate().toString().padStart(2, '0');
|
|
|
|
|
// 组合成日期时间字符串
|
|
|
|
|
return `${year}-${month}-${day}`;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-22 11:54:28 +08:00
|
|
|
|
//转换为double
|
|
|
|
|
// utils.js
|
|
|
|
|
export function convertToDouble(value, decimalPlaces = 1) {
|
|
|
|
|
if (value !== undefined && value !== null) {
|
|
|
|
|
const parsedValue = parseFloat(value);
|
|
|
|
|
if (!isNaN(parsedValue)) {
|
|
|
|
|
return parsedValue.toFixed(decimalPlaces);
|
|
|
|
|
} else {
|
|
|
|
|
console.error('转换失败,值不是有效的数字');
|
|
|
|
|
return '0.0'; // 可以设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
console.error('值不存在');
|
|
|
|
|
return '0.0'; // 可以设置一个默认值
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-10-22 15:06:49 +08:00
|
|
|
|
/**
|
|
|
|
|
* 生成一个16位的纯数字的唯一ID
|
|
|
|
|
* 生成策略 head + 当前时间戳 + 随机数
|
|
|
|
|
* @param head 前缀
|
|
|
|
|
*/
|
|
|
|
|
export function createUniqueCodeByHead(head = '') {
|
|
|
|
|
const min = 100; // 最小值
|
|
|
|
|
const max = 999; // 最大值
|
|
|
|
|
return head.toString() + Date.now().toString() + Math.floor(Math.random() * (max - min + 1)) + min;
|
|
|
|
|
}
|
2024-10-18 20:04:30 +08:00
|
|
|
|
|