index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  1. <template>
  2. <div class="app-container">
  3. <!--<el-form-->
  4. <!-- :model="queryParams"-->
  5. <!-- ref="queryForm"-->
  6. <!-- size="small"-->
  7. <!-- :inline="true"-->
  8. <!-- v-show="showSearch"-->
  9. <!-- label-width="68px"-->
  10. <!--&gt;-->
  11. <!-- <el-form-item label="品质" prop="name">-->
  12. <!-- <el-input-->
  13. <!-- v-model="queryParams.name"-->
  14. <!-- placeholder="请输入品质"-->
  15. <!-- clearable-->
  16. <!-- @keyup.enter.native="handleQuery"-->
  17. <!-- />-->
  18. <!-- </el-form-item>-->
  19. <!-- <el-form-item label="概率值" prop="value">-->
  20. <!-- <el-input-->
  21. <!-- v-model="queryParams.value"-->
  22. <!-- placeholder="请输入概率值"-->
  23. <!-- clearable-->
  24. <!-- @keyup.enter.native="handleQuery"-->
  25. <!-- />-->
  26. <!-- </el-form-item>-->
  27. <!-- <el-form-item label="背景颜色" prop="bgColor">-->
  28. <!-- <el-select-->
  29. <!-- v-model="queryParams.bgColor"-->
  30. <!-- placeholder="请选择背景颜色"-->
  31. <!-- clearable-->
  32. <!-- style="width: 180px"-->
  33. <!-- >-->
  34. <!-- <el-option label="bg-rarity-epic" value="bg-rarity-epic" />-->
  35. <!-- <el-option label="bg-rarity-rare" value="bg-rarity-rare" />-->
  36. <!-- <el-option label="bg-rarity-fine" value="bg-rarity-fine" />-->
  37. <!-- <el-option label="bg-rarity-common" value="bg-rarity-common" />-->
  38. <!-- </el-select>-->
  39. <!-- </el-form-item>-->
  40. <!-- <el-form-item label="稀有度" prop="rarity">-->
  41. <!-- <el-select-->
  42. <!-- v-model="queryParams.rarity"-->
  43. <!-- placeholder="请选择稀有度"-->
  44. <!-- clearable-->
  45. <!-- style="width: 180px"-->
  46. <!-- >-->
  47. <!-- <el-option label="史诗" value="史诗" />-->
  48. <!-- <el-option label="稀有" value="稀有" />-->
  49. <!-- <el-option label="精良" value="精良" />-->
  50. <!-- <el-option label="普通" value="普通" />-->
  51. <!-- </el-select>-->
  52. <!-- </el-form-item>-->
  53. <!-- &lt;!&ndash;<el-form-item label="关联卡池id" prop="poolId">&ndash;&gt;-->
  54. <!-- &lt;!&ndash; <el-input&ndash;&gt;-->
  55. <!-- &lt;!&ndash; v-model="queryParams.poolId"&ndash;&gt;-->
  56. <!-- &lt;!&ndash; placeholder="请输入关联卡池id"&ndash;&gt;-->
  57. <!-- &lt;!&ndash; clearable&ndash;&gt;-->
  58. <!-- &lt;!&ndash; @keyup.enter.native="handleQuery"&ndash;&gt;-->
  59. <!-- &lt;!&ndash; />&ndash;&gt;-->
  60. <!-- &lt;!&ndash;</el-form-item>&ndash;&gt;-->
  61. <!-- <el-form-item>-->
  62. <!-- <el-button-->
  63. <!-- type="primary"-->
  64. <!-- icon="el-icon-search"-->
  65. <!-- size="mini"-->
  66. <!-- @click="handleQuery"-->
  67. <!-- >搜索</el-button-->
  68. <!-- >-->
  69. <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"-->
  70. <!-- >重置</el-button-->
  71. <!-- >-->
  72. <!-- </el-form-item>-->
  73. <!--</el-form>-->
  74. <el-row :gutter="10" class="mb8">
  75. <!--<el-col :span="1.5">-->
  76. <!-- <el-button-->
  77. <!-- type="primary"-->
  78. <!-- plain-->
  79. <!-- icon="el-icon-plus"-->
  80. <!-- size="mini"-->
  81. <!-- @click="handleAdd"-->
  82. <!-- v-hasPermi="['system:probabilities:add']"-->
  83. <!-- >新增</el-button-->
  84. <!-- >-->
  85. <!--</el-col>-->
  86. <!--<el-col :span="1.5">-->
  87. <!-- <el-button-->
  88. <!-- type="success"-->
  89. <!-- plain-->
  90. <!-- icon="el-icon-edit"-->
  91. <!-- size="mini"-->
  92. <!-- :disabled="single"-->
  93. <!-- @click="handleUpdate"-->
  94. <!-- v-hasPermi="['system:probabilities:edit']"-->
  95. <!-- >修改</el-button-->
  96. <!-- >-->
  97. <!--</el-col>-->
  98. <!--<el-col :span="1.5">-->
  99. <!-- <el-button-->
  100. <!-- type="danger"-->
  101. <!-- plain-->
  102. <!-- icon="el-icon-delete"-->
  103. <!-- size="mini"-->
  104. <!-- :disabled="multiple"-->
  105. <!-- @click="handleDelete"-->
  106. <!-- v-hasPermi="['system:probabilities:remove']"-->
  107. <!-- >删除</el-button-->
  108. <!-- >-->
  109. <!--</el-col>-->
  110. <el-col :span="1.5">
  111. <el-button
  112. type="warning"
  113. plain
  114. icon="el-icon-download"
  115. size="mini"
  116. @click="handleExport"
  117. v-hasPermi="['system:probabilities:export']"
  118. >导出</el-button
  119. >
  120. </el-col>
  121. <el-col :span="6" style="display: flex; align-items: center">
  122. <span
  123. style="margin-left: 10px"
  124. :style="{ color: totalProbability === 100 ? '#409EFF' : 'red' }"
  125. >
  126. 总概率值:{{ totalProbability }}
  127. </span>
  128. </el-col>
  129. <!--<right-toolbar-->
  130. <!-- :showSearch.sync="showSearch"-->
  131. <!-- @queryTable="getList"-->
  132. <!--&gt;</right-toolbar>-->
  133. </el-row>
  134. <el-table
  135. v-loading="loading"
  136. :data="probabilitiesList"
  137. @selection-change="handleSelectionChange"
  138. >
  139. <el-table-column type="selection" width="55" align="center" />
  140. <!--<el-table-column label="id" align="center" prop="id" />-->
  141. <!--<el-table-column type="index" label="序号" width="60" align="center" />-->
  142. <el-table-column label="品质" align="center" prop="name" />
  143. <el-table-column
  144. label="概率值"
  145. align="center"
  146. prop="value"
  147. ></el-table-column>
  148. <!--<el-table-column label="颜色设置" align="center" prop="colorClass" />-->
  149. <!--<el-table-column label="关联卡池id" align="center" prop="poolId" />-->
  150. <el-table-column
  151. label="操作"
  152. align="center"
  153. class-name="small-padding fixed-width"
  154. >
  155. <template slot-scope="scope">
  156. <el-button
  157. size="mini"
  158. type="text"
  159. icon="el-icon-edit"
  160. @click="handleUpdate(scope.row)"
  161. v-hasPermi="['system:probabilities:edit']"
  162. >修改概率</el-button
  163. >
  164. <!--<el-button-->
  165. <!-- size="mini"-->
  166. <!-- type="text"-->
  167. <!-- icon="el-icon-delete"-->
  168. <!-- @click="handleDelete(scope.row)"-->
  169. <!-- v-hasPermi="['system:probabilities:remove']"-->
  170. <!-- >删除</el-button-->
  171. <!--&gt;-->
  172. </template>
  173. </el-table-column>
  174. </el-table>
  175. <!--<pagination-->
  176. <!-- v-show="total > 0"-->
  177. <!-- :total="total"-->
  178. <!-- :page.sync="queryParams.pageNum"-->
  179. <!-- :limit.sync="queryParams.pageSize"-->
  180. <!-- @pagination="getList"-->
  181. <!--/>-->
  182. <!-- 添加或修改概率设置对话框 -->
  183. <el-dialog
  184. :title="title"
  185. :visible.sync="open"
  186. width="500px"
  187. append-to-body
  188. style="margin-right: 0"
  189. >
  190. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  191. <!--<el-form-item label="品质" prop="name">-->
  192. <!-- <el-input v-model="form.name" placeholder="请输入品质" />-->
  193. <!--</el-form-item>-->
  194. <el-form-item label="概率值" prop="value">
  195. <el-input v-model="form.value" placeholder="请输入概率值" />
  196. </el-form-item>
  197. <!--<el-form-item label="背景颜色" prop="bgColor">-->
  198. <!-- <el-select-->
  199. <!-- v-model="form.bgColor"-->
  200. <!-- placeholder="请选择背景颜色"-->
  201. <!-- style="width: 100%"-->
  202. <!-- >-->
  203. <!-- <el-option label="bg-rarity-epic" value="bg-rarity-epic" />-->
  204. <!-- <el-option label="bg-rarity-rare" value="bg-rarity-rare" />-->
  205. <!-- <el-option label="bg-rarity-fine" value="bg-rarity-fine" />-->
  206. <!-- <el-option label="bg-rarity-common" value="bg-rarity-common" />-->
  207. <!-- </el-select>-->
  208. <!--</el-form-item>-->
  209. <!--<el-form-item label="稀有度" prop="rarity">-->
  210. <!-- <el-select-->
  211. <!-- v-model="form.rarity"-->
  212. <!-- placeholder="请选择稀有度"-->
  213. <!-- style="width: 100%"-->
  214. <!-- >-->
  215. <!-- <el-option label="史诗" value="史诗" />-->
  216. <!-- <el-option label="稀有" value="稀有" />-->
  217. <!-- <el-option label="精良" value="精良" />-->
  218. <!-- <el-option label="普通" value="普通" />-->
  219. <!-- </el-select>-->
  220. <!--</el-form-item>-->
  221. <!--<el-form-item label="关联卡池id" prop="poolId">-->
  222. <!-- <el-input v-model="form.poolId" placeholder="请输入关联卡池id" />-->
  223. <!--</el-form-item>-->
  224. </el-form>
  225. <div slot="footer" class="dialog-footer">
  226. <el-button type="primary" @click="submitForm">确 定</el-button>
  227. <el-button @click="cancel">取 消</el-button>
  228. </div>
  229. </el-dialog>
  230. </div>
  231. </template>
  232. <script>
  233. import {
  234. listProbabilities,
  235. getProbabilities,
  236. delProbabilities,
  237. addProbabilities,
  238. updateProbabilities,
  239. } from "@/api/system/probabilities";
  240. export default {
  241. name: "Probabilities",
  242. props: {
  243. pool: {
  244. type: Object,
  245. default: null,
  246. },
  247. },
  248. data() {
  249. return {
  250. // 遮罩层
  251. loading: true,
  252. // 选中数组
  253. ids: [],
  254. // 非单个禁用
  255. single: true,
  256. // 非多个禁用
  257. multiple: true,
  258. // 显示搜索条件
  259. showSearch: true,
  260. // 总条数
  261. total: 0,
  262. // 概率设置表格数据
  263. probabilitiesList: [],
  264. // 弹出层标题
  265. title: "",
  266. // 是否显示弹出层
  267. open: false,
  268. // 查询参数
  269. queryParams: {
  270. pageNum: 1,
  271. pageSize: 10,
  272. name: null,
  273. value: null,
  274. colorClass: null,
  275. poolId: this.poolId,
  276. rarity: null, // 新增
  277. },
  278. // 表单参数
  279. form: {
  280. id: null,
  281. name: null,
  282. value: null,
  283. colorClass: null,
  284. poolId: null,
  285. rarity: null, // 新增
  286. },
  287. // 表单校验
  288. rules: {
  289. poolId: [
  290. { required: true, message: "关联卡池id不能为空", trigger: "blur" },
  291. ],
  292. },
  293. poolId: null,
  294. };
  295. },
  296. mounted() {
  297. console.log(this.pool);
  298. // 直接用 this.pool.id
  299. this.loadDataByPoolId(this.pool.id);
  300. this.getList();
  301. },
  302. methods: {
  303. loadDataByPoolId(poolId) {
  304. this.queryParams.poolId = poolId;
  305. this.getList();
  306. },
  307. /** 查询概率设置列表 */
  308. getList() {
  309. this.loading = true;
  310. listProbabilities(this.queryParams).then((response) => {
  311. this.probabilitiesList = response.rows;
  312. this.total = response.total;
  313. this.loading = false;
  314. });
  315. },
  316. // 取消按钮
  317. cancel() {
  318. this.open = false;
  319. this.reset();
  320. },
  321. // 表单重置
  322. reset() {
  323. this.form = {
  324. id: null,
  325. name: null,
  326. value: null,
  327. colorClass: null,
  328. poolId: null,
  329. rarity: null, // 新增
  330. };
  331. this.resetForm("form");
  332. },
  333. /** 搜索按钮操作 */
  334. handleQuery() {
  335. this.queryParams.pageNum = 1;
  336. this.getList();
  337. },
  338. /** 重置按钮操作 */
  339. resetQuery() {
  340. this.resetForm("queryForm");
  341. this.handleQuery();
  342. },
  343. // 多选框选中数据
  344. handleSelectionChange(selection) {
  345. this.ids = selection.map((item) => item.id);
  346. this.single = selection.length !== 1;
  347. this.multiple = !selection.length;
  348. },
  349. /** 新增按钮操作 */
  350. handleAdd() {
  351. this.reset();
  352. this.open = true;
  353. this.title = "添加概率设置";
  354. },
  355. /** 修改按钮操作 */
  356. handleUpdate(row) {
  357. this.reset();
  358. const id = row.id || this.ids;
  359. getProbabilities(id).then((response) => {
  360. this.form = response.data;
  361. this.open = true;
  362. this.title = "修改概率设置";
  363. });
  364. },
  365. /** 提交按钮 */
  366. submitForm() {
  367. this.$refs["form"].validate((valid) => {
  368. this.form.poolId = this.poolId;
  369. if (valid) {
  370. if (this.form.id != null) {
  371. updateProbabilities(this.form).then((response) => {
  372. this.$modal.msgSuccess("修改成功");
  373. this.open = false;
  374. this.getList();
  375. });
  376. } else {
  377. addProbabilities(this.form).then((response) => {
  378. this.$modal.msgSuccess("新增成功");
  379. this.open = false;
  380. this.getList();
  381. });
  382. }
  383. }
  384. });
  385. },
  386. /** 删除按钮操作 */
  387. handleDelete(row) {
  388. const ids = row.id || this.ids;
  389. this.$modal
  390. .confirm('是否确认删除概率设置编号为"' + ids + '"的数据项?')
  391. .then(function () {
  392. return delProbabilities(ids);
  393. })
  394. .then(() => {
  395. this.getList();
  396. this.$modal.msgSuccess("删除成功");
  397. })
  398. .catch(() => {});
  399. },
  400. /** 导出按钮操作 */
  401. handleExport() {
  402. this.download(
  403. "system/probabilities/export",
  404. {
  405. ...this.queryParams,
  406. },
  407. `probabilities_${new Date().getTime()}.xlsx`
  408. );
  409. },
  410. },
  411. computed: {
  412. totalProbability() {
  413. return this.probabilitiesList.reduce(
  414. (sum, row) => sum + Number(row.value || 0),
  415. 0
  416. );
  417. },
  418. },
  419. watch: {
  420. totalProbability(newVal) {
  421. if (newVal !== 100) {
  422. this.$message.error("当前总概率值不为100,请赶快修改!");
  423. }
  424. },
  425. },
  426. };
  427. </script>