You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

226 lines
5.0 KiB

<template>
<!-- 添加设备报修 -->
<view class="add-form-container">
<u-form :model="form" ref="form1" label-width="160rpx">
<u-form-item label="故障描述" prop="describes" required>
<u-input v-model="form.describes" placeholder="请输入故障描述" />
</u-form-item>
<u-form-item :label="`${type=='DEVICE'?'设备' : '模具'}编码`" prop="deviceNumber" required>
<u-input v-model="form.deviceNumber" @blur="blur()"
:placeholder="`请输入${type=='DEVICE'?'设备' : '模具'}编码`" />
<view class="right-button" @click="chickRightButton">
扫描
</view>
</u-form-item>
<u-form-item :label="`${type=='DEVICE'?'设备' : '模具'}名称`" prop="deviceName" required>
<u-input v-model="form.deviceName" :placeholder="`请输入${type=='DEVICE'?'设备' : '模具'}名称`" disabled />
</u-form-item>
<u-form-item label="所属厂区" prop="factoryAreaName" required>
<u-input v-model="form.factoryAreaName" placeholder="请输入所属厂区" disabled />
</u-form-item>
</u-form>
<view class="footer">
<view class="btns">
<button class="reset" @click="reset">重置</button>
<button class="sure" @click="submit" :loading='loading' :disabled='loading'>确定</button>
</view>
<view style="height: constant(safe-area-inset-bottom); height: env(safe-area-inset-bottom);"></view>
</view>
</view>
</template>
<script>
import * as deviceApi from "@/api/device.js"
export default {
data() {
return {
loading: false,
type: "",
form: {
describes: "",
deviceNumber: '',
deviceName: '',
factoryAreaName: '',
factoryAreaNumber: '',
}
}
},
methods: {
// 扫描设备条码
chickRightButton(field) {
uni.scanCode({
success: function(res) {
this.form.deviceNumber = res.result
this.getDetailsByNumber()
}
});
},
blur() {
if (this.form.deviceNumber) {
this.getDetailsByNumber()
}
},
// 根据设备/模具号查询信息
getDetailsByNumber() {
const data = {
number: this.form.deviceNumber,
type: this.type,
id: ''
}
deviceApi.getDetailsByNumber(data).then((res) => {
if (res.data) {
this.form.deviceName = res.data.name
this.form.factoryAreaName = res.data.factoryAreaName
this.form.factoryAreaNumber = res.data.factoryAreaNumber
} else {
this.$modal.showToast(`找不到该${this.type=='DEVICE'?'设备' : '模具'}`)
}
})
},
// 触发提交表单
submit() {
// 校验
if (!this.form.describes) {
this.$modal.showToast('请输入故障描述')
return;
}
if (!this.form.deviceNumber) {
this.$modal.showToast(`请输入${this.type=='DEVICE'?'设备' : '模具'}编码`)
return;
}
if (!this.form.deviceName) {
this.$modal.showToast(`请输入${this.type=='DEVICE'?'设备' : '模具'}名称`)
return;
}
if (!this.form.factoryAreaName) {
this.$modal.showToast('请输入所属厂区')
return;
}
const data = {
describes: this.form.describes,
deviceNumber: this.form.deviceNumber,
factoryAreaNumber: this.form.factoryAreaNumber,
type: this.type
}
this.$modal.confirm('是否添加报修').then(() => {
this.$modal.loading('加载中')
this.loading = true
deviceApi.deviceRepairCreate(data).then((res) => {
this.$modal.closeLoading()
if (res.data) {
this.$modal.showToast('添加成功')
setTimeout(() => {
this.$tab.navigateBack()
this.loading = false
}, 1500)
} else {
this.$modal.showToast('添加失败')
this.loading = false
}
}).catch(() => {
this.$modal.closeLoading()
this.loading = false
})
})
},
// 重置
reset() {
console.log('表单数据信息1:', this.data);
this.form = {}
},
},
onLoad(option) {
if (option.type) this.type = option.type;
}
}
</script>
<style lang="scss" scoped>
.add-form-container {
min-height: calc(100vh - 140rpx);
background: white;
padding: 0px 30rpx 140rpx;
}
.list {
padding-bottom: 20rpx;
.item {
margin-top: 20rpx;
background: white;
padding: 30rpx;
display: flex;
align-items: center;
image {
width: 160rpx;
height: 160rpx;
margin-right: 20rpx;
}
.title {
font-size: 32rpx;
font-weight: bold;
}
.dec1 {
font-size: 28rpx;
margin-top: 16rpx;
color: #acacac;
}
.dec2 {
font-size: 28rpx;
margin-top: 6rpx;
color: #acacac;
}
}
}
.footer {
position: fixed;
bottom: 0px;
left: 0px;
width: 100%;
}
.btns {
display: flex;
button {
flex: 1;
}
.sure {
background: #409eff;
color: white;
border-radius: 0px;
&::after {
border: 1px solid #409eff;
border-radius: 0px;
}
}
.reset {
background: #F5F5F5;
border-radius: 0px;
&::after {
border-radius: 0px;
}
}
}
.right-button {
background: #409eff;
color: white;
padding: 0rpx 30rpx;
border-radius: 16rpx;
text-align: center;
font-size: 28rpx;
}
</style>