relateProDialog.vue
5.3 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<!-- 编辑商品弹窗 -->
<template>
<d2-dialog
title="关联升级商品"
:isVisible.sync="relateProVisible"
btnOkLabel="关联"
@confirmDialog="handleRelateProConfirm"
@closeDialog="handleRelateProClose"
>
<div class="relateProDialog flex">
<img :src="proInfo.thumbUrl" />
<el-form
:model="proInfo"
:rules="rules"
label-width="110px"
ref="proRuleForm"
>
<el-form-item
label="关联升级商品"
prop="goodsCode"
>
<el-select
v-model="proInfo.goodsCode"
placeholder="请选择关联商品"
value-key="goodsCode"
@change="handleChangeGood"
>
<el-option
v-for="item in proList"
:key="item.goodsCode"
:label="item.goodsName"
:value="item.goodsCode"
:disabled="item.disabled"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="类别">
<el-input
disabled
value="升级"
class="dis-in-block"
></el-input>
</el-form-item>
<el-form-item
label="建议升级价"
prop="upgradePrice"
>
<el-input
v-model="proInfo.upgradePrice"
placeholder="请输入建议升级价"
class="dis-in-block"
@input="handleUpgradePrice"
></el-input>
<span>元</span>
</el-form-item>
<el-form-item
label="到店价"
prop="shopPrice"
>
<el-input
v-model="proInfo.shopPrice"
placeholder="请输入建议到店价"
class="dis-in-block"
@input="handleShopPrice"
></el-input>
<span>元</span>
</el-form-item>
<el-form-item label="升级最大折扣">
<el-input
v-model="proInfo.maxUpgradeDiscount"
placeholder="请输入升级最大折扣"
clearable
class="dis-in-block"
@input="handleMaxUpgradeDiscount"
></el-input>
<span>折</span>
</el-form-item>
</el-form>
</div>
</d2-dialog>
</template>
<script>
import _ from 'lodash'
import { limitPrice } from '@/common/constants'
export default {
name: 'relateProDialog',
data() {
return {
goodVal: {},
proInfo: {
// thumbUrl: 'https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=1244233290,1050095100&fm=26&gp=0.jpg',
thumbUrl: '',
goodsCode: '',
goodsName: '',
type: '',
upgradePrice: '',
shopPrice: '',
maxUpgradeDiscount: ''
},
rules: {
goodsCode: [{ required: true, message: '请选择关联升级商品', trigger: 'blur' }],
upgradePrice: [{ required: true, message: '请输入建议升级价', trigger: 'blur' }],
shopPrice: [{ required: true, message: '请输入到店价', trigger: 'blur' }]
},
oldVal: {
upgradePrice: '',
shopPrice: '',
maxUpgradeDiscount: ''
}
}
},
// watch: {
// 'proInfo.upgradePrice'(val, oldVal) {
// this.proInfo.upgradePrice = limitPrice(val, oldVal, 8, 2)
// },
// 'proInfo.shopPrice'(val, oldVal) {
// this.proInfo.shopPrice = limitPrice(val, oldVal, 6, 2)
// },
// 'proInfo.maxUpgradeDiscount'(val, oldVal) {
// this.proInfo.maxUpgradeDiscount = limitPrice(val, oldVal, 1, 1, 1)
// }
// },
props: {
relateProVisible: {
type: Boolean,
default: false
},
proList: {
type: Array,
default: () => []
},
originProInfo: {
type: Object,
default: () => { }
}
},
mounted() {
this.proInfo = _.cloneDeep(this.originProInfo) || _.cloneDeep(this.proInfo)
// console.log(this.proInfo)
// console.log(this.proList)
},
methods: {
handleChangeGood(value) {
var targetItem = this.proList.find(item => item.goodsCode === value)
this.proInfo.goodsName = targetItem.goodsName
this.proInfo.goodsCode = targetItem.goodsCode
this.proInfo.thumbUrl = targetItem.thumbUrl
// console.log(value)
},
handleRelateProConfirm() {
// console.log(this.proInfo)
this.$refs.proRuleForm.validate(valid => {
if (valid) {
this.$emit('handleRelateProConfirm', this.proInfo)
}
})
},
handleRelateProClose() {
this.$emit('handleRelateProClose')
},
handleUpgradePrice(newVal) {
this.proInfo.upgradePrice = limitPrice(newVal, this.oldVal.upgradePrice, 8, 2)
this.oldVal.upgradePrice = this.proInfo.upgradePrice
},
handleShopPrice(newVal) {
this.proInfo.shopPrice = limitPrice(newVal, this.oldVal.shopPrice, 6, 2)
this.oldVal.shopPrice = this.proInfo.shopPrice
},
handleMaxUpgradeDiscount(newVal) {
this.proInfo.maxUpgradeDiscount = limitPrice(newVal, this.oldVal.maxUpgradeDiscount, 1, 1, 1)
this.oldVal.maxUpgradeDiscount = this.proInfo.maxUpgradeDiscount
}
}
}
</script>
<style scoped>
.relateProDialog.flex {
display: flex;
}
.relateProDialog img {
width: 160px;
height: 160px;
margin-right: 20px;
}
.relateProDialog .dis-in-block {
display: inline-block;
width: 75%;
margin-right: 6px;
}
</style>