소스 검색

活动管理

DESKTOP-SVI9JE1\muzen 2 년 전
부모
커밋
a38f920e17
2개의 변경된 파일306개의 추가작업 그리고 0개의 파일을 삭제
  1. 144 0
      src/views/operation/activity/detail.vue
  2. 162 0
      src/views/operation/activity/index.vue

+ 144 - 0
src/views/operation/activity/detail.vue

@@ -0,0 +1,144 @@
+<template>
+  <div class='app-container'>
+    <el-form label-width="100px" :disabled="disabled">
+      <el-form-item label="活动名称:">
+        <el-input v-model="form.name" placeholder="请输入活动名称" />
+      </el-form-item>
+      <el-form-item label="活动图片:">
+        <Upload listType="picture-card" :url="form.pic" @upload="upload" />
+      </el-form-item>
+      <el-form-item label="有效时间:">
+        <el-date-picker type="datetimerange" v-model="form.timeList" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm:ss" />
+      </el-form-item>
+      <el-form-item label="活动设备:" style="width: 1000px">
+        <el-button type="primary" icon="el-icon-plus" @click="handlePush">添加</el-button>
+        <el-table :data="form.deviceRespList">
+          <el-table-column label="关联设备" align="center">
+            <template slot-scope="scope">
+              <el-select v-model="scope.row.deviceId" placeholder="请选择关联设备" :disabled="disabledActivity">
+                <el-option v-for="item in devOptions" :key="item.value" :value="item.value" :label="item.label"
+                  :disabled="item.disabled" />
+              </el-select>
+            </template>
+          </el-table-column>
+          <el-table-column label="活动权益" align="center">
+            <template slot-scope="scope">
+              <el-select v-model="scope.row.indate" placeholder="请选择活动权益" :disabled="disabledActivity">
+                <el-option v-for="item in serviceTimeOptions" :key="item.value" :value="item.value" :label="item.label" />
+              </el-select>
+            </template>
+          </el-table-column>
+          <el-table-column label="领取数量" align="center">
+            <template slot-scope="scope">
+              <el-input-number v-model="scope.row.totalNum" :controls="false" :min="1" />
+            </template>
+          </el-table-column>
+          <el-table-column label="操作" align="center">
+            <template slot-scope="scope">
+              <el-button type="delete" @click="getDelete(scope.row.deviceId, scope.$index)" :disabled="disabledActivity">删除</el-button>
+            </template>
+          </el-table-column>
+        </el-table>
+      </el-form-item>
+    </el-form>
+    <div class="form-btn">
+      <el-button @click="cancel">取消</el-button>
+      <el-button v-if="!disabled" type="primary" @click="getSubmit">确定</el-button>
+    </div>
+  </div>
+</template>
+
+<script>
+import { detail, submit } from "@/api/operation/activity"
+import { serviceTimeMixin, devMixin } from '@/mixin/index'
+export default {
+  mixins: [serviceTimeMixin, devMixin],
+  data() {
+    return {
+      // 表单
+      form: {
+        deviceRespList: []
+      },
+      // 除蓝牙设备
+      types: [2, 4],
+      // 生效期内禁止修改活动设备
+      disabledActivity: this.$route.query.activityState == 0 ? true : false,
+      // 只读
+      disabled: Boolean(this.$route.query.boolean)
+    }
+  },
+  watch: {
+    // 禁用已关联设备
+    'form.deviceRespList': {
+      handler(val) {
+        for (let i in this.devOptions) {
+          this.devOptions[i].disabled = false
+        }
+        val.map(i => {
+          if (i.deviceId) {
+            let index = this.devOptions.findIndex(j => j.value === i.deviceId)
+            this.devOptions[index].disabled = true
+          }
+        })
+      },
+      deep: true
+    }
+  },
+  mounted() {
+    if (this.$route.query.id) {
+      this.getDetail()
+    }
+  },
+  methods: {
+    // 详情
+    getDetail() {
+      detail(this.$route.query.id).then(res => {
+        if (res.code === 0) {
+          this.form = res.data
+        }
+      })
+    },
+
+    // 上传图片
+    upload(e) {
+      this.form.pic = e.file
+    },
+
+    // 添加
+    handlePush() {
+      this.form.deviceRespList.push({})
+    },
+
+    // 删除
+    getDelete(deviceId, index) {
+      this.form.deviceRespList.splice(index, 1)
+      this.devOptions.map(i => {
+        if (i.value === deviceId) {
+          i.disabled = false
+        }
+      })
+    },
+
+    // 取消
+    cancel() {
+      this.$tab.closeOpenPage('/operation/activity')
+    },
+
+    // 确定
+    getSubmit() {
+      submit(this.form).then(res => {
+        if (res.code === 0) {
+          this.$message.success('提交成功!')
+          this.cancel()
+        }
+      })
+    }
+  }
+}
+</script>
+
+<style lang="scss" scoped>
+.el-form-item {
+  width: 500px;
+}
+</style>

+ 162 - 0
src/views/operation/activity/index.vue

@@ -0,0 +1,162 @@
+<template>
+  <div class='app-container'>
+    <!-- 搜索 -->
+    <el-form inline size="mini">
+      <el-form-item label="活动名称:">
+        <el-input v-model="form.name" placeholder="请输入活动名称" clearable />
+      </el-form-item>
+      <el-form-item label="当前状态:">
+        <el-select v-model="form.activityState" placeholder="请选择当前状态" clearable>
+          <el-option v-for="item in currentOptions" :key="item.value" :value="item.value" :label="item.label" />
+        </el-select>
+      </el-form-item>
+      <el-form-item label="上下架状态:">
+        <el-select v-model="form.status" placeholder="请选择上下架状态" clearable>
+          <el-option v-for="item in disabledOptions" :key="item.value" :value="item.value" :label="item.label" />
+        </el-select>
+      </el-form-item>
+      <el-form-item>
+        <el-button type="primary" icon="el-icon-search" @click="getSearch">搜索</el-button>
+        <el-button icon="el-icon-refresh" @click="getRefresh">重置</el-button>
+        <el-button type="primary" icon="el-icon-plus" plain @click="getDetail">新增</el-button>
+      </el-form-item>
+    </el-form>
+    <!-- 列表 -->
+    <el-table :data="tableData" v-loading="loading">
+      <el-table-column label="序号" align="center" type="index" />
+      <el-table-column label="活动id" align="center" prop="id" show-overflow-tooltip />
+      <el-table-column label="活动名称" align="center" prop="name" show-overflow-tooltip />
+      <el-table-column label="活动图片" align="center" width="100px">
+        <template slot-scope="scope">
+          <el-image :src="scope.row.pic" />
+        </template>
+      </el-table-column>
+      <el-table-column label="创建时间" align="center" prop="createTime" />
+      <el-table-column label="有效时间" align="center" show-overflow-tooltip>
+        <template slot-scope="scope">
+          {{ scope.row.timeList.join(' - ') }}
+        </template>
+      </el-table-column>
+      <el-table-column label="当前状态" align="center" :formatter="activityFormatter" width="150px" />
+      <el-table-column label="上下架状态" align="center" :formatter="statusFormatter" width="150px" />
+      <el-table-column label="操作" align="center">
+        <template slot-scope="scope">
+          <el-button type="text" @click="getDetail(scope.row, true)">查看</el-button>
+          <el-button type="text" v-if="scope.row.status === 1" @click="getChange(scope.row.id, 0, '上架')">上架</el-button>
+          <span v-else style="margin: 0 10px">
+            <el-button type="text" @click="getDetail(scope.row)">编辑</el-button>
+            <el-button type="text" @click="getChange(scope.row.id, 1, '下架')">下架</el-button>
+            <el-button type="delete" @click="getDelete(scope.row)">删除</el-button>
+          </span>
+          <el-button type="text" v-clipboard:copy="scope.row.copyUrl" v-clipboard:success="getCopy">复制链接</el-button>
+        </template>
+      </el-table-column>
+    </el-table>
+    <pagination v-show="total > 0" :total="total" :page.sync="form.pageNum" :limit.sync="form.pageSize"
+      @pagination="getList" />
+  </div>
+</template>
+
+<script>
+import { list, change } from '@/api/operation/activity'
+import { currentMixin, disabledMixin } from '@/mixin/index'
+export default {
+  mixins: [currentMixin, disabledMixin],
+  data() {
+    return {
+      // 遮罩层
+      loading: false,
+      // 表单
+      form: {
+        pageNum: 1,
+        pageSize: 10
+      },
+      // 总数据
+      total: 0,
+      // 列表
+      tableData: []
+    }
+  },
+  mounted() {
+    this.getList()
+  },
+  methods: {
+    // 列表
+    getList() {
+      this.loading = true
+      list(this.form).then(res => {
+        if (res.code === 0) {
+          this.tableData = res.data.records
+          this.total = res.data.total
+          this.loading = false
+        }
+      })
+    },
+
+    // 搜索
+    getSearch() {
+      this.form.pageNum = 1
+      this.getList()
+    },
+
+    // 重置
+    getRefresh() {
+      this.form = {
+        pageNum: 1,
+        pageSize: 10
+      }
+      this.getList()
+    },
+
+    // 详情
+    getDetail(row, boolean) {
+      this.$router.push({
+        path: `/operation/activity/detail`,
+        query: {
+          id: row.id,
+          boolean: boolean,
+          activityState: row.activityState
+        }
+      })
+    },
+
+    // 上下架
+    getChange(id, status, title) {
+      change(id, status).then(res => {
+        if (res.code === 0) {
+          this.$message.success(`${title}成功!`)
+          this.getList()
+        }
+      })
+    },
+
+    // 删除
+    getDelete(row) {
+      this.$confirm(`是否删除${row.name}?`, '提示', {
+        type: 'warning'
+      }).then(() => {
+        change(row.id, 2).then(res => {
+          if (res.code === 0) {
+            this.$message.success('删除成功!')
+            this.getList()
+          }
+        })
+      })
+    },
+
+    // 复制链接
+    getCopy() {
+      this.$message.success('复制成功!')
+    },
+
+    // 字典翻译
+    activityFormatter(row) {
+      return this.selectDictLabel(this.currentOptions, row.activityState)
+    },
+
+    statusFormatter(row) {
+      return this.selectDictLabel(this.disabledOptions, row.status)
+    }
+  }
+}
+</script>