add replace report

main
chenshuichuan 2 years ago
parent 3c00e5ec30
commit 4a3f0f04ad

@ -0,0 +1,318 @@
<template>
<view class="container">
<view class="example">
<!-- 自定义表单校验 -->
<uni-forms ref="customForm" :rules="customRules" labelWidth="60px" :modelValue="customFormData">
<uni-forms-item required label="工人" name="userId">
<uni-data-select v-model="customFormData.userId" :localdata="userList" @change="handleUserChange" :disabled="disableEnable">
</uni-data-select>
</uni-forms-item>
<uni-forms-item label="工序" required name="orgType">
<uni-data-checkbox v-model="customFormData.orgType" :localdata="processTypes()" :disabled="disableEnable"/>
</uni-forms-item>
<uni-forms-item label="班别" required name="groupType">
<uni-data-checkbox v-model="customFormData.groupType" :localdata="groupTypes()" :disabled="disableEnable"/>
</uni-forms-item>
<uni-forms-item label="日期" required name="reportDateString">
<uni-datetime-picker v-model="customFormData.reportDateString" type="date" :clear-icon="true" @change="maskClick" :disabled="disableEnable"/>
</uni-forms-item>
<uni-forms-item v-if="customFormData.userId && customFormData.reportDateString" label="工位" required name="orgId">
<uni-data-select v-model="customFormData.orgId" :localdata="orgIdList" :disabled="disableEnable" ></uni-data-select>
</uni-forms-item>
<uni-forms-item label="计件时段" name="reportTime">
<uni-easyinput type="text" v-model="customFormData.reportTime" placeholder="如:8:00-12:00" />
</uni-forms-item>
<uni-forms-item label="计件时间/h" required name="totalTime">
<uni-easyinput type="number" v-model="customFormData.totalTime" placeholder="" />
</uni-forms-item>
<uni-group title="card 模式" mode="card" v-for="(item,index) in customFormData.productList" :key="item.id"
:name="['productList',index,'value']">
<template v-slot:title>
<view class="uni-group-title">
<uni-row>
<uni-col :span="12">
<uni-forms-item label="产品" required name="productId">
<uni-data-select v-model="customFormData.productList[index].productId" :localdata="planProductList"></uni-data-select>
</uni-forms-item>
</uni-col>
<uni-col :span="12" align="center">
<uni-icons type="trash" size="25" color="red" @click="del(item.id)"></uni-icons>
</uni-col>
</uni-row>
</view>
</template>
<uni-row>
<uni-col :span="12">
<uni-forms-item label="成品数" required name="qualityNumber">
<uni-easyinput type="number" v-model="customFormData.productList[index].qualityNumber" @change="changeNumber(item.id)"/>
</uni-forms-item>
</uni-col>
<uni-col :span="12">
<uni-forms-item label="废品数" name="wasteNumber">
<uni-easyinput type="number" v-model="customFormData.productList[index].wasteNumber" @change="changeNumber(item.id)"/>
</uni-forms-item>
</uni-col>
</uni-row>
<uni-row>
<uni-col :span="12">
<uni-forms-item label="总数" name="totalNumber">
<uni-easyinput disabled v-model="customFormData.productList[index].totalNumber" placeholder="" />
</uni-forms-item>
</uni-col>
<uni-col :span="12">
<uni-forms-item label="成品率%" required name="qualityRate">
<uni-easyinput disabled type="number" v-model="customFormData.productList[index].qualityRate" />
</uni-forms-item>
</uni-col>
</uni-row>
<uni-row>
<uni-col :span="12">
<uni-forms-item label="打包数" name="packageNumber">
<uni-easyinput type="number" v-model="customFormData.productList[index].packageNumber" />
</uni-forms-item>
</uni-col>
<uni-col :span="12">
<uni-forms-item label="备注" name="remark">
<uni-easyinput type="text" v-model="customFormData.productList[index].remark" />
</uni-forms-item>
</uni-col>
</uni-row>
</uni-group>
</uni-forms>
<view class="button-group">
<button type="primary" size="mini" @click="add">
<uni-icons type="plus" size="15"></uni-icons>
新增产品
</button>
<button type="primary" size="mini" @click="submit('customForm')"></button>
</view>
</view>
</view>
</template>
<script>
import useUserStore from "@/store/modules/user";
import {processTypes, groupTypes} from "@/api/system/dict/data";
import { getProductList, createReport, getOtherPersonalUser,getOtherOrgList} from "@/api/mes/organization"
import {getCurrentDate, timestampToTime} from "@/utils/dateUtil"
import {showConfirm} from "@/utils/common";
import tab from "@/plugins/tab";
import modal from "@/plugins/modal";
import {getById, getDetailByReportId, update} from "@/api/mes/report";
export default {
components: {},
data() {
return {
//
customFormData: {
id: undefined,
name: undefined,
userId: undefined,
orgId: undefined,
orgType: undefined,
reportTime: undefined,
totalTime: 0,
reportStatus: undefined,
remark: undefined,
groupType: undefined,
reportType: undefined,
reportDateString: getCurrentDate(),
reportDate: undefined,
productList: []
},
//
customRules: {
userId: {rules: [{required: true, errorMessage: '工人不能为空'}]},
orgId: {rules: [{required: true, errorMessage: '工位不能为空'}]},
orgType: {rules: [{required: true, errorMessage: '工序不能为空'}]},
reportDateString: {rules: [{required: true, errorMessage: '报工日期不能为空'}]},
totalTime: {rules: [{required: true, errorMessage: '计件时间不能为空'},
{format: 'number', errorMessage: '计件时间格式错误,应填计件小时数'}]},
groupType: {rules: [{required: true, errorMessage: '班别不能为空'}]},
productList: {rules: [
{format: 'array', errorMessage: '产品列表格式错误'},
{validateFunction: function(rule, value, data, callback) {
console.log('value:'+value)
console.log('data:'+data)
if (value.length < 2) {
callback('产品信息不能为空')
}
return true
}
}]
}
},
orgIdList:[],
planProductList:[],
userList: [],
updateId: undefined,
disableEnable:false
}
},
computed: {
},
onLoad() {
this.getPlanProductList()
this.getUserList()
this.updateId = tab.getParams()
console.log(this.updateId)
if(this.updateId){
this.disableEnable = true
//
getById(this.updateId).then(response => {
this.customFormData = response.data
this.customFormData.reportDateString = timestampToTime(this.customFormData.reportDate)
// this.getOrgIdList()
getDetailByReportId(this.updateId).then(res => {
this.customFormData.productList = res.data
})
})
}
},
onReady() {
//
this.$refs.customForm.setRules(this.customRules)
},
methods: {
processTypes() {return processTypes},
groupTypes() {return groupTypes},
submit(ref) {
if(this.customFormData.reportDateString.length<11)this.customFormData.reportDateString+=' 00:00:00';
this.customFormData.reportType = '代报工';
console.log(this.customFormData);
this.$refs[ref].validate().then(res => {
var ok = 1;
if(this.customFormData.productList && this.customFormData.productList.length > 0) {
for (let i = 0; i < this.customFormData.productList.length; i++) {
if(!this.customFormData.productList[i].productId || this.customFormData.productList[i].productId===''
|| !this.customFormData.productList[i].qualityNumber|| this.customFormData.productList[i].qualityNumber <= 0) {
ok = 0;
uni.showToast({
title: `产品信息不能为空!`
})
break;
}
}
}
if(ok===1){
showConfirm("确认保存生产报工单吗?").then(res => {
if (res.confirm) {
if(this.updateId){
this.customFormData.id = this.updateId
update(this.customFormData).then(response => {
modal.msgSuccess("修改成功")
tab.navigateBack()
})
}else{
this.customFormData.id = null
createReport(this.customFormData).then(response => {
modal.msgSuccess("保存成功")
tab.navigateBack()
})
}
}
})
}
}).catch(err => {
console.log('err', err);
})
},
maskClick(e){
this.customFormData.reportDateString =e
if(this.customFormData.userId)
this.getOrgIdList()
},
getOrgIdList() {
this.customFormData.orgId = undefined
let dateStr = this.customFormData.reportDateString.length < 11 ?
this.customFormData.reportDateString+" 00:00:00": this.customFormData.reportDateString;
let data = {
'userId': this.customFormData.userId,
// 'orgType': this.customFormData.orgType,
'reportDate': dateStr,
'groupType': this.customFormData.groupType
}
getOtherOrgList(data).then(response => {
this.orgIdList = response.data;
if(!this.orgIdList || this.orgIdList.length===0){
uni.showToast({
title: '日期:'+this.customFormData.reportDateString+`未查询到该工人的工位安排!请先安排工位!`
})
}
else if(this.orgIdList.length===1){
this.customFormData.orgId = this.orgIdList[0].value
}
})
},
getPlanProductList() {
getProductList().then(response => {
this.planProductList = response.data;
if(!this.planProductList || this.orgIdList.planProductList===0){}
})
},
getUserList() {
getOtherPersonalUser().then(response => {
this.userList = response.data
})
},
add() {
this.customFormData.productList.push({
id: Date.now(),
productId: undefined,
qualityNumber: 0,
wasteNumber: 0,
totalNumber: 0,
qualityRate:0,
packageNumber: 0,
remark: ''
})
},
del(id) {
let index = this.customFormData.productList.findIndex(v => v.id === id)
this.customFormData.productList.splice(index, 1)
},
changeNumber(id){
let index = this.customFormData.productList.findIndex(v => v.id === id)
if(!this.customFormData.productList[index].qualityNumber)
this.customFormData.productList[index].qualityNumber=0;
if(!this.customFormData.productList[index].wasteNumber)
this.customFormData.productList[index].wasteNumber=0;
this.customFormData.productList[index].totalNumber =
Number(this.customFormData.productList[index].qualityNumber) + Number(this.customFormData.productList[index].wasteNumber);
this.customFormData.productList[index].qualityRate =
(Number(this.customFormData.productList[index].qualityNumber)*100/Number(this.customFormData.productList[index].totalNumber)).toFixed(2);
},
handleUserChange(e){
this.customFormData.userId = e
this.getOrgIdList()
}
}
}
</script>
<style lang="scss">
.example {
padding: 15px;
background-color: #fff;
}
.button-group {
margin-top: 15px;
display: flex;
justify-content: space-around;
}
.button {
display: flex;
align-items: center;
height: 35px;
line-height: 35px;
margin-left: 10px;
}
.uni-group-title{
padding-top: 5px;
background-color: #f4c7c7;
}
</style>

@ -84,7 +84,7 @@
<uni-icons type="plus" size="15"></uni-icons>
新增产品
</button>
<button type="primary" size="mini" @click="submit('customForm')"></button>
<button type="primary" size="mini" @click="submit('customForm')"></button>
</view>
</view>
</view>
@ -96,13 +96,12 @@ import useUserStore from "@/store/modules/user";
import {processTypes, groupTypes} from "@/api/system/dict/data";
import {getOrgList, getProductList,createReport} from "@/api/mes/organization"
import {getCurrentDate} from "@/utils/dateUtil"
import {View} from "@element-plus/icons-vue";
import {showConfirm} from "@/utils/common";
import tab from "@/plugins/tab";
import modal from "@/plugins/modal";
const userStore = useUserStore()
export default {
components: {View},
components: {},
data() {
return {
//

@ -70,6 +70,12 @@
"style": {
"navigationBarTitleText": "生产报工"
}
},
{
"path": "replaceForm",
"style": {
"navigationBarTitleText": "代报工"
}
}
]
},

@ -1,5 +1,6 @@
<template>
<view>
<view class="container">
<view class="example">
<el-tabs v-loading="loading" v-model="activeName" class="demo-tabs" @tab-click="handleTabClick">
<el-tab-pane label="个人报工" name="first">
<uni-list :border="true">
@ -64,7 +65,7 @@
</template>
<!-- 自定义 footer-->
<template v-slot:footer>
<el-button v-if="item.reportStatus === 0" type="primary" size="small" :icon="Edit" circle @click="editOrAddReport(item.id)"/>
<el-button v-if="item.reportStatus === 0" type="primary" size="small" :icon="Edit" circle @click="addReplaceReport(item.id)"/>
<el-button v-if="item.reportStatus === 0" type="success" size="small" :icon="Promotion" circle @click="updateReport(item.id,1)"/>
<el-button v-if="item.reportStatus < 2" type="danger" size="small" :icon="Delete" circle @click="deleteReport(item.id)"/>
</template>
@ -108,7 +109,7 @@
</template>
<!-- 自定义 footer-->
<template v-slot:footer>
<el-button v-if="item.reportStatus === 0" type="primary" size="small" :icon="Edit" circle @click="editOrAddReport(item.id)"/>
<el-button v-if="item.reportStatus === 0" type="primary" size="small" :icon="Edit" circle @click="addReplaceReport(item.id)"/>
<el-button v-if="item.reportStatus === 0" type="success" size="small" :icon="Promotion" circle @click="updateReport(item.id,1,'提交')"/>
<el-button v-if="item.reportStatus === 1" type="success" size="small" :icon="Check" circle @click="updateReport(item.id,2,'通过')"/>
<el-button v-if="item.reportStatus === 1" type="warning" size="small" :icon="Close" circle @click="updateReport(item.id,3,'驳回')"/>
@ -123,6 +124,7 @@
<el-tab-pane label="报工报表" name="four">报工报表</el-tab-pane>
</el-tabs>
</view>
</view>
</template>
<script>
@ -255,8 +257,8 @@ export default {
else tab.navigateTo("",id)
},
addReplaceReport(id){
if(id===null || id===undefined)tab.navigateTo('/page_report/reportForm')
else tab.navigateTo("",id)
if(id===null || id===undefined)tab.navigateTo('/page_report/replaceForm')
else tab.navigateTo('/page_report/replaceForm',id)
},
maskClick(e){
this.valiFormData.reportDateString = e
@ -283,7 +285,10 @@ export default {
</script>
<style lang="scss" scoped>
.example {
padding: 15px;
background-color: #fff;
}
.addSite {
display: flex;
justify-content: space-around;

@ -6,7 +6,7 @@ export function timestampToTime(timestamp: number | null): string {
let date = new Date(timestamp!); // 时间戳为10位需*1000时间戳为13位的话不需乘1000
let Y = date.getFullYear() + '-';
let M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
let D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate());
// let h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
// let m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
// let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds();

Loading…
Cancel
Save