fields.vue 5.0 KB

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