listComponent.vue 10 KB

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