list.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. <template>
  2. <el-card shadow="never" class="aui-card--fill">
  3. <div class="mod-home">
  4. <div class="title">活动列表</div>
  5. <el-row :gutter="20" style="margin-top: 20px;">
  6. <el-col :span="6" class="adfac">
  7. <div class="query_text">活动类型</div>
  8. <el-select v-model="queryParams.typeId" placeholder="请选择活动类型" class="select-box" style="width: 100%;" clearable>
  9. <el-option v-for="item in typeOptions" :key="item.id" :label="item.typeName" :value="item.id"></el-option>
  10. </el-select>
  11. </el-col>
  12. <el-col :span="6" class="adfac">
  13. <div class="query_text">活动分类</div>
  14. <el-select v-model="queryParams.categoryId" placeholder="请选择活动分类" class="select-box" style="width: 100%;" clearable>
  15. <el-option v-for="item in categoryOptions" :key="item.id" :label="item.categoryName" :value="item.id"></el-option>
  16. </el-select>
  17. </el-col>
  18. </el-row>
  19. <el-row :gutter="20" style="margin-top: 20px;">
  20. <el-col :span="6" class="adfac">
  21. <div class="query_text">活动名称</div>
  22. <el-input v-model="queryParams.activityName" placeholder="请输入活动名称" class="input-box" clearable></el-input>
  23. </el-col>
  24. <el-col :span="6" class="adfac">
  25. <div class="query_text">活动时间</div>
  26. <el-date-picker v-model="queryParams.startEndDate" @change="handleDateChange" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 100%;"></el-date-picker>
  27. </el-col>
  28. <el-col :span="12" class="adfac">
  29. <el-button type="default" @click="handleReset">重置</el-button>
  30. <el-button type="primary" @click="getList">查询</el-button>
  31. <el-button type="primary" @click="handleAdd" v-if="$hasPermission('core:activity:save')">新增活动</el-button>
  32. </el-col>
  33. </el-row>
  34. <el-table :data="dataList" border cell-class-name="vertical-top-cell" v-loading="loading" empty-text="暂无活动" style="margin-top: 24px;">
  35. <el-table-column prop="id" label="活动ID" width="200"></el-table-column>
  36. <el-table-column prop="activityName" label="活动名称" width="350"></el-table-column>
  37. <el-table-column prop="typeName" label="活动类型" width="120"></el-table-column>
  38. <el-table-column prop="categoryName" label="活动分类" width="120"></el-table-column>
  39. <el-table-column prop="" label="报名时间" width="320">
  40. <template #default="scope">{{ scope.row.signupStartTime }} - {{ scope.row.signupEndTime }}</template>
  41. </el-table-column>
  42. <el-table-column prop="" label="报名人数" width="120">
  43. <template #default="scope">
  44. <div class="adfac"><span style="color: #00AE57;">{{ scope.row.recruitmentNow||0 }}</span>/{{ scope.row.recruitmentMax||'无限制' }}</div>
  45. </template>
  46. </el-table-column>
  47. <el-table-column prop="totalLoveValue" label="总爱心值" width="120">
  48. <template #default="scope">
  49. {{ scope.row.totalLoveValue||0 }}
  50. </template>
  51. </el-table-column>
  52. <el-table-column prop="" label="上下架" width="120">
  53. <template #default="scope">
  54. <span v-if="scope.row.state==1" style="color: #00AE57;">已上架</span>
  55. <span v-if="scope.row.state==0">已下架</span>
  56. </template>
  57. </el-table-column>
  58. <el-table-column prop="activeState" label="活动状态" width="150">
  59. <template #default="scope">
  60. <div class="as" :class="activeStateColorDict[scope.row.activeState]||'grey'">{{ activeStateCfg[scope.row.activeState] || '未知' }}</div>
  61. </template>
  62. </el-table-column>
  63. <el-table-column prop="" label="活动时间" width="320">
  64. <template #default="scope">{{ scope.row.activityStartTime }} - {{ scope.row.activityEndTime }}</template>
  65. </el-table-column>
  66. <el-table-column prop="channelName" label="渠道方" width="120"></el-table-column>
  67. <el-table-column prop="organizerName" label="举办方" width="120" show-overflow-tooltip></el-table-column>
  68. <el-table-column prop="createDate" label="创建时间" width="180"></el-table-column>
  69. <el-table-column label="操作" width="300" fixed="right">
  70. <template #default="scope">
  71. <!-- <el-button link type="text" @click="handleEdit(scope.row)" v-if="scope.row.activeState!=3&&$hasPermission('core:activity:update')">编辑</el-button> -->
  72. <el-button link type="text" @click="handleEdit(scope.row)" v-if="scope.row.activeState<2&&$hasPermission('core:activity:update')">编辑</el-button>
  73. <el-button link type="text" @click="handleDetail(scope.row)" v-if="$hasPermission('core:activity:detail')&&scope.row.activeState>-2">详情</el-button>
  74. <el-button link type="text" @click="handleInfo(scope.row)" v-if="$hasPermission('core:activity:info')&&scope.row.activeState>-2">报名信息</el-button>
  75. <el-button link type="text" @click="handleCode(scope.row)" v-if="!scope.row.signCode&&scope.row.activeState==2&&$hasPermission('core:activity:code')">生成签到码</el-button>
  76. <el-button link type="text" @click="handleReviewCode(scope.row)" v-if="scope.row.signCode&&scope.row.activeState==2&&$hasPermission('core:activity:code')">查看签到码</el-button>
  77. <!-- <el-button link type="text" @click="handleUpDown(scope.row,0)" v-if="scope.row.state==1&&(scope.row.activeState==0||scope.row.activeState==3)&&$hasPermission('core:activity:updown')">下架</el-button> -->
  78. <el-button link type="text" @click="handleUpDown(scope.row,0)" v-if="scope.row.state==1&&$hasPermission('core:activity:updown')&&scope.row.activeState>-2">下架</el-button>
  79. <el-button link type="text" @click="handleUpDown(scope.row,1)" v-if="scope.row.state==0&&$hasPermission('core:activity:updown')&&scope.row.activeState>-2">上架</el-button>
  80. <el-button link type="text" @click="handleCancel(scope.row)" v-if="$hasPermission('core:activity:cancel')&&scope.row.activeState!=-1&&(Date.parse(new Date())>Date.parse(scope.row.signupEndTime)&&Date.parse(new Date())<Date.parse(scope.row.activityStartTime))">取消</el-button>
  81. <el-button link type="text" @click="handleDelete(scope.row)" v-if="($hasPermission('core:activity:delete')&&scope.row.state==0&&scope.row.activeState==0)||($hasPermission('core:activity:delete')&&scope.row.activeState==-2)">删除</el-button>
  82. </template>
  83. </el-table-column>
  84. </el-table>
  85. <el-pagination
  86. :current-page="queryParams.page"
  87. :page-sizes="[10, 20, 50, 100]"
  88. :page-size="queryParams.limit"
  89. :total="total"
  90. layout="total, sizes, prev, pager, next, jumper"
  91. @size-change="pageSizeChangeHandle"
  92. @current-change="pageCurrentChangeHandle">
  93. </el-pagination>
  94. </div>
  95. <el-dialog width="600px" :visible.sync="show" title="签到码" @close="cancel">
  96. <div class="code-img adffcacjc">
  97. <img :src="signCodeUrl">
  98. </div>
  99. <div class="demo-drawer__footer" style="display: flex;justify-content: end;margin-top: 50px;">
  100. <el-button type="primary" @click="downloadImg">下 载</el-button>
  101. <el-button @click="cancel" style="margin-right: 5%;">取 消</el-button>
  102. </div>
  103. </el-dialog>
  104. </el-card>
  105. </template>
  106. <script>
  107. import moment from 'moment'
  108. export default {
  109. data () {
  110. return {
  111. activeStateCfg: {
  112. '-2': '草稿',
  113. '-1': '已取消',
  114. 0: '未开始',
  115. 1: '报名中',
  116. 2: '进行中',
  117. 3: '已结束'
  118. },
  119. activeStateColorDict: {
  120. '-2': 'grey',
  121. '-1': 'grey',
  122. 0: 'red',
  123. 1: 'yellow',
  124. 2: 'blue',
  125. 3: 'grey'
  126. },
  127. typeOptions: [],
  128. categoryOptions: [],
  129. queryParams: {
  130. page: 1,
  131. limit: 10,
  132. typeId: '',
  133. categoryId: '',
  134. activityName: '',
  135. startEndDate: '',
  136. startDate: '',
  137. endDate: ''
  138. },
  139. total: 0,
  140. dataList: [],
  141. loading: false,
  142. show: false,
  143. signCodeUrl: ''
  144. }
  145. },
  146. created () {
  147. this.getTypeOptions()
  148. this.getCategoryOptions()
  149. },
  150. mounted () {
  151. this.getList()
  152. },
  153. methods: {
  154. getList () {
  155. this.loading = true
  156. let { startEndDate, ...newParams } = JSON.parse(JSON.stringify(this.queryParams))
  157. this.$http.get('/core/activity/page', { params: newParams }).then(res => {
  158. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  159. this.dataList = res.data.data.list || []
  160. this.total = res.data.data.total || 0
  161. this.loading = false
  162. })
  163. },
  164. handleReset () {
  165. this.queryParams = {
  166. page: 1,
  167. limit: 10,
  168. typeId: '',
  169. categoryId: '',
  170. activityName: '',
  171. startEndDate: '',
  172. startDate: '',
  173. endDate: ''
  174. }
  175. this.getList()
  176. },
  177. pageSizeChangeHandle (val) {
  178. this.queryParams.limit = val
  179. this.getList()
  180. },
  181. pageCurrentChangeHandle (val) {
  182. this.queryParams.page = val
  183. this.getList()
  184. },
  185. handleDateChange (val) {
  186. this.queryParams.startDate = moment(val[0]).format('YYYY-MM-DD')
  187. this.queryParams.endDate = moment(val[1]).format('YYYY-MM-DD')
  188. },
  189. getTypeOptions () {
  190. this.$http.get('/core/activity/type/page', { params: { page: 1, limit: -1 } }).then(res => {
  191. this.typeOptions = res.data.data.list || []
  192. })
  193. },
  194. getCategoryOptions () {
  195. this.$http.get('/core/activity/category/page', { params: { page: 1, limit: -1 } }).then(res => {
  196. this.categoryOptions = res.data.data.list || []
  197. })
  198. },
  199. handleAdd () {
  200. this.$router.push({ name: 'activityAdd' })
  201. },
  202. handleEdit (row) {
  203. this.$router.push({ name: 'activityAdd', query: { id: row.id } })
  204. },
  205. handleDetail (row) {
  206. this.$router.push({ name: 'activityDetail', query: { id: row.id } })
  207. },
  208. handleInfo (row) {
  209. this.$router.push({ name: 'activityApplyInfo', query: { id: row.id } })
  210. },
  211. handleCode (row) {
  212. this.$http.get('/core/activity/genSignCode/' + row.id).then(res => {
  213. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  214. this.$message.success('生成成功')
  215. this.getList()
  216. })
  217. },
  218. handleReviewCode (row) {
  219. this.show = true
  220. this.signCodeUrl = row.signCode
  221. },
  222. cancel () {
  223. this.show = false
  224. },
  225. downloadImg () {
  226. const link = document.createElement('a')
  227. link.style.display = 'none'
  228. link.href = this.signCodeUrl
  229. link.setAttribute('download', '签到码')
  230. document.body.appendChild(link)
  231. link.click()
  232. document.body.removeChild(link)
  233. this.show = false
  234. },
  235. handleUpDown (row, state) {
  236. if ([0, 1, 2].includes(row.activeState) && row.recruitmentNow > 0) return this.$message.error(`当前活动已存在报名人数,无法${state ? '上架' : '下架'}`)
  237. this.$confirm(`是否确认${state ? '上架' : '下架'}活动【${row.activityName}】?`, '提示', {
  238. confirmButtonText: '确定',
  239. cancelButtonText: '取消',
  240. type: 'warning'
  241. }).then(() => {
  242. this.$http.post('/core/activity/updState', { id: row.id, state }).then(res => {
  243. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  244. this.$message.success((state ? '上架' : '下架') + '成功')
  245. this.getList()
  246. })
  247. })
  248. },
  249. handleCancel (row) {
  250. this.$confirm(`是否确认取消活动【${row.activityName}】?`, '提示', {
  251. confirmButtonText: '确定',
  252. cancelButtonText: '取消',
  253. type: 'warning'
  254. }).then(() => {
  255. this.$http.get(`core/activity/cancelEvent/${row.id}`).then(res => {
  256. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  257. this.$message.success('取消成功')
  258. this.getList()
  259. })
  260. }).catch(() => {})
  261. },
  262. handleDelete (row) {
  263. this.$confirm(`是否确认删除活动【${row.activityName}】?`, '提示', {
  264. confirmButtonText: '确定',
  265. cancelButtonText: '取消',
  266. type: 'warning'
  267. }).then(() => {
  268. this.$http.delete('/core/activity', { 'data': [row.id] }).then(res => {
  269. if (res.data.code !== 0) return this.$message.error(res.data.msg)
  270. this.$message.success('删除成功')
  271. this.getList()
  272. })
  273. }).catch(() => {
  274. this.$message({
  275. type: 'info',
  276. message: '已取消删除'
  277. })
  278. })
  279. }
  280. }
  281. }
  282. </script>
  283. <style scoped lang="scss">
  284. .title{
  285. font-family: PingFang-SC, PingFang-SC;
  286. font-weight: bold;
  287. font-size: 16px;
  288. color: #252525;
  289. line-height: 22px;
  290. }
  291. .query_text{
  292. font-family: PingFangSC, PingFang SC;
  293. font-weight: 400;
  294. font-size: 14px;
  295. color: #393939;
  296. line-height: 20px;
  297. width: 80px;
  298. margin-right: 16px;
  299. }
  300. .as{
  301. width: 58px;
  302. height: 24px;
  303. font-family: PingFangSC, PingFang SC;
  304. font-weight: 400;
  305. font-size: 14px;
  306. color: #646464;
  307. line-height: 24px;
  308. text-align: center;
  309. background: #F7F7F7;
  310. border-radius: 6px;
  311. display: inline-block;
  312. &.blue{
  313. background: rgba(46,105,235,0.08);
  314. color: #2E69EB;
  315. }
  316. &.red{
  317. background: rgba(253,79,102,0.11);
  318. color: #FD4F66;
  319. }
  320. &.yellow{
  321. background: rgba(255,152,10,0.08);
  322. color: #FF980A;
  323. }
  324. }
  325. .code-img{
  326. width: 100%;
  327. height: 500px;
  328. img{
  329. width: 100%;
  330. height: auto;
  331. }
  332. }
  333. </style>