luckDraw.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. <template>
  2. <div class="luckDraw">
  3. <div class="luckDraw_title">
  4. <span class="text">中奖名单</span>
  5. </div>
  6. <div class="luckDraw_select">
  7. <el-input v-model="form.text1" placeholder="请输入中奖姓名" clearable></el-input>
  8. <el-button type="primary" @click="selectClick" :loading="selectLoading">
  9. <i class="el-icon-search"></i> 查询
  10. </el-button>
  11. <el-button type="primary" @click="exportData()" :loading="downloadLoading">
  12. <i class="el-icon-document"></i> 导出(Excel)
  13. </el-button>
  14. </div>
  15. <div class="luckDraw_table">
  16. <el-table
  17. ref="tab"
  18. :data="tableData"
  19. style="width: 100%;"
  20. border
  21. :height="height"
  22. :stripe="true"
  23. :highlight-current-row="false"
  24. :row-style="tableRowStyle"
  25. :header-cell-style="tableHeaderColor"
  26. :loading="tableLoading"
  27. element-tableLoading-text="玩命加载中"
  28. element-tableLoading-spinner="el-icon-tableLoading"
  29. >
  30. <el-table-column
  31. type="index"
  32. label="序号"
  33. fixed="left"
  34. width="50"
  35. >
  36. </el-table-column>
  37. <el-table-column
  38. sortable
  39. v-for="(item,i) in tablehead"
  40. :key="i"
  41. :prop="item.prop"
  42. :label="item.label"
  43. :min-width="item.width || width">
  44. </el-table-column>
  45. </el-table>
  46. <div class="fy">
  47. <el-pagination
  48. @size-change="handleSizeChange"
  49. @current-change="handleCurrentChange"
  50. :current-page="currentPage"
  51. :page-sizes="pageSizes"
  52. :page-size="pageSize"
  53. layout="total, sizes, prev, pager, next, jumper"
  54. :total="total"
  55. :hide-on-single-page="true">
  56. </el-pagination>
  57. </div>
  58. </div>
  59. </div>
  60. </template>
  61. <script>
  62. import luckDrawTableHead from './luckDrawTableHead'
  63. export default {
  64. data(){
  65. return{
  66. //查询按钮的状态
  67. selectLoading:false,
  68. //导出按钮的状态
  69. downloadLoading:false,
  70. //导出excel文件的名字
  71. tableTitle:'中奖名单',
  72. //表格的高度
  73. height:null,
  74. //表格的每一列的宽度,若没有再表头设置则采用
  75. width:150,
  76. //总条目数
  77. total:null,
  78. //每页显示条目个数
  79. pageSize: 100,
  80. //每一页面的显示的条目个数数组
  81. pageSizes: [50, 100, 200, 300],
  82. //当前页数
  83. currentPage: 1,
  84. //表格的加载状态
  85. tableLoading: false,
  86. //查询条件
  87. form:{
  88. text1:null,
  89. },
  90. //后端给的数据
  91. tableData1:[],
  92. //表格渲染的数据
  93. tableData:[],
  94. //表格的表头数据
  95. tablehead:[],
  96. }
  97. },
  98. created(){
  99. this.tablehead = luckDrawTableHead.luckDrawTableHead;
  100. //动态监听页面的高度,如果改变则改变
  101. window.addEventListener("resize", this.getHeight);
  102. this.getHeight();
  103. this.initialization();
  104. this.changeList();
  105. },
  106. methods:{
  107. getHeight(){
  108. this.height = window.innerHeight - 200
  109. },
  110. initialization(){
  111. let arr;
  112. for(var i = 0 ;i<1000;i++){
  113. let num = i + 1;
  114. arr = {
  115. prop1:'测试' + num,
  116. }
  117. this.tableData1.push(arr)
  118. }
  119. this.total = this.tableData1.length;
  120. },
  121. //查询事件
  122. selectClick(){
  123. this.selectLoading = true;
  124. this.axios.get('/game/v1/rflemplotterys/').then((res)=>{
  125. console.log(res);
  126. })
  127. this.selectLoading = false;
  128. },
  129. //行间样式
  130. tableRowStyle(){
  131. return 'background-color:#CCF1FF;color:#000;text-align:center;height:10px'
  132. },
  133. //表头样式
  134. tableHeaderColor(){
  135. return 'background-color:#0C2278;color:#fff;text-align:center;height:20px'
  136. },
  137. changeList(){
  138. if(this.tableData1.length){
  139. this.tableData = [];
  140. var x = (this.currentPage - 1) * this.pageSize;
  141. var y = this.currentPage * this.pageSize;
  142. if(x >= this.total){
  143. x = this.total;
  144. }
  145. if(y >= this.total){
  146. y = this.total
  147. }
  148. for(x;x<y;x++){
  149. this.tableData.push(this.tableData1[x])
  150. }
  151. }
  152. this.tableLoading = false;
  153. },
  154. handleSizeChange(val) {
  155. this.tableLoading = true;
  156. this.pageSize = val
  157. this.changeList();
  158. },
  159. handleCurrentChange(val) {
  160. this.tableLoading = true;
  161. this.currentPage = val
  162. this.changeList();
  163. },
  164. exportData(){
  165. if(this.tableData.length){
  166. let tHeader = [];
  167. let filterVal = [];
  168. this.tablehead.filter( (item,i) =>{
  169. tHeader.push(item.label);
  170. filterVal.push(item.prop);
  171. } )
  172. this.export2Excel(tHeader,filterVal,this.tableData);
  173. }else{
  174. this.$alert('没有查询到数据,不能使用导出功能', '提示', {
  175. confirmButtonText: '确定',
  176. callback: action => {
  177. }
  178. });
  179. }
  180. },
  181. export2Excel(tHeader,filterVal,dataTabel) {
  182. var that = this;
  183. this.downloadLoading = true
  184. require.ensure([], () => {
  185. const { export_json_to_excel } = require("@/assets/excel/Export2Excel.js"); //这里必须使用绝对路径,使用@/+存放export2Excel的路径
  186. let list = dataTabel;
  187. let data = that.formatJson(filterVal, list);
  188. export_json_to_excel(tHeader, data, that.tableTitle); // 导出的表格名称
  189. });
  190. this.downloadLoading = false;
  191. },
  192. //3.格式转换
  193. formatJson(filterVal, jsonData) {
  194. return jsonData.map((v) => filterVal.map((j) => v[j]));
  195. },
  196. }
  197. }
  198. </script>
  199. <style lang="scss">
  200. .luckDraw{
  201. .luckDraw_title{
  202. width: 100%;height: 100px;
  203. display: flex;
  204. justify-content: center;
  205. align-items: center;
  206. font-size: 46px;
  207. font-weight: 900;
  208. color: red;
  209. }
  210. .luckDraw_select{
  211. display: flex;
  212. align-items: center;
  213. width: 100%;height: 60px;
  214. padding-left: 50px;
  215. .el-input{
  216. width: 200px;
  217. margin-right: 20px;
  218. }
  219. }
  220. .fy{
  221. display: flex;
  222. align-items: center;
  223. height: 40px;
  224. width: 100%;
  225. }
  226. }
  227. </style>