fields.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <template>
  2. <div>
  3. <el-dialog
  4. custom-class="myFields"
  5. title="显示栏位管理"
  6. :visible.sync="dialogVisible"
  7. width="300px"
  8. :before-close="handleClose"
  9. :close-on-click-modal="false"
  10. :append-to-body="true"
  11. >
  12. <div>
  13. <el-checkbox
  14. :indeterminate="isIndeterminate"
  15. v-model="checkAll"
  16. @change="handleCheckAllChange"
  17. >全选</el-checkbox
  18. >
  19. <p></p>
  20. <el-checkbox-group v-model="checked" @change="handleCheckedChange">
  21. <template>
  22. <div v-for="(field,index) in filedList" :key="field.value" style="padding:5px 0;">
  23. <el-checkbox :label="field.value">
  24. <div>
  25. <div>{{ field.name }}</div>
  26. <div>
  27. <el-button type="text" :disabled="index == filedList.length-1" class="down"> <i class="el-icon-sort-down" @click.stop.prevent="down(index,field)"></i></el-button>
  28. <el-button type="text" :disabled="index == 0" class="up"><i class="el-icon-sort-up" @click.stop.prevent="up(index,field)"></i></el-button>
  29. </div>
  30. </div>
  31. </el-checkbox>
  32. </div>
  33. </template>
  34. </el-checkbox-group>
  35. </div>
  36. <span slot="footer" class="dialog-footer">
  37. <el-button @click="handleClose">取 消</el-button>
  38. <el-button type="primary" :loading="loading" @click="submit">确 定</el-button>
  39. </span>
  40. </el-dialog>
  41. </div>
  42. </template>
  43. <script>
  44. export default {
  45. components: {},
  46. props: {
  47. type:{
  48. type:String,
  49. default:''
  50. }
  51. },
  52. data() {
  53. return {
  54. //控制显示弹窗
  55. dialogVisible: false,
  56. //是否全选
  57. isIndeterminate: false,
  58. //全选
  59. checkAll: false,
  60. //选择
  61. checked: [],
  62. //显示栏位
  63. filedList:[],
  64. //按钮加载
  65. loading:false
  66. };
  67. },
  68. watch: {},
  69. computed: {},
  70. created() {},
  71. mounted() {
  72. },
  73. methods: {
  74. //打开栏位
  75. open(data) {
  76. this.filedList = JSON.parse(JSON.stringify(data))
  77. this.checked = data.filter(item=>{
  78. return item.ifHidden == false
  79. }).map(item=>{
  80. return item.value
  81. })
  82. this.handleCheckedChange(this.checked)
  83. this.dialogVisible = true;
  84. },
  85. //下移
  86. down(index,file){
  87. var arr = this.filedList
  88. this.filedList.splice(index, 2, arr[index + 1], arr[index])
  89. },
  90. //上移
  91. up(index,file){
  92. var arr = this.filedList
  93. this.filedList.splice(index - 1, 2, arr[index], arr[index - 1])
  94. },
  95. //关闭弹窗
  96. handleClose() {
  97. this.dialogVisible = false;
  98. },
  99. //提交更改
  100. submit() {
  101. for(var i = 0; i < this.filedList.length; i++ ){
  102. if(this.checked.includes(this.filedList[i].value)){
  103. this.filedList[i].ifHidden = false
  104. }else{
  105. this.filedList[i].ifHidden = true
  106. }
  107. }
  108. var params = {
  109. tableName : this.type,
  110. value:this.filedList
  111. }
  112. this.loading = true
  113. this.$api.setCustomField(params).then((response)=>{
  114. if(response.code == 200){
  115. this.loading = false
  116. this.handleClose()
  117. this.$emit('getFieldList',this.filedList)
  118. }
  119. }).catch(error=>{
  120. this.loading = false
  121. })
  122. },
  123. //全选
  124. handleCheckAllChange(val) {
  125. this.checked = val ? this.filedList.map(item=>{
  126. return item.value
  127. }) : [];
  128. this.isIndeterminate = false;
  129. },
  130. //勾选
  131. handleCheckedChange(value) {
  132. let checkedCount = value.length;
  133. this.checkAll = checkedCount === this.filedList.length;
  134. this.isIndeterminate = checkedCount > 0 && checkedCount < this.filedList.length;
  135. },
  136. },
  137. };
  138. </script>
  139. <style lang="scss">
  140. .myFields{
  141. .el-checkbox{
  142. width: 100%;
  143. .el-checkbox__label{
  144. width:calc(100% - 10px);
  145. div{
  146. display: flex;
  147. justify-content: space-between;
  148. align-items: center;
  149. .down,.up{
  150. padding: 0;
  151. margin: 0;
  152. }
  153. i{
  154. color: #999;
  155. }
  156. i:hover{
  157. color: #409EFF;
  158. }
  159. }
  160. }
  161. }
  162. }
  163. </style>