task.vue 28 KB

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