index.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="红包状态" prop="redStatus">
  5. <el-select v-model="queryParams.redStatus" placeholder="请选择红包状态" clearable size="small">
  6. <el-option v-for="(item,index) in redStatusOptions" :key="item.dictValue+index" :label="item.dictLabel" :value="item.dictValue" />
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item label="红包类型" prop="redType">
  10. <el-select v-model="queryParams.redType" placeholder="请选择红包类型" clearable size="small">
  11. <el-option v-for="(item,index) in redTypeOptions" :key="item.dictValue+index" :label="item.dictLabel" :value="item.dictValue" />
  12. </el-select>
  13. </el-form-item>
  14. <el-form-item label="直播间ID" prop="liveId" >
  15. <el-input
  16. v-model="queryParams.liveId"
  17. placeholder="请输入直播间ID"
  18. clearable
  19. size="small"
  20. :disabled="canLiveId"
  21. @keyup.enter.native="handleQuery"
  22. />
  23. </el-form-item>
  24. <el-form-item label="红包标题" prop="desc">
  25. <el-input
  26. v-model="queryParams.desc"
  27. placeholder="请输入描述"
  28. clearable
  29. size="small"
  30. @keyup.enter.native="handleQuery"
  31. />
  32. </el-form-item>
  33. <el-form-item label="创建日期" prop="createTime">
  34. <el-date-picker clearable size="small"
  35. v-model="queryParams.createTime"
  36. type="date"
  37. value-format="yyyy-MM-dd"
  38. placeholder="选择创建日期">
  39. </el-date-picker>
  40. </el-form-item>
  41. <el-form-item label="修改日期" prop="updateTime">
  42. <el-date-picker clearable size="small"
  43. v-model="queryParams.updateTime"
  44. type="date"
  45. value-format="yyyy-MM-dd"
  46. placeholder="选择修改日期">
  47. </el-date-picker>
  48. </el-form-item>
  49. <el-form-item>
  50. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  51. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  52. </el-form-item>
  53. </el-form>
  54. <el-row :gutter="10" class="mb8">
  55. <el-col :span="1.5">
  56. <el-button
  57. type="primary"
  58. plain
  59. icon="el-icon-plus"
  60. size="mini"
  61. @click="handleAdd"
  62. v-hasPermi="['live:liveRedConf:add']"
  63. >新增</el-button>
  64. </el-col>
  65. <el-col :span="1.5">
  66. <el-button
  67. type="success"
  68. plain
  69. icon="el-icon-edit"
  70. size="mini"
  71. :disabled="single"
  72. @click="handleUpdate"
  73. v-hasPermi="['live:liveRedConf:edit']"
  74. >修改</el-button>
  75. </el-col>
  76. <el-col :span="1.5">
  77. <el-button
  78. type="warning"
  79. plain
  80. icon="el-icon-download"
  81. size="mini"
  82. :loading="exportLoading"
  83. @click="handleExport"
  84. v-hasPermi="['live:liveRedConf:export']"
  85. >导出</el-button>
  86. </el-col>
  87. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  88. </el-row>
  89. <el-table border v-loading="loading" :data="liveRedConfList" @selection-change="handleSelectionChange">
  90. <el-table-column type="selection" width="55" align="center" />
  91. <el-table-column label="红包ID" align="center" prop="redId" />
  92. <el-table-column label="红包状态" align="center" prop="redStatus" :formatter="redStatusFormatter"/>
  93. <el-table-column label="有效时间 单位:分" align="center" prop="duration" />
  94. <el-table-column label="红包类型" align="center" prop="redType" :formatter="redTypeFormatter"/>
  95. <el-table-column label="直播间ID" align="center" prop="liveId" />
  96. <el-table-column label="芳华币数量" align="center" prop="redNum" />
  97. <el-table-column label="可中奖份量" align="center" prop="totalLots" />
  98. <el-table-column label="实际发放奖励份量" align="center" prop="totalSend" />
  99. <el-table-column label="红包标题" align="center" prop="desc" />
  100. <el-table-column label="创建日期" align="center" prop="createTime" width="120">
  101. <template slot-scope="scope">
  102. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  103. </template>
  104. </el-table-column>
  105. <el-table-column label="修改日期" align="center" prop="updateTime" width="120">
  106. <template slot-scope="scope">
  107. <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
  108. </template>
  109. </el-table-column>
  110. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  111. <template slot-scope="scope">
  112. <el-button
  113. size="mini"
  114. type="text"
  115. icon="el-icon-edit"
  116. @click="handleUpdate(scope.row)"
  117. v-hasPermi="['live:liveRedConf:edit']"
  118. style="margin-left: 10px"
  119. >修改</el-button>
  120. <!-- 开始 -->
  121. <el-button
  122. size="mini"
  123. type="text"
  124. icon="el-icon-delete"
  125. @click="handleStatusChange(scope.row,'1')"
  126. v-hasPermi="['live:liveRedConf:edit']"
  127. >开始</el-button>
  128. <!-- 暂停 -->
  129. <el-button
  130. size="mini"
  131. type="text"
  132. icon="el-icon-delete"
  133. @click="handleStatusChange(scope.row,'3')"
  134. v-hasPermi="['live:liveRedConf:edit']"
  135. >暂停</el-button>
  136. <!-- 结算 -->
  137. <el-button
  138. size="mini"
  139. type="text"
  140. icon="el-icon-delete"
  141. @click="handleStatusChange(scope.row,'2')"
  142. v-hasPermi="['live:liveRedConf:edit']"
  143. >结算</el-button>
  144. <el-button
  145. size="mini"
  146. type="text"
  147. icon="el-icon-delete"
  148. @click="handleDelete(scope.row)"
  149. v-hasPermi="['live:liveRedConf:edit']"
  150. >删除</el-button>
  151. </template>
  152. </el-table-column>
  153. </el-table>
  154. <pagination
  155. v-show="total>0"
  156. :total="total"
  157. :page.sync="queryParams.pageNum"
  158. :limit.sync="queryParams.pageSize"
  159. @pagination="getList"
  160. />
  161. <!-- 添加或修改直播红包记录配置对话框 -->
  162. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  163. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  164. <el-form-item label="持续时间" prop="duration">
  165. <el-input v-model="form.duration" placeholder="请输入红包有效时间 单位:分" />
  166. </el-form-item>
  167. <!-- <el-form-item label="红包类型" prop="redType">
  168. <el-select v-model="form.redType" placeholder="请选择红包类型">
  169. <el-option v-for="(item,index) in redTypeOptions" :key="item.dictValue+index" :label="item.dictLabel" :value="item.dictValue" />
  170. </el-select>
  171. </el-form-item>-->
  172. <el-form-item label="直播间ID" prop="liveId">
  173. <el-input v-model="form.liveId" placeholder="请输入直播间ID" :disabled="canLiveId"/>
  174. </el-form-item>
  175. <el-form-item label="芳华币数" prop="redNum">
  176. <el-input v-model="form.redNum" placeholder="请输入芳华币数量" />
  177. </el-form-item>
  178. <el-form-item label="中奖份量" prop="totalLots">
  179. <el-input v-model="form.totalLots" placeholder="请输入可中奖份量" />
  180. </el-form-item>
  181. <el-form-item label="红包标题" prop="desc">
  182. <el-input v-model="form.desc" placeholder="请输入红包描述" />
  183. </el-form-item>
  184. </el-form>
  185. <div slot="footer" class="dialog-footer">
  186. <el-button type="primary" @click="submitForm">确 定</el-button>
  187. <el-button @click="cancel">取 消</el-button>
  188. </div>
  189. </el-dialog>
  190. </div>
  191. </template>
  192. <script>
  193. import { listLiveRedConf, getLiveRedConf, delLiveRedConf, addLiveRedConf, updateLiveRedConf, exportLiveRedConf } from "@/api/live/liveRedConf";
  194. export default {
  195. name: "LiveRedConf",
  196. data() {
  197. return {
  198. //字典
  199. redStatusOptions: [],
  200. redTypeOptions: [],
  201. canLiveId:false,
  202. //parentLiveId
  203. parentLiveId : null,
  204. // 遮罩层
  205. loading: true,
  206. // 导出遮罩层
  207. exportLoading: false,
  208. // 选中数组
  209. ids: [],
  210. // 非单个禁用
  211. single: true,
  212. // 非多个禁用
  213. multiple: true,
  214. // 显示搜索条件
  215. showSearch: true,
  216. // 总条数
  217. total: 0,
  218. // 直播红包记录配置表格数据
  219. liveRedConfList: [],
  220. // 弹出层标题
  221. title: "",
  222. // 是否显示弹出层
  223. open: false,
  224. // 查询参数
  225. queryParams: {
  226. pageNum: 1,
  227. pageSize: 10,
  228. redStatus: null,
  229. redType: null,
  230. liveId: null,
  231. desc: null,
  232. createTime: null,
  233. updateTime: null,
  234. },
  235. // 表单参数
  236. form: {},
  237. // 表单校验
  238. rules: {
  239. duration: [
  240. { required: true, message: "有效时间 单位:分不能为空", trigger: "blur" }
  241. ],
  242. /* redType: [
  243. { required: true, message: "红包类型不能为空", trigger: "change" }
  244. ], */
  245. liveId: [
  246. { required: true, message: "直播间ID不能为空", trigger: "blur" }
  247. ],
  248. redNum: [
  249. { required: true, message: "芳华币数量不能为空", trigger: "blur" }
  250. ],
  251. totalLots: [
  252. { required: true, message: "可中奖份量不能为空", trigger: "blur" }
  253. ],
  254. desc: [
  255. { required: true, message: "描述不能为空", trigger: "blur" }
  256. ],
  257. }
  258. };
  259. },
  260. created() {
  261. this.getDicts("sys_live_red_status").then(response => {
  262. this.redStatusOptions = response.data;
  263. });
  264. this.getDicts("sys_live_red_type").then(response => {
  265. this.redTypeOptions = response.data;
  266. });
  267. this.parentLiveId = this.liveId;
  268. this.queryParams.liveId = this.parentLiveId;
  269. if(this.queryParams.liveId){
  270. this.form.liveId = this.parentLiveId;
  271. //设置查询条件直播间ID不可修改
  272. this.canLiveId = true;
  273. }
  274. this.getList();
  275. },
  276. computed: {
  277. liveId() {
  278. return this.$route.params.liveId;
  279. }
  280. },
  281. methods: {
  282. handleStatusChange(row, status) {
  283. //结束的抽奖不能进行操作
  284. if(row.redStatus+"" === "2"){
  285. this.msgError("已结束的红包不能进行操作");
  286. return;
  287. }
  288. switch (status+"") {
  289. case "1":
  290. //只能对未开启的抽奖进行操作
  291. if(row.redStatus+"" !== "0" && row.redStatus+"" !== "3"){
  292. this.msgError("只能对未开启或暂停的红包进行开始操作");
  293. return;
  294. }
  295. break;
  296. case "2":
  297. //只能对进行中或暂停的红包进行结算
  298. if(row.redStatus+"" !== "1" && row.redStatus+"" !== "3"){
  299. this.msgError("只能对进行中或暂停的红包进行结算");
  300. return;
  301. }
  302. break;
  303. case "3":
  304. //只能对进行中的抽奖执行暂停操作
  305. if(row.redStatus+"" !== "1"){
  306. this.msgError("只能对进行中的红包执行暂停操作");
  307. return;
  308. }
  309. break;
  310. default:
  311. return;
  312. }
  313. const doRedParam = {
  314. redId: row.redId,
  315. redStatus: status
  316. };
  317. updateLiveRedConf(doRedParam).then(response => {
  318. if(response.code === 200){
  319. this.$store.state.liveWs[this.liveId].sendWs("red",response.msg, row.redId,this.liveId);
  320. this.getList();
  321. this.msgSuccess("修改成功");
  322. }else{
  323. this.msgError(response.msg);
  324. }
  325. this.open = false;
  326. });
  327. },
  328. redStatusFormatter(row, column) {
  329. return this.selectDictLabel(this.redStatusOptions, row.redStatus);
  330. },
  331. redTypeFormatter(row, column) {
  332. return this.selectDictLabel(this.redTypeOptions, row.redType);
  333. },
  334. /** 查询直播红包记录配置列表 */
  335. getList() {
  336. this.loading = true;
  337. listLiveRedConf(this.queryParams).then(response => {
  338. this.liveRedConfList = response.rows;
  339. this.total = response.total;
  340. this.loading = false;
  341. });
  342. },
  343. // 取消按钮
  344. cancel() {
  345. this.open = false;
  346. this.reset();
  347. },
  348. // 表单重置
  349. reset() {
  350. this.form = {
  351. redId: null,
  352. redStatus: null,
  353. duration: null,
  354. //redType: null,
  355. liveId: null,
  356. redNum: null,
  357. totalLots: null,
  358. totalSend: null,
  359. desc: null,
  360. createTime: null,
  361. updateTime: null,
  362. createBy: null,
  363. updateBy: null
  364. };
  365. this.resetForm("form");
  366. this.checkParentLiveId();
  367. },
  368. //判断父页面传入参数
  369. checkParentLiveId(){
  370. if(this.parentLiveId){
  371. this.form.liveId = this.parentLiveId;
  372. this.queryParams.liveId = this.parentLiveId;
  373. }
  374. },
  375. /** 搜索按钮操作 */
  376. handleQuery() {
  377. this.queryParams.pageNum = 1;
  378. this.getList();
  379. },
  380. /** 重置按钮操作 */
  381. resetQuery() {
  382. this.resetForm("queryForm");
  383. this.checkParentLiveId();
  384. this.handleQuery();
  385. },
  386. // 多选框选中数据
  387. handleSelectionChange(selection) {
  388. this.ids = selection.map(item => item.redId)
  389. this.single = selection.length!==1
  390. this.multiple = !selection.length
  391. },
  392. /** 新增按钮操作 */
  393. handleAdd() {
  394. this.reset();
  395. this.open = true;
  396. this.title = "添加直播红包记录配置";
  397. },
  398. /** 修改按钮操作 */
  399. handleUpdate(row) {
  400. //只能对未开始或暂停的抽奖进行修改
  401. if(row.redStatus+"" !== "0" && row.redStatus+"" !== "3"){
  402. this.msgError("只能对未开始或暂停的红包进行修改");
  403. return;
  404. }
  405. this.reset();
  406. const redId = row.redId || this.ids
  407. getLiveRedConf(redId).then(response => {
  408. this.form = response.data;
  409. this.open = true;
  410. this.title = "修改直播红包记录配置";
  411. });
  412. },
  413. /** 提交按钮 */
  414. submitForm() {
  415. this.$refs["form"].validate(valid => {
  416. if (valid) {
  417. if (this.form.redId != null) {
  418. updateLiveRedConf(this.form).then(response => {
  419. this.msgSuccess("修改成功");
  420. this.open = false;
  421. this.getList();
  422. });
  423. } else {
  424. this.form.redType = 1;
  425. addLiveRedConf(this.form).then(response => {
  426. this.msgSuccess("新增成功");
  427. this.open = false;
  428. this.getList();
  429. });
  430. }
  431. }
  432. });
  433. },
  434. /** 删除按钮操作 */
  435. handleDelete(row) {
  436. //如果状态不为0,则不能删除
  437. if (row.redStatus+"" !== "0") {
  438. this.msgError("只能删除未发放的红包");
  439. return;
  440. }
  441. const redIds = row.redId || this.ids;
  442. this.$confirm('是否确认删除直播红包记录配置编号为"' + redIds + '"的数据项?', "警告", {
  443. confirmButtonText: "确定",
  444. cancelButtonText: "取消",
  445. type: "warning"
  446. }).then(function() {
  447. return delLiveRedConf(redIds);
  448. }).then(() => {
  449. this.getList();
  450. this.msgSuccess("删除成功");
  451. }).catch(() => {});
  452. },
  453. /** 导出按钮操作 */
  454. handleExport() {
  455. const queryParams = this.queryParams;
  456. this.$confirm('是否确认导出所有直播红包记录配置数据项?', "警告", {
  457. confirmButtonText: "确定",
  458. cancelButtonText: "取消",
  459. type: "warning"
  460. }).then(() => {
  461. this.exportLoading = true;
  462. return exportLiveRedConf(queryParams);
  463. }).then(response => {
  464. this.download(response.msg);
  465. this.exportLoading = false;
  466. }).catch(() => {});
  467. }
  468. }
  469. };
  470. </script>