Commit 440bbf78 by 李伟康

11月底需求

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