index.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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="giftName">
  5. <el-input
  6. v-model="queryParams.giftName"
  7. placeholder="请输入礼物名称"
  8. clearable
  9. size="small"
  10. @keyup.enter.native="handleQuery"
  11. />
  12. </el-form-item>
  13. <el-form-item label="礼物当前状态" prop="status" label-width="120px">
  14. <el-select v-model="queryParams.status" placeholder="请选择礼物当前状态" clearable size="small">
  15. <el-option
  16. v-for="dict in statusOptions"
  17. :key="dict.dictValue"
  18. :label="dict.dictLabel"
  19. :value="dict.dictValue"
  20. ></el-option>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item>
  24. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  25. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  26. </el-form-item>
  27. </el-form>
  28. <el-row :gutter="10" class="mb8">
  29. <el-col :span="1.5">
  30. <el-button
  31. type="primary"
  32. plain
  33. icon="el-icon-plus"
  34. size="mini"
  35. @click="handleAdd"
  36. v-hasPermi="['live:gift:add']"
  37. >新增</el-button>
  38. </el-col>
  39. <el-col :span="1.5">
  40. <el-button
  41. type="success"
  42. plain
  43. icon="el-icon-edit"
  44. size="mini"
  45. :disabled="single"
  46. @click="handleUpdate"
  47. v-hasPermi="['live:gift:edit']"
  48. >修改</el-button>
  49. </el-col>
  50. <el-col :span="1.5">
  51. <el-button
  52. type="danger"
  53. plain
  54. icon="el-icon-delete"
  55. size="mini"
  56. :disabled="multiple"
  57. @click="handleDelete"
  58. v-hasPermi="['live:gift:remove']"
  59. >删除</el-button>
  60. </el-col>
  61. <el-col :span="1.5">
  62. <el-button
  63. type="warning"
  64. plain
  65. icon="el-icon-download"
  66. size="mini"
  67. :loading="exportLoading"
  68. @click="handleExport"
  69. v-hasPermi="['live:gift:export']"
  70. >导出</el-button>
  71. </el-col>
  72. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  73. </el-row>
  74. <el-table border v-loading="loading" :data="giftList" @selection-change="handleSelectionChange">
  75. <el-table-column type="selection" width="55" align="center" />
  76. <el-table-column label="礼物唯一标识" align="center" prop="giftId" />
  77. <el-table-column label="礼物名称" align="center" prop="giftName" />
  78. <el-table-column label="礼物描述" align="center" prop="description" />
  79. <el-table-column label="礼物图标链接地址" align="center" prop="iconUrl" />
  80. <el-table-column label="礼物价格" align="center" prop="price" />
  81. <el-table-column label="礼物当前状态" align="center" prop="status" :formatter="formatStatus" />
  82. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  83. <template slot-scope="scope">
  84. <el-button
  85. size="mini"
  86. type="text"
  87. icon="el-icon-edit"
  88. @click="handleUpdate(scope.row)"
  89. v-hasPermi="['live:gift:edit']"
  90. >修改</el-button>
  91. <el-button
  92. size="mini"
  93. type="text"
  94. icon="el-icon-delete"
  95. @click="handleDelete(scope.row)"
  96. v-hasPermi="['live:gift:remove']"
  97. >删除</el-button>
  98. </template>
  99. </el-table-column>
  100. </el-table>
  101. <pagination
  102. v-show="total>0"
  103. :total="total"
  104. :page.sync="queryParams.pageNum"
  105. :limit.sync="queryParams.pageSize"
  106. @pagination="getList"
  107. />
  108. <!-- 添加或修改直播间礼物配置对话框 -->
  109. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  110. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  111. <el-form-item label="礼物名称" prop="giftName">
  112. <el-input v-model="form.giftName" placeholder="请输入礼物名称" />
  113. </el-form-item>
  114. <el-form-item label="礼物描述" prop="description">
  115. <el-input v-model="form.description" type="textarea" placeholder="请输入内容" />
  116. </el-form-item>
  117. <el-form-item label="图标链接地址" prop="iconUrl">
  118. <el-input v-model="form.iconUrl" placeholder="请输入礼物图标链接地址" />
  119. </el-form-item>
  120. <el-form-item label="礼物价格" prop="price">
  121. <el-input v-model="form.price" placeholder="请输入礼物价格" />
  122. </el-form-item>
  123. <el-form-item label="礼物当前状态">
  124. <el-radio-group v-model="form.status">
  125. <el-radio
  126. v-for="dict in statusOptions"
  127. :key="dict.dictValue"
  128. :label="dict.dictValue"
  129. >
  130. {{ dict.dictLabel }}
  131. </el-radio>
  132. </el-radio-group>
  133. </el-form-item>
  134. </el-form>
  135. <div slot="footer" class="dialog-footer">
  136. <el-button type="primary" @click="submitForm">确 定</el-button>
  137. <el-button @click="cancel">取 消</el-button>
  138. </div>
  139. </el-dialog>
  140. </div>
  141. </template>
  142. <script>
  143. import { listGift, getGift, delGift, addGift, updateGift, exportGift,getDictData } from "@/api/live/gift";
  144. export default {
  145. name: "Gift",
  146. data() {
  147. return {
  148. // 遮罩层
  149. loading: true,
  150. // 导出遮罩层
  151. exportLoading: false,
  152. // 选中数组
  153. ids: [],
  154. // 非单个禁用
  155. single: true,
  156. // 非多个禁用
  157. multiple: true,
  158. // 显示搜索条件
  159. showSearch: true,
  160. // 总条数
  161. total: 0,
  162. // 直播间礼物配置表格数据
  163. giftList: [],
  164. // 弹出层标题
  165. title: "",
  166. // 是否显示弹出层
  167. open: false,
  168. // 查询参数
  169. queryParams: {
  170. pageNum: 1,
  171. pageSize: 10,
  172. giftName: null,
  173. description: null,
  174. status: null
  175. },
  176. statusOptions:[],
  177. // 表单参数
  178. form: {},
  179. // 表单校验
  180. rules: {
  181. giftName: [
  182. { required: true, message: "礼物名称不能为空", trigger: "blur" }
  183. ],
  184. price: [
  185. { required: true, message: "礼物价格不能为空", trigger: "blur" }
  186. ],
  187. }
  188. };
  189. },
  190. created() {
  191. this.getList();
  192. this.getDict();
  193. },
  194. methods: {
  195. formatStatus(row, column, cellValue) {
  196. const found = this.statusOptions.find(d => d.dictValue === cellValue);
  197. return found ? found.dictLabel : '未知';
  198. },
  199. getDict() {
  200. getDictData("sys_normal_disable").then(response => {
  201. this.statusOptions = response.data;
  202. });
  203. },
  204. /** 查询直播间礼物配置列表 */
  205. getList() {
  206. this.loading = true;
  207. listGift(this.queryParams).then(response => {
  208. this.giftList = response.rows;
  209. this.total = response.total;
  210. this.loading = false;
  211. });
  212. },
  213. // 取消按钮
  214. cancel() {
  215. this.open = false;
  216. this.reset();
  217. },
  218. // 表单重置
  219. reset() {
  220. this.form = {
  221. giftId: null,
  222. giftName: null,
  223. description: null,
  224. iconUrl: null,
  225. price: null,
  226. status: "0"
  227. };
  228. this.resetForm("form");
  229. },
  230. /** 搜索按钮操作 */
  231. handleQuery() {
  232. this.queryParams.pageNum = 1;
  233. this.getList();
  234. },
  235. /** 重置按钮操作 */
  236. resetQuery() {
  237. this.resetForm("queryForm");
  238. this.handleQuery();
  239. },
  240. // 多选框选中数据
  241. handleSelectionChange(selection) {
  242. this.ids = selection.map(item => item.giftId)
  243. this.single = selection.length!==1
  244. this.multiple = !selection.length
  245. },
  246. /** 新增按钮操作 */
  247. handleAdd() {
  248. this.reset();
  249. this.open = true;
  250. this.title = "添加直播间礼物配置";
  251. },
  252. /** 修改按钮操作 */
  253. handleUpdate(row) {
  254. this.reset();
  255. const giftId = row.giftId || this.ids
  256. getGift(giftId).then(response => {
  257. this.form = response.data;
  258. this.open = true;
  259. this.title = "修改直播间礼物配置";
  260. });
  261. },
  262. /** 提交按钮 */
  263. submitForm() {
  264. this.$refs["form"].validate(valid => {
  265. if (valid) {
  266. if (this.form.giftId != null) {
  267. updateGift(this.form).then(response => {
  268. this.msgSuccess("修改成功");
  269. this.open = false;
  270. this.getList();
  271. });
  272. } else {
  273. addGift(this.form).then(response => {
  274. this.msgSuccess("新增成功");
  275. this.open = false;
  276. this.getList();
  277. });
  278. }
  279. }
  280. });
  281. },
  282. /** 删除按钮操作 */
  283. handleDelete(row) {
  284. const giftIds = row.giftId || this.ids;
  285. this.$confirm('是否确认删除直播间礼物配置编号为"' + giftIds + '"的数据项?', "警告", {
  286. confirmButtonText: "确定",
  287. cancelButtonText: "取消",
  288. type: "warning"
  289. }).then(function() {
  290. return delGift(giftIds);
  291. }).then(() => {
  292. this.getList();
  293. this.msgSuccess("删除成功");
  294. }).catch(() => {});
  295. },
  296. /** 导出按钮操作 */
  297. handleExport() {
  298. const queryParams = this.queryParams;
  299. this.$confirm('是否确认导出所有直播间礼物配置数据项?', "警告", {
  300. confirmButtonText: "确定",
  301. cancelButtonText: "取消",
  302. type: "warning"
  303. }).then(() => {
  304. this.exportLoading = true;
  305. return exportGift(queryParams);
  306. }).then(response => {
  307. this.download(response.msg);
  308. this.exportLoading = false;
  309. }).catch(() => {});
  310. }
  311. }
  312. };
  313. </script>