index.vue 14.8 KB
Newer Older
geqilin's avatar
geqilin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
<template lang="pug">
    el-container(style="padding:0px;height:77.6vh;")
        el-aside( width="333px" style="z-index:1000;box-shadow: 2px 0 8px 0 rgba(0, 0, 0, 0.2);")
            el-card.treeCard(style='background:#f4f4f4;box-sizing:border-box;height:100%' :body-style="{ 'overflow-x': 'hidden', 'overflow-y': 'auto' }")
                div.title-bold(slot='header' style='padding-right:150px;margin-left:10px;z-index:1001;') 数据字典维护
                el-tree.dic_tree(style='background:#f4f4f4;' :data="data" node-key='id' :highlight-current='true' :props="defaultProps" :default-expand-all='true' @node-click="handleNodeClick" ref = "tree")
                    //- div(slot-scope="{ node, data }" )
                    span(class="custom-tree-node" style='width:90%;line-height: 18px;' slot-scope="{ node, data }")
                        div(v-if="data.children&&data.children.length>0" style='background:#f4f4f4;')
                          div.dic_tree_header( ) 数据字典项
                        span(v-else)
                            div.tree_point
                            span &nbsp; {{ node.label }}
        el-container()
            el-header(style='height:42px;line-height:42px;background: #f4f4f4;z-index:1001;border: 1px solid rgba(196, 196, 196, 1);')
                span.title-bold.title-left-color(v-if="listTitle") {{listTitle}}
                span.title-bold.title-left-color(v-else) 数据字典项
                el-popover( placement="bottom" width="150")
                        el-button( slot="reference" size='mini' type="primary" icon="el-icon-s-tools" style='float:right;transform:translateY(6px)')  筛选
                        el-checkbox-group( v-model="checkList")
                            el-col( :span="24")
                                el-checkbox( v-for="(item,index) in tableHeader" :label="item" :key="index" )
                                  span {{item.label}}
                el-button(v-if="isAuth('sys:dic:save')",type='primary' size='mini' icon='el-icon-plus',style='float:right;transform:translateY(6px);margin-right:20px;' :disabled="flag" @click='addOrUpdateHandle()') 新增
            el-main.box_main
                el-card.tableCard
                    //- el-table(:data='dataList' @sort-change='sortChange'  :stripe='true' v-loading='dataListLoading' style='width: 100%;' highlight-current-row :header-cell-style="{background:'#EEF8FF',color:'#333333'}")
                    //-     el-table-column(type='index', header-align='center', align='center', label='序号')
                    //-       template(scope="scope")
                    //-         span {{scope.$index+(pageIndex - 1) * pageSize + 1}}
                    //-     el-table-column(prop='name', header-align='center', align='center', label='字典项名称' sortable='custom')
                    //-     el-table-column(prop='value', header-align='center', align='center', label='字典项值' sortable='custom')
                    //-     el-table-column(prop='sortValue',column-key='sort_value', header-align='center', align='center', label='排序值' sortable='custom')
                    //-     el-table-column(prop='',header-align='center',align='center',label='操作' width='200px')
                    //-         template(slot-scope="scope")
                    //-             el-button(type="text"  v-if="isAuth('sys:dic:update')"  @click="addOrUpdateHandle(scope.row)") 编辑
                    //-             el-button(type="text"  v-if="isAuth('sys:dic:delete')"  @click="deleteHandle(scope.row)") 删除
                    drag-table( :data="dataList" :header="checkList" :isToLine='true' :option="tableOption"  @getDataList="getDataList" v-loading="dataListLoading"  :operationNum="4"  :isShowOperate="true")
                      //- -- 插槽
                      el-table-column(slot="fixed"  fixed  prop=""  label="序号"  width='80'  header-align="center" align="center")
                          template( slot-scope="scope")
                            span   {{scope.$index+(pageIndex - 1) * pageSize + 1}}
                      //- 操作项
                      template( slot-scope="scope" )
                          el-button(type="text"  v-if="isAuth('sys:dic:update')"  @click="addOrUpdateHandle(scope.row)") 编辑
                          el-button(type="text"  v-if="isAuth('sys:dic:delete')"  @click="deleteHandle(scope.row)") 删除

            el-footer.box_footer
                el-pagination(@size-change='sizeChangeHandle' background  @current-change='currentChangeHandle' :current-page='pageIndex', :page-sizes='[10, 20, 50, 100]', :page-size='pageSize', :total='totalPage', layout='total, sizes, prev, pager, next, jumper')
                el-dialog(width="40%",:append-to-body='true' :visible.sync='visible' :modal-append-to-body='false' @close="closeForm('ruleForm')")
                    div.title-bold(slot='title') {{!ruleForm.id ? '添加字典项': '修改字典项'}}
                    el-form(:model="ruleForm", :inline="false" :rules="rules" ref="ruleForm", label-width="100px", @submit.native.prevent)
                        el-card(shadow="never")
                            el-row(:span='24')
                                el-col(:span='24')
                                    el-form-item(label="上级字典项ID:" prop="parentId" v-if='false')
                                        el-input(v-model='ruleForm.parentId' placeholder=""  clearable v-if='false')
                                el-col(:span='24')
                                    el-form-item(label="字典项名称:" prop="name")
                                        el-input(v-model='ruleForm.name' placeholder="请输入字典项名称"  clearable )
                                el-col(:span='12')
                                    el-form-item(label="字典项值:" prop="value")
                                        el-input(v-model='ruleForm.value' placeholder="请输字典项值"  clearable )
                                el-col(:span='12')
                                    el-form-item(label="排序值:" prop="sortValue")
                                        el-input(v-model.number='ruleForm.sortValue' placeholder="请输入字典项排序" clearable oninput="if(value.length>9)value=value.slice(0,9)")

                    div(slot="footer" style=' text-align: center;')
                        el-button(type='primary' size='medium' @click="cancel") 取 消
                        el-button(type='primary' size='medium' @click="addsave" v-prevent-re-click) 保存
</template>

<script>
import dragTable from '../../../components/tab'

export default {
  data () {
    let validateNumber = (rule, value, callback) => {
      if (value < 0) {
        callback(new Error('只能输入正整数'))
      } else {
        callback()
      }
    }
    return {
      checkList: [], //筛选数据
      tableHeader: [
        { label: '字典项名称', prop: 'name' },
        { label: '字典项值', prop: 'value' },
        { label: '排序值', prop: 'sortValue' }
      ],
      tableOption: {
        border: false, //是否边框
        maxHeight: 500 //高度
      },
      listTitle: '',
      flag: true,
      clickFlag: false,
      word: '', //查询
      dataList: [], //列表
      dataListLoading: false,
      logTimeout: null,
      stationId: localStorage.getItem('stationId'),
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      sort: 'sort_value',
      order: 'asc',
      addOrUpdateVisible: false,
      ruleForm: {},
      visible: false,
      dicInfo: {},
      dicId: '',
      rules: {//添加规则
        name: [{ required: true, message: '字典项名称不能为空', trigger: 'blur' },
        { min: 1, max: 30, message: '长度在 1 到 30 个字符', trigger: 'blur' }],
        value: [{ min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }],
        sortValue: [{ required: true, message: '排序值不能为空' },
        // { min: 1, max: 10, message: '排序值超出范围', trigger: 'blur' },
        { type: 'number', message: '排序值必须为数字' },
        { validator: validateNumber, trigger: ['blur', 'change'] }
        // { pattern: /^[1-9]\d*$/, message: '只能输入正整数', trigger: 'change' }
        ]
      },
      data: [],
      defaultProps: {
        children: 'children',
        label: 'name',
        id: 'id'
      }
    }
  },
  components: {
    dragTable
  },
  watch: {
    totalPage() { //注意这个函数的名字必须和你监听data中的属性的名字一样,这样才能当你data中的属性发生变化时,触发这个函数
      let pages = Math.ceil(this.totalPage / this.pageSize)//新数据总页数
      //总页数小于当前页数则重新加载列表数据
      if (pages < this.pageIndex) {
          this.pageIndex = pages || 1
          this.getDataList()//获取表格数据的方法
      }
    }
  },
  created() {
    this.getList()
    this.dicInfo = this.data[0]
    this.checkList = [...this.tableHeader]
  },
  methods: {
    getList() {
      this.$http({
        url: this.$http.rtAdornUrl('/rtSysDictionary/dictionaryAllList'),
        method: 'GET',
        params: {
          stationId: this.stationId
        }
      }).then(data => {
        if (data) {
          this.data = data.list
        }
      })
    },
    sortChange(column) {
      if (column.order === 'descending') {
        this.order = 'desc'
      } else {
        this.order = 'asc'
      }
      if (column.column.columnKey) {
        this.sort = column.column.columnKey
      } else {
        this.sort = column.prop
      }
      this.getDataList()
    },
    handleNodeClick(data) {
      this.listTitle = data.name
      if (data.parentId != '-1') {
        this.flag = false
      } else {
        this.flag = true
      }
      this.ruleForm.parentId = data.id
      this.dicId = data.id
      this.dicInfo = data
      this.getDataList()
    },
    getDataList(sort, order) {
      // console.log(this.ruleForm.parentId)
      this.dataListLoading = true
      this.$http({
        url: this.$http.rtAdornUrl('/rtSysDictionary/dictionaryList'),
        method: 'post',
        data: {
          page: this.pageIndex,
          rows: this.pageSize,
          parentId: this.dicId,
          sort: sort || 'sort_value',
          order,
          stationId: this.stationId
        }
      }).then(data => {
        if (data) {
          this.dataList = data.page.rows
          this.totalPage = data.page.total
        } else {
          this.dataList = []
          this.totalPage = 0
        }
        this.dataListLoading = false
      })
    },
    // 删除
    deleteHandle(row) {
      row.deleted = 1
      this.$confirm(`确认删除该字典项?`, '删除字典项', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        closeOnClickModal: false
      }).then(() => {
        this.$http({
          url: this.$http.rtAdornUrl('/rtSysDictionary/deleteById'),
          method: 'post',
          data: row
        }).then((res) => {
          if (res && res.code === 0) {
            this.$message({
              message: '操作成功',
              type: 'success',
              duration: 1500,
              onClose: () => {
                this.getDataList()
              }
            })
          } else {
            this.$message.error(res.msg)
          }
        })
      })
    },
    //添加或修改事件
    addOrUpdateHandle(row, flagType) {
      this.clickFlag = false
      this.visible = true
      if (row) {
        this.ruleForm = JSON.parse(JSON.stringify(row))
      } else {
        this.ruleForm = {}
        if (this.dicInfo) {
          this.ruleForm.parentId = this.dicInfo.id
        }
      }
    },
    // 提交
    addsave() {
      this.$refs['ruleForm'].validate(valid => {
        if (valid) {
          this.clickFlag = true
          this.ruleForm.stationId = this.stationId
          this.$http({
            url: this.$http.rtAdornUrl(
                `/rtSysDictionary/${!this.ruleForm.id ? 'save' : 'update'}`
            ),
            method: 'post',
            data: this.ruleForm
          }).then(data => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.getDataList()
                  //如果左边菜单栏点击的是最上层则不刷新
                  if (this.ruleForm.parentId === '6070da6f5d9b40121359d993f9791b09') {
                    this.getList()
                  }
                }
              })
            } else {
              this.clickFlag = false
              this.$message.error(data.msg)
            }
          })
        }
      })
    },
    closeForm(formRule) {
      this.ruleForm = {}
      this.$refs[formRule].resetFields()
      this.visible = false
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val
      this.getDataList()
    },
    //取消
    cancel() {
      this.$confirm('确认取消?', !this.ruleForm.id ? '添加字典项' : '修改字典项', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
          .then(() => {
            this.closeForm('ruleForm')
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消退出'
            })
          })
    }
  }
}
</script>
<style lang='scss' scoped>
.dic_tree_header {
  width: 330px;
  height: 30px;
  line-height: 30px;
  text-indent: 20px;
  background: white !important;
  border-radius: 15px 0 0 15px;
  box-shadow: 0px 0px 8px 0px rgba(0, 0, 0, 0.05);
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: rgba(0, 0, 0, 1);
}

.tree_point {
  width: 6px;
  height: 6px;
  display: inline-block;
  transform: translateY(-3px);
  background: rgba(23, 41, 71, 1);
  opacity: 0.3;
  border-radius: 50%;
  margin-left: 7px;
}

.dic_tree /deep/ .el-tree-node__children {
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: bold;
  color: rgba(0, 0, 0, 1);
}

.dic_tree /deep/ .el-tree-node__expand-icon.expanded {
  position: absolute !important;
  left: 100px !important;
}

.dic_tree /deep/ .el-tree-node__content > .el-tree-node__expand-icon {
  position: absolute !important;
  left: 100px !important;
}
</style>
<style lang="scss">
    .el-tree--highlight-current
    .el-tree-node.is-current
    > .el-tree-node__content
    .custom-tree-node {
        background-color: #33b0f6 !important;
        color: aliceblue;
    }
    .el-tree--highlight-current .el-tree-node.is-current > .el-tree-node__content {
        background-color: transparent;
    }
</style>