index.vue 2.35 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
<template>
  <div class="">
    <dee-as-com
      ref="templateList"
      :lay-config="{
        typeName: 'DxProjectItemTemplate',
        layKey: 'defaultResult',
      }"
      :current-classify="currentClassify"
      @disable="onDisableClick"
      @enable="onEnableClick"
      @import="importTemplate"
    />
    <el-upload
      :show-file-list="false"
      action="#"
      accept=".zip"
      :http-request="(file) => {importZip(file)}"
    >
      <div id="upload" />
    </el-upload>
  </div>
</template>

<script>
import { post } from '@/utils/http'
import { enableProjectTemplate } from '@/api/plan'
export default {
  name: 'ProjectTemplate',
  componentName: '项目模板页面',
  data() {
    return {
      nodeData: {},
      emitMethods: [
        {
          methods: 'getData',
          methodsName: '获取列表数据'
        }
      ],
      currentClassify: {}
    }
  },
  methods: {
    onDisableClick(rows) {
      this.batchOpertion(rows, false)
    },
    onEnableClick(rows) {
      this.batchOpertion(rows, true)
    },
    batchOpertion(rows, isEnable) {
      const params = JSON.parse(JSON.stringify(rows))
      params.forEach((r) => {
        r.operator = 'MODIFY'
        r.dynamicAttrs.templateState = isEnable
      })
      enableProjectTemplate(params).then((res) => {
        this.$emit('completeEven')
        this.getData(this.nodeData)
        this.$utils.showMessageSuccess(res.message)
      })
    },
    refreshTable(params) {
      this.$refs.templateList.$refs.asCom.getData(params)
    },
    getData(nodeData) {
      this.nodeData = nodeData
      this.currentClassify = { ...nodeData }
      const params = [
        {
          fieldName: 'templateClassifyId',
          operator: 'EQ',
          value: nodeData.id
        }
      ]
      this.refreshTable(params)
    },
    importTemplate() {
      document.getElementById('upload').click()
    },
    importZip(file) {
      const formData = new FormData()
      if (!file) return this.$utils.showMessageWarning('请选择文件')
      if (file !== '') {
        formData.append('file', file.file)
        formData.append('importType', 'ZIP')
        post('/DxProjectItem/import/template', formData).then(res => {
          this.$utils.showMessageSuccess('导入成功')
          this.getData(this.nodeData)
        })
      }
    }
  }
}
</script>

<style lang="scss" scoped></style>