table-template.blade.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. @include('public.admin.box-item')
  2. <style scoped>
  3. .search-box{display: flex;flex-wrap: wrap;}
  4. .search-item{width: 240px;margin: 10px;}
  5. .page{width: calc(100% - 275px);position: fixed;bottom: 0;z-index: 199;box-sizing: border-box;box-shadow: 0px -1px 10px rgb(0 0 0 / 10%);background-color: #fff;height: 60px;display: flex;justify-content: center;align-items: center;border-radius: 10px 10px 0 0;}
  6. </style>
  7. <template id="table-template">
  8. <div>
  9. <box-item :text="searchText">
  10. <div class="search-box">
  11. <template v-for="(item,i) in searchList">
  12. <el-input v-model="search[item.key]" :placeholder="item.p" class="search-item" clearable @keyup.enter.native="searchValue" v-if="!item.type || item.type == 'input'"></el-input>
  13. <el-select v-model="search[item.key]" :placeholder="item.p" class="search-item" clearable v-else-if="item.type == 'select'">
  14. <el-option v-for="(option,index) in item.options" :key="index" :label="option.label" :value="option.value" clearable></el-option>
  15. </el-select>
  16. <el-date-picker v-model="date" type="datetimerange" :picker-options="pickerOptions" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"
  17. align="right" @change="changeDate" clearable v-else-if="item.type == 'date'" value-format="timestamp" style="margin:10px;">
  18. </el-date-picker>
  19. <div style="margin: 10px;" v-else-if="item.type=='slot'">
  20. <slot :name="item.name"></slot>
  21. </div>
  22. </template>
  23. <div style="margin:10px;">
  24. <el-button v-if="isInit" @click="initSearch">重置</el-button>
  25. <el-button v-if="exportUrl" @click="exportData">导出EXCEL</el-button>
  26. <slot name="search-btn"></slot>
  27. <el-button type="primary" icon="el-icon-search" v-if="isSearch" @click="searchValue" :disabled="loading">搜索</el-button>
  28. </div>
  29. </div>
  30. <slot name="btn" slot="btn"></slot>
  31. </box-item>
  32. <box-item :text="tableText">
  33. <slot name="teble-btn" slot="btn"></slot>
  34. <el-table :data="tableData" style="width: 100%;" v-loading="loading">
  35. <template v-for="(item,i) in tableList">
  36. <el-table-column :label="item.label" :align="item.align || 'center'" v-if="item.type == 'slot'">
  37. <template slot-scope="scope">
  38. <slot slot-scope="scope" :row="scope.row" :name="item.name"></slot>
  39. </template>
  40. </el-table-column>
  41. <el-table-column :prop="item.prop" :label="item.label" :align="item.align || 'center'" v-else></el-table-column>
  42. </template>
  43. </el-table>
  44. </box-item>
  45. <vue-page v-if="total > 0">
  46. <el-pagination @current-change="getdata" :current-page.sync="page" :page-size="per_page" layout="prev, pager, next, jumper" :total="total" background :disabled="loading"></el-pagination>
  47. </vue-page>
  48. </div>
  49. </template>
  50. <script>
  51. Vue.component("table-template", {
  52. delimiters: ['[[', ']]'],
  53. props: {
  54. "search-text": {
  55. type: String | Array,
  56. default:"筛选"
  57. },
  58. "table-text": {
  59. type: String | Array,
  60. default:"记录列表"
  61. },
  62. "search-list":{
  63. type:Array
  64. },
  65. "table-list":{
  66. type:Array
  67. },
  68. "is-search":{
  69. type:Boolean,
  70. default:true
  71. },
  72. "is-init":{
  73. type:Boolean,
  74. default:false
  75. },
  76. "search_url":{
  77. type:String
  78. },
  79. "params":{
  80. type:Function | Object
  81. },
  82. "data-key":{
  83. type:String,
  84. default:"list"
  85. },
  86. "tab-date-type":{},
  87. "export-url":{
  88. type:String,
  89. default:""
  90. },
  91. "data-format":{
  92. type:String,
  93. default:""
  94. }
  95. },
  96. data(){
  97. function dateData(day){
  98. function onClick(picker) {
  99. const end = new Date();
  100. const start = new Date();
  101. start.setTime(start.getTime() - 3600 * 1000 * 24 * day);
  102. picker.$emit('pick', [start, end]);
  103. }
  104. return onClick
  105. }
  106. return{
  107. search:{},
  108. searchData:{},
  109. date:[],
  110. pickerOptions: {
  111. shortcuts: [
  112. {text: '最近一周',onClick:dateData(7)},
  113. {text: '最近一个月',onClick:dateData(30)},
  114. {text: '最近三个月',onClick:dateData(90)}
  115. ]
  116. },
  117. tableData:[],
  118. loading:false,
  119. page:1,
  120. per_page:10,
  121. total:0,
  122. amount_total:0
  123. }
  124. },
  125. created(){
  126. this.initdata();
  127. this.getdata();
  128. },
  129. methods:{
  130. initSearch(){
  131. this.$confirm('此操作会重置所有的筛选条件, 继续?', '提示', {
  132. confirmButtonText: '确定',
  133. cancelButtonText: '取消',
  134. type: 'warning'
  135. }).then(() => {
  136. this.$emit("init");
  137. this.search = {};
  138. });
  139. },
  140. initdata(){
  141. this.page = 1;
  142. this.total = 0;
  143. this.amount_total = 0;
  144. this.loading = false;
  145. },
  146. getJson(dataFormat){
  147. let params = {};
  148. if(typeof(this.params) === "function"){
  149. params = this.params()
  150. }else if(typeof(this.params) === "object" && !(Array.isArray(this.params))){
  151. params = this.params;
  152. }
  153. if(dataFormat){
  154. let json = {};
  155. json[dataFormat] = {...this.searchData,page:this.page,...params};
  156. return json;
  157. }
  158. return {...this.searchData,page:this.page,...params};
  159. },
  160. getdata(){
  161. this.loading = true;
  162. let data = this.getJson(this.dataFormat);
  163. this.$http.post(this.search_url,data).then(({data:{result,msg,data}})=>{
  164. this.loading = false;
  165. if(result == 1){
  166. let list = data[this.dataKey];
  167. this.tableData = list.data;
  168. this.total = list.total;
  169. this.total = list.total;
  170. this.per_page = list.per_page;
  171. this.amount_total = data.amount_total;
  172. this.$emit("gettotal",this.total);
  173. this.$emit("getamounttotal",this.amount_total);
  174. this.$emit("getdata",{data,result,msg});
  175. }else this.$message.error(msg);
  176. })
  177. },
  178. searchValue(){
  179. this.page = 1;
  180. this.searchData = this.search;
  181. this.getdata();
  182. this.$emit("search",this.search);
  183. },
  184. changeDate(data){
  185. if(this.tabDateType){
  186. if(data){
  187. this.search.start = parseInt(data[0] / 1000);
  188. this.search.end = parseInt(data[1] / 1000);
  189. }else{
  190. delete this.search.start;
  191. delete this.search.end;
  192. }
  193. return false;
  194. }
  195. if(data) this.search.time = {
  196. start:parseInt(data[0] / 1000),
  197. end:parseInt(data[1] / 1000)
  198. }
  199. else delete this.search.time;
  200. },
  201. exportData(){
  202. let data = this.getJson();
  203. let url = this.exportUrl;
  204. for (const key in data) {
  205. url += `&${key}=${data[key]}`
  206. }
  207. window.open(url);
  208. }
  209. },
  210. template: `#table-template`,
  211. })
  212. </script>