PriceEdit.vue
3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<template>
<a-modal :title="title" :visible="innerVisible" @cancel="handleCancel" @ok="handleSubmit" cancelText="关闭"
:confirm-loading="confirmLoading">
<j-form-container>
<a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
<a-form-model-item label="工时费" prop="price" :labelCol="labelCol" :wrapperCol="wrapperCol">
<a-input-number v-model="model.price" :min="0" :max="9999" :precision="0" :formatter="limitNumber"
:parser="limitNumber" placeholder="请输入工时费" style="width: 100%" />
</a-form-model-item>
</a-form-model>
</j-form-container>
</a-modal>
</template>
<script>
import { getAction, httpAction } from '@/api/manage'
export default {
name: 'PriceEdit',
props: {
visible: {
type: Boolean,
default: false
},
},
data() {
return {
title: "工费编辑",
innerVisible: false,
disabled: true,
model: {
price: 0
},
validatorRules: {
price: [{ required: true, message: '请输入工时费!' }],
},
labelCol: {
xs: { span: 24 },
sm: { span: 5 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 16 },
},
oldPrice: 0,
confirmLoading: false,
}
},
watch: {
visible: {
immediate: true,
handler(val) {
if (val) {
}
this.innerVisible = val
}
},
innerVisible(val) {
this.$emit('update:visible', val)
},
},
created() {
this.getPrice();
},
methods: {
limitNumber(value) {
if (typeof value === 'string') {
return !isNaN(Number(value)) ? value.replace(/\./g, '') : 0
} else if (typeof value === 'number') {
return !isNaN(value) ? String(value).replace(/\./g, '') : 0
} else {
return 0
}
},
getPrice() {
getAction("/work_order/tblPrice/getPrice").then(res => {
if (res.success) {
this.model.price = res.result.price;
this.oldPrice = res.result.price;
this.innerVisible = true;
}
})
},
changeInput() {
this.disabled = !this.disabled;
},
handleCancel() {
this.innerVisible = false
},
handleSubmit() {
const _this = this
this.$refs.form.validate((valid) => {
if (valid) {
_this.confirmLoading = true
if (_this.model.price === _this.oldPrice) {
this.innerVisible = false
return;
}
_this.model.id = 0;
httpAction("/work_order/tblPrice/edit", _this.model, "post").then(res => {
if (res.success) {
_this.$message.success(res.message)
this.innerVisible = false;
} else {
_this.$message.warning(res.message)
}
}).finally(() => {
_this.confirmLoading = false
})
}
})
},
onFinish(e) {
console.log('onFinish', e)
},
onFinishFailed(e) {
console.log('onFinishFailed', e)
}
}
}
</script>