index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <div ref="commonTable">
  3. <!-- 搜索栏 -->
  4. <el-form v-if="formList.length > 0" :inline="true" :model="searchDataClone" label-width="105px" ref="searchDataClone"
  5. id="commonTable" class="demo-form-inline device-wrapper">
  6. <el-form-item v-for="f in formList" :key="f.prop" :label="f.label" :prop="f.prop">
  7. <template>
  8. <template v-if="f.type === 'input'">
  9. <el-input clearable v-model.trim="searchDataClone[f.prop]" size="small"
  10. :placeholder="'请输入' + f.label"></el-input>
  11. </template>
  12. <template v-else-if="f.type === 'company'">
  13. <el-select size="small" clearable v-model="searchDataClone[f.prop]" :placeholder="'请输入' + f.label">
  14. <el-option label="不限" value v-if="f.selectAuto"></el-option>
  15. <el-option v-for="(s, i) in InsCompanyList" :key="i" :label="s.name" :value="s.id"></el-option>
  16. </el-select>
  17. </template>
  18. <template v-else-if="f.type === 'companyCheck'">
  19. <el-select class="selectLength" multiple collapse-tags size="small" v-model="searchDataClone[f.prop]"
  20. :placeholder="'请输入' + f.label">
  21. <el-option label="不限" value v-if="f.selectAuto"></el-option>
  22. <el-option v-for="(s, i) in InsCompanyList" :key="i" :label="s.name" :value="s.id"></el-option>
  23. </el-select>
  24. </template>
  25. <template v-else-if="f.type === 'select'">
  26. <el-select size="small" clearable v-model="searchDataClone[f.prop]" :placeholder="'请输入' + f.label">
  27. <el-option label="不限" value v-if="f.selectAuto"></el-option>
  28. <el-option v-for="(s, i) in f.options" :key="i" :label="s.label || s.dictTag"
  29. :value="s.value || s.dictValue"></el-option>
  30. </el-select>
  31. </template>
  32. <template v-else-if="f.type === 'datePicker'">
  33. <!-- 日期区间 -->
  34. <el-date-picker type="daterange" size="small" v-model="searchDataClone[f.prop]" align="right" unlink-panels
  35. range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" value-format="yyyy-MM-dd HH:mm:ss"
  36. :default-time="['00:00:00', '23:59:59']" :clearable="true"></el-date-picker>
  37. </template>
  38. <template v-else-if="f.type === 'date'">
  39. <!-- 一天 -->
  40. <el-date-picker type="date" size="small" v-model="searchDataClone[f.prop]" placeholder="选择日期"
  41. value-format="yyyy-MM-dd"></el-date-picker>
  42. </template>
  43. <!-- 年份 -->
  44. <template v-else-if="f.type === 'year'">
  45. <el-date-picker type="year" size="small" v-model="searchDataClone[f.prop]" placeholder="选择年">
  46. </el-date-picker>
  47. </template>
  48. <template v-else-if="f.type === 'radio'">
  49. <el-radio-group v-model="searchDataClone[f.prop]" :placeholder="'请输入' + f.label">
  50. <el-radio v-for="(r, i) in f.radioList" :key="i" :label="r.value">{{ r.label }}</el-radio>
  51. </el-radio-group>
  52. </template>
  53. <template v-else-if="f.type === 'slot'">
  54. <slot show-overflow-tooltip :name="f.name"></slot>
  55. </template>
  56. </template>
  57. </el-form-item>
  58. <el-form-item>
  59. <el-button style="margin-left:30px" size="small" @click="resetForm('searchDataClone')">重置</el-button>
  60. <el-button type="primary" size="small" @click="handleSearchList()">查询</el-button>
  61. <template v-if="btnGroup.length > 0">
  62. <span v-for="(val, idx) in btnGroup" :key="idx" style="margin-left:10px">
  63. <slot v-if="val.slot" show-overflow-tooltip :name="val.name"></slot>
  64. <el-button v-else :type="val.type || 'primary'" size="small" @click="val.click()">{{ val.name }}</el-button>
  65. </span>
  66. </template>
  67. </el-form-item>
  68. <!-- <el-form-item v-if="btnGroup.length>0" >
  69. <el-button v-for="(val, idx) in btnGroup" :key="idx" :type="val.type || 'primary'" size="small" @click="tabFun(val)">{{ val.name }}</el-button>
  70. </el-form-item> -->
  71. </el-form>
  72. <!--表格-->
  73. <el-table :data="data" border size="small" style="width: 100%" :height="tableHeight" v-loading="tableConfig.loading"
  74. element-loading-text="数据加载中" element-loading-spinner="el-icon-loading" @selection-change="handleSelectionChange"
  75. :row-style="{ height: '55px' }" :cell-style="{ padding: '0px' }"
  76. :header-cell-style="{ background: '#F2F7FC', fontWeight: '700', color: '#606266' }" :cell-class-name="rowClass">
  77. <el-table-column type="selection" :width="tableConfig.selectionWidth || '50'" v-if="tableConfig.isCheckBox"
  78. align="center" />
  79. <el-table-column type="index" :width="tableConfig.indexWidth || '50'" v-if="tableConfig.isShowIndex" align="center"
  80. label="序号" />
  81. <template v-for="(item, index) in tableConfig.columns">
  82. <!-- 日期内容 -->
  83. <el-table-column v-if="item.type === 'date'" :align="'center'" :fixed="item.fixed" :width="item.width || 150"
  84. show-overflow-tooltip :label="item.label" :key="item.prop">
  85. <template slot-scope="scope">
  86. <div>{{ scope.row[item.prop] | formateDate }}</div>
  87. </template>
  88. </el-table-column>
  89. <!-- 字典项 -->
  90. <el-table-column v-if="item.type === 'dic'" :align="'center'" :width="item.width || ''" :fixed="item.fixed"
  91. show-overflow-tooltip :label="item.label" :key="item.prop" :prop="item.prop">
  92. <template slot-scope="scope">
  93. <span>{{ selectDictLabel(dictData[item.dic], scope.row[item.prop]) }}</span>
  94. </template>
  95. </el-table-column>
  96. <el-table-column v-if="item.type === 'statMap'" :align="'center'" :width="item.width || ''" :fixed="item.fixed"
  97. show-overflow-tooltip :label="item.label" :key="item.prop" :prop="item.prop">
  98. <template slot-scope="scope">
  99. <span> {{ statMaps(item.options)[scope.row[item.prop]] || '--' }}</span>
  100. </template>
  101. </el-table-column>
  102. <!-- 自定义内容 -->
  103. <slot v-if="item.type === 'slot'" show-overflow-tooltip :name="item.name"></slot>
  104. <!-- 常规文本内容 -->
  105. <el-table-column v-if="item.type === 'text'" :align="'center'" :width="item.width || ''" :fixed="item.fixed"
  106. :label="item.label" :key="item.prop" :prop="item.prop"></el-table-column>
  107. </template>
  108. <!-- <slot name="operate" :row="scope.row"></slot> -->
  109. <!-- 自定义操作栏 -->
  110. <el-table-column v-if="tableConfig.operateShow" label="操作" align="center"
  111. :min-width="tableConfig.operationWidth || '100'" fixed="right">
  112. <template slot-scope="scope">
  113. <slot name="operate" :row="scope.row"></slot>
  114. </template>
  115. </el-table-column>
  116. <!-- 数组形式的操作栏,用于普通按钮 -->
  117. <!-- // optBtns:[
  118. // {
  119. // type:'primary',
  120. // label:'修改',
  121. // hide:(row) => {
  122. // return row.importStatus == 1?true:false
  123. // },
  124. // click:(row, index) => {return this.modifyFun(row)},
  125. // }
  126. // ] -->
  127. <el-table-column v-if="tableConfig.optBtns" :min-width="tableConfig.operationWidth || '100'" label="操作"
  128. fixed="right" header-align="center" align="center">
  129. <template slot-scope="scope">
  130. <span v-for="(btn, index) in tableConfig.optBtns" :key="index">
  131. <!-- <el-button style="margin:0 10px" v-if="!btn.hide || (btn.hide && btn.hide(scope.row))" v-permission="btn.perm"
  132. @click="btn.click(scope.row, index)" :type="btn.type || 'primary'" :icon="btn.icon" size="small">{{
  133. btn.label
  134. }} </el-button> -->
  135. <kt-button style="margin:0 10px" v-if="!btn.hide || (btn.hide && btn.hide(scope.row))" :icon="btn.icon" :label="btn.label"
  136. :type="btn.type || 'primary'" size="small" :perms="btn.perm" @click="btn.click(scope.row, index)" />
  137. </span>
  138. </template>
  139. </el-table-column>
  140. </el-table>
  141. <!-- 分页 -->
  142. <div class="block" ref="bottomFixed">
  143. <el-pagination v-if="tableConfig.isPaginationShow && pagination.totalSize" style="margin-top: 10px"
  144. :page-size="pagination.pageSize" :current-page.sync="pagination.pageNum" :total="pagination.totalSize"
  145. layout="total, sizes,prev, pager, next,jumper" :page-sizes="[10, 20, 50, 100]" @size-change="handleSizeChange"
  146. @current-change="handleCurrentChange" />
  147. </div>
  148. </div>
  149. </template>
  150. <script type="text/ecmascript-6">
  151. import KtButton from "@/views/Core/KtButton";
  152. export default {
  153. components: {
  154. KtButton,
  155. },
  156. props: {
  157. formList: {
  158. type: Array,
  159. default: () => {
  160. return [];
  161. }
  162. },
  163. btnGroup: {
  164. type: Array,
  165. default: () => {
  166. return [];
  167. }
  168. },
  169. tableConfig: {
  170. type: Object,
  171. default: () => {
  172. return {};
  173. }
  174. },
  175. // searchDataClone: {
  176. // type: Object,
  177. // default: () => {
  178. // return {};
  179. // }
  180. // },
  181. pagination: {
  182. type: Object,
  183. default: () => ({
  184. pageNum: 1,
  185. pageSize: 20,
  186. totalSize: 0,
  187. }),
  188. },
  189. rowClass: {
  190. type: Function,
  191. default: () => '',
  192. },
  193. data: {
  194. type: Array,
  195. default: () => []
  196. },
  197. },
  198. data() {
  199. return {
  200. tableHeight: 0,
  201. InsCompanyList: [],
  202. searchDataClone: {}
  203. };
  204. },
  205. created() {
  206. if(this.formList.length>0 && this.formList.find(val=>val.type=='company' || val.type=='companyCheck')){
  207. this.companyFun()
  208. }
  209. },
  210. mounted() {
  211. setTimeout(() => {
  212. var divHg = 0;
  213. if (document.getElementById("commonTable") != null) {
  214. divHg = document.getElementById("commonTable").clientHeight
  215. } else {
  216. divHg = 100
  217. }
  218. let bottomTop = this.$refs.bottomFixed.offsetTop;
  219. this.tableHeight = window.innerHeight - bottomTop - divHg - 80 + "px";
  220. }, 10);
  221. },
  222. filters: {
  223. formateDate(val) {
  224. return formatDateTime(val)
  225. }
  226. },
  227. methods: {
  228. formatDateTime(date) {
  229. let d = new Date(date),
  230. month = '' + (d.getMonth() + 1),
  231. day = '' + d.getDate(),
  232. year = d.getFullYear();
  233. if (month.length < 2) month = '0' + month;
  234. if (day.length < 2) day = '0' + day;
  235. return [year, month, day].join('-');
  236. },
  237. companyFun() {
  238. this.$api.cost.gainTopList({ type: 1 }).then(res => {
  239. if (res.data) {
  240. this.InsCompanyList = res.data;
  241. }
  242. });
  243. },
  244. statMaps(list) {
  245. if (!list) return;
  246. let obj = {};
  247. list.forEach(item => {
  248. obj[item.value || item.id] = item.label || item.value;
  249. });
  250. return obj;
  251. },
  252. selectDictLabel(dicts, value) {
  253. if (value === undefined) {
  254. return '';
  255. }
  256. if (dicts === undefined) {
  257. return '';
  258. }
  259. const actions = [];
  260. Object.keys(dicts).some((key) => {
  261. if (dicts[key].value === `${value}`) {
  262. actions.push(dicts[key].label);
  263. return true;
  264. }
  265. });
  266. if (actions.length === 0) {
  267. actions.push(value);
  268. }
  269. return actions.join('');
  270. },
  271. // 表格多选
  272. handleSelectionChange(currentRow) {
  273. this.$emit('selectionChange', currentRow);
  274. },
  275. handleSizeChange(value) {
  276. this.pagination.pageSize = value;
  277. this.pagination.pageNum = 1;
  278. this.$emit('getList',this.pagination);
  279. },
  280. handleCurrentChange(val) {
  281. this.pagination.pageNum = val;
  282. this.$emit('getList',this.pagination);
  283. },
  284. // 搜索
  285. handleSearchList() {
  286. // 更新父组件searchData
  287. this.pagination.pageNum = 1;
  288. this.pagination.pageSize = 20;
  289. this.$emit("handleSearchList", this.searchDataClone);
  290. },
  291. // 重置
  292. resetForm(formName) {
  293. this.searchDataClone = {}
  294. // this.$refs[formName].resetFields();
  295. this.handleSearchList();
  296. },
  297. handleOpt(row, index) {
  298. this.$emit('handleOpt', row, index)
  299. },
  300. }
  301. };
  302. </script>
  303. <style scoped>
  304. .selectLength /deep/ .el-select__tags-text {
  305. display: inline-block;
  306. max-width: 110px;
  307. overflow: hidden;
  308. text-overflow: ellipsis;
  309. white-space: nowrap;
  310. }
  311. </style>