|
@@ -122,7 +122,7 @@
|
|
|
<el-row>
|
|
<el-row>
|
|
|
<el-col :span="12">
|
|
<el-col :span="12">
|
|
|
<el-form-item label="排序" prop="sort">
|
|
<el-form-item label="排序" prop="sort">
|
|
|
- <el-input-number v-model="form.sort" :min="0" controls-position="right" style="width: 100%;" />
|
|
|
|
|
|
|
+ <el-input-number v-model="form.sort" :min="0" controls-position="right" style="width: 200px;" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
</el-col>
|
|
</el-col>
|
|
|
</el-row>
|
|
</el-row>
|
|
@@ -145,6 +145,7 @@
|
|
|
<el-form-item label="选项列表">
|
|
<el-form-item label="选项列表">
|
|
|
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openFieldDialog">新增选项</el-button>
|
|
<el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openFieldDialog">新增选项</el-button>
|
|
|
<el-table
|
|
<el-table
|
|
|
|
|
+ v-loading="fieldLoading"
|
|
|
:data="fieldList"
|
|
:data="fieldList"
|
|
|
border
|
|
border
|
|
|
size="small"
|
|
size="small"
|
|
@@ -180,12 +181,18 @@
|
|
|
size="mini"
|
|
size="mini"
|
|
|
type="text"
|
|
type="text"
|
|
|
icon="el-icon-delete"
|
|
icon="el-icon-delete"
|
|
|
- @click="deleteFieldRow(scope.$index)"
|
|
|
|
|
- v-if="fieldList.length > 0"
|
|
|
|
|
|
|
+ @click="deleteFieldRow(scope.row)"
|
|
|
>删除</el-button>
|
|
>删除</el-button>
|
|
|
</template>
|
|
</template>
|
|
|
</el-table-column>
|
|
</el-table-column>
|
|
|
</el-table>
|
|
</el-table>
|
|
|
|
|
+ <pagination
|
|
|
|
|
+ v-show="fieldTotal > 0"
|
|
|
|
|
+ :total="fieldTotal"
|
|
|
|
|
+ :page.sync="fieldQueryParams.pageNum"
|
|
|
|
|
+ :limit.sync="fieldQueryParams.pageSize"
|
|
|
|
|
+ @pagination="handleFieldPagination"
|
|
|
|
|
+ />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
</el-form>
|
|
</el-form>
|
|
|
<div slot="footer" class="dialog-footer">
|
|
<div slot="footer" class="dialog-footer">
|
|
@@ -204,7 +211,7 @@
|
|
|
<el-switch v-model="fieldForm.isRequired" :active-value="1" :inactive-value="0" />
|
|
<el-switch v-model="fieldForm.isRequired" :active-value="1" :inactive-value="0" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
<el-form-item label="类型" prop="fieldType">
|
|
<el-form-item label="类型" prop="fieldType">
|
|
|
- <el-select v-model="fieldForm.fieldType" placeholder="请选择类型" style="width: 100%;" @change="handleFieldTypeChange">
|
|
|
|
|
|
|
+ <el-select v-model="fieldForm.fieldType" placeholder="请选择类型" style="width: 200px;" @change="handleFieldTypeChange">
|
|
|
<el-option
|
|
<el-option
|
|
|
v-for="item in fieldTypeOptions"
|
|
v-for="item in fieldTypeOptions"
|
|
|
:key="item.value"
|
|
:key="item.value"
|
|
@@ -226,7 +233,7 @@
|
|
|
/>
|
|
/>
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
<el-form-item label="排序" prop="sort">
|
|
<el-form-item label="排序" prop="sort">
|
|
|
- <el-input-number v-model="fieldForm.sort" :min="0" controls-position="right" style="width: 100%;" />
|
|
|
|
|
|
|
+ <el-input-number v-model="fieldForm.sort" :min="0" controls-position="right" style="width: 200px;" />
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
<el-form-item label="状态" prop="status">
|
|
<el-form-item label="状态" prop="status">
|
|
|
<el-radio-group v-model="fieldForm.status">
|
|
<el-radio-group v-model="fieldForm.status">
|
|
@@ -236,7 +243,7 @@
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
</el-form>
|
|
</el-form>
|
|
|
<div slot="footer" class="dialog-footer">
|
|
<div slot="footer" class="dialog-footer">
|
|
|
- <el-button type="primary" @click="submitFieldForm">确 定</el-button>
|
|
|
|
|
|
|
+ <el-button type="primary" :loading="fieldSubmitLoading" @click="submitFieldForm">确 定</el-button>
|
|
|
<el-button @click="fieldOpen = false">取 消</el-button>
|
|
<el-button @click="fieldOpen = false">取 消</el-button>
|
|
|
</div>
|
|
</div>
|
|
|
</el-dialog>
|
|
</el-dialog>
|
|
@@ -251,7 +258,11 @@ import {
|
|
|
addFsStoreProductUserTemp,
|
|
addFsStoreProductUserTemp,
|
|
|
updateFsStoreProductUserTemp
|
|
updateFsStoreProductUserTemp
|
|
|
} from '@/api/hisStore/storeProductUserTemp'
|
|
} from '@/api/hisStore/storeProductUserTemp'
|
|
|
-import { listFsStoreProductUserTempField } from '@/api/hisStore/storeProductUserTempField'
|
|
|
|
|
|
|
+import {
|
|
|
|
|
+ listFsStoreProductUserTempField,
|
|
|
|
|
+ addFsStoreProductUserTempField,
|
|
|
|
|
+ delFsStoreProductUserTempField
|
|
|
|
|
+} from '@/api/hisStore/storeProductUserTempField'
|
|
|
|
|
|
|
|
export default {
|
|
export default {
|
|
|
name: 'FsStoreProductUserTemp',
|
|
name: 'FsStoreProductUserTemp',
|
|
@@ -275,7 +286,15 @@ export default {
|
|
|
title: '',
|
|
title: '',
|
|
|
open: false,
|
|
open: false,
|
|
|
fieldOpen: false,
|
|
fieldOpen: false,
|
|
|
|
|
+ fieldSubmitLoading: false,
|
|
|
|
|
+ fieldLoading: false,
|
|
|
fieldList: [],
|
|
fieldList: [],
|
|
|
|
|
+ fieldTotal: 0,
|
|
|
|
|
+ fieldQueryParams: {
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ pageSize: 10,
|
|
|
|
|
+ tempId: null
|
|
|
|
|
+ },
|
|
|
statusOptions: [],
|
|
statusOptions: [],
|
|
|
fieldTypeOptions: [
|
|
fieldTypeOptions: [
|
|
|
{ label: '文本', value: 'text' },
|
|
{ label: '文本', value: 'text' },
|
|
@@ -311,6 +330,70 @@ export default {
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
methods: {
|
|
methods: {
|
|
|
|
|
+ parseTemplateId(response) {
|
|
|
|
|
+ if (response.id != null && response.id !== '') {
|
|
|
|
|
+ return response.id
|
|
|
|
|
+ }
|
|
|
|
|
+ const data = response.data
|
|
|
|
|
+ if (data == null || data === '') {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ if (typeof data === 'object') {
|
|
|
|
|
+ return data.id != null && data.id !== '' ? data.id : null
|
|
|
|
|
+ }
|
|
|
|
|
+ return data
|
|
|
|
|
+ },
|
|
|
|
|
+ fetchTemplateIdByName() {
|
|
|
|
|
+ return listFsStoreProductUserTemp({
|
|
|
|
|
+ name: this.form.name,
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ pageSize: 10
|
|
|
|
|
+ }).then(response => {
|
|
|
|
|
+ const rows = (response.rows || []).filter(item => item.name === this.form.name)
|
|
|
|
|
+ if (!rows.length) {
|
|
|
|
|
+ return null
|
|
|
|
|
+ }
|
|
|
|
|
+ rows.sort((a, b) => Number(b.id) - Number(a.id))
|
|
|
|
|
+ return rows[0].id
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ resolveTemplateIdFromResponse(response) {
|
|
|
|
|
+ const id = this.parseTemplateId(response)
|
|
|
|
|
+ if (id != null) {
|
|
|
|
|
+ return Promise.resolve(id)
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.fetchTemplateIdByName()
|
|
|
|
|
+ },
|
|
|
|
|
+ saveTemplateAndGetId() {
|
|
|
|
|
+ return addFsStoreProductUserTemp(this.buildTemplatePayload()).then(response => {
|
|
|
|
|
+ if (response.code !== 200) {
|
|
|
|
|
+ return Promise.reject()
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.resolveTemplateIdFromResponse(response)
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
|
|
+ buildTemplatePayload() {
|
|
|
|
|
+ const payload = { ...this.form }
|
|
|
|
|
+ if (payload.id == null || payload.id === '') {
|
|
|
|
|
+ delete payload.id
|
|
|
|
|
+ }
|
|
|
|
|
+ return payload
|
|
|
|
|
+ },
|
|
|
|
|
+ hasTemplateId() {
|
|
|
|
|
+ return this.form.id != null && this.form.id !== ''
|
|
|
|
|
+ },
|
|
|
|
|
+ mapFieldItem(item) {
|
|
|
|
|
+ return {
|
|
|
|
|
+ id: item.id,
|
|
|
|
|
+ tempId: item.tempId,
|
|
|
|
|
+ fieldName: item.fieldName,
|
|
|
|
|
+ isRequired: item.isRequired != null ? Number(item.isRequired) : 0,
|
|
|
|
|
+ fieldType: item.fieldType,
|
|
|
|
|
+ fieldOption: item.fieldOption || '',
|
|
|
|
|
+ sort: item.sort != null ? Number(item.sort) : 0,
|
|
|
|
|
+ status: item.status != null ? Number(item.status) : 1
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
getFieldTypeLabel(value) {
|
|
getFieldTypeLabel(value) {
|
|
|
const item = this.fieldTypeOptions.find(opt => opt.value === value)
|
|
const item = this.fieldTypeOptions.find(opt => opt.value === value)
|
|
|
return item ? item.label : value
|
|
return item ? item.label : value
|
|
@@ -323,26 +406,33 @@ export default {
|
|
|
this.loading = false
|
|
this.loading = false
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- loadFieldList(tempId) {
|
|
|
|
|
- if (!tempId) {
|
|
|
|
|
|
|
+ loadFieldList(tempId, resetPage = true) {
|
|
|
|
|
+ if (tempId != null && tempId !== '') {
|
|
|
|
|
+ this.fieldQueryParams.tempId = tempId
|
|
|
|
|
+ if (resetPage) {
|
|
|
|
|
+ this.fieldQueryParams.pageNum = 1
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!this.fieldQueryParams.tempId) {
|
|
|
this.fieldList = []
|
|
this.fieldList = []
|
|
|
|
|
+ this.fieldTotal = 0
|
|
|
return Promise.resolve()
|
|
return Promise.resolve()
|
|
|
}
|
|
}
|
|
|
|
|
+ this.fieldLoading = true
|
|
|
return listFsStoreProductUserTempField({
|
|
return listFsStoreProductUserTempField({
|
|
|
- tempId,
|
|
|
|
|
- pageNum: 1,
|
|
|
|
|
- pageSize: 1000
|
|
|
|
|
|
|
+ tempId: this.fieldQueryParams.tempId,
|
|
|
|
|
+ pageNum: this.fieldQueryParams.pageNum,
|
|
|
|
|
+ pageSize: this.fieldQueryParams.pageSize
|
|
|
}).then(response => {
|
|
}).then(response => {
|
|
|
- this.fieldList = (response.rows || []).map(item => ({
|
|
|
|
|
- fieldName: item.fieldName,
|
|
|
|
|
- isRequired: item.isRequired != null ? Number(item.isRequired) : 0,
|
|
|
|
|
- fieldType: item.fieldType,
|
|
|
|
|
- fieldOption: item.fieldOption || '',
|
|
|
|
|
- sort: item.sort != null ? Number(item.sort) : 0,
|
|
|
|
|
- status: item.status != null ? Number(item.status) : 1
|
|
|
|
|
- }))
|
|
|
|
|
|
|
+ this.fieldList = (response.rows || []).map(item => this.mapFieldItem(item))
|
|
|
|
|
+ this.fieldTotal = response.total || 0
|
|
|
|
|
+ }).finally(() => {
|
|
|
|
|
+ this.fieldLoading = false
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
|
|
+ handleFieldPagination() {
|
|
|
|
|
+ this.loadFieldList(null, false)
|
|
|
|
|
+ },
|
|
|
cancel() {
|
|
cancel() {
|
|
|
this.open = false
|
|
this.open = false
|
|
|
this.reset()
|
|
this.reset()
|
|
@@ -356,6 +446,12 @@ export default {
|
|
|
remark: null
|
|
remark: null
|
|
|
}
|
|
}
|
|
|
this.fieldList = []
|
|
this.fieldList = []
|
|
|
|
|
+ this.fieldTotal = 0
|
|
|
|
|
+ this.fieldQueryParams = {
|
|
|
|
|
+ pageNum: 1,
|
|
|
|
|
+ pageSize: 10,
|
|
|
|
|
+ tempId: null
|
|
|
|
|
+ }
|
|
|
this.resetForm('form')
|
|
this.resetForm('form')
|
|
|
},
|
|
},
|
|
|
resetFieldForm() {
|
|
resetFieldForm() {
|
|
@@ -394,11 +490,7 @@ export default {
|
|
|
this.form = response.data
|
|
this.form = response.data
|
|
|
this.form.status = this.form.status != null ? Number(this.form.status) : 1
|
|
this.form.status = this.form.status != null ? Number(this.form.status) : 1
|
|
|
this.form.sort = this.form.sort != null ? Number(this.form.sort) : 0
|
|
this.form.sort = this.form.sort != null ? Number(this.form.sort) : 0
|
|
|
- if (response.data.fieldList && response.data.fieldList.length) {
|
|
|
|
|
- this.fieldList = response.data.fieldList
|
|
|
|
|
- } else {
|
|
|
|
|
- return this.loadFieldList(id)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return this.loadFieldList(id)
|
|
|
}).then(() => {
|
|
}).then(() => {
|
|
|
this.open = true
|
|
this.open = true
|
|
|
this.title = '修改商品信息采集模板'
|
|
this.title = '修改商品信息采集模板'
|
|
@@ -413,40 +505,100 @@ export default {
|
|
|
this.fieldForm.fieldOption = ''
|
|
this.fieldForm.fieldOption = ''
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
+ addTemplateIfNeeded() {
|
|
|
|
|
+ if (this.hasTemplateId()) {
|
|
|
|
|
+ return Promise.resolve(this.form.id)
|
|
|
|
|
+ }
|
|
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
|
|
+ this.$refs.form.validate(valid => {
|
|
|
|
|
+ if (!valid) {
|
|
|
|
|
+ this.$message.warning('请先完善模板基本信息')
|
|
|
|
|
+ reject()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.saveTemplateAndGetId().then(id => {
|
|
|
|
|
+ if (id == null) {
|
|
|
|
|
+ this.$message.error('模板已保存,但未获取到模板编号,无法新增选项')
|
|
|
|
|
+ reject()
|
|
|
|
|
+ return
|
|
|
|
|
+ }
|
|
|
|
|
+ this.$set(this.form, 'id', id)
|
|
|
|
|
+ this.title = '修改商品信息采集模板'
|
|
|
|
|
+ resolve(id)
|
|
|
|
|
+ }).catch(() => {
|
|
|
|
|
+ this.$message.error('模板保存失败,无法新增选项')
|
|
|
|
|
+ reject()
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ },
|
|
|
submitFieldForm() {
|
|
submitFieldForm() {
|
|
|
this.$refs.fieldForm.validate(valid => {
|
|
this.$refs.fieldForm.validate(valid => {
|
|
|
- if (valid) {
|
|
|
|
|
- this.fieldList.push({ ...this.fieldForm })
|
|
|
|
|
- this.fieldList.sort((a, b) => a.sort - b.sort)
|
|
|
|
|
- this.fieldOpen = false
|
|
|
|
|
|
|
+ if (!valid) {
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+ this.fieldSubmitLoading = true
|
|
|
|
|
+ this.addTemplateIfNeeded()
|
|
|
|
|
+ .then(templateId => {
|
|
|
|
|
+ return addFsStoreProductUserTempField({
|
|
|
|
|
+ ...this.fieldForm,
|
|
|
|
|
+ tempId: templateId
|
|
|
|
|
+ })
|
|
|
|
|
+ })
|
|
|
|
|
+ .then(response => {
|
|
|
|
|
+ if (response.code === 200) {
|
|
|
|
|
+ this.msgSuccess('新增选项成功')
|
|
|
|
|
+ this.fieldOpen = false
|
|
|
|
|
+ return this.loadFieldList(this.form.id)
|
|
|
|
|
+ }
|
|
|
|
|
+ this.$message.error('新增选项失败')
|
|
|
|
|
+ })
|
|
|
|
|
+ .catch(() => {})
|
|
|
|
|
+ .finally(() => {
|
|
|
|
|
+ this.fieldSubmitLoading = false
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- deleteFieldRow(index) {
|
|
|
|
|
- this.fieldList.splice(index, 1)
|
|
|
|
|
|
|
+ deleteFieldRow(row) {
|
|
|
|
|
+ if (row && row.id) {
|
|
|
|
|
+ this.$confirm('是否确认删除该选项?', '警告', {
|
|
|
|
|
+ confirmButtonText: '确定',
|
|
|
|
|
+ cancelButtonText: '取消',
|
|
|
|
|
+ type: 'warning'
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ return delFsStoreProductUserTempField(row.id)
|
|
|
|
|
+ }).then(() => {
|
|
|
|
|
+ this.msgSuccess('删除成功')
|
|
|
|
|
+ if (this.fieldList.length === 1 && this.fieldQueryParams.pageNum > 1) {
|
|
|
|
|
+ this.fieldQueryParams.pageNum -= 1
|
|
|
|
|
+ }
|
|
|
|
|
+ return this.loadFieldList(null, false)
|
|
|
|
|
+ }).catch(() => {})
|
|
|
|
|
+ }
|
|
|
},
|
|
},
|
|
|
submitForm() {
|
|
submitForm() {
|
|
|
this.$refs.form.validate(valid => {
|
|
this.$refs.form.validate(valid => {
|
|
|
- if (valid) {
|
|
|
|
|
- if (this.fieldList.length === 0) {
|
|
|
|
|
- this.$message.warning('请至少添加一个选项')
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
- const params = {
|
|
|
|
|
- ...this.form,
|
|
|
|
|
- fieldList: this.fieldList
|
|
|
|
|
- }
|
|
|
|
|
- const request = params.id != null
|
|
|
|
|
- ? updateFsStoreProductUserTemp(params)
|
|
|
|
|
- : addFsStoreProductUserTemp(params)
|
|
|
|
|
- request.then(response => {
|
|
|
|
|
- if (response.code === 200) {
|
|
|
|
|
- this.msgSuccess(params.id != null ? '修改成功' : '新增成功')
|
|
|
|
|
- this.open = false
|
|
|
|
|
- this.getList()
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ if (!valid) {
|
|
|
|
|
+ return
|
|
|
}
|
|
}
|
|
|
|
|
+ const isUpdate = this.hasTemplateId()
|
|
|
|
|
+ const request = isUpdate
|
|
|
|
|
+ ? updateFsStoreProductUserTemp({ ...this.form })
|
|
|
|
|
+ : addFsStoreProductUserTemp(this.buildTemplatePayload())
|
|
|
|
|
+ request.then(response => {
|
|
|
|
|
+ if (response.code === 200) {
|
|
|
|
|
+ if (!isUpdate) {
|
|
|
|
|
+ this.resolveTemplateIdFromResponse(response).then(id => {
|
|
|
|
|
+ if (id != null) {
|
|
|
|
|
+ this.$set(this.form, 'id', id)
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
|
|
+ }
|
|
|
|
|
+ this.msgSuccess(isUpdate ? '修改成功' : '新增成功')
|
|
|
|
|
+ this.open = false
|
|
|
|
|
+ this.getList()
|
|
|
|
|
+ }
|
|
|
|
|
+ })
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
handleDelete(row) {
|
|
handleDelete(row) {
|