chenhaozhe
2025-08-12 2b29d38bf7ee6355463e79fff1c6a90dd7f94c5b
Merge branch 'Dev' of http://101.37.171.70:10101/r/~jhz/STUWMS into Dev
3个文件已修改
286 ■■■■ 已修改文件
pages/gongxuOut/form.vue 100 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/index/tab1.vue 93 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
utils/getdateTime.js 93 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
pages/gongxuOut/form.vue
@@ -99,7 +99,7 @@
                <view class="form-item">
                    <view class="title">工时:</view>
                    <view class="right">
                        <input v-model="hform.HWorkTimes" placeholder="请输入工时" />
                        <input v-model="hform.HWorkTimes" placeholder="请输入工时" @blur="HWorkTimesChange"/>
                    </view>
                </view>
                <view class="form-item">
@@ -111,6 +111,22 @@
                    </checkbox-group>
                </view>
            </view>
            <view class="form-item">
                <view class="title">开工时间:</view>
                <view class="right">
                     <uni-datetime-picker v-model="hform.HRelBeginTime" @change="HRelBeginTimeChange" v-if="hform.HIsTimeFlag==1" :hide-second="true">
                         <input disabled v-model="hform.HRelBeginTime" placeholder="请选择开工时间"  style="pointer-events: none;"/>
                     </uni-datetime-picker>
                </view>
            </view>
            <view class="form-item">
                <view class="title">完工时间:</view>
                <view class="right">
                     <uni-datetime-picker v-model="hform.HRelEndTime" @change="HRelEndTimeChange" v-if="hform.HIsTimeFlag==1" :hide-second="true">
                         <input disabled v-model="hform.HRelEndTime" placeholder="请选择完工时间" />
                     </uni-datetime-picker>
                </view>
            </view>
            <!-- 
                <view class="title">是否计时</view>
                <checkbox-group name="checkboxGroup" @change="onCGChangeHandler">
@@ -515,6 +531,8 @@
                    HProcNumber: '',
                    HNotReportQty: 0,
                    HIsTimeFlag: 0,
                    HRelBeginTime:'',
                    HRelEndTime:'',
                    // HPieceQty:'',
                    HWasterQty: 0,
                    HSourceName: '',
@@ -639,6 +657,10 @@
                detail
            }) {
                this.hform.HIsTimeFlag = detail.value[0] || 0
                if(detail.value[0]){
                    this.getNewHRelBeginDate()
                    this.hform.HRelEndTime = getDateTime.dateTimeStr('y-m-d h:i');
                }
            },
            //通过登录用户获取默认值
            getDefValByUser() {
@@ -751,7 +773,20 @@
                console.log(e.detail.value)
                this.hform.HDate = e.detail.value
            },
            HRelBeginTimeChange(e) {
                console.log(e)
                this.hform.HRelBeginTime = e
                this.hform.HWorkTimes=getDateTime.calculateHoursDiff(this.hform.HRelBeginTime,this.hform.HRelEndTime);
            },
            HRelEndTimeChange(e) {
                console.log(e)
                this.hform.HRelEndTime = e
                this.hform.HWorkTimes=getDateTime.calculateHoursDiff(this.hform.HRelBeginTime,this.hform.HRelEndTime);
            },
            HWorkTimesChange(e){
                console.log(e);
                this.hform.HRelEndTime = getDateTime.addHoursToDate(this.hform.HRelBeginTime,e.detail.value);
            },
            //获取产品数据
            getHMaterList() {
                var Value = " Where HStopFlag=0  and HEndFlag=1 and HUSEORGID = " + uni.getStorageSync('OrganizationID')
@@ -1389,7 +1424,62 @@
                    },
                });
            },
            //新增
            //获取最新的报工日期
            getNewHRelBeginDate(){
                uni.request({
                    url: this.serverUrl + '/Cj_StationOutBill/get_Display',
                    data:{
                        sWhere: ` and HEmpID = N'${this.hform.HEmpID}'`,
                        user: uni.getStorageSync('HUserName'),
                        HBillSubType:'',
                    },
                    success: (res) => {
                        if(res.data.count == 1){
                            //获取列表数据
                            const listData = res.data.data
                            // 获取当前日期(去掉时间部分)
                            const today = new Date();
                            today.setHours(0, 0, 0, 0);
                            if(listData.length==0){
                                this.hform.HRelBeginTime = getDateTime.dateTimeSetHoureStr(7, 40, 0, 0,'y-m-d h:i');
                                this.hform.HWorkTimes=getDateTime.calculateHoursDiff(this.hform.HRelBeginTime,this.hform.HRelEndTime);
                            }else{
                                // 从对象数组中提取所有日期字段并找到最大值
                                const maxDate = listData.reduce((max, obj) => {
                                    const date = new Date(obj[出站时间]);
                                    return date > max ? date : max;
                                }, new Date(0)); // 初始值为最小日期
                                // 比较最大日期和今天的日期部分(不比较时间)
                                const maxDateDateOnly = new Date(maxDate);
                                maxDateDateOnly.setHours(0, 0, 0, 0);
                                  // 比较最大日期和今天
                                if (maxDateDateOnly.getTime() !== today.getTime()) {
                                    // 如果不是今天,返回当前日期
                                    this.hform.HRelBeginTime = getDateTime.dateTimeSetHoureStr(7, 40, 0, 0,'y-m-d h:i');
                                    this.hform.HWorkTimes=getDateTime.calculateHoursDiff(this.hform.HRelBeginTime,this.hform.HRelEndTime);
                                }else{
                                    this.hform.HRelBeginTime = maxDate.replace(/(:\d{2})(:\d{2}\.\d{3})/, '$1');//使用正则表达式去除秒和毫秒
                                    this.hform.HWorkTimes=getDateTime.calculateHoursDiff(this.hform.HRelBeginTime,this.hform.HRelEndTime);
                                }
                            }
                        }else{
                            uni.showToast({
                                title:res.data.Message,
                                icon:'none'
                            })
                        }
                    },
                    fail: (res) => {
                        console.log(res);
                        uni.showToast({
                            title:'接口请求失败',
                            icon:'none'
                        })
                    },
                });
            },
            //新增
            getNewData() {
                uni.request({
                    url: this.serverUrl + '/Web/GetMAXNum',
@@ -1644,7 +1734,9 @@
        margin: 20rpx auto;
        padding-bottom: 240rpx;
    }
    picker input{
        pointer-events: none;
    }
    .tab_area {
        width: 100%;
        height: 50rpx;
pages/index/tab1.vue
@@ -92,49 +92,56 @@
                        id: 8,
                        hidden: false,
                    }
                    // , {
                    //     img: '../../static/icon/icon1.png',
                    //     text: '设备档案查询',
                    //     tip: '查看详情',
                    //     url: '/pages/shebeidangan/table',
                    //     id: 9,
                    // }, {
                    //     img: '../../static/icon/icon8.png',
                    //     text: '设备履历查询',
                    //     tip: '查看详情',
                    //     url: '/pages/shebeilvli/table',
                    //     id: 10,
                    // }, {
                    //     img: '../../static/icon/icon14.png',
                    //     text: '我的报工平台',
                    //     tip: '点击进入',
                    //     url: '/pages/baogong/table',
                    //     id: 11,
                    // }, {
                    //     img: '../../static/icon/icon13.png',
                    //     text: '上模单',
                    //     tip: '查看详情',
                    //     url: '/pages/MJGL/shangmudan/table',
                    //     id: 12,
                    // }, {
                    //     img: '../../static/icon/icon13.png',
                    //     text: '下模单',
                    //     tip: '查看详情',
                    //     url: '',
                    //     id: 13,
                    // }, {
                    //     img: '../../static/icon/icon32.png',
                    //     text: '设备运行状态',
                    //     tip: '查看详情',
                    //     url: '/pages/shebeiyunxingzhuangtai/shebeiyunxingzhuangtai',
                    //     id: 14,
                    // }, {
                    //     img: '../../static/icon/icon6.png',
                    //     text: '模具状态分析',
                    //     tip: '查看详情',
                    //     url: '/pages/mujvzhuangtai/mujvzhuangtai',
                    //     id: 15,
                    // },
                    , {
                        img: '../../static/icon/icon1.png',
                        text: '设备档案查询',
                        tip: '查看详情',
                        url: '/pages/shebeidangan/table',
                        id: 9,
                        hidden: true,
                    }, {
                        img: '../../static/icon/icon8.png',
                        text: '设备履历查询',
                        tip: '查看详情',
                        url: '/pages/shebeilvli/table',
                        id: 10,
                        hidden: true,
                    }, {
                        img: '../../static/icon/icon14.png',
                        text: '我的报工平台',
                        tip: '点击进入',
                        url: '/pages/baogong/table',
                        id: 11,
                        hidden: true,
                    }, {
                        img: '../../static/icon/icon13.png',
                        text: '上模单',
                        tip: '查看详情',
                        url: '/pages/MJGL/shangmudan/table',
                        id: 12,
                        hidden: true,
                    }, {
                        img: '../../static/icon/icon13.png',
                        text: '下模单',
                        tip: '查看详情',
                        url: '',
                        id: 13,
                        hidden: true,
                    }, {
                        img: '../../static/icon/icon32.png',
                        text: '设备运行状态',
                        tip: '查看详情',
                        url: '/pages/shebeiyunxingzhuangtai/shebeiyunxingzhuangtai',
                        id: 14,
                        hidden: true,
                    }, {
                        img: '../../static/icon/icon6.png',
                        text: '模具状态分析',
                        tip: '查看详情',
                        url: '/pages/mujvzhuangtai/mujvzhuangtai',
                        id: 15,
                        hidden: true,
                    },
                ]
                // itemData: [{
                //     //  img:'../../static/icon0.png',
utils/getdateTime.js
@@ -34,7 +34,98 @@
    }
    return str;
}
/**
 * @param {Object} hour 小时的数值
 * @param {Object} min 分钟的数值。
 * @param {Object} sec 秒的数值。
 * @param {Object} millisec 毫秒的数值。
 * @param {Object} str (y-m-d h:i:s) y:年 m:月 d:日 h:时 i:分 s:秒
 */
function dateTimeSetHoureStr(hour,min,sec,millisec,str){
    var date = new Date();
    date.setHours(hour,min,sec,millisec);
    var year = date.getFullYear(), //年
    month = date.getMonth() + 1, //月
    day = date.getDate(), //日
    hour = date.getHours() < 10 ? "0" + date.getHours() : date.getHours(), //时
    minute = date.getMinutes() < 10 ? date.getMinutes() : date.getMinutes(), //分
    second = date.getSeconds() < 10 ? date.getSeconds() : date.getSeconds(); //秒
    month >= 1 && month <= 9 ? (month = "0" + month) : "";
    day >= 0 && day <= 9 ? (day = "0" + day) : "";
    hour >= 0 && hour <= 9 ? hour : "";
    minute >= 0 && minute <= 9 ? (minute = "0" + minute) : "";
    second >= 0 && second <= 9 ? (second = "0" + second) : "";
    if(str.indexOf('y') != -1){
        str = str.replace('y', year)
    }
    if(str.indexOf('m') != -1){
        str = str.replace('m', month)
    }
    if(str.indexOf('d') != -1){
        str = str.replace('d', day)
    }
    if(str.indexOf('h') != -1){
        str = str.replace('h', hour)
    }
    if(str.indexOf('i') != -1){
        str = str.replace('i', minute)
    }
    if(str.indexOf('s') != -1){
        str = str.replace('s', second)
    }
    return str;
}
/** 计算两者时间差以小时为单位
 * @param {Object} beginStr YYYY-MM-DD HH:MM
 * @param {Object} endStr YYYY-MM-DD HH:MM
 */
function calculateHoursDiff(beginStr, endStr) {
    // 解析开始时间
    const parseDateTime = (dateTimeStr) => {
        const [datePart, timePart] = dateTimeStr.split(' ');
        const [yyyy, mm, dd] = datePart.split('-').map(Number);
        const [hh, min] = timePart.split(':').map(Number);
        return new Date(yyyy, mm - 1, dd, hh, min);
    };
    const beginTime = parseDateTime(beginStr);
    const endTime = parseDateTime(endStr);
    // 计算毫秒差,并转换为小时(保留2位小数)
    const diffMs = endTime - beginTime;
    const diffHours = (diffMs / (1000 * 60 * 60)).toFixed(2);
    return parseFloat(diffHours)>0?parseFloat(diffHours):0; // 返回数字类型,如 3.25
}
/**返回时间加上小时
 * @param {Object} dateTimeStr YYYY-MM-DD HH:MM
 * @param {Object} hoursToAdd 小时
 */
function addHoursToDate(dateTimeStr, hoursToAdd) {
  // 解析输入日期时间
  const [datePart, timePart] = dateTimeStr.split(' ');
  const [yyyy, mm, dd] = datePart.split('-').map(Number);
  const [hh, min] = timePart.split(':').map(Number);
  // 创建Date对象
  const date = new Date(yyyy, mm - 1, dd, hh, min);
  // 添加指定小时数(支持小数小时)
  date.setTime(date.getTime() + hoursToAdd * 60 * 60 * 1000);
  // 格式化为YYYY-MM-DD HH:MM
  const newYYYY = String(date.getFullYear()).padStart(4, '0');
  const newMM = String(date.getMonth() + 1).padStart(2, '0');
  const newDD = String(date.getDate()).padStart(2, '0');
  const newHH = String(date.getHours()).padStart(2, '0');
  const newMin = String(date.getMinutes()).padStart(2, '0');
  return `${newYYYY}-${newMM}-${newDD} ${newHH}:${newMin}`;
}
module.exports = {
    dateTimeStr: dateTimeStr,
    dateTimeSetHoureStr:dateTimeSetHoureStr,
    calculateHoursDiff:calculateHoursDiff,
    addHoursToDate:addHoursToDate,
}