fields.vue 5.8 KB

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