changeObjectAdd.vue 4.68 KB
Newer Older
wangdanlei's avatar
wangdanlei 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
<template>
  <div>
    <dee-form
      label-width="90px"
      :form="form.propForm"
      :form-data="form.propFormData"
      :form-buttons="formButtons"
      form-btn-position="center"
      @on-submit="submit"
      @on-cancel="cancel"
    >
      <div slot="search" style="display: flex;justify-content: center">
        <el-button size="small" type="primary" @click="search">查询</el-button>
      </div>
      <dee-table
        slot="table"
        ref="table"
        :data="tableData"
        :columns="columns"
        selection-row
        :pagination="pagination"
        :options="{maxHeight:300}"
        @pagination-current-change="paginationCurrentChange"
        @pagination-size-change="paginationSizeChange"
        @selection-change="selectionChange"
      />
    </dee-form>
  </div>
</template>

<script>
import { post } from '@/utils/http'

export default {
// import引入的组件需要注入到对象中才能使用
  components: {},

  props: {
    form: {
      type: Object,
      default: () => {
        return {}
      }
    },
    isRadio: {
      type: Boolean,
      default: () => false
    }
  },

  data() {
    // 这里存放数据
    return {
      pagination: {
        currentPage: 1,
        pageSize: 10,
        total: 0,
        pageSizes: [10, 20, 50]
      },
      selectedData: [],
      tableData: [],
      dictLists: {},
      columns: [
        { title: '编号', key: 'number', headerAlign: 'center' },
        { title: '名称', key: 'name', headerAlign: 'center' },
        { title: '对象类型', key: 'subTypeDisplayName', headerAlign: 'center' },
        { title: '状态', key: 'state', headerAlign: 'center', fildProp: {
          type: 'DictDataVO',
          rule: {
            dictTypeCode: 'ObjStatus' }
        }},
        { title: '修改者', key: 'modifier.userName', headerAlign: 'center' },
        { title: '上次修改时间', key: 'modifyTime', headerAlign: 'center' }
      ],
      formButtons: [
        {
          'text': '确定',
          'type': 'submit',
          'component': {
            'type': 'primary'
          }
        },
        {
          'text': '取消',
          'type': 'cancel',
          'component': {
          }
        }
      ]
    }
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 生命周期 - 创建完成(可以访问当前this实例)
  async created() {
    await this.$dict.getDictList(this.columns).then(res => {
      this.dictLists = res
    })
  },
  // 生命周期 - 挂载完成(可以访问DOM元素)
  mounted() {

  },
  activated() {
  },
  // 方法集合
  methods: {
    selectionChange(selection) {
      if (this.isRadio) {
        if (selection.length > 1) {
          this.$refs.table.$refs.deeTable.clearSelection()
          this.$refs.table.$refs.deeTable.toggleRowSelection(selection.pop())
        }
      }
      this.selectedData = selection
    },
    paginationCurrentChange(val) {
      this.pagination.currentPage = val
      this.search()
    },
    paginationSizeChange(val) {
      this.pagination.pageSize = val
      this.search()
    },
    search() {
      const data = [
        {
          'fieldName': 'id',
          'operator': 'NEQ',
          'value': 0
        },
        {
          'fieldName': 'latest',
          'operator': 'EQ',
          'value': true
        },
        {
          'fieldName': 'checkOuted',
          'operator': 'NEQ',
          'value': true
        }
      ]
      Object.entries(this.form.propForm).forEach(x => {
        if (x[1] && x[0] !== 'subTypeName') {
          data.push({
            'fieldName': x[0],
            'operator': 'LIKE',
            'value': x[1]
          })
        }
      })
      const params = {
        // 'indices': ['DxChangeRequest'],
        'searchItems': {
          'items': data
        },
        'sortItem': [
          {
            'fieldName': 'modifyTime',
            'sortOrder': 'desc'
          }
        ],
        'pageFrom': this.pagination.currentPage,
        'pageSize': this.pagination.pageSize
      }
      post(`/${this.form.propForm.subTypeName}/find/recursion`, params).then(res => {
        this.setTableData(res)
      })
    },
    setTableData(res) {
      this.tableData = res.items.content.map(item => {
        return this.$dict.displayDictValue(item, this.dictLists)
      })
      this.pagination.total = res.items.totalElements
    },
    submit() {
      this.$emit('submit', this.selectedData)
    },
    cancel() {
      this.tableData = []
      this.selectedData = []
      this.form.propForm = {
        number: '',
        name: '',
        subTypeName: ''
      }
      this.$emit('close')
    }
  }
}
</script>
<style lang='scss'>
</style>