liveRedConf.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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" v-if="!isPasswordBagMode">
  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="isPasswordBagMode ? '标题' : '红包标题'" 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>
  34. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  35. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  36. </el-form-item>
  37. </el-form>
  38. <el-row :gutter="10" class="mb8">
  39. <el-col :span="1.5">
  40. <el-button
  41. type="primary"
  42. plain
  43. icon="el-icon-plus"
  44. size="mini"
  45. @click="handleAdd"
  46. v-hasPermi="['live:liveRedConf:add']"
  47. >新增</el-button>
  48. </el-col>
  49. <el-col :span="1.5" v-if="!isPasswordBagMode">
  50. <el-button
  51. type="success"
  52. plain
  53. icon="el-icon-edit"
  54. size="mini"
  55. :disabled="single"
  56. @click="handleUpdate"
  57. v-hasPermi="['live:liveRedConf:edit']"
  58. >修改</el-button>
  59. </el-col>
  60. <el-col :span="1.5" v-if="!isPasswordBagMode">
  61. <el-button
  62. type="warning"
  63. plain
  64. icon="el-icon-download"
  65. size="mini"
  66. :loading="exportLoading"
  67. @click="handleExport"
  68. v-hasPermi="['live:liveRedConf:export']"
  69. >导出</el-button>
  70. </el-col>
  71. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  72. </el-row>
  73. <el-table border v-loading="loading" :data="liveRedConfList" @selection-change="handleSelectionChange">
  74. <el-table-column type="selection" width="55" align="center" v-if="!isPasswordBagMode" />
  75. <el-table-column label="红包ID" align="center" prop="redId" />
  76. <el-table-column label="红包状态" align="center" prop="redStatus" :formatter="redStatusFormatter"/>
  77. <el-table-column :label="isPasswordBagMode ? '持续时间(分)' : '有效时间 单位:分'" align="center" prop="duration" />
  78. <el-table-column label="发放类型" align="center" prop="distributeType" :formatter="distributeTypeFormatter" v-if="!isPasswordBagMode" />
  79. <el-table-column label="红包类型" align="center" prop="redType" :formatter="redTypeFormatter" v-if="!isPasswordBagMode"/>
  80. <el-table-column label="口令" align="center" prop="passwordCmd" v-if="isPasswordBagMode" :show-overflow-tooltip="true" />
  81. <el-table-column label="直播间ID" align="center" prop="liveId" />
  82. <el-table-column :label="isPasswordBagMode ? '奖励积分' : '芳华币数量'" align="center" prop="redNum" />
  83. <el-table-column :label="isPasswordBagMode ? '奖励份数' : '可中奖份量'" align="center" prop="totalLots" />
  84. <el-table-column label="参与人数" align="center" prop="joinCount" v-if="isPasswordBagMode" />
  85. <el-table-column label="实际发放奖励份量" align="center" prop="totalSend" v-if="!isPasswordBagMode" />
  86. <el-table-column :label="isPasswordBagMode ? '标题' : '红包标题'" align="center" prop="desc" />
  87. <el-table-column label="创建日期" align="center" prop="createTime" width="120">
  88. <template slot-scope="scope">
  89. <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
  90. </template>
  91. </el-table-column>
  92. <el-table-column label="修改日期" align="center" prop="updateTime" width="120" v-if="!isPasswordBagMode">
  93. <template slot-scope="scope">
  94. <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
  95. </template>
  96. </el-table-column>
  97. <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="220">
  98. <template slot-scope="scope">
  99. <template v-if="isPasswordBagMode">
  100. <el-button
  101. v-if="String(scope.row.redStatus) === '0'"
  102. size="mini"
  103. type="text"
  104. @click="handleStatusChange(scope.row,'1')"
  105. v-hasPermi="['live:liveRedConf:edit']"
  106. >开始</el-button>
  107. <el-button
  108. v-if="String(scope.row.redStatus) === '0'"
  109. size="mini"
  110. type="text"
  111. icon="el-icon-edit"
  112. @click="handleUpdate(scope.row)"
  113. v-hasPermi="['live:liveRedConf:edit']"
  114. >修改</el-button>
  115. <el-button
  116. v-if="String(scope.row.redStatus) === '1'"
  117. size="mini"
  118. type="text"
  119. @click="handleStatusChange(scope.row,'2')"
  120. v-hasPermi="['live:liveRedConf:edit']"
  121. >结束</el-button>
  122. <el-button
  123. size="mini"
  124. type="text"
  125. icon="el-icon-delete"
  126. @click="handleDelete(scope.row)"
  127. v-hasPermi="['live:liveRedConf:edit']"
  128. >删除</el-button>
  129. </template>
  130. <template v-else>
  131. <el-button
  132. size="mini"
  133. type="text"
  134. icon="el-icon-edit"
  135. @click="handleUpdate(scope.row)"
  136. v-hasPermi="['live:liveRedConf:edit']"
  137. style="margin-left: 10px"
  138. >修改</el-button>
  139. <el-button
  140. size="mini"
  141. type="text"
  142. icon="el-icon-delete"
  143. @click="handleStatusChange(scope.row,'1')"
  144. v-hasPermi="['live:liveRedConf:edit']"
  145. >开始</el-button>
  146. <el-button
  147. size="mini"
  148. type="text"
  149. icon="el-icon-delete"
  150. @click="handleStatusChange(scope.row,'3')"
  151. v-hasPermi="['live:liveRedConf:edit']"
  152. >暂停</el-button>
  153. <el-button
  154. size="mini"
  155. type="text"
  156. icon="el-icon-delete"
  157. @click="handleStatusChange(scope.row,'2')"
  158. v-hasPermi="['live:liveRedConf:edit']"
  159. >结算</el-button>
  160. <el-button
  161. size="mini"
  162. type="text"
  163. icon="el-icon-delete"
  164. @click="handleDelete(scope.row)"
  165. v-hasPermi="['live:liveRedConf:edit']"
  166. >删除</el-button>
  167. </template>
  168. </template>
  169. </el-table-column>
  170. </el-table>
  171. <pagination
  172. v-show="total>0"
  173. :total="total"
  174. :page.sync="queryParams.pageNum"
  175. :limit.sync="queryParams.pageSize"
  176. @pagination="getList"
  177. />
  178. <!-- 添加或修改直播红包记录配置对话框 -->
  179. <el-dialog :title="title" :visible.sync="open" width="520px" append-to-body>
  180. <el-form ref="form" :model="form" :rules="rules" label-width="100px">
  181. <el-form-item label="发放类型" prop="distributeType" v-if="!isPasswordBagMode">
  182. <el-radio-group v-model="form.distributeType" :disabled="form.redId != null">
  183. <el-radio :label="1">普通均分</el-radio>
  184. <el-radio :label="2">拼手气</el-radio>
  185. <el-radio :label="3">口令福袋</el-radio>
  186. </el-radio-group>
  187. </el-form-item>
  188. <el-form-item label="口令" prop="passwordCmd" v-if="showPasswordFields">
  189. <el-input
  190. v-model="form.passwordCmd"
  191. maxlength="30"
  192. show-word-limit
  193. placeholder="请输入口令,最多30字"
  194. />
  195. </el-form-item>
  196. <el-form-item :label="showPasswordFields ? '持续时间' : '持续时间'" prop="duration">
  197. <el-input v-model="form.duration" :placeholder="showPasswordFields ? '请输入持续时间(分)' : '请输入红包有效时间 单位:分'" />
  198. </el-form-item>
  199. <el-form-item label="直播间ID" prop="liveId">
  200. <el-input v-model="form.liveId" placeholder="请输入直播间ID" :disabled="canLiveId"/>
  201. </el-form-item>
  202. <el-form-item :label="showPasswordFields ? '奖励积分' : '积分'" prop="redNum">
  203. <el-input v-model="form.redNum" :placeholder="showPasswordFields ? '请输入奖励积分' : '请输入积分数量'" />
  204. </el-form-item>
  205. <el-form-item :label="showPasswordFields ? '奖励份数' : '中奖份量'" prop="totalLots">
  206. <el-input v-model="form.totalLots" :placeholder="showPasswordFields ? '请输入奖励份数' : '请输入可中奖份量'" />
  207. </el-form-item>
  208. <el-form-item :label="showPasswordFields ? '标题' : '红包标题'" prop="desc">
  209. <el-input v-model="form.desc" :placeholder="showPasswordFields ? '请输入标题' : '请输入红包描述'" />
  210. </el-form-item>
  211. </el-form>
  212. <div slot="footer" class="dialog-footer">
  213. <el-button type="primary" @click="submitForm">确 定</el-button>
  214. <el-button @click="cancel">取 消</el-button>
  215. </div>
  216. </el-dialog>
  217. </div>
  218. </template>
  219. <script>
  220. import { listLiveRedConf, getLiveRedConf, delLiveRedConf, addLiveRedConf, updateLiveRedConf, exportLiveRedConf } from "@/api/live/liveRedConf";
  221. export default {
  222. name: "LiveRedConf",
  223. props: {
  224. forceDistributeType: {
  225. type: Number,
  226. default: null
  227. }
  228. },
  229. data() {
  230. const validatePassword = (rule, value, callback) => {
  231. if (!this.showPasswordFields) {
  232. callback()
  233. return
  234. }
  235. if (!value || !String(value).trim()) {
  236. callback(new Error('口令不能为空'))
  237. } else if (String(value).trim().length > 30) {
  238. callback(new Error('口令不能超过30字'))
  239. } else {
  240. callback()
  241. }
  242. }
  243. return {
  244. //字典
  245. redStatusOptions: [],
  246. redTypeOptions: [],
  247. distributeTypeMap: {
  248. 1: '普通均分',
  249. 2: '拼手气',
  250. 3: '口令福袋'
  251. },
  252. canLiveId:false,
  253. //parentLiveId
  254. parentLiveId : null,
  255. // 遮罩层
  256. loading: true,
  257. // 导出遮罩层
  258. exportLoading: false,
  259. // 选中数组
  260. ids: [],
  261. // 非单个禁用
  262. single: true,
  263. // 非多个禁用
  264. multiple: true,
  265. // 显示搜索条件
  266. showSearch: true,
  267. // 总条数
  268. total: 0,
  269. // 直播红包记录配置表格数据
  270. liveRedConfList: [],
  271. // 弹出层标题
  272. title: "",
  273. // 是否显示弹出层
  274. open: false,
  275. // 查询参数
  276. queryParams: {
  277. pageNum: 1,
  278. pageSize: 10,
  279. redStatus: null,
  280. redType: null,
  281. liveId: null,
  282. desc: null,
  283. distributeType: null,
  284. createTime: null,
  285. updateTime: null,
  286. },
  287. // 表单参数
  288. form: {},
  289. // 表单校验
  290. rules: {
  291. distributeType: [
  292. { required: true, message: "发放类型不能为空", trigger: "change" }
  293. ],
  294. passwordCmd: [
  295. { validator: validatePassword, trigger: "blur" }
  296. ],
  297. duration: [
  298. { required: true, message: "有效时间 单位:分不能为空", trigger: "blur" }
  299. ],
  300. liveId: [
  301. { required: true, message: "直播间ID不能为空", trigger: "blur" }
  302. ],
  303. redNum: [
  304. { required: true, message: "积分数量不能为空", trigger: "blur" }
  305. ],
  306. totalLots: [
  307. { required: true, message: "份量不能为空", trigger: "blur" }
  308. ],
  309. desc: [
  310. { required: true, message: "描述不能为空", trigger: "blur" }
  311. ],
  312. },
  313. liveId: null,
  314. };
  315. },
  316. computed: {
  317. isPasswordBagMode() {
  318. return this.forceDistributeType === 3
  319. },
  320. showPasswordFields() {
  321. return this.isPasswordBagMode || Number(this.form.distributeType) === 3
  322. }
  323. },
  324. watch: {
  325. // 监听路由的 query 参数变化
  326. '$route.query': {
  327. handler(newQuery) {
  328. if (this.$route.params.liveId) {
  329. this.liveId = this.$route.params.liveId;
  330. }else {
  331. this.liveId = this.$route.query.liveId;
  332. }
  333. this.queryParams.liveId = this.liveId;
  334. this.parentLiveId = this.liveId;
  335. if (this.isPasswordBagMode) {
  336. this.queryParams.distributeType = 3
  337. }
  338. if(this.queryParams.liveId){
  339. this.form.liveId = this.parentLiveId;
  340. //设置查询条件直播间ID不可修改
  341. this.canLiveId = true;
  342. }
  343. if(this.liveId == null) {
  344. return;
  345. }
  346. this.getList();
  347. },
  348. // 初始化时立即执行一次
  349. immediate: true
  350. }
  351. },
  352. created() {
  353. if (this.isPasswordBagMode) {
  354. this.queryParams.distributeType = 3
  355. }
  356. this.getDicts("sys_live_red_status").then(response => {
  357. this.redStatusOptions = response.data;
  358. });
  359. this.getDicts("sys_live_red_type").then(response => {
  360. this.redTypeOptions = response.data;
  361. });
  362. },
  363. methods: {
  364. handleStatusChange(row, status) {
  365. if (this.$store.state.liveWs[this.liveId] == null) {
  366. this.msgError("请从直播间进行操作!");
  367. return;
  368. }
  369. //结束的抽奖不能进行操作
  370. if(row.redStatus+"" === "2"){
  371. this.msgError("已结束的红包不能进行操作");
  372. return;
  373. }
  374. switch (status+"") {
  375. case "1":
  376. //只能对未开启的抽奖进行操作
  377. if(row.redStatus+"" !== "0" && row.redStatus+"" !== "3"){
  378. this.msgError("只能对未开启或暂停的红包进行开始操作");
  379. return;
  380. }
  381. break;
  382. case "2":
  383. //只能对进行中或暂停的红包进行结算
  384. if(row.redStatus+"" !== "1" && row.redStatus+"" !== "3"){
  385. this.msgError("只能对进行中或暂停的红包进行结算");
  386. return;
  387. }
  388. break;
  389. case "3":
  390. //只能对进行中的抽奖执行暂停操作
  391. if(row.redStatus+"" !== "1"){
  392. this.msgError("只能对进行中的红包执行暂停操作");
  393. return;
  394. }
  395. break;
  396. default:
  397. return;
  398. }
  399. const doRedParam = {
  400. redId: row.redId,
  401. redStatus: status,
  402. totalLots: row.totalLots,
  403. totalSend: row.totalSend,
  404. redType: row.redType,
  405. redNum: row.redNum,
  406. liveId: this.liveId,
  407. duration: row.duration,
  408. distributeType: row.distributeType,
  409. passwordCmd: row.passwordCmd,
  410. status: status
  411. };
  412. updateLiveRedConf(doRedParam).then(response => {
  413. if(response.code === 200){
  414. const msg = {
  415. cmd: 'red',
  416. data: doRedParam
  417. };
  418. this.$store.state.liveWs[this.liveId].send(JSON.stringify(msg));
  419. this.msgSuccess("修改成功");
  420. }else{
  421. this.msgError(response.msg);
  422. }
  423. this.open = false;
  424. this.getList();
  425. });
  426. },
  427. redStatusFormatter(row, column) {
  428. return this.selectDictLabel(this.redStatusOptions, row.redStatus);
  429. },
  430. redTypeFormatter(row, column) {
  431. return this.selectDictLabel(this.redTypeOptions, row.redType);
  432. },
  433. distributeTypeFormatter(row) {
  434. return this.distributeTypeMap[row.distributeType] || this.distributeTypeMap[1]
  435. },
  436. /** 查询直播红包记录配置列表 */
  437. getList() {
  438. this.loading = true;
  439. if (this.isPasswordBagMode) {
  440. this.queryParams.distributeType = 3
  441. }
  442. listLiveRedConf(this.queryParams).then(response => {
  443. this.liveRedConfList = response.rows;
  444. this.total = response.total;
  445. this.loading = false;
  446. });
  447. },
  448. // 取消按钮
  449. cancel() {
  450. this.open = false;
  451. this.reset();
  452. },
  453. // 表单重置
  454. reset() {
  455. this.form = {
  456. redId: null,
  457. redStatus: null,
  458. duration: null,
  459. //redType: null,
  460. liveId: null,
  461. redNum: null,
  462. totalLots: null,
  463. totalSend: null,
  464. desc: null,
  465. distributeType: this.isPasswordBagMode ? 3 : 1,
  466. passwordCmd: null,
  467. createTime: null,
  468. updateTime: null,
  469. createBy: null,
  470. updateBy: null
  471. };
  472. this.resetForm("form");
  473. this.checkParentLiveId();
  474. },
  475. //判断父页面传入参数
  476. checkParentLiveId(){
  477. if(this.parentLiveId){
  478. this.form.liveId = this.parentLiveId;
  479. this.queryParams.liveId = this.parentLiveId;
  480. }
  481. },
  482. /** 搜索按钮操作 */
  483. handleQuery() {
  484. this.queryParams.pageNum = 1;
  485. this.getList();
  486. },
  487. /** 重置按钮操作 */
  488. resetQuery() {
  489. this.resetForm("queryForm");
  490. this.checkParentLiveId();
  491. if (this.isPasswordBagMode) {
  492. this.queryParams.distributeType = 3
  493. }
  494. this.handleQuery();
  495. },
  496. // 多选框选中数据
  497. handleSelectionChange(selection) {
  498. this.ids = selection.map(item => item.redId)
  499. this.single = selection.length!==1
  500. this.multiple = !selection.length
  501. },
  502. /** 新增按钮操作 */
  503. handleAdd() {
  504. this.reset();
  505. this.open = true;
  506. this.title = this.isPasswordBagMode ? "添加口令福袋" : "添加直播红包记录配置";
  507. },
  508. /** 修改按钮操作 */
  509. handleUpdate(row) {
  510. //只能对未开始或暂停的抽奖进行修改
  511. if(row.redStatus+"" !== "0" && row.redStatus+"" !== "3"){
  512. this.msgError("只能对未开始或暂停的红包进行修改");
  513. return;
  514. }
  515. this.reset();
  516. const redId = row.redId || this.ids
  517. getLiveRedConf(redId).then(response => {
  518. this.form = response.data;
  519. if (this.form.distributeType == null) {
  520. this.form.distributeType = 1
  521. }
  522. this.open = true;
  523. this.title = this.isPasswordBagMode ? "修改口令福袋" : "修改直播红包记录配置";
  524. });
  525. },
  526. /** 提交按钮 */
  527. submitForm() {
  528. this.$refs["form"].validate(valid => {
  529. if (valid) {
  530. const data = {
  531. ...this.form,
  532. distributeType: this.isPasswordBagMode ? 3 : this.form.distributeType,
  533. passwordCmd: this.showPasswordFields && this.form.passwordCmd
  534. ? String(this.form.passwordCmd).trim()
  535. : this.form.passwordCmd
  536. }
  537. if (data.redId != null) {
  538. updateLiveRedConf(data).then(response => {
  539. this.msgSuccess("修改成功");
  540. this.open = false;
  541. this.getList();
  542. });
  543. } else {
  544. data.redType = 1;
  545. addLiveRedConf(data).then(response => {
  546. this.msgSuccess("新增成功");
  547. this.open = false;
  548. this.getList();
  549. });
  550. }
  551. }
  552. });
  553. },
  554. /** 删除按钮操作 */
  555. handleDelete(row) {
  556. // 口令福袋允许按状态删除;普通红包仅未发放可删
  557. if (!this.isPasswordBagMode && row.redStatus+"" !== "0") {
  558. this.msgError("只能删除未发放的红包");
  559. return;
  560. }
  561. const redIds = row.redId || this.ids;
  562. this.$confirm('是否确认删除直播红包记录配置编号为"' + redIds + '"的数据项?', "警告", {
  563. confirmButtonText: "确定",
  564. cancelButtonText: "取消",
  565. type: "warning"
  566. }).then(function() {
  567. return delLiveRedConf(redIds);
  568. }).then(() => {
  569. this.getList();
  570. this.msgSuccess("删除成功");
  571. if (this.$store.state.liveWs[this.liveId]) {
  572. const msg = {
  573. cmd: 'red',
  574. data: {
  575. redId: row.redId,
  576. redStatus: 2,
  577. totalLots: row.totalLots,
  578. duration: row.duration,
  579. distributeType: row.distributeType,
  580. passwordCmd: row.passwordCmd
  581. }
  582. };
  583. this.$store.state.liveWs[this.liveId].send(JSON.stringify(msg));
  584. }
  585. }).catch(() => {});
  586. },
  587. /** 导出按钮操作 */
  588. handleExport() {
  589. const queryParams = this.queryParams;
  590. this.$confirm('是否确认导出所有直播红包记录配置数据项?', "警告", {
  591. confirmButtonText: "确定",
  592. cancelButtonText: "取消",
  593. type: "warning"
  594. }).then(() => {
  595. this.exportLoading = true;
  596. return exportLiveRedConf(queryParams);
  597. }).then(response => {
  598. this.download(response.msg);
  599. this.exportLoading = false;
  600. }).catch(() => {});
  601. }
  602. }
  603. };
  604. </script>