更新门店历史

feature/0423
Wayne 9 months ago
parent cd5c456d32
commit e5d2a2cb80
  1. 85
      src/views/store/shop/Create.vue
  2. 107
      src/views/store/shop/Update.vue

@ -77,10 +77,36 @@
<a-radio-group v-decorator="['is_main', { initialValue: 0, rules: [{ required: true }] }]">
<a-radio :value="0">不是</a-radio>
<a-radio :value="1"></a-radio>
</a-radio-group>
</a-form-item>
<a-form-item
v-for="(k, index) in form.getFieldValue('historys')"
:key="k.id"
:label="index === 0 ? '门店历史' : ''"
:labelCol="labelCol"
v-bind="index === 0 ? {wrapperCol} : formItemLayoutWithOutLabel"
required>
<a-date-picker
format="YYYY-MM-DD"
v-decorator="[`historysTime${index}`, { rules: [{ required: true, message: '请指定日期' }] }]"
style="width: 30%; margin-right: 8px"
/>
<a-input placeholder="请输入门店历史" v-decorator="[`historysContent${index}`, { rules: [{ required: true }] }]" style="width: 30%; margin-right: 8px" />
<a-icon
v-if="form.getFieldValue('historys').length > 0"
class="dynamic-delete-button"
type="minus-circle-o"
:disabled="form.getFieldValue('historys').length === 1"
@click="() => handleRemoveHistory(index)"
/>
</a-form-item>
<a-form-item v-bind="formItemLayoutWithOutLabel">
<a-button type="dashed" style="width: calc(60% + 8px)" @click="handleAddHistory">
<a-icon type="plus" /> 新增门店历史
</a-button>
</a-form-item>
<a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
<div>
<template v-for="(tag, index) in tags">
@ -130,6 +156,7 @@
</template>
<script>
import moment from 'moment'
import * as Api from '@/api/store/shop'
import { SelectImage, SelectRegion, Getpoint } from '@/components'
@ -149,13 +176,21 @@ export default {
//
wrapperCol: { span: 10 },
//
form: this.$form.createForm(this),
// form: this.$form.createForm(this),
tags: [],
tagInputVisible: false,
tagInputValue: ''
tagInputValue: '',
formItemLayoutWithOutLabel: {
wrapperCol: { span: 10, offset: 3 }
}
}
},
beforeCreate () {
this.form = this.$form.createForm(this)
this.form.getFieldDecorator('historys', { initialValue: [], preserve: true })
},
created () {
},
methods: {
@ -188,6 +223,38 @@ export default {
})
},
generateRandomString (length) {
let result = ''
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}
return result
},
handleRemoveHistory (index) {
const { form } = this
const keys = form.getFieldValue('historys')
if (keys.length === 0) {
return
}
const historys = keys.filter((x, i) => i !== index)
form.setFieldsValue({
historys
})
},
handleAddHistory () {
const { form } = this
const keys = form.getFieldValue('historys')
const nextKeys = keys.concat([{ historysTime: '', historysContent: '', id: this.generateRandomString(8) }])
form.setFieldsValue({
historys: nextKeys
})
},
//
setCoordinate (coordinate) {
const { form, $nextTick } = this
@ -208,9 +275,19 @@ export default {
// api
onFormSubmit (values) {
const form = { ...values, remark: this.tags, shop_image_id: values.shop_image_id.join(',') }
form.history = form.historys.map((x, i) => {
return {
time: form[`historysTime${i}`] && form[`historysTime${i}`].format('YYYY-MM-DD'),
content: form[`historysContent${i}`]
}
})
delete form['historys']
this.isLoading = true
this.isBtnLoading = true
Api.add({ form: { ...values, remark: this.tags, shop_image_id: values.shop_image_id.join(',') } })
Api.add({ form })
.then(result => {
//
this.$message.success(result.message, 1.5)

@ -83,6 +83,33 @@
</a-radio-group>
</a-form-item>
<a-form-item
v-for="(k, index) in form.getFieldValue('historys')"
:key="k.id"
:label="index === 0 ? '门店历史' : ''"
:labelCol="labelCol"
v-bind="index === 0 ? {wrapperCol} : formItemLayoutWithOutLabel"
required>
<a-date-picker
format="YYYY-MM-DD"
v-decorator="[`historysTime${index}`, { rules: [{ required: true, message: '请指定日期' }] }]"
style="width: 30%; margin-right: 8px"
/>
<a-input placeholder="请输入门店历史" v-decorator="[`historysContent${index}`, { rules: [{ required: true }] }]" style="width: 30%; margin-right: 8px" />
<a-icon
v-if="form.getFieldValue('historys').length > 0"
class="dynamic-delete-button"
type="minus-circle-o"
:disabled="form.getFieldValue('historys').length === 1"
@click="() => handleRemoveHistory(index)"
/>
</a-form-item>
<a-form-item v-bind="formItemLayoutWithOutLabel">
<a-button type="dashed" style="width: calc(60% + 8px)" @click="handleAddHistory">
<a-icon type="plus" /> 新增门店历史
</a-button>
</a-form-item>
<a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol">
<div>
<template v-for="(tag, index) in tags">
@ -132,10 +159,12 @@
</template>
<script>
import moment from 'moment'
import pick from 'lodash.pick'
import * as Api from '@/api/store/shop'
import { isEmpty } from '@/utils/util'
import { SelectImage, SelectRegion, Getpoint } from '@/components'
import { log } from '@/api/market/points'
export default {
components: {
@ -153,7 +182,7 @@ export default {
//
wrapperCol: { span: 10 },
//
form: this.$form.createForm(this),
// form: this.$form.createForm(this),
// ID
shopId: null,
//
@ -161,9 +190,17 @@ export default {
tags: [],
tagInputVisible: false,
tagInputValue: ''
tagInputValue: '',
formItemLayoutWithOutLabel: {
wrapperCol: { span: 10, offset: 3 }
}
}
},
beforeCreate () {
this.form = this.$form.createForm(this)
this.form.getFieldDecorator('historys', { initialValue: [], preserve: true })
},
created () {
// ID
this.shopId = this.$route.query.shopId
@ -217,12 +254,33 @@ export default {
//
setFieldsValue () {
const { record, form, $nextTick } = this
const timeAry = []
const contentAry = []
if (record.history) {
record.history = JSON.parse(record.history)
record.historys = record.history.map(x => {
x.id = this.generateRandomString(8)
return x
})
record.historys.forEach((x, i) => {
x.time && (record[`historysTime${i}`] = moment(new Date(x.time)))
record[`historysContent${i}`] = x.content
timeAry.push(`historysTime${i}`)
contentAry.push(`historysContent${i}`)
this.form.getFieldDecorator(`historysTime${i}`, { initialValue: '', preserve: true })
this.form.getFieldDecorator(`historysContent${i}`, { initialValue: '', preserve: true })
})
}
//
!isEmpty(form.getFieldsValue()) && $nextTick(() => {
form.setFieldsValue(pick(record, [
'shop_name', 'logo_image_id', 'linkman', 'phone',
'shop_hours', 'address', 'summary', 'cascader',
'coordinate', 'sort', 'is_check', 'status', 'is_main'
'coordinate', 'sort', 'is_check', 'status', 'is_main', 'historys', ...timeAry, ...contentAry
]))
})
@ -230,6 +288,37 @@ export default {
this.tags = JSON.parse(record.remark)
}
},
generateRandomString (length) {
let result = ''
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}
return result
},
handleRemoveHistory (index) {
const { form } = this
const keys = form.getFieldValue('historys')
if (keys.length === 0) {
return
}
keys.splice(index, 1)
console.log(keys)
form.setFieldsValue({
historys: keys
})
},
handleAddHistory () {
const { form } = this
const keys = form.getFieldValue('historys')
const nextKeys = keys.concat([{ historysTime: '', historysContent: '', id: this.generateRandomString(8) }])
form.setFieldsValue({
historys: nextKeys
})
},
//
setCoordinate (coordinate) {
@ -251,9 +340,19 @@ export default {
// api
onFormSubmit (values) {
const form = { ...values, remark: this.tags, shop_image_id: values.shop_image_id.join(',') }
form.history = form.historys.map((x, i) => {
return {
time: form[`historysTime${i}`] && form[`historysTime${i}`].format('YYYY-MM-DD'),
content: form[`historysContent${i}`]
}
})
delete form['historys']
this.isLoading = true
this.isBtnLoading = true
Api.edit({ shopId: this.shopId, form: { ...values, remark: this.tags, shop_image_id: values.shop_image_id.join(',') } })
Api.edit({ shopId: this.shopId, form })
.then(result => {
//
this.$message.success(result.message, 1.5)

Loading…
Cancel
Save