listComponent.vue 8.5 KB

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