|
|
@@ -0,0 +1,465 @@
|
|
|
+<template>
|
|
|
+ <el-dialog
|
|
|
+ title="积分活动"
|
|
|
+ :visible.sync="pointsActivity"
|
|
|
+ width="900px"
|
|
|
+ :before-close="handleClose"
|
|
|
+ custom-class="activity-edit-dialog">
|
|
|
+
|
|
|
+ <el-form :model="form" :rules="rules" ref="formRef" label-width="140px" class="activity-form">
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="活动名称" prop="name">
|
|
|
+ <el-input v-model="form.name" placeholder="请输入活动名称" :disabled="type === 'view'"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="活动简述" prop="description">
|
|
|
+ <el-input v-model="form.description" placeholder="请输入活动简述" :disabled="type === 'view'"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="活动城市" prop="city">
|
|
|
+ <DictSelect v-model="form.city" :dictOptions="cityOptions" placeholder="请选择" :disabled="type === 'view'"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="活动类型" prop="activityType">
|
|
|
+ <DictSelect v-model="form.activityType" :dictOptions="activityTypeOption" placeholder="请选择" :disabled="type === 'view'" @change="handleActivityTypeChange"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="活动时间" prop="isLongTerm">
|
|
|
+ <el-radio-group v-model="form.isLongTerm" :disabled="type === 'view'">
|
|
|
+ <el-radio label="1">长期有效</el-radio>
|
|
|
+ <el-radio label="2">指定时间</el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12" v-if="form.isLongTerm === '2'">
|
|
|
+ <el-form-item label="指定时间" prop="dateRange">
|
|
|
+ <el-date-picker
|
|
|
+ v-model="form.dateRange"
|
|
|
+ type="daterange"
|
|
|
+ range-separator="→"
|
|
|
+ start-placeholder="开始日期"
|
|
|
+ end-placeholder="结束日期"
|
|
|
+ style="width: 100%"
|
|
|
+ :disabled="type === 'view'"
|
|
|
+ :picker-options="pickerOptions"
|
|
|
+ @change="handleDateChange"
|
|
|
+ ></el-date-picker>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <!-- 签到活动特有的内容 -->
|
|
|
+ <template v-if="form.activityType === '1'">
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="每日签到基础积分" prop="dailyBasePoints">
|
|
|
+ <el-input v-model="form.dailyBasePoints" type="number" placeholder="请输入" :disabled="type === 'view'"></el-input>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-form-item label="连续签到加成">
|
|
|
+ <el-table :data="form.consecutiveBonus" style="width: 100%" :disabled="type === 'view'" size="mini">
|
|
|
+ <el-table-column prop="period" label="连续签到周期(天)">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span v-if="type === 'view'">
|
|
|
+ {{ scope.row.period }}天
|
|
|
+ </span>
|
|
|
+ <el-input v-else v-model="scope.row.period" type="number" placeholder="天数" @blur="updatePeriod(scope.$index, scope.row.period)"></el-input>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="points" label="连续签到积分">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span v-if="type === 'view'">
|
|
|
+ {{ scope.row.points }}
|
|
|
+ </span>
|
|
|
+ <el-input v-else v-model="scope.row.points" type="number" placeholder="积分"></el-input>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column width="50">
|
|
|
+ <template slot="header" slot-scope="scope">
|
|
|
+ <span>
|
|
|
+ <el-button v-if="type !== 'view' && form.consecutiveBonus.length < 5" type="text" size="medium" @click="addPeriod" title="添加周期">
|
|
|
+ <i class="el-icon-circle-plus-outline"></i>
|
|
|
+ </el-button>
|
|
|
+ </span>
|
|
|
+ </template>
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-button v-if="type !== 'view'" type="text" @click="deletePeriod(scope.$index)" title="删除周期">
|
|
|
+ <i class="el-icon-remove-outline"></i>
|
|
|
+ </el-button>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item label="断签规则">
|
|
|
+ <el-radio-group v-model="form.breakRule" :disabled="type === 'view'">
|
|
|
+ <el-radio label="reset">
|
|
|
+ 断签重置
|
|
|
+ </el-radio>
|
|
|
+ <el-radio label="keep">
|
|
|
+ 保留进度
|
|
|
+ </el-radio>
|
|
|
+ </el-radio-group>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </template>
|
|
|
+
|
|
|
+ <!-- 其他活动类型的内容 -->
|
|
|
+ <template v-else>
|
|
|
+ <el-row :gutter="20">
|
|
|
+ <el-col :span="24">
|
|
|
+ <el-form-item label="任务列表">
|
|
|
+ <el-table :data="form.tasks" style="width: 100%" :disabled="type === 'view'" size="medium">
|
|
|
+ <el-table-column prop="taskName" label="任务名称" width="150">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span>{{ scope.row.taskName }}</span>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="triggerCondition" label="触发条件" width="150">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span v-if="type === 'view'">{{ scope.row.triggerCondition }}</span>
|
|
|
+ <el-input v-else v-model="scope.row.triggerCondition" placeholder="请输入"></el-input>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="points" label="积分">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span v-if="type === 'view'">{{ scope.row.points }}</span>
|
|
|
+ <el-input v-else v-model="scope.row.points" type="number" placeholder="请输入"></el-input>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column prop="limit" label="次数限制" width="120">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <span v-if="type === 'view'">{{ scope.row.limit }}</span>
|
|
|
+ <el-select v-else v-model="scope.row.limit" placeholder="请选择">
|
|
|
+ <el-option label="无限制" value="无限制"></el-option>
|
|
|
+ <el-option label="每日1次" value="每日1次"></el-option>
|
|
|
+ <el-option label="每周1次" value="每周1次"></el-option>
|
|
|
+ <el-option label="每月1次" value="每月1次"></el-option>
|
|
|
+ </el-select>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ <el-table-column label="是否开启" width="120">
|
|
|
+ <template slot-scope="scope">
|
|
|
+ <el-switch v-model="scope.row.isEnabled" :disabled="type === 'view'"></el-switch>
|
|
|
+ </template>
|
|
|
+ </el-table-column>
|
|
|
+ </el-table>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ </template>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ <div class="button-container" v-if="type !== 'view'">
|
|
|
+ <el-button @click="handleCancel" class="cancel-btn">取消</el-button>
|
|
|
+ <el-button @click="handleSaveDraft" class="cancel-btn">保存草稿</el-button>
|
|
|
+ <el-button type="primary" @click="handlePublish" class="confirm-btn">发布</el-button>
|
|
|
+ </div>
|
|
|
+ <div class="button-container" v-else>
|
|
|
+ <el-button type="primary" @click="handleClose" class="confirm-btn">关闭</el-button>
|
|
|
+ </div>
|
|
|
+ </el-dialog>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+export default {
|
|
|
+ name: "Activity_editBox",
|
|
|
+ props: ['activityTypeOption', 'cityOptions'],
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ pointsActivity: false,
|
|
|
+ type: '',
|
|
|
+ minDate: null,
|
|
|
+ form: {
|
|
|
+ name: '',
|
|
|
+ description: '',
|
|
|
+ city: '',
|
|
|
+ activityType: '',
|
|
|
+ isLongTerm: '',
|
|
|
+ startTime: '',
|
|
|
+ endTime: '',
|
|
|
+ dateRange: '',
|
|
|
+ dailyBasePoints: '',
|
|
|
+ consecutiveBonus: [
|
|
|
+ { period: '3', points: '' },
|
|
|
+ ],
|
|
|
+ breakRule: 'reset', // reset: 断签重置, keep: 保留进度
|
|
|
+ tasks: [
|
|
|
+ { taskName: '完成订单', triggerCondition: '', points: '', limit: '无限制', isEnabled: false },
|
|
|
+ { taskName: '充值任务', triggerCondition: '', points: '', limit: '无限制', isEnabled: false },
|
|
|
+ { taskName: '分享服务号', triggerCondition: '', points: '', limit: '无限制', isEnabled: false },
|
|
|
+ { taskName: '浏览动态', triggerCondition: '', points: '', limit: '无限制', isEnabled: false },
|
|
|
+ { taskName: '浏览商户', triggerCondition: '', points: '', limit: '无限制', isEnabled: false }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ pickerOptions: {
|
|
|
+ onPick: ({ maxDate, minDate }) => {
|
|
|
+ if (minDate) {
|
|
|
+ this.minDate = minDate;
|
|
|
+ }
|
|
|
+ if (maxDate) {
|
|
|
+ this.minDate = null;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ disabledDate: (time) => {
|
|
|
+ if (this.minDate) {
|
|
|
+ const minTime = this.minDate.getTime();
|
|
|
+ const sevenDaysLater = minTime + 6 * 24 * 60 * 60 * 1000; // 6天后(总共7天)
|
|
|
+ return time.getTime() < minTime || (time.getTime() < sevenDaysLater && time.getTime() > minTime);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ rules: {
|
|
|
+ name: [
|
|
|
+ { required: true, message: '请输入活动名称', trigger: 'blur' },
|
|
|
+ { min: 2, max: 18, message: '请输入2-18个字符', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ description: [
|
|
|
+ { required: true, message: '请输入活动简述', trigger: 'blur' },
|
|
|
+ { min: 2, max: 30, message: '请输入2-30个字符', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ city: [
|
|
|
+ { required: true, message: '请选择活动城市', trigger: 'change' }
|
|
|
+ ],
|
|
|
+ activityType: [
|
|
|
+ { required: true, message: '请选择活动类型', trigger: 'change' }
|
|
|
+ ],
|
|
|
+ dailyBasePoints: [
|
|
|
+ { required: true, message: '请输入基础积分', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ dateRange: [
|
|
|
+ { required: true, message: '请选择活动时间', trigger: 'change' }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ getRow(row, type) {
|
|
|
+ /** type ==== 添加:add 复制:copy 编辑:edit 查看:view */
|
|
|
+ this.type = type;
|
|
|
+ // 重置表单
|
|
|
+ this.resetForm();
|
|
|
+ if (row) {
|
|
|
+ if (type === 'copy') {
|
|
|
+ this.form = {...row, id: ''};
|
|
|
+ } else if (type === 'edit' || type === 'view') {
|
|
|
+ this.form = { ...row };
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.pointsActivity = true;
|
|
|
+ },
|
|
|
+ handleClose() {
|
|
|
+ this.pointsActivity = false;
|
|
|
+ },
|
|
|
+ resetForm() {
|
|
|
+ this.form = {
|
|
|
+ name: '',
|
|
|
+ description: '',
|
|
|
+ city: '',
|
|
|
+ activityType: '1',
|
|
|
+ isLongTerm: '1',
|
|
|
+ startTime: '',
|
|
|
+ endTime: '',
|
|
|
+ dateRange: '',
|
|
|
+ dailyBasePoints: '',
|
|
|
+ consecutiveBonus: [
|
|
|
+ { period: '3', points: '' },
|
|
|
+ ],
|
|
|
+ breakRule: 'reset',
|
|
|
+ tasks: [
|
|
|
+ { taskName: '完成订单', triggerCondition: '', points: '', limit: '无限制', isEnabled: false },
|
|
|
+ { taskName: '充值任务', triggerCondition: '', points: '', limit: '无限制', isEnabled: false },
|
|
|
+ { taskName: '分享服务号', triggerCondition: '', points: '', limit: '无限制', isEnabled: false },
|
|
|
+ { taskName: '浏览动态', triggerCondition: '', points: '', limit: '无限制', isEnabled: false },
|
|
|
+ { taskName: '浏览商户', triggerCondition: '', points: '', limit: '无限制', isEnabled: false }
|
|
|
+ ]
|
|
|
+ };
|
|
|
+ },
|
|
|
+ handleDateChange(val) {
|
|
|
+ if (val) {
|
|
|
+ this.form.startTime = val[0];
|
|
|
+ this.form.endTime = val[1];
|
|
|
+ } else {
|
|
|
+ this.form.startTime = '';
|
|
|
+ this.form.endTime = '';
|
|
|
+ }
|
|
|
+ },
|
|
|
+ deletePeriod(index) {
|
|
|
+ if (this.form.consecutiveBonus.length <= 1) {
|
|
|
+ this.$message.warning('至少保留一个连续签到周期');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.form.consecutiveBonus.splice(index, 1);
|
|
|
+ },
|
|
|
+ handleActivityTypeChange() {
|
|
|
+ // 重置相关内容
|
|
|
+ if (this.form.activityType === '1') {
|
|
|
+ // 签到活动
|
|
|
+ this.form.dailyBasePoints = '';
|
|
|
+ this.form.consecutiveBonus = [
|
|
|
+ { period: '3', points: ''},
|
|
|
+ ];
|
|
|
+ this.form.breakRule = 'reset';
|
|
|
+ } else {
|
|
|
+ // 其他活动
|
|
|
+ this.form.tasks = [
|
|
|
+ { taskName: '完成订单', triggerCondition: '', points: '', limit: '无限制', isEnabled: true },
|
|
|
+ { taskName: '充值任务', triggerCondition: '', points: '', limit: '无限制', isEnabled: true },
|
|
|
+ { taskName: '分享服务号', triggerCondition: '', points: '', limit: '无限制', isEnabled: true },
|
|
|
+ { taskName: '浏览动态', triggerCondition: '', points: '', limit: '无限制', isEnabled: true },
|
|
|
+ { taskName: '浏览商户', triggerCondition: '', points: '', limit: '无限制', isEnabled: true }
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ },
|
|
|
+ addPeriod() {
|
|
|
+ // 添加新周期
|
|
|
+ this.form.consecutiveBonus.push({
|
|
|
+ period: '',
|
|
|
+ points: ''
|
|
|
+ });
|
|
|
+ },
|
|
|
+ updatePeriod(index, value) {
|
|
|
+ // 计算活动总天数
|
|
|
+ let totalDays = 0;
|
|
|
+
|
|
|
+ if (this.form.isLongTerm === '2' && this.form.startTime && this.form.endTime) {
|
|
|
+ const start = new Date(this.form.startTime);
|
|
|
+ const end = new Date(this.form.endTime);
|
|
|
+ totalDays = Math.floor((end - start) / (1000 * 60 * 60 * 24)) + 1;
|
|
|
+ }
|
|
|
+ console.log(totalDays)
|
|
|
+ // 检查当前周期是否大于前一个
|
|
|
+ if (index > 0 && Number(value) <= Number(this.form.consecutiveBonus[index - 1].period)) {
|
|
|
+ this.$message.warning('后一个周期必须大于前一个周期');
|
|
|
+ this.form.consecutiveBonus[index].period = Number(this.form.consecutiveBonus[index - 1].period) + 1;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查当前周期是否小于后一个
|
|
|
+ if (index < this.form.consecutiveBonus.length - 1 && Number(value) >= Number(this.form.consecutiveBonus[index + 1].period)) {
|
|
|
+ this.$message.warning('前一个周期必须小于后一个周期');
|
|
|
+ this.form.consecutiveBonus[index].period = Number(this.form.consecutiveBonus[index + 1].period) - 1;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果选择指定时间,检查当前周期是否大于总天数
|
|
|
+ if (this.form.isLongTerm === '2' && totalDays > 0 && Number(value) > totalDays) {
|
|
|
+ this.$message.warning('连续签到周期不能大于活动总天数');
|
|
|
+ this.form.consecutiveBonus[index].period = totalDays;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handleCancel() {
|
|
|
+ this.pointsActivity = false;
|
|
|
+ },
|
|
|
+ handleSaveDraft() {
|
|
|
+ this.$refs.formRef.validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ console.log('Form内容:', this.form);
|
|
|
+ // 保存草稿逻辑
|
|
|
+ this.$message.success('草稿已保存');
|
|
|
+ this.pointsActivity = false;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ handlePublish() {
|
|
|
+ this.$refs.formRef.validate((valid) => {
|
|
|
+ if (valid) {
|
|
|
+ // 发布逻辑
|
|
|
+ this.$message.success('活动已发布');
|
|
|
+ this.pointsActivity = false;
|
|
|
+ } else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped lang="scss">
|
|
|
+.activity-edit-dialog {
|
|
|
+ .el-dialog__header {
|
|
|
+ padding: 20px;
|
|
|
+ border-bottom: 1px solid #e8e8e8;
|
|
|
+
|
|
|
+ .el-dialog__title {
|
|
|
+ font-size: 16px;
|
|
|
+ font-weight: 600;
|
|
|
+ color: #303133;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-dialog__body {
|
|
|
+ padding: 25px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-dialog__footer {
|
|
|
+ padding: 15px 20px;
|
|
|
+ border-top: 1px solid #e8e8e8;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.activity-form {
|
|
|
+ .form-tip {
|
|
|
+ font-size: 12px;
|
|
|
+ color: #f56c6c;
|
|
|
+ margin-top: 5px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-form-item {
|
|
|
+ margin-bottom: 20px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-table {
|
|
|
+ margin-top: 10px;
|
|
|
+ border: 1px solid #ebeef5;
|
|
|
+ border-radius: 4px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-table__header-wrapper {
|
|
|
+ background-color: #f5f7fa;
|
|
|
+ }
|
|
|
+
|
|
|
+ .el-table th {
|
|
|
+ font-weight: 600;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+.button-container {
|
|
|
+ display: flex;
|
|
|
+ justify-content: flex-end;
|
|
|
+ margin-top: 30px;
|
|
|
+
|
|
|
+ .cancel-btn {
|
|
|
+ margin-right: 10px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .confirm-btn {
|
|
|
+ min-width: 100px;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|