liveRedConf.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. liveId: null,
  259. };
  260. },
  261. watch: {
  262. // 监听路由的 query 参数变化
  263. '$route.query': {
  264. handler(newQuery) {
  265. if (this.$route.params.liveId) {
  266. this.liveId = this.$route.params.liveId;
  267. }else {
  268. this.liveId = this.$route.query.liveId;
  269. }
  270. this.queryParams.liveId = this.liveId;
  271. this.parentLiveId = this.liveId;
  272. if(this.queryParams.liveId){
  273. this.form.liveId = this.parentLiveId;
  274. //设置查询条件直播间ID不可修改
  275. this.canLiveId = true;
  276. }
  277. if(this.liveId == null) {
  278. return;
  279. }
  280. this.getList();
  281. },
  282. // 初始化时立即执行一次
  283. immediate: true
  284. }
  285. },
  286. created() {
  287. this.getDicts("sys_live_red_status").then(response => {
  288. this.redStatusOptions = response.data;
  289. });
  290. this.getDicts("sys_live_red_type").then(response => {
  291. this.redTypeOptions = response.data;
  292. });
  293. },
  294. computed: {
  295. },
  296. methods: {
  297. handleStatusChange(row, status) {
  298. if (this.$store.state.liveWs[this.liveId] == null) {
  299. this.msgError("请从直播间进行操作!");
  300. return;
  301. }
  302. //结束的抽奖不能进行操作
  303. if(row.redStatus+"" === "2"){
  304. this.msgError("已结束的红包不能进行操作");
  305. return;
  306. }
  307. switch (status+"") {
  308. case "1":
  309. //只能对未开启的抽奖进行操作
  310. if(row.redStatus+"" !== "0" && row.redStatus+"" !== "3"){
  311. this.msgError("只能对未开启或暂停的红包进行开始操作");
  312. return;
  313. }
  314. break;
  315. case "2":
  316. //只能对进行中或暂停的红包进行结算
  317. if(row.redStatus+"" !== "1" && row.redStatus+"" !== "3"){
  318. this.msgError("只能对进行中或暂停的红包进行结算");
  319. return;
  320. }
  321. break;
  322. case "3":
  323. //只能对进行中的抽奖执行暂停操作
  324. if(row.redStatus+"" !== "1"){
  325. this.msgError("只能对进行中的红包执行暂停操作");
  326. return;
  327. }
  328. break;
  329. default:
  330. return;
  331. }
  332. const doRedParam = {
  333. redId: row.redId,
  334. redStatus: status,
  335. totalLots: row.totalLots,
  336. liveId: this.liveId,
  337. duration: row.duration,
  338. status: status
  339. };
  340. updateLiveRedConf(doRedParam).then(response => {
  341. if(response.code === 200){
  342. const msg = {
  343. cmd: 'red',
  344. data: doRedParam
  345. };
  346. this.$store.state.liveWs[this.liveId].send(JSON.stringify(msg));
  347. this.msgSuccess("修改成功");
  348. }else{
  349. this.msgError(response.msg);
  350. }
  351. this.open = false;
  352. this.getList();
  353. });
  354. },
  355. redStatusFormatter(row, column) {
  356. return this.selectDictLabel(this.redStatusOptions, row.redStatus);
  357. },
  358. redTypeFormatter(row, column) {
  359. return this.selectDictLabel(this.redTypeOptions, row.redType);
  360. },
  361. /** 查询直播红包记录配置列表 */
  362. getList() {
  363. this.loading = true;
  364. listLiveRedConf(this.queryParams).then(response => {
  365. this.liveRedConfList = response.rows;
  366. this.total = response.total;
  367. this.loading = false;
  368. });
  369. },
  370. // 取消按钮
  371. cancel() {
  372. this.open = false;
  373. this.reset();
  374. },
  375. // 表单重置
  376. reset() {
  377. this.form = {
  378. redId: null,
  379. redStatus: null,
  380. duration: null,
  381. //redType: null,
  382. liveId: null,
  383. redNum: null,
  384. totalLots: null,
  385. totalSend: null,
  386. desc: null,
  387. createTime: null,
  388. updateTime: null,
  389. createBy: null,
  390. updateBy: null
  391. };
  392. this.resetForm("form");
  393. this.checkParentLiveId();
  394. },
  395. //判断父页面传入参数
  396. checkParentLiveId(){
  397. if(this.parentLiveId){
  398. this.form.liveId = this.parentLiveId;
  399. this.queryParams.liveId = this.parentLiveId;
  400. }
  401. },
  402. /** 搜索按钮操作 */
  403. handleQuery() {
  404. this.queryParams.pageNum = 1;
  405. this.getList();
  406. },
  407. /** 重置按钮操作 */
  408. resetQuery() {
  409. this.resetForm("queryForm");
  410. this.checkParentLiveId();
  411. this.handleQuery();
  412. },
  413. // 多选框选中数据
  414. handleSelectionChange(selection) {
  415. this.ids = selection.map(item => item.redId)
  416. this.single = selection.length!==1
  417. this.multiple = !selection.length
  418. },
  419. /** 新增按钮操作 */
  420. handleAdd() {
  421. this.reset();
  422. this.open = true;
  423. this.title = "添加直播红包记录配置";
  424. },
  425. /** 修改按钮操作 */
  426. handleUpdate(row) {
  427. //只能对未开始或暂停的抽奖进行修改
  428. if(row.redStatus+"" !== "0" && row.redStatus+"" !== "3"){
  429. this.msgError("只能对未开始或暂停的红包进行修改");
  430. return;
  431. }
  432. this.reset();
  433. const redId = row.redId || this.ids
  434. getLiveRedConf(redId).then(response => {
  435. this.form = response.data;
  436. this.open = true;
  437. this.title = "修改直播红包记录配置";
  438. });
  439. },
  440. /** 提交按钮 */
  441. submitForm() {
  442. this.$refs["form"].validate(valid => {
  443. if (valid) {
  444. if (this.form.redId != null) {
  445. updateLiveRedConf(this.form).then(response => {
  446. this.msgSuccess("修改成功");
  447. this.open = false;
  448. this.getList();
  449. });
  450. } else {
  451. this.form.redType = 1;
  452. addLiveRedConf(this.form).then(response => {
  453. this.msgSuccess("新增成功");
  454. this.open = false;
  455. this.getList();
  456. });
  457. }
  458. }
  459. });
  460. },
  461. /** 删除按钮操作 */
  462. handleDelete(row) {
  463. //如果状态不为0,则不能删除
  464. if (row.redStatus+"" !== "0") {
  465. this.msgError("只能删除未发放的红包");
  466. return;
  467. }
  468. const redIds = row.redId || this.ids;
  469. this.$confirm('是否确认删除直播红包记录配置编号为"' + redIds + '"的数据项?', "警告", {
  470. confirmButtonText: "确定",
  471. cancelButtonText: "取消",
  472. type: "warning"
  473. }).then(function() {
  474. return delLiveRedConf(redIds);
  475. }).then(() => {
  476. this.getList();
  477. this.msgSuccess("删除成功");
  478. const msg = {
  479. cmd: 'red',
  480. data: {
  481. redId: row.redId,
  482. redStatus: 2,
  483. totalLots: row.totalLots,
  484. duration: row.duration
  485. }
  486. };
  487. this.$store.state.liveWs[this.liveId].send(JSON.stringify(msg));
  488. }).catch(() => {});
  489. },
  490. /** 导出按钮操作 */
  491. handleExport() {
  492. const queryParams = this.queryParams;
  493. this.$confirm('是否确认导出所有直播红包记录配置数据项?', "警告", {
  494. confirmButtonText: "确定",
  495. cancelButtonText: "取消",
  496. type: "warning"
  497. }).then(() => {
  498. this.exportLoading = true;
  499. return exportLiveRedConf(queryParams);
  500. }).then(response => {
  501. this.download(response.msg);
  502. this.exportLoading = false;
  503. }).catch(() => {});
  504. }
  505. }
  506. };
  507. </script>