From cefb24ace56972f4cefa8c2699b3c8ade1b6f4ca Mon Sep 17 00:00:00 2001 From: zhaojintian <729234283@qq.com> Date: Mon, 20 May 2019 21:29:13 +0800 Subject: [PATCH] update --- src/utils/consts/product-specifications.js | 20 ++++++ src/utils/consts/product-units.js | 10 +++ src/views/products/form/index.vue | 76 +++++++++++++++++++--- 3 files changed, 96 insertions(+), 10 deletions(-) create mode 100644 src/utils/consts/product-specifications.js create mode 100644 src/utils/consts/product-units.js diff --git a/src/utils/consts/product-specifications.js b/src/utils/consts/product-specifications.js new file mode 100644 index 00000000..77ae9918 --- /dev/null +++ b/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 斤' + } + ] + } +] diff --git a/src/utils/consts/product-units.js b/src/utils/consts/product-units.js new file mode 100644 index 00000000..cc11463f --- /dev/null +++ b/src/utils/consts/product-units.js @@ -0,0 +1,10 @@ +export default [ + { + value: '1', + label: '斤' + }, + { + value: '2', + label: '件' + } +] diff --git a/src/views/products/form/index.vue b/src/views/products/form/index.vue index bce1906f..e8a49b61 100644 --- a/src/views/products/form/index.vue +++ b/src/views/products/form/index.vue @@ -23,15 +23,7 @@ @on-change="value => { cForm.formValidate.categoryId = value }" style="width: 320px;" /> - - - 元 - + @@ -57,7 +50,44 @@ :min="0" :max="100000" v-model="cForm.formValidate.stock" /> - 件 + + + + + + + 元 + + +
+ + 元 / {{ item.label }} +
+ {{ this.cForm.formValidate }} @@ -128,10 +159,17 @@ 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, @@ -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) } } @@ -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) {