listComponent.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. <template>
  2. <div>
  3. <div style="width: 100%;height: 40px;">
  4. <div style="margin: 0 12px;float: left;">
  5. <el-button
  6. v-for="item in customButton"
  7. :type="item.type"
  8. :size="item.size"
  9. :icon="item.icon"
  10. :disabled="item.disabled"
  11. @click="buttonList(item)">
  12. {{ item.name }}
  13. </el-button>
  14. </div>
  15. <div class="tabSetting">
  16. <div style="margin-left:10px;float: right">
  17. <el-button
  18. icon="el-icon-setting"
  19. size="mini"
  20. circle
  21. @click="showSetting = !showSetting"
  22. ></el-button>
  23. </div>
  24. <right-toolbar
  25. v-if="isItHidden"
  26. @showSearch="showSearch"
  27. @queryTable="getList"
  28. ></right-toolbar>
  29. </div>
  30. <div style="margin-right:10px;float: right" v-if="isItHidden">
  31. <el-button
  32. type="success"
  33. plain
  34. icon="el-icon-search"
  35. size="mini"
  36. @click="feedback('搜索')"
  37. >搜索</el-button>
  38. <el-button
  39. type="warning"
  40. plain
  41. icon="el-icon-refresh-left"
  42. @click="feedback('重置')"
  43. size="mini"
  44. >重置</el-button>
  45. <el-button
  46. type="info"
  47. plain
  48. icon="el-icon-open"
  49. @click="feedback('展开')"
  50. size="mini"
  51. >展开</el-button>
  52. </div>
  53. </div>
  54. <el-table
  55. :data="tableData"
  56. style="width: 100%"
  57. @selection-change="handleSelectionChange"
  58. :row-class-name="rowClassName"
  59. show-summary
  60. :summary-method="listTotal"
  61. >
  62. <el-table-column type="selection" width="55" align="center"/>
  63. <el-table-column
  64. v-for="(item,index) in queryList.columnList"
  65. :key="index"
  66. :prop="item.label"
  67. :label="item.name"
  68. :width="item.width"
  69. :fixed="item.fixed"
  70. align="center"
  71. sortable
  72. >
  73. <template slot-scope="scope">
  74. <span v-if="item.name === '操作'">
  75. <span v-if="item.operation == 1">
  76. <el-button type="text" @click="viewMethod(scope)">查看</el-button>
  77. <el-button type="text" @click="modification(scope)">修改</el-button>
  78. <el-button type="text" @click="deletion(scope)">删除</el-button>
  79. </span>
  80. <span v-if="item.operation == 2">
  81. <el-button type="text" @click="deleteRow(scope.$index, tableData)" :disabled="item.disabled">移除</el-button>
  82. </span>
  83. </span>
  84. <span v-else-if="item.changeable">
  85. <el-select v-if="item.changeable == 1" :disabled="item.disabled" v-model="scope.row[item.label]" slot="prepend" placeholder="请选择">
  86. <el-option
  87. v-for="(item,index) in item.data"
  88. :key="index"
  89. :label="item.label"
  90. :value="item.value"
  91. ></el-option>
  92. </el-select>
  93. <el-input v-if="item.changeable == 2" :disabled="item.disabled" v-model="scope.row[item.label]" placeholder="请输入内容" :onkeyup="item.onabort"></el-input>
  94. <el-date-picker
  95. v-if="item.changeable == 3"
  96. v-model="scope.row[item.label]"
  97. type="date"
  98. style="width: 100%"
  99. placeholder="选择日期"
  100. >
  101. </el-date-picker>
  102. </span>
  103. <span v-else>{{ scope.row[item.label] }}</span>
  104. </template>
  105. </el-table-column>
  106. </el-table>
  107. <el-dialog title="自定义列显示" :visible.sync="showSetting" width="700px">
  108. <div>配置排序列数据(拖动调整顺序)</div>
  109. <div style="margin-left: 17px">
  110. <el-checkbox
  111. v-model="allCheck"
  112. label="全选"
  113. @change="allChecked"
  114. ></el-checkbox>
  115. </div>
  116. <div style="padding: 4px; display: flex; justify-content: center">
  117. <draggable
  118. v-model="setRowList"
  119. group="site"
  120. animation="300"
  121. @start="onStart"
  122. @end="onEnd"
  123. handle=".indraggable"
  124. >
  125. <transition-group>
  126. <div
  127. v-for="item in setRowList"
  128. :key="item.surface"
  129. class="listStyle"
  130. >
  131. <div style="width: 500px" class="indraggable">
  132. <div class="progress" :style="{ width: item.width + 'px' }">
  133. <el-checkbox
  134. :label="item.name"
  135. v-model="item.checked"
  136. :true-label="0"
  137. :false-label="1"
  138. >{{ item.name }}
  139. </el-checkbox>
  140. </div>
  141. </div>
  142. <el-input-number
  143. v-model.number="item.width"
  144. controls-position="right"
  145. :min="1"
  146. :max="500"
  147. size="mini"
  148. ></el-input-number>
  149. </div>
  150. </transition-group>
  151. </draggable>
  152. </div>
  153. <span slot="footer" class="dialog-footer">
  154. <el-button @click="showSetting = false">取 消</el-button>
  155. <el-button @click="delRow" type="danger">重 置</el-button>
  156. <el-button type="primary" @click="save">确 定</el-button>
  157. </span>
  158. </el-dialog>
  159. </div>
  160. </template>
  161. <script>
  162. import { addSet, resetModule } from "@/api/system/set";
  163. import Cookies from "js-cookie";
  164. export default {
  165. name: 'listComponent',
  166. props: ['tableData', 'listStyle','queryList','customButton','arrow','setRowList','isItHidden','tatolLabel'],
  167. data() {
  168. return {
  169. showSetting: false,
  170. allCheck: false
  171. }
  172. },
  173. watch:{
  174. // 'queryList.columnList':(newValue,oldValue){
  175. // console.log(setRowList)
  176. // // this.initData()
  177. // }
  178. queryList: function (newValue,oldValue) {
  179. console.log(newValue,oldValue)
  180. this.queryList.columnList = newValue.columnList
  181. },
  182. },
  183. created() {
  184. console.log(this.listStyle)
  185. console.log(this.queryList)
  186. console.log(this.queryList.columnList.length)
  187. },
  188. methods: {
  189. listTotal(param) {
  190. const { columns, data } = param
  191. const sums = []
  192. for(let item in this.tatolLabel){
  193. columns.forEach((column, index) => {
  194. if (index === 0) {
  195. sums[index] = '合计'
  196. } else if (column.label == this.tatolLabel[item]) {
  197. const values = data.map((item) => Number(item[column.property]))
  198. if (!values.every((value) => isNaN(value))) {
  199. sums[index] = values.reduce((prev, curr) => {
  200. const value = Number(curr)
  201. if (!isNaN(value)) {
  202. return prev + curr
  203. } else {
  204. return prev
  205. }
  206. }, 0)
  207. }
  208. }
  209. })
  210. }
  211. console.log(sums[columns])
  212. return sums
  213. },
  214. initData(){
  215. this.queryList.columnList = this.queryList.columnList
  216. console.log(this.queryList.columnList)
  217. },
  218. //行号设置
  219. rowClassName({row, rowIndex}) {
  220. // console.log(row,rowIndex)
  221. //把每一行的索引放进row.id
  222. row.serialNumber = rowIndex+1;
  223. // console.log(row.fLineNumber)
  224. },
  225. //列设置全选
  226. allChecked() {
  227. if (this.allCheck == true) {
  228. this.queryList.columnList.map((e) => {
  229. return (e.checked = 0);
  230. });
  231. } else {
  232. this.queryList.columnList.map((e) => {
  233. return (e.checked = 1);
  234. });
  235. }
  236. },
  237. //开始拖拽事件
  238. onStart() {
  239. this.drag = true;
  240. },
  241. //拖拽结束事件
  242. onEnd() {
  243. this.drag = false;
  244. },
  245. //保存列设置
  246. save() {
  247. this.showSetting = false;
  248. let data = {
  249. tableName: this.queryList.tableName,
  250. userId: Cookies.get("userName"),
  251. sysTableSetList: this.queryList.columnList,
  252. };
  253. addSet(data).then((res) => {
  254. if (res.code == 200) {
  255. console.log(res)
  256. this.showSetting = false;
  257. this.queryList.columnList = this.setRowList.filter((e) => e.checked == 0);
  258. }
  259. });
  260. },
  261. //自定义列
  262. delRow() {
  263. this.data = {
  264. tableName: this.queryList.tableName,
  265. userId: Cookies.get("userName"),
  266. };
  267. resetModule(this.data).then((res) => {
  268. if (res.code == 200) {
  269. this.showSetting = false;
  270. this.queryList.columnList = this.listStyle;
  271. console.log(this.getRowList)
  272. }
  273. });
  274. },
  275. showSearch(){
  276. this.$emit('showSearch')
  277. },
  278. //刷新按钮
  279. getList(){
  280. this.$emit('getList')
  281. },
  282. //搜索、重置、展开
  283. feedback(res){
  284. this.$emit('feedback',res)
  285. },
  286. //所有按钮
  287. buttonList(row){
  288. this.$emit('buttonList', row)
  289. },
  290. //查看
  291. viewMethod(scope) {
  292. this.$emit('see', scope)
  293. },
  294. //修改
  295. modification(scope){
  296. this.$emit('modify', scope)
  297. },
  298. //删除
  299. deletion(scope){
  300. this.$emit('deletion', scope)
  301. },
  302. //移出
  303. deleteRow(index, rows) {
  304. this.$emit('deletRows',index,rows)
  305. },
  306. //选择
  307. handleSelectionChange(selection){
  308. this.$emit('selectionbox', selection)
  309. },
  310. handleClick(){
  311. this.$emit('handleClick')
  312. },
  313. },
  314. }
  315. </script>
  316. <style scoped>
  317. .listStyle {
  318. display: flex;
  319. border-top: 1px solid #dcdfe6;
  320. border-left: 1px solid #dcdfe6;
  321. border-right: 1px solid #dcdfe6;
  322. }
  323. .listStyle:last-child {
  324. border-bottom: 1px solid #dcdfe6;
  325. }
  326. .progress {
  327. display: flex;
  328. align-items: center;
  329. padding: 2px;
  330. background-color: rgba(0, 0, 0, 0.05);
  331. height: 100%;
  332. }
  333. </style>