Commit 440bbf78 by 李伟康

11月底需求

1 parent 2b3cf4f1
...@@ -113,5 +113,16 @@ export default { ...@@ -113,5 +113,16 @@ export default {
url, url,
data: params, data: params,
}) })
} },
/**
* 更新调查问卷
*/
updateQuestionnaire (params) {
params.method = 'marketing.api.activityQuestionnaireForm.update'
return http({
url,
data: params,
})
},
} }
\ No newline at end of file \ No newline at end of file
...@@ -192,6 +192,31 @@ const activityStatusList = [ ...@@ -192,6 +192,31 @@ const activityStatusList = [
{ text: '红包已用完', id: 2 }, { text: '红包已用完', id: 2 },
{ text: '活动已结束', id: 3 } { text: '活动已结束', id: 3 }
] ]
const transformData = (data, childrenDepth) => {
const result = []
data.forEach(item => {
const levels = item.split('/')
let currentLevel = result
for (let i = 0; i < childrenDepth; i++) {
const label = levels[i],
value = label,
existingOption = currentLevel && currentLevel.find((option) => option.label === label)
if (existingOption) {
if (i === childrenDepth - 1) continue
if (existingOption.children) currentLevel = existingOption.children
} else {
if (label && value) {
const newOption = { label, value }
if (levels[i + 1]) newOption.children = []
currentLevel.push(newOption)
if (i === childrenDepth - 1) delete newOption.children
currentLevel = newOption.children
}
}
}
})
return result
}
export { export {
limitPrice, limitPrice,
orderManageStatusList, orderManageStatusList,
...@@ -205,5 +230,6 @@ export { ...@@ -205,5 +230,6 @@ export {
orderStatusList, orderStatusList,
exportFn, exportFn,
getExplorer, getExplorer,
activityStatusList activityStatusList,
transformData
} }
\ No newline at end of file \ No newline at end of file
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
type="primary" type="primary"
@click="handleConfirm" @click="handleConfirm"
size="medium" size="medium"
>{{step == 1?'下一步':'提交'}}</el-button> >{{step == 1?'下一步': readonly ? '返回' :'提交'}}</el-button>
</GLFooter> </GLFooter>
</div> </div>
</template> </template>
...@@ -55,17 +55,19 @@ ...@@ -55,17 +55,19 @@
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import StepOne from './components/StepOne/index.vue' import StepOne from './components/StepOne/index.vue'
import StepTwo from './components/StepTwo/index.vue' import StepTwo from './components/StepTwo/index.vue'
import { transformData } from '@/common/constant'
export default { export default {
components: { StepOne, StepTwo }, components: { StepOne, StepTwo },
name: '', name: '',
data () { data () {
return { return {
parsedData: [], parsedData: [],
step: 2, step: 1,
tabs: ['基本信息', '配置内容'], tabs: ['基本信息', '配置内容'],
loading: false, loading: false,
readonly: false, readonly: false,
fromId: '' fromId: '',
isEdit: false
} }
}, },
mounted () { mounted () {
...@@ -74,6 +76,7 @@ export default { ...@@ -74,6 +76,7 @@ export default {
this.fromId = id this.fromId = id
this.readonly = !type this.readonly = !type
this.getQuestionnaireDetail() this.getQuestionnaireDetail()
this.isEdit = type
} }
}, },
methods: { methods: {
...@@ -88,7 +91,6 @@ export default { ...@@ -88,7 +91,6 @@ export default {
} = this } = this
this.setStepOneData(stepOne, data) this.setStepOneData(stepOne, data)
this.setStepTwoData(stepTwo, data) this.setStepTwoData(stepTwo, data)
console.log(data)
}, },
setStepOneData (stepOne, data) { setStepOneData (stepOne, data) {
stepOne.merchantObj.data = [{ stepOne.merchantObj.data = [{
...@@ -113,23 +115,48 @@ export default { ...@@ -113,23 +115,48 @@ export default {
} }
if (!this.readonly || data.activityId) stepOne.getActivityList() if (!this.readonly || data.activityId) stepOne.getActivityList()
}, },
setStepTwoData (stepTwo, data) { setStepTwoData (stepTwo, res) {
stepTwo.configForm = data stepTwo.configForm = {
title: res.title,
desc: res.desc,
questions: res.questions,
}
res.questions.map(e => {
let { type, option } = e,
data = type == 3 ? option : option.split('\n')
if (type != 3) {
if (type == 5) {
const [, two, three] = data[0].split('/')
data.splice(0, 1)
data = transformData(data, three ? 3 : two ? 2 : 1)
}
}
stepTwo.questionsList.push({
type,
required: e.required,
text: e.text,
userInfoField: e.userInfoField,
option,
data
})
})
}, },
handleCancel () { handleCancel () {
const { step } = this const { step } = this
step == 1 ? this.$router.go(-1) : this.step = 1 step == 1 ? this.$router.go(-1) : this.step = 1
}, },
handleConfirm () { handleConfirm (autoJump = true) {
const { step, $refs: { const { step, isEdit, fromId, readonly, $refs: {
stepOne, stepOne,
stepTwo stepTwo
} } = this } } = this,
apiName = fromId ? 'updateQuestionnaire' : 'addQuestionnaire'
if (step == 1) { if (step == 1) {
stepOne.formRef().validate(valid => { stepOne.formRef().validate(valid => {
if (valid) this.step = 2 if (valid) this.step = 2
}) })
} else { } else {
if (readonly) return this.$router.go(-1)
stepTwo.formRef().validate(async valid => { stepTwo.formRef().validate(async valid => {
if (valid) { if (valid) {
this.loading = true this.loading = true
...@@ -138,16 +165,22 @@ export default { ...@@ -138,16 +165,22 @@ export default {
...stepOne.configForm, ...stepOne.configForm,
...stepTwo.configForm, ...stepTwo.configForm,
status: 0 status: 0
}, res = await this.$apis.questionnaire.addQuestionnaire(params) }
console.log(res) if (fromId) params.id = fromId
const res = await this.$apis.questionnaire[apiName](params)
if (res) { if (res) {
this.$message({ if (autoJump) {
message: '创建成功', this.$message({
type: 'success' message: isEdit ? '编辑成功' : '创建成功',
}) type: 'success'
this.$router.go(-1) })
this.$router.go(-1)
} else {
this.fromId = res.id
this.loading = false
}
} }
else throw '创建失败' else throw isEdit ? '编辑失败' : '创建失败'
} catch (error) { } catch (error) {
this.loading = false this.loading = false
if (error) this.$message.error(error) if (error) this.$message.error(error)
...@@ -155,7 +188,8 @@ export default { ...@@ -155,7 +188,8 @@ export default {
} }
}) })
} }
} },
} }
} }
......
...@@ -211,6 +211,7 @@ ...@@ -211,6 +211,7 @@
<script type='text/ecmascript-6'> <script type='text/ecmascript-6'>
import * as XLSX from 'xlsx' import * as XLSX from 'xlsx'
import { transformData } from '@/common/constant'
const inputKeyObject = { const inputKeyObject = {
1: 'radioValue', 1: 'radioValue',
2: 'checkboxValue', 2: 'checkboxValue',
...@@ -289,7 +290,7 @@ export default { ...@@ -289,7 +290,7 @@ export default {
if (type != 3) { if (type != 3) {
this.configForm[inputKeyObject[type]] = String(data.option) this.configForm[inputKeyObject[type]] = String(data.option)
if (userInfoField) { if (userInfoField) {
if (type == 5) this.userInfoFields = userInfoField.split('/').map(e => Number(e)) if (type == 5) this.userInfoFields = userInfoField.split('/').map(e => e ? Number(e) : '')
else this.configForm.userInfoField = Number(userInfoField) else this.configForm.userInfoField = Number(userInfoField)
} }
} else this.configForm.maxLength = data.option } else this.configForm.maxLength = data.option
...@@ -396,7 +397,7 @@ export default { ...@@ -396,7 +397,7 @@ export default {
option = data.join('\n') option = data.join('\n')
if (this.checkData(option)) throw '' if (this.checkData(option)) throw ''
data.splice(0, 1) data.splice(0, 1)
data = this.transformData(data, three ? 3 : two ? 2 : 1) data = transformData(data, three ? 3 : two ? 2 : 1)
userInfoField = userInfoFields.join('/') userInfoField = userInfoFields.join('/')
} }
} }
...@@ -415,31 +416,6 @@ export default { ...@@ -415,31 +416,6 @@ export default {
} }
} }
}) })
},
transformData (data, childrenDepth) {
const result = []
data.forEach(item => {
const levels = item.split('/')
let currentLevel = result
for (let i = 0; i < childrenDepth; i++) {
const label = levels[i],
value = label,
existingOption = currentLevel && currentLevel.find((option) => option.label === label)
if (existingOption) {
if (i === childrenDepth - 1) continue
if (existingOption.children) currentLevel = existingOption.children
} else {
if (label && value) {
const newOption = { label, value }
if (levels[i + 1]) newOption.children = []
currentLevel.push(newOption)
if (i === childrenDepth - 1) delete newOption.children
currentLevel = newOption.children
}
}
}
})
return result
} }
} }
} }
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
v-model="configForm.title" v-model="configForm.title"
placeholder="请输入" placeholder="请输入"
maxlength="8" maxlength="8"
:disabled="readonly"
></el-input> ></el-input>
</el-form-item> </el-form-item>
<el-form-item <el-form-item
...@@ -33,6 +34,7 @@ ...@@ -33,6 +34,7 @@
placeholder="请输入" placeholder="请输入"
maxlength="50" maxlength="50"
show-word-limit show-word-limit
:disabled="readonly"
></el-input> ></el-input>
</el-form-item> </el-form-item>
<el-form-item <el-form-item
...@@ -116,7 +118,7 @@ ...@@ -116,7 +118,7 @@
:key="ind" :key="ind"
type="text" type="text"
@click="controlClick(index,ind)" @click="controlClick(index,ind)"
:disabled="controlDisabled(index,ind)" :disabled="controlDisabled(index,ind) || readonly"
> >
{{c}} {{c}}
</el-button> </el-button>
...@@ -130,6 +132,7 @@ ...@@ -130,6 +132,7 @@
icon="el-icon-plus" icon="el-icon-plus"
size="small" size="small"
@click="editQuestionsObj.show = true" @click="editQuestionsObj.show = true"
:disabled="readonly"
>添加题目</el-button> >添加题目</el-button>
</div> </div>
</el-form-item> </el-form-item>
...@@ -196,7 +199,7 @@ export default { ...@@ -196,7 +199,7 @@ export default {
addEvent () { addEvent () {
const _this = this const _this = this
document.addEventListener('keydown', function (event) { document.addEventListener('keydown', function (event) {
if (event.ctrlKey && event.key === 'z') { if (event.ctrlKey && event.key.toLocaleLowerCase() === 'z') {
event.preventDefault() event.preventDefault()
const { delList } = _this const { delList } = _this
if (delList.length) { if (delList.length) {
...@@ -204,6 +207,7 @@ export default { ...@@ -204,6 +207,7 @@ export default {
_this.questionsList.splice(index, 0, questionsList) _this.questionsList.splice(index, 0, questionsList)
_this.configForm.questions.splice(index, 0, questions) _this.configForm.questions.splice(index, 0, questions)
delList.pop() delList.pop()
_this.updateQuestionnaire()
} }
} }
}) })
...@@ -215,14 +219,15 @@ export default { ...@@ -215,14 +219,15 @@ export default {
const res = await this.$apis.questionnaire.getUserInfoFieldList() const res = await this.$apis.questionnaire.getUserInfoFieldList()
this.userInfoFieldList = res || [] this.userInfoFieldList = res || []
}, },
addQuestions (params, index) { async addQuestions (params, index) {
params.itemValue = params.type == 2 || params.type == 5 ? [] : '' params.itemValue = params.type == 2 || params.type == 5 ? [] : ''
const obj = { const obj = {
type: params.type, type: params.type,
required: params.required, required: params.required,
text: params.text, text: params.text,
userInfoField: params.userInfoField userInfoField: params.userInfoField
} }, { fromId } = this.$parent,
{ title, desc } = this.configForm
if (params.type == 3) obj.maxLength = params.data if (params.type == 3) obj.maxLength = params.data
else obj.option = params.option else obj.option = params.option
if (index > -1) { if (index > -1) {
...@@ -231,25 +236,33 @@ export default { ...@@ -231,25 +236,33 @@ export default {
} else { } else {
this.questionsList.push(params) this.questionsList.push(params)
this.configForm.questions.push(obj) this.configForm.questions.push(obj)
if (!fromId && title && desc) this.$parent.handleConfirm(false)
} }
this.updateQuestionnaire()
this.formRef().validateField('questions') this.formRef().validateField('questions')
}, },
async updateQuestionnaire () {
const { fromId } = this.$parent,
{ questions } = this.configForm
if (fromId) await this.$apis.questionnaire.updateQuestionnaire({
id: fromId,
questions
})
},
controlClick (index, ind) { controlClick (index, ind) {
const { questionsList } = this, const { questionsList } = this,
{ questions } = this.configForm, { questions } = this.configForm,
moveItem = (array, originalIndex, newIndex) => { moveItem = (array, originalIndex, newIndex) => {
if (originalIndex < 0 || originalIndex >= array.length || newIndex < 0 || newIndex >= array.length) return array if (originalIndex < 0 || originalIndex >= array.length || newIndex < 0 || newIndex >= array.length) return array
const elementToMove = array[originalIndex] const elementToMove = array[originalIndex]
array.splice(originalIndex, 1) // 从原索引位置删除元素 array.splice(originalIndex, 1)
array.splice(newIndex, 0, elementToMove) // 在新索引位置插入元素 array.splice(newIndex, 0, elementToMove)
return array return array
} }
if (ind == 0) { if (ind == 0) this.editQuestionsObj = {
this.editQuestionsObj = { show: true,
show: true, data: questionsList[index],
data: questionsList[index], index
index
}
} }
else if (ind == 1) this.delObj = { else if (ind == 1) this.delObj = {
show: true, show: true,
...@@ -265,7 +278,6 @@ export default { ...@@ -265,7 +278,6 @@ export default {
}[ind] }[ind]
moveItem(questionsList, index, targetIndex) moveItem(questionsList, index, targetIndex)
moveItem(questions, index, targetIndex) moveItem(questions, index, targetIndex)
console.log(this.configForm.questions)
} }
}, },
delItem () { delItem () {
...@@ -281,8 +293,7 @@ export default { ...@@ -281,8 +293,7 @@ export default {
this.delObj = { this.delObj = {
show: false show: false
} }
this.updateQuestionnaire()
console.log(this.delList)
}, },
controlDisabled (index, ind) { controlDisabled (index, ind) {
const { questionsList } = this const { questionsList } = this
......
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
<GLDialog <GLDialog
title="结束" title="结束"
@onOk="overQiestion" @onOk="overQiestion"
@onCancel="dialogVisible = false" @onCancel="closeParams.show = false"
:visible.sync="dialogVisible" :visible.sync="closeParams.show"
mode="small" mode="small"
> >
<template #default> <template #default>
...@@ -97,7 +97,21 @@ ...@@ -97,7 +97,21 @@
</div> </div>
</template> </template>
</GLDialog> </GLDialog>
<GLDialog
title="发布问卷"
@onOk="issueQiestion"
@onCancel="issueParmas.show = false"
:visible.sync="issueParmas.show"
mode="small"
>
<template #default>
<div class="over-box">
<div class="el-icon-warning"></div>
请确认是否发布以下调查问卷?
<div class="tips">问卷名称:{{issueParmas.name}}</div>
</div>
</template>
</GLDialog>
</div> </div>
</template> </template>
...@@ -199,9 +213,9 @@ export default { ...@@ -199,9 +213,9 @@ export default {
}, },
condition: row => row.status == 1, condition: row => row.status == 1,
listeners: { listeners: {
click: row => { click: row => this.closeParams = {
this.dialogVisible = true show: true,
this.closeParams = row id: row.id
} }
} }
}, },
...@@ -213,7 +227,11 @@ export default { ...@@ -213,7 +227,11 @@ export default {
}, },
condition: row => row.status == 0, condition: row => row.status == 0,
listeners: { listeners: {
// click: row => this.jumpDetail(row) click: row => this.issueParmas = {
show: true,
id: row.id,
name: row.name
}
} }
}, },
{ {
...@@ -249,8 +267,12 @@ export default { ...@@ -249,8 +267,12 @@ export default {
}, },
], ],
dataObj: {}, dataObj: {},
dialogVisible: false, closeParams: {
closeParams: {} show: false
},
issueParmas: {
show: false
}
} }
}, },
mounted () { mounted () {
...@@ -273,7 +295,9 @@ export default { ...@@ -273,7 +295,9 @@ export default {
const { id } = this.closeParams, const { id } = this.closeParams,
res = await this.$apis.questionnaire.closeQuestionnaire({ id }) res = await this.$apis.questionnaire.closeQuestionnaire({ id })
if (res) { if (res) {
this.dialogVisible = false this.closeParams = {
show: false
}
this.$message({ this.$message({
message: '操作成功', message: '操作成功',
type: 'success' type: 'success'
...@@ -281,6 +305,17 @@ export default { ...@@ -281,6 +305,17 @@ export default {
this.handleSearch() this.handleSearch()
} else this.$message.error('操作失败,请重试。') } else this.$message.error('操作失败,请重试。')
}, },
async issueQiestion () {
// const { id } = this.issueParmas,
// res = await this.$apis.questionnaire.updateQuestionnaire({
// id,
// status: 1
// })
// console.log(res)
this.issueParmas = {
show: false
}
},
handleExport () { handleExport () {
this.$apis.questionnaire.exportQuestionnaireList({ ...this.searchForm, ...this.$refs.listRef.page }).then(res => { this.$apis.questionnaire.exportQuestionnaireList({ ...this.searchForm, ...this.$refs.listRef.page }).then(res => {
exportFn(res) exportFn(res)
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!