lizhenhao %!s(int64=2) %!d(string=hai) anos
pai
achega
391cf4a1c2

+ 46 - 0
src/api/luckyDraw/LuckyDrawEventsService.js

@@ -0,0 +1,46 @@
+import request from '@/utils/httpRequest'
+
+export default class LuckyDrawEventsService {
+  list (params) {
+    return request({
+      url: '/luckyDraw/events/list',
+      method: 'get',
+      params: params
+    })
+  }
+  save (param) {
+    return request({
+      url: '/luckyDraw/events/save',
+      method: 'post',
+      data: param
+    })
+  }
+  queryById (id) {
+    return request({
+      url: '/luckyDraw/events/queryById',
+      method: 'get',
+      params: {id: id}
+    })
+  }
+  delete (ids) {
+    return request({
+      url: '/luckyDraw/events/delete',
+      method: 'delete',
+      params: {ids: ids}
+    })
+  }
+  openEvent (id) {
+    return request({
+      url: '/luckyDraw/events/openEvent',
+      method: 'get',
+      params: {id: id}
+    })
+  }
+  closeEvent (id) {
+    return request({
+      url: '/luckyDraw/events/closeEvent',
+      method: 'get',
+      params: {id: id}
+    })
+  }
+}

+ 225 - 0
src/views/modules/luckyDraw/LuckyDrawEventsForm.vue

@@ -0,0 +1,225 @@
+<template xmlns:v-slot="http://www.w3.org/1999/XSL/Transform">
+  <el-dialog
+    :title="title"
+    :close-on-click-modal="false"
+    v-dialogDrag
+    width="900px"
+    :visible.sync="visible">
+    <el-form size="small" :model="inputForm" ref="inputForm" @keyup.enter.native="doSubmit()"
+             label-width="95px" v-loading="loading" :class="method==='view'?'readonly':''" :disabled="method==='view'" @submit.native.prevent>
+      <el-divider content-position="left"><i class="el-icon-document"></i> 活动信息</el-divider>
+      <el-row :gutter="15">
+        <el-col :span="12">
+          <el-form-item label="活动名称" :rules="[{required: true, message: '活动名称不能为空', trigger: 'blur'}]" prop="name">
+            <el-input size="large" v-model="inputForm.name" placeholder="请输入活动名称"></el-input>
+          </el-form-item>
+        </el-col>
+        <el-col :span="24">
+          <el-form-item label="活动详情" :rules="[{required: true, message: '活动详情不能为空', trigger: 'blur'}]" prop="detail">
+            <el-input size="large" v-model="inputForm.detail" :autosize="{minRows: 2, maxRows: 8}" type="textarea" maxlength="200" placeholder="请输入活动详情" show-word-limit></el-input>
+          </el-form-item>
+        </el-col>
+      </el-row>
+      <el-divider content-position="left"><i class="el-icon-document"></i>
+        活动奖项
+        <el-button style="margin-left: 20px" type="primary" :disabled="method==='view'" size="mini" @click="insertEvent()" plain>
+          新增
+        </el-button>
+      </el-divider>
+      <el-row  :gutter="15">
+        <vxe-table
+          border
+          show-overflow
+          show-footer
+          ref="luckyTable"
+          class="vxe-table-element"
+          :data="inputForm.luckyDrawAwardsDTOList"
+          style="margin-left: 1em"
+          @cell-click=""
+          @edit-closed=""
+          :key="tableKey"
+          highlight-current-row
+          :edit-rules="validRules"
+          :edit-config="{trigger: 'click', mode: 'row', showStatus: false, autoClear: true, icon: '#'}"
+        >
+          <vxe-table-column field="name" min-width="180" align="center" title="奖项名称" :edit-render="{}">
+            <template v-slot:edit="scope">
+              <vxe-input v-model="scope.row.name" placeholder="奖项名称"></vxe-input>
+            </template>
+          </vxe-table-column>
+          <vxe-table-column field="number" min-width="180" align="center" title="奖品数量" :edit-render="{}">
+            <template v-slot:edit="scope">
+              <vxe-input v-model="scope.row.number" type="number" placeholder="奖品数量"></vxe-input>
+            </template>
+          </vxe-table-column>
+          <vxe-table-column field="prizeName" min-width="180" align="center" title="奖品名称" :edit-render="{}">
+            <template v-slot:edit="scope">
+              <vxe-input v-model="scope.row.prizeName" placeholder="奖品名称"></vxe-input>
+            </template>
+          </vxe-table-column>
+          <vxe-table-column title="操作" width="100" align="center">
+            <template v-slot="scope">
+              <el-button size="mini" type="danger" @click="removeEvent(scope.row,scope.$rowIndex)">删除</el-button>
+            </template>
+          </vxe-table-column>
+        </vxe-table>
+      </el-row>
+    </el-form>
+    <span slot="footer" class="dialog-footer">
+      <el-button size="small" @click="visible = false" icon="el-icon-circle-close">关闭</el-button>
+      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" icon="el-icon-circle-check" v-noMoreClick>确定</el-button>
+    </span>
+  </el-dialog>
+</template>
+
+<script>
+  import LuckyDrawEventsService from '@/api/luckyDraw/LuckyDrawEventsService'
+  export default {
+    data () {
+      return {
+        visible: false,
+        loading: false,
+        title: '',
+        method: '',
+        inputForm: {
+          id: '',
+          name: '',
+          detail: '',
+          luckyDrawAwardsDTOList: []
+        },
+        tableKey: '',
+        validRules: {
+          name: [
+            {required: true, message: '奖项类型不能为空'}
+          ],
+          number: [
+            {required: true, message: '奖品数量不能为空'}
+          ],
+          prizeName: [
+            {required: true, message: '奖品名称不能为空'}
+          ]
+        }
+      }
+    },
+    luckyDrawEventsService: null,
+    created () {
+      this.luckyDrawEventsService = new LuckyDrawEventsService()
+    },
+    mounted () {
+    },
+    components: {
+    },
+    methods: {
+      init (method, id) {
+        this.method = method
+        this.inputForm = {
+          id: '',
+          name: '',
+          detail: '',
+          luckyDrawAwardsDTOList: []
+        }
+        this.inputForm.id = id
+        if (method === 'add') {
+          this.title = `新建活动`
+        } else if (method === 'edit') {
+          this.title = '修改活动信息'
+        } else if (method === 'view') {
+          this.title = '查看活动详情'
+        }
+        this.visible = true
+        this.$nextTick(() => {
+          this.$refs.inputForm.resetFields()
+          if (method === 'edit' || method === 'view') { // 修改或者查看
+            this.loading = true
+            this.luckyDrawEventsService.queryById(this.inputForm.id).then(({data}) => {
+              this.inputForm = this.recover(this.inputForm, data)
+              if (this.commonJS.isEmpty(this.inputForm.luckyDrawAwardsDTOList)) {
+                this.inputForm.luckyDrawAwardsDTOList = []
+              }
+              this.loading = false
+            })
+          }
+        })
+      },
+      // 表单提交
+      doSubmit () {
+        this.$refs['inputForm'].validate((valid) => {
+          if (valid) {
+            this.loading = true
+            if (this.commonJS.isEmpty(this.inputForm.luckyDrawAwardsDTOList)) {
+              this.inputForm.luckyDrawAwardsDTOList = []
+              this.$message.error('活动奖项未填写')
+              this.loading = false
+              throw new Error('活动奖项未填写')
+            }
+            this.inputForm.luckyDrawAwardsDTOList.forEach((item, index) => {
+              if (this.commonJS.isEmpty(item.name)) {
+                this.$message.error('活动奖项中第' + (index + 1) + '条数据的“奖项名称”未填写')
+                this.loading = false
+                throw new Error()
+              }
+              if (this.commonJS.isEmpty(item.number) || item.number === 0 || item.number === '0') {
+                this.$message.error('活动奖项中第' + (index + 1) + '条数据的“奖品数量”不可以为空或“0”')
+                this.loading = false
+                throw new Error()
+              }
+              if (this.commonJS.isEmpty(item.prizeName)) {
+                this.$message.error('活动奖项中第' + (index + 1) + '条数据的“奖品名称”未填写')
+                this.loading = false
+                throw new Error()
+              }
+            })
+            this.luckyDrawEventsService.save(this.inputForm).then(({data}) => {
+              this.$message.success(data)
+              this.loading = false
+              this.visible = false
+              this.$emit('refreshDataList')
+            }).catch(() => {
+              this.loading = false
+            })
+          }
+        })
+      },
+      // 新增
+      insertEvent () {
+        let d = {
+          name: '',
+          number: '',
+          prizeName: ''
+        }
+        if (this.commonJS.isEmpty(this.inputForm.luckyDrawAwardsDTOList)) {
+          this.inputForm.luckyDrawAwardsDTOList = []
+        }
+        this.$refs.luckyTable.insertAt(d)
+        this.inputForm.luckyDrawAwardsDTOList.push(d)
+        this.tableKey = Math.random()
+      },
+      // 删除
+      removeEvent (row, rowIndex) {
+        this.$refs.luckyTable.remove(row)
+        this.inputForm.luckyDrawAwardsDTOList.splice(rowIndex, 1)
+      },
+      close () {
+        this.inputForm = {
+          id: '',
+          name: '',
+          detail: '',
+          luckyDrawAwardsDTOList: []
+        }
+        this.$refs.inputForm.resetFields()
+        this.tableKey = Math.random()
+        this.visible = false
+        this.loading = false
+      }
+    }
+  }
+</script>
+<style scoped>
+  .avatar{
+    height: 100px;
+  }
+  .el-divider__text {
+    font-weight: bold;
+    font-size: 16px;
+  }
+</style>

+ 222 - 0
src/views/modules/luckyDraw/LuckyDrawEventsList.vue

@@ -0,0 +1,222 @@
+<template>
+  <div class="page">
+    <el-form size="small" :inline="true" class="query-form" ref="searchForm" :model="searchForm" @keyup.enter.native="refreshList()" @submit.native.prevent>
+      <el-form-item prop="name">
+        <el-input size="small" v-model="searchForm.name" placeholder="活动名称" clearable></el-input>
+      </el-form-item>
+      <el-form-item>
+        <el-button  type="primary" @click="refreshList()" size="small" icon="el-icon-search">查询</el-button>
+        <el-button @click="resetSearch()" size="small" icon="el-icon-refresh-right">重置</el-button>
+      </el-form-item>
+    </el-form>
+    <div class="bg-white top">
+      <vxe-toolbar   :refresh="{query: refreshList}" custom>
+        <template #buttons>
+          <el-button v-if="hasPermission('lucky_draw:events:add')" icon="el-icon-plus" type="primary" size="small"  @click="add()">新建</el-button>
+          <el-button v-if="hasPermission('lucky_draw:events:del')" icon="el-icon-delete" type="danger"  size="small"  @click="del()" :disabled="$refs.luckyTable && $refs.luckyTable.getCheckboxRecords().length === 0" plain>删除</el-button>
+        </template>
+      </vxe-toolbar>
+      <div style="height: calc(100% - 80px);">
+        <vxe-table
+          border="inner"
+          auto-resize
+          resizable
+          height="auto"
+          :loading="loading"
+          size="small"
+          ref="luckyTable"
+          show-header-overflow
+          show-overflow
+          highlight-hover-row
+          :print-config="{}"
+          :import-config="{}"
+          :export-config="{}"
+          :sort-config="{remote:true}"
+          :data="dataList"
+          :expand-config="{iconOpen: 'el-icon-caret-top', iconClose: 'el-icon-caret-bottom', accordion: true}"
+        >
+          <vxe-column type="seq" width="60" title="序号"></vxe-column>
+          <vxe-column type="checkbox"  width="40px"></vxe-column>
+          <vxe-column min-width="150" title="活动名称" type="expand" field="name" align="left">
+            <template #default="{ row, rowIndex }">
+              <span>{{ row.name }}</span>
+            </template>
+            <template #content="{ row, rowIndex }">
+              <div class="expand-wrapper">
+                <vxe-table
+                  border
+                  :data="row.luckyDrawAwardsDTOList">
+                  <vxe-column field="name" title="奖项名称" align="center"></vxe-column>
+                  <vxe-column field="number" title="奖品数量" align="center"></vxe-column>
+                  <vxe-column field="prizeName" title="奖品名称" align="center"></vxe-column>
+                </vxe-table>
+              </div>
+            </template>
+          </vxe-column>
+          <vxe-column min-width="180" title="活动详情" field="detail" align="left"></vxe-column>
+          <vxe-column width="90" title="状态" field="switchFlag" align="center">
+            <template slot-scope="scope">
+              <span v-if="scope.row.switchFlag === '1'" style="color: #67C23A">已开启</span>
+              <span v-if="scope.row.switchFlag === '0'" style="color: #F56C6C">已关闭</span>
+            </template>
+          </vxe-column>
+          <vxe-column title="操作" width="200" fixed="right" align="center">
+            <template slot-scope="scope">
+              <el-button v-if="hasPermission('lucky_draw:events:edit')" type="text" size="small" @click="edit(scope.row.id)">修改</el-button>
+              <el-button v-if="hasPermission('lucky_draw:events:edit')" type="text" size="small" @click="changeSwitch(scope.row)">
+                {{scope.row.switchFlag === '1' ? '关闭活动' : '开启活动'}}
+              </el-button>
+              <el-button v-if="hasPermission('lucky_draw:events:del')" type="text" size="small" @click="del(scope.row.id)">删除</el-button>
+
+            </template>
+          </vxe-column>
+        </vxe-table>
+        <vxe-pager
+          background
+          size="small"
+          :current-page="tablePage.currentPage"
+          :page-size="tablePage.pageSize"
+          :total="tablePage.total"
+          :page-sizes="[10, 20, 100, 1000, {label: '全量数据', value: 1000000}]"
+          :layouts="['PrevPage', 'JumpNumber', 'NextPage', 'FullJump', 'Sizes', 'Total']"
+          @page-change="currentChangeHandle">
+        </vxe-pager>
+      </div>
+      <!-- 弹窗, 新增 / 修改 -->
+      <LuckyDrawEventsForm  ref="luckyDrawEventsForm" @refreshDataList="refreshList"></LuckyDrawEventsForm>
+    </div>
+  </div>
+</template>
+
+<script>
+  import LuckyDrawEventsForm from './LuckyDrawEventsForm'
+  import LuckyDrawEventsService from '@/api/luckyDraw/LuckyDrawEventsService'
+
+  export default {
+    data () {
+      return {
+        searchForm: {
+          name: ''
+        },
+        dataList: [],
+        tablePage: {
+          total: 0,
+          currentPage: 1,
+          pageSize: 10,
+          orders: []
+        },
+        loading: false
+      }
+    },
+    components: {
+      LuckyDrawEventsForm
+    },
+    luckyDrawEventsService: null,
+    created () {
+      this.luckyDrawEventsService = new LuckyDrawEventsService()
+    },
+    activated () {
+      this.refreshList()
+    },
+    watch: {
+    },
+    methods: {
+      // 获取数据列表
+      refreshList () {
+        this.loading = true
+        this.luckyDrawEventsService.list({
+          'current': this.tablePage.currentPage,
+          'size': this.tablePage.pageSize,
+          'orders': this.tablePage.orders,
+          ...this.searchForm
+        }).then(({data}) => {
+          this.dataList = data.records
+          this.tablePage.total = data.total
+          this.loading = false
+        })
+      },
+      // 当前页
+      currentChangeHandle ({ currentPage, pageSize }) {
+        this.tablePage.currentPage = currentPage
+        this.tablePage.pageSize = pageSize
+        this.refreshList()
+      },
+      // 新建
+      add () {
+        this.$refs.luckyDrawEventsForm.init('add')
+      },
+      // 修改
+      edit (id) {
+        id = id || this.$refs.luckyTable.getCheckboxRecords().map(item => {
+          return item.id
+        })[0]
+        this.$refs.luckyDrawEventsForm.init('edit', id)
+      },
+      // 查看
+      view (id) {
+        this.$refs.luckyDrawEventsForm.init('view', id)
+      },
+      resetSearch () {
+        this.$refs.searchForm.resetFields()
+        this.refreshList()
+      },
+      changeSwitch (row) {
+        if (row.switchFlag === '0') {
+          this.$confirm(`确定开启此活动吗?`, '提示', {
+            confirmButtonText: '确定',
+            cancelButtonText: '取消',
+            type: 'warning'
+          }).then(() => {
+            this.luckyDrawEventsService.openEvent(row.id).then(({data}) => {
+              this.$message.success(data)
+              this.refreshList()
+            })
+          }).catch(() => {
+            this.refreshList()
+          })
+        } else if (row.switchFlag === '1') {
+          this.$confirm(`确定关闭此活动吗?`, '提示', {
+            confirmButtonText: '确定',
+            cancelButtonText: '取消',
+            type: 'warning'
+          }).then(() => {
+            this.luckyDrawEventsService.closeEvent(row.id).then(({data}) => {
+              this.$message.success(data)
+              this.refreshList()
+            })
+          }).catch(() => {
+            this.refreshList()
+          })
+        }
+      },
+      // 删除
+      del (id) {
+        let ids = id || this.$refs.luckyTable.getCheckboxRecords().map(item => {
+          return item.id
+        }).join(',')
+        this.$confirm(`确定删除所选项吗?`, '提示', {
+          confirmButtonText: '确定',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }).then(() => {
+          this.loading = true
+          this.luckyDrawEventsService.delete(ids).then(({data}) => {
+            this.$message.success(data)
+            this.refreshList()
+            this.loading = false
+          })
+        })
+      }
+    }
+  }
+</script>
+<style lang="scss">
+  .el-card__body {
+    overflow: auto;
+  }
+</style>
+<style>
+  .expand-wrapper {
+    padding: 10px;
+  }
+</style>