listComponent.vue 11 KB

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