task.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  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="直播间ID" prop="liveId">
  5. <el-input
  6. v-model="queryParams.liveId"
  7. placeholder="请输入直播间ID"
  8. clearable
  9. :disabled="liveAbled"
  10. size="small"
  11. @keyup.enter.native="handleQuery"
  12. />
  13. </el-form-item>
  14. <el-form-item label="任务名称" prop="taskName">
  15. <el-input
  16. v-model="queryParams.taskName"
  17. placeholder="请输入任务名称"
  18. clearable
  19. size="small"
  20. @keyup.enter.native="handleQuery"
  21. />
  22. </el-form-item>
  23. <el-form-item label="任务类型" prop="taskType">
  24. <el-select v-model="queryParams.taskType" placeholder="请选择任务类型" clearable size="small">
  25. <el-option v-for="i in taskTypeOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
  26. </el-select>
  27. </el-form-item>
  28. <!-- <el-form-item label="触发类型" prop="triggerType">-->
  29. <!-- <el-select v-model="queryParams.triggerType" placeholder="请选择触发类型" clearable size="small">-->
  30. <!-- <el-option v-for="i in triggerTypeOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>-->
  31. <!-- </el-select>-->
  32. <!-- </el-form-item>-->
  33. <el-form-item label="状态" prop="status">
  34. <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
  35. <el-option v-for="i in statusOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item>
  39. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  40. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  41. </el-form-item>
  42. </el-form>
  43. <el-row :gutter="10" class="mb8">
  44. <el-col :span="1.5">
  45. <el-button
  46. :disabled="isViewOnly"
  47. type="primary"
  48. plain
  49. icon="el-icon-plus"
  50. size="mini"
  51. @click="handleAdd"
  52. v-hasPermi="['live:task:add']"
  53. >新增</el-button>
  54. </el-col>
  55. <el-col :span="1.5">
  56. <el-button
  57. type="success"
  58. plain
  59. icon="el-icon-edit"
  60. size="mini"
  61. :disabled="single || isViewOnly"
  62. @click="handleUpdate"
  63. v-hasPermi="['live:task:edit']"
  64. >修改</el-button>
  65. </el-col>
  66. <el-col :span="1.5">
  67. <el-button
  68. type="danger"
  69. plain
  70. icon="el-icon-delete"
  71. size="mini"
  72. :disabled="multiple || isViewOnly"
  73. @click="handleDelete"
  74. v-hasPermi="['live:task:remove']"
  75. >删除</el-button>
  76. </el-col>
  77. <el-col :span="1.5">
  78. <el-button
  79. :disabled="isViewOnly"
  80. type="warning"
  81. plain
  82. icon="el-icon-download"
  83. size="mini"
  84. :loading="exportLoading"
  85. @click="handleExport"
  86. v-hasPermi="['live:task:export']"
  87. >导出</el-button>
  88. </el-col>
  89. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  90. </el-row>
  91. <el-table border v-loading="loading" :data="taskList" @selection-change="handleSelectionChange">
  92. <el-table-column type="selection" width="55" align="center" />
  93. <el-table-column label="编号" align="center" prop="id" />
  94. <el-table-column label="任务名称" align="center" prop="taskName" />
  95. <el-table-column label="任务类型" align="center" prop="taskType" :formatter="taskTypeFormatter" />
  96. <el-table-column label="触发类型" align="center" prop="triggerType" :formatter="triggerTypeFormatter" />
  97. <el-table-column label="触发时间" align="center" prop="triggerValue" :formatter="triggerValueFormatter" />
  98. <el-table-column label="产品名称" align="center" prop="productName" :formatter="productNameFormatter" />
  99. <el-table-column label="状态" align="center" prop="status" :formatter="statusFormatter" />
  100. <!-- <el-table-column label="完成状态" align="center" prop="finishStatus" :formatter="finishStatusFormatter" />-->
  101. <el-table-column label="更新时间" align="center" prop="updatedTime" width="180">
  102. <template slot-scope="scope">
  103. <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
  104. </template>
  105. </el-table-column>
  106. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  107. <template slot-scope="scope">
  108. <el-button
  109. :disabled="isViewOnly"
  110. size="mini"
  111. type="text"
  112. icon="el-icon-edit"
  113. @click="handleUpdate(scope.row)"
  114. v-hasPermi="['live:task:edit']"
  115. >修改</el-button>
  116. <el-button
  117. :disabled="isViewOnly"
  118. size="mini"
  119. type="text"
  120. icon="el-icon-delete"
  121. @click="handleDelete(scope.row)"
  122. v-hasPermi="['live:task:remove']"
  123. >删除</el-button>
  124. </template>
  125. </el-table-column>
  126. </el-table>
  127. <pagination
  128. v-show="total>0"
  129. :total="total"
  130. :page.sync="queryParams.pageNum"
  131. :limit.sync="queryParams.pageSize"
  132. @pagination="getList"
  133. />
  134. <!-- 添加或修改直播间自动化任务配置对话框 -->
  135. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  136. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  137. <el-form-item label="直播间ID" prop="liveId">
  138. <el-input :disabled="liveAbled" v-model="form.liveId" placeholder="请输入直播间ID" />
  139. </el-form-item>
  140. <el-form-item label="任务名称" prop="taskName">
  141. <el-input v-model="form.taskName" placeholder="请输入任务名称" />
  142. </el-form-item>
  143. <el-form-item label="任务类型" prop="taskType">
  144. <el-select v-model="form.taskType" placeholder="请选择任务类型" @change="updateTaskType()" >
  145. <el-option v-for="i in taskTypeOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
  146. </el-select>
  147. </el-form-item>
  148. <el-form-item label="商品选择" prop="content" v-if="form.taskType == 1">
  149. <el-select v-model="form.content" placeholder="请选择商品" ref="selectRef" >
  150. <el-option v-for="i in productOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
  151. <!-- 加载载中状态 -->
  152. <div v-if="isLoading" class="loading-indicator">
  153. <i class="el-icon-loading"></i>
  154. <span>加载中...</span>
  155. </div>
  156. <!-- 没有更多数据 -->
  157. <div v-if="!hasMore && !isLoading" class="no-more">
  158. 没有更多数据了
  159. </div>
  160. </el-select>
  161. </el-form-item>
  162. <el-form-item label="红包选择" prop="content" v-if="form.taskType == 2">
  163. <el-select v-model="form.content" placeholder="请选择红包" ref="selectRef" >
  164. <el-option v-for="i in redOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
  165. <!-- 加载载中状态 -->
  166. <div v-if="isLoading" class="loading-indicator">
  167. <i class="el-icon-loading"></i>
  168. <span>加载中...</span>
  169. </div>
  170. <!-- 没有更多数据 -->
  171. <div v-if="!hasMore && !isLoading" class="no-more">
  172. 没有更多数据了
  173. </div>
  174. </el-select>
  175. </el-form-item>
  176. <el-form-item label="抽奖选择" prop="content" v-if="form.taskType == 4">
  177. <el-select v-model="form.content" placeholder="请选择抽奖" ref="selectRef" >
  178. <el-option v-for="i in lotteryOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
  179. <!-- 加载载中状态 -->
  180. <div v-if="isLoading" class="loading-indicator">
  181. <i class="el-icon-loading"></i>
  182. <span>加载中...</span>
  183. </div>
  184. <!-- 没有更多数据 -->
  185. <div v-if="!hasMore && !isLoading" class="no-more">
  186. 没有更多数据了
  187. </div>
  188. </el-select>
  189. </el-form-item>
  190. <el-form-item label="优惠券" prop="content" v-if="form.taskType == 5">
  191. <el-select v-model="form.content" placeholder="请选择优惠券" ref="selectCoupon" >
  192. <el-option v-for="i in couponOptions" :key="i.value" :label="i.label" :value="i.value"></el-option>
  193. <!-- 加载载中状态 -->
  194. <div v-if="isLoading" class="loading-indicator">
  195. <i class="el-icon-loading"></i>
  196. <span>加载中...</span>
  197. </div>
  198. <!-- 没有更多数据 -->
  199. <div v-if="!hasMore && !isLoading" class="no-more">
  200. 没有更多数据了
  201. </div>
  202. </el-select>
  203. </el-form-item>
  204. <el-form-item label="触发时间" prop="content">
  205. <el-time-picker
  206. default-value="2025-01-01 00:00:00"
  207. v-model="form.triggerValue"
  208. :picker-options="{
  209. selectableRange: '00:00:00 - 23:59:59'
  210. }"
  211. placeholder="任意时间点">
  212. </el-time-picker>
  213. </el-form-item>
  214. <!-- <el-form-item label="触发类型" prop="triggerType">-->
  215. <!-- <el-select v-model="form.triggerType" placeholder="请选择触发类型">-->
  216. <!-- <el-option label="请选择字典生成" value="" />-->
  217. <!-- </el-select>-->
  218. <!-- </el-form-item>-->
  219. <!-- <el-form-item label="触发值" prop="triggerValue">-->
  220. <!-- <el-input v-model="form.triggerValue" placeholder="请输入触发值" />-->
  221. <!-- </el-form-item>-->
  222. <!-- <el-form-item label="任务内容">-->
  223. <!-- <editor v-model="form.content" :min-height="192"/>-->
  224. <!-- </el-form-item>-->
  225. <el-form-item label="状态">
  226. <el-radio-group v-model="form.status">
  227. <el-radio :label="1">启用</el-radio>
  228. <el-radio :label="0">禁用</el-radio>
  229. </el-radio-group>
  230. </el-form-item>
  231. </el-form>
  232. <div slot="footer" class="dialog-footer">
  233. <el-button type="primary" @click="submitForm">确 定</el-button>
  234. <el-button @click="cancel">取 消</el-button>
  235. </div>
  236. </el-dialog>
  237. </div>
  238. </template>
  239. <script>
  240. import { listTask, getTask, delTask, addTask, updateTask, exportTask } from "@/api/live/task";
  241. import {listLiveGoods} from "@/api/live/liveGoods";
  242. import {listLiveRedConfOn} from "@/api/live/liveRedConf";
  243. import {listLiveLotteryConfOn} from "@/api/live/liveLotteryConf";
  244. import {listLiveCouponOn} from "@/api/live/liveCoupon";
  245. export default {
  246. props:{
  247. isViewOnly: {
  248. type: Boolean,
  249. default: false,
  250. }
  251. },
  252. name: "Task",
  253. data() {
  254. return {
  255. taskTypeOptions:[
  256. {
  257. value: 1,
  258. label: "定时卡片推荐商品"
  259. },
  260. {
  261. value: 2,
  262. label: "定时红包发送"
  263. },
  264. {
  265. value: 4,
  266. label: "定时抽奖"
  267. },
  268. {
  269. value: 5,
  270. label: "定时优惠券"
  271. }
  272. ],
  273. statusOptions:[{
  274. value: "0",
  275. label: "禁用"
  276. },
  277. {
  278. value: "1",
  279. label: "启用"
  280. }
  281. ],
  282. productOptions:[],
  283. haveData:{
  284. goods:false,
  285. red:false,
  286. lottery:false,
  287. coupon:false
  288. },
  289. redOptions:[],
  290. lotteryOptions:[],
  291. couponOptions:[],
  292. // 遮罩层
  293. loading: true,
  294. // 导出遮罩层
  295. exportLoading: false,
  296. // 选中数组
  297. ids: [],
  298. // 非单个禁用
  299. single: true,
  300. // 非多个禁用
  301. multiple: true,
  302. // 显示搜索条件
  303. showSearch: true,
  304. // 总条数
  305. total: 0,
  306. liveAbled: false,
  307. // 直播间自动化任务配置表格数据
  308. taskList: [],
  309. // 弹出层标题
  310. title: "",
  311. // 是否显示弹出层
  312. open: false,
  313. // 查询参数
  314. queryParams: {
  315. pageNum: 1,
  316. pageSize: 10,
  317. liveId: null,
  318. taskName: null,
  319. taskType: null,
  320. triggerType: null,
  321. triggerValue: null,
  322. content: null,
  323. status: null,
  324. createdTime: null,
  325. updatedTime: null
  326. },
  327. // 表单参数
  328. form: {},
  329. // 表单校验
  330. rules: {
  331. liveId: [
  332. { required: true, message: "直播间ID不能为空", trigger: "blur" }
  333. ],
  334. taskName: [
  335. { required: true, message: "任务名称不能为空", trigger: "blur" }
  336. ],
  337. taskType: [
  338. { required: true, message: "任务类型:1-定时推送卡片商品 2-定时发送红包 ", trigger: "change" }
  339. ],
  340. triggerType: [
  341. { required: true, message: "触发类型:相对直播开始时间不能为空", trigger: "change" }
  342. ],
  343. triggerValue: [
  344. { required: true, message: "触发值:绝对时间用yyyy-MM-dd HH:mm:ss,相对时间用分钟数不能为空", trigger: "blur" }
  345. ],
  346. status: [
  347. { required: true, message: "状态:0-禁用 1-启用不能为空", trigger: "blur" }
  348. ],
  349. createdTime: [
  350. { required: true, message: "创建时间不能为空", trigger: "blur" }
  351. ],
  352. updatedTime: [
  353. { required: true, message: "更新时间不能为空", trigger: "blur" }
  354. ]
  355. },
  356. liveId: null,
  357. listParams: {
  358. pageNum: 1,
  359. pageSize: 10,
  360. liveId: null
  361. },
  362. socket: null,
  363. isLoading: false, // 是否正在加载
  364. hasMore: true, // 是否还有更多数据
  365. };
  366. },
  367. watch: {
  368. // 监听路由的 query 参数变化
  369. '$route.query': {
  370. handler(newQuery) {
  371. if (this.$route.params.liveId) {
  372. this.liveId = this.$route.params.liveId;
  373. }else {
  374. this.liveId = this.$route.query.liveId;
  375. }
  376. if(this.liveId == null) {
  377. return;
  378. }
  379. this.liveAbled = true
  380. this.queryParams.liveId = this.liveId;
  381. this.getList();
  382. },
  383. // 初始化时立即执行一次
  384. immediate: true
  385. }
  386. },
  387. created() {
  388. this.socket = this.$store.state.liveWs[this.liveId]
  389. },
  390. methods: {
  391. statusFormatter(row, column, value){
  392. if (!value) return '--'; // 空值处理
  393. switch ( value){
  394. case 0:
  395. return "禁用";
  396. case 1:
  397. return "启用";
  398. default:
  399. return "--";
  400. }
  401. },
  402. finishStatusFormatter(row, column, value){
  403. if (!value) return '--'; // 空值处理
  404. switch ( value){
  405. case 0:
  406. return "未执行";
  407. case 1:
  408. return "已执行";
  409. default:
  410. return "--";
  411. }
  412. },
  413. taskTypeFormatter(row, column, value){
  414. if (!value) return '--'; // 空值处理
  415. switch (value) {
  416. case 1:
  417. return "定时推送卡片商品";
  418. case 2:
  419. return "定时发送红包";
  420. case 4:
  421. return "定时抽奖";
  422. case 5:
  423. return "定时优惠券";
  424. default:
  425. return "--";
  426. }
  427. },
  428. triggerTypeFormatter(row, column, value){
  429. if (!value) return '--'; // 空值处理
  430. switch (value) {
  431. case 1:
  432. return "相对直播开始时间";
  433. case 2:
  434. return "相对时间";
  435. default:
  436. return "--";
  437. }
  438. },
  439. productNameFormatter(row, column, value){
  440. let content = JSON.parse(row.content)
  441. if(content.productName) {
  442. return content.productName
  443. }
  444. return "--";
  445. },
  446. triggerValueFormatter(row, column, value) {
  447. if (!value) return '--'; // 空值处理
  448. // 创建日期对象(兼容时间戳和字符串)
  449. let date;
  450. if (typeof value === 'number') {
  451. // 处理时间戳(注意:如果是10位时间戳需要乘以1000)
  452. date = new Date(value.toString().length === 10 ? value * 1000 : value);
  453. } else if (typeof value === 'string') {
  454. // 处理字符串格式(尝试直接转换)
  455. date = new Date(value);
  456. } else {
  457. return '格式错误';
  458. }
  459. // 检查日期是否有效
  460. if (isNaN(date.getTime())) {
  461. return '无效时间';
  462. }
  463. // 格式化日期为 "yyyy-MM-dd HH:mm:ss"
  464. const hours = String(date.getHours()).padStart(2, '0');
  465. const minutes = String(date.getMinutes()).padStart(2, '0');
  466. const seconds = String(date.getSeconds()).padStart(2, '0');
  467. return `${hours}:${minutes}:${seconds}`;
  468. },
  469. async updateTaskType(){
  470. this.hasMore = true;
  471. this.listParams = {
  472. pageNum: 1,
  473. pageSize: 10,
  474. liveId: null
  475. }
  476. if (this.isLoading || !this.hasMore) return;
  477. this.isLoading = true;
  478. this.listParams.liveId = this.liveId;
  479. if(this.listParams.liveId == null) {
  480. this.$message.error("页面错误,请联系管理员");
  481. return;
  482. }
  483. try{
  484. if (this.form.taskType == 1) {
  485. await this.addGoodsList();
  486. }else if (this.form.taskType == 2) {
  487. await this.addRedList();
  488. }else if (this.form.taskType == 4) {
  489. await this.addLotteryList();
  490. }else if(this.form.taskType == 5){
  491. await this.addCouponList();
  492. }
  493. }catch ( err){
  494. console.error('加载数据失败:', err);
  495. }finally {
  496. this.isLoading = false;
  497. }
  498. },
  499. addGoodsList() {
  500. if(this.haveData.goods) return
  501. listLiveGoods(this.listParams).then(res => {
  502. if(res.rows.length > 0) {
  503. res.rows.forEach(item => {
  504. // 根据productName和goodsId组装成为label和value
  505. this.productOptions.push({
  506. value: item.goodsId,
  507. label: item.productName
  508. })
  509. })
  510. this.listParams.pageNum++;
  511. // 判断是否还有更多数据
  512. this.hasMore = this.productOptions.length < res.total;
  513. if (this.hasMore) {
  514. this.addGoodsList();
  515. } else {
  516. this.haveData.goods = true;
  517. }
  518. } else {
  519. this.hasMore = false;
  520. this.haveData.goods = true;
  521. }
  522. });
  523. },
  524. addRedList() {
  525. if(this.haveData.red) return
  526. listLiveRedConfOn(this.listParams).then(res => {
  527. if(res.rows.length > 0) {
  528. res.rows.forEach(item => {
  529. // 根据productName和goodsId组装成为label和value
  530. this.redOptions.push({
  531. value: item.redId,
  532. label: item.desc
  533. })
  534. })
  535. this.listParams.pageNum++;
  536. // 判断是否还有更多数据
  537. this.hasMore = this.redOptions.length < res.total;
  538. if (this.hasMore) {
  539. this.addRedList();
  540. } else {
  541. this.haveData.red = true
  542. }
  543. } else {
  544. this.haveData.red = true
  545. this.hasMore = false;
  546. }
  547. });
  548. },
  549. addLotteryList() {
  550. if(this.haveData.lottery) return
  551. listLiveLotteryConfOn(this.listParams).then(res => {
  552. if(res.rows.length > 0) {
  553. res.rows.forEach(item => {
  554. // 根据productName和goodsId组装成为label和value
  555. this.lotteryOptions.push({
  556. value: item.lotteryId,
  557. label: item.desc
  558. })
  559. })
  560. this.listParams.pageNum++;
  561. // 判断是否还有更多数据
  562. this.hasMore = this.lotteryOptions.length < res.total;
  563. if (this.hasMore) {
  564. this.addLotteryList();
  565. } else {
  566. this.haveData.lottery = true
  567. }
  568. } else {
  569. this.haveData.lottery = true
  570. this.hasMore = false;
  571. }
  572. });
  573. },
  574. addCouponList() {
  575. if(this.haveData.coupon) return
  576. listLiveCouponOn(this.listParams).then(res => {
  577. if(res.rows.length > 0) {
  578. res.rows.forEach(item => {
  579. // 根据productName和goodsId组装成为label和value
  580. this.couponOptions.push({
  581. value: item.couponId,
  582. label: item.title
  583. })
  584. })
  585. this.listParams.pageNum++;
  586. // 判断是否还有更多数据
  587. this.hasMore = this.couponOptions.length < res.total;
  588. if (this.hasMore) {
  589. this.addCouponList();
  590. } else {
  591. this.haveData.coupon = true
  592. }
  593. } else {
  594. this.haveData.coupon = true
  595. this.hasMore = false;
  596. }
  597. });
  598. },
  599. /** 查询直播间自动化任务配置列表 */
  600. getList() {
  601. if(this.liveId == null) {
  602. this.$message.error("页面错误,请联系管理员");
  603. return;
  604. }
  605. this.loading = true;
  606. listTask(this.queryParams).then(res => {
  607. this.taskList = res.rows;
  608. this.total = res.total;
  609. this.loading = false;
  610. });
  611. },
  612. // 取消按钮
  613. cancel() {
  614. this.open = false;
  615. this.reset();
  616. },
  617. // 表单重置
  618. reset() {
  619. this.form = {
  620. id: null,
  621. liveId: this.liveId,
  622. taskName: null,
  623. taskType: null,
  624. triggerType: null,
  625. triggerValue: null,
  626. content: null,
  627. status: 1,
  628. createdTime: null,
  629. updatedTime: null
  630. };
  631. this.listParams={
  632. pageNum: 1,
  633. pageSize: 10,
  634. liveId: this.liveId
  635. }
  636. this.hasMore = true;
  637. this.resetForm("form");
  638. },
  639. /** 搜索按钮操作 */
  640. handleQuery() {
  641. this.queryParams.pageNum = 1;
  642. this.getList();
  643. },
  644. /** 重置按钮操作 */
  645. resetQuery() {
  646. this.resetForm("queryForm");
  647. this.handleQuery();
  648. },
  649. // 多选框选中数据
  650. handleSelectionChange(selection) {
  651. this.ids = selection.map(item => item.id)
  652. this.single = selection.length!==1
  653. this.multiple = !selection.length
  654. },
  655. /** 新增按钮操作 */
  656. handleAdd() {
  657. this.reset();
  658. this.open = true;
  659. this.title = "添加直播间自动化任务配置";
  660. },
  661. /** 修改按钮操作 */
  662. async handleUpdate(row) {
  663. this.reset();
  664. if(row.taskType == 1){
  665. await this.addGoodsList();
  666. }else if(row.taskType == 2){
  667. await this.addRedList();
  668. }else if(row.taskType == 4){
  669. await this.addLotteryList();
  670. }else if(row.taskType == 5) {
  671. await this.addCouponList();
  672. }
  673. const id = row.id || this.ids
  674. getTask(id).then(response => {
  675. this.form = response.data;
  676. let content = JSON.parse( response.data.content)
  677. if (this.form.taskType == 1) {
  678. this.form.content = content.goodsId;
  679. }else if (this.form.taskType == 2) {
  680. this.form.content = content.desc;
  681. }else if (this.form.taskType == 4) {
  682. this.form.content = content.desc;
  683. }else if(this.form.taskType == 5){
  684. this.form.content = content.couponId;
  685. }
  686. this.open = true;
  687. this.title = "修改直播间自动化任务配置";
  688. });
  689. },
  690. /** 提交按钮 */
  691. submitForm() {
  692. this.form.liveId = this.liveId;
  693. if(this.liveId == null) {
  694. this.msgError("请选择直播间");
  695. return;
  696. }
  697. this.$refs["form"].validate(valid => {
  698. if (valid) {
  699. if (this.form.id != null) {
  700. updateTask(this.form).then(response => {
  701. this.msgSuccess("修改成功");
  702. this.open = false;
  703. this.getList();
  704. });
  705. } else {
  706. addTask(this.form).then(response => {
  707. this.msgSuccess("新增成功");
  708. this.open = false;
  709. this.getList();
  710. });
  711. }
  712. }
  713. });
  714. },
  715. /** 删除按钮操作 */
  716. handleDelete(row) {
  717. if(this.socket == null) {
  718. this.$message.error("请进入直播间后,在进行操作!")
  719. return;
  720. }
  721. const ids = row.id || this.ids;
  722. this.$confirm('是否确认删除直播间自动化任务配置编号为"' + ids + '"的数据项?', "警告", {
  723. confirmButtonText: "确定",
  724. cancelButtonText: "取消",
  725. type: "warning"
  726. }).then(function() {
  727. return delTask(ids);
  728. }).then(() => {
  729. this.getList();
  730. this.msgSuccess("删除成功");
  731. const msg={
  732. cmd:'delAutoTask',
  733. data:row.absValue,
  734. liveId:this.liveId,
  735. userType:1
  736. }
  737. this.socket.send(JSON.stringify( msg))
  738. }).catch(() => {});
  739. },
  740. /** 导出按钮操作 */
  741. handleExport() {
  742. const queryParams = this.queryParams;
  743. this.$confirm('是否确认导出所有直播间自动化任务配置数据项?', "警告", {
  744. confirmButtonText: "确定",
  745. cancelButtonText: "取消",
  746. type: "warning"
  747. }).then(() => {
  748. this.exportLoading = true;
  749. return exportTask(queryParams);
  750. }).then(response => {
  751. this.download(response.msg);
  752. this.exportLoading = false;
  753. }).catch(() => {});
  754. },
  755. }
  756. };
  757. </script>
  758. <style scoped>
  759. .loading-indicator {
  760. padding: 10px;
  761. text-align: center;
  762. color: #606266;
  763. font-size: 12px;
  764. display: flex;
  765. align-items: center;
  766. justify-content: center;
  767. }
  768. .loading-indicator .el-icon-loading {
  769. margin-right: 5px;
  770. animation: rotate 1s linear infinite;
  771. }
  772. .no-more {
  773. padding: 10px;
  774. text-align: center;
  775. color: #909399;
  776. font-size: 12px;
  777. }
  778. @keyframes rotate {
  779. from { transform: rotate(0deg); }
  780. to { transform: rotate(360deg); }
  781. }
  782. </style>