building-sign/pages/worker/overtime/overtime.vue

159 lines
4.3 KiB
Vue
Raw Normal View History

2022-11-15 10:03:13 +00:00
<template>
<view class="pad-x120">
<!-- 头部 -->
2022-11-16 10:20:26 +00:00
<status-nav :ifReturn="false" navBarTitle="加班提交"></status-nav>
<view class="content" :style="{'padding-top':statusHeight+50+'px'}" v-if="isLoding">
<view class="overtime-from font26">
<view class="item">
<view class="title">工地</view>
<picker class="input" mode="selector" :range="worksiteList" @change="bindWorksiteChange" :value="worksiteIndex" :range-key="'name'">
<view class="name">
<text>{{worksiteList[worksiteIndex].name}}</text>
<image src="/static/icon/icon-arrow-02.png" mode="aspectFit"></image>
</view>
</picker>
</view>
<view class="item">
<view class="title">日期</view>
<picker class="input" mode="date" :range="date" @change="bindDateChange" :start="startDate" :end="endDate">
<view class="name">
<text>{{date.split('-')[0]+'年'+date.split('-')[1]+'月'+date.split('-')[2]+'日'}}</text>
<image src="/static/icon/icon-arrow-02.png" mode="aspectFit"></image>
</view>
</picker>
</view>
<view class="item">
<view class="title">加班时长</view>
<view class="time-input">
<picker class="input" mode="selector" :range="timeList" @change="bindTimeChange" :value="timeIndex">
<view class="name">
<text>{{timeList[timeIndex]}}</text>
<image src="/static/icon/icon-arrow-02.png" mode="aspectFit"></image>
</view>
</picker>
<view class="unit font24">小时</view>
</view>
</view>
<view class="item">
<view class="title">备注</view>
<textarea class="input textarea" v-model="remarks"></textarea>
</view>
<view class="submit-btn color-white font30" @tap="submitOvertime"></view>
</view>
</view>
2022-11-15 10:03:13 +00:00
<!-- 尾部 -->
2022-11-16 10:20:26 +00:00
<tabbar :userType="userType" current="1"></tabbar>
2022-11-15 10:03:13 +00:00
</view>
</template>
<script>
import tabbar from '@/components/tabbar/tabbar';
2022-11-16 10:20:26 +00:00
function getDate(type) {
const date = new Date();
let year = date.getFullYear();
let month = date.getMonth() + 1;
let day = date.getDate();
if (type === 'start') {
year = year - 10;
} else if (type === 'end') {
year = year + 10;
}
month = month > 9 ? month : '0' + month;
day = day > 9 ? day : '0' + day;
return `${year}-${month}-${day}`;
}
2022-11-15 10:03:13 +00:00
export default {
components:{
tabbar
},
data() {
return {
statusHeight:uni.getSystemInfoSync().statusBarHeight, //状态栏高度
userType:'worker', //账户类型 工人worker 负责人director
2022-11-16 10:20:26 +00:00
worksiteList:[], //工地列表
worksiteIndex:0, //当前选择
timeList:[], //加班时长列表
timeIndex:0, //当前选择
remarks:'', //备注
date: getDate({
format: true
}),
startDate: getDate('start'),
endDate: getDate('end'),
flag:true, //是否允许提交
isLoding:false, //是否加载完成
2022-11-15 10:03:13 +00:00
}
},
onLoad() {
2022-11-16 10:20:26 +00:00
// 获取工地列表
this.getWorksiteList();
// 获取加班时间
this.getTimeList();
2022-11-15 10:03:13 +00:00
},
methods: {
2022-11-16 10:20:26 +00:00
// 获取工地列表
getWorksiteList(){
this.$requst.get('/api/v1/common/worksite-list').then(res=>{
if(res.code==0){
this.worksiteList = res.data.list;
this.isLoding = true;
}
})
},
// 获取加班时间
getTimeList(){
let timeArr = [];
for(let i=1;i<=48;i++){
timeArr.push(i-0.5,i)
}
this.timeList = timeArr;
},
// 提交加班
submitOvertime(){
if(this.flag){
this.flag = false;
let params = {
day:this.date,
time:this.timeList[this.timeIndex],
worksite_id:this.worksiteList[this.worksiteIndex].id,
remarks:this.remarks
}
this.$requst.post('/api/v1/worker/overtime',params).then(res=>{
if(res.code==0){
this.$toolAll.tools.showToast('提交成功');
setTimeout(()=>{
uni.reLaunch({
url:'/pages/worker/sign/sign'
})
},1000)
}else{
this.$toolAll.tools.showToast(res.msg);
}
setTimeout(()=>{
this.flag = true;
},2000)
})
}
},
2022-11-15 10:03:13 +00:00
2022-11-16 10:20:26 +00:00
// 选择工地
bindWorksiteChange(e) {
this.worksiteIndex = e.detail.value;
},
// 选择日期
bindDateChange(e) {
this.date = e.detail.value;
},
// 选择加班时长
bindTimeChange(e) {
this.timeIndex = e.detail.value;
}
2022-11-15 10:03:13 +00:00
}
}
</script>
<style scoped>
</style>