Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaotoday committed May 20, 2019
1 parent a28de51 commit cefb24a
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 10 deletions.
20 changes: 20 additions & 0 deletions src/utils/consts/product-specifications.js
@@ -0,0 +1,20 @@
export default [
{
value: '1',
label: '农产品',
specifications: [
{
value: '1:1',
label: '2 斤'
},
{
value: '1:2',
label: '5 斤'
},
{
value: '1:3',
label: '10 斤'
}
]
}
]
10 changes: 10 additions & 0 deletions src/utils/consts/product-units.js
@@ -0,0 +1,10 @@
export default [
{
value: '1',
label: '斤'
},
{
value: '2',
label: '件'
}
]
76 changes: 66 additions & 10 deletions src/views/products/form/index.vue
Expand Up @@ -23,15 +23,7 @@
@on-change="value => { cForm.formValidate.categoryId = value }"
style="width: 320px;" />
</Form-item>
<Form-item
label="价格"
prop="price">
<InputNumber
:min="0"
:max="100000"
v-model="cForm.formValidate.price" />
</Form-item>
<!--
<Form-item
label="进货价"
prop="dealerPrice">
Expand All @@ -50,14 +42,52 @@
v-model="cForm.formValidate.marketPrice" />
</Form-item>
-->
<Form-item
label="库存"
prop="stock">
<InputNumber
:min="0"
:max="100000"
v-model="cForm.formValidate.stock" />
</Form-item>
<Form-item
label="单位"
prop="unit">
<Select
v-model="cForm.formValidate.unit"
style="width: 320px">
<Option
v-for="item in $consts.PRODUCT_UNITS"
:value="item.value"
:key="item.value">
{{ item.label }}
</Option>
</Select>
</Form-item>
<Form-item
label="价格"
prop="price">
<InputNumber
:min="0"
:max="100000"
v-model="cForm.formValidate.price" />
</Form-item>
<Form-item
label="规格"
prop="specifications">
<div
v-for="(item, index) in $consts.PRODUCT_SPECIFICATIONS[0].specifications"
:key="item.value"
style="padding-bottom: 5px;">
<InputNumber
:min="0"
:max="100000"
:value="cForm.formValidate.specifications[index].price"
@on-change="value => { handleSpecificationPriceChange(index, value) }" />
元 / {{ item.label }}
</div>
</Form-item>
<Form-item
label="详情"
Expand Down Expand Up @@ -121,17 +151,25 @@
</Button>
</Form-item>
</Form>
{{ this.cForm.formValidate }}
</div>
</template>

<script>
import { mapState } from 'vuex'
import routeParamsMixin from '@/mixins/route-params'
import formMixin from '@/mixins/form'
import consts from '@/utils/consts'
const getFormSpecifications = () => {
const { specifications } = consts.PRODUCT_SPECIFICATIONS[0]
return specifications.map(item => ({ ...item, price: 0 }))
}
const module = 'products'
const initForm = {
price: 0,
specifications: getFormSpecifications(),
dealerPrice: 0,
marketPrice: 0,
stock: 0,
Expand Down Expand Up @@ -189,6 +227,9 @@ export default {
detail: {
handler (newVal) {
this.$set(this.cForm, 'formValidate', newVal)
if (!newVal.specifications) {
this.cForm.formValidate.specifications = getFormSpecifications()
}
this.$refs.editor.html(newVal.content)
}
}
Expand All @@ -197,6 +238,21 @@ export default {
this.id && this.getDetail(module, this.id)
},
methods: {
handleSpecificationPriceChange (index, value) {
const { specifications } = this.cForm.formValidate
this.$set(
this.cForm,
'formValidate',
{
...this.cForm.formValidate,
specifications: specifications.map((item, i) => ({
...item,
price: index === i ? value : item.price
}))
}
)
},
handleSave () {
this.$refs.formValidate.validate(async valid => {
if (valid) {
Expand Down

0 comments on commit cefb24a

Please sign in to comment.