DxDocumentAdd.vue 4.51 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
/**
* @Description:
* @author cxg
* @date 2020/07/22
*/
<template>
  <div class="add-page">
    <div class="full-border-content">
      <el-scrollbar class="scroll-container" style="height:100%">
        <div class="task-name">新建文档</div>
        <dee-form
          :form="typeForm"
          :form-data="typeFormData"
          :border="configDetails&&configDetails.base&&configDetails.base.borderShow"
          :label-width="configDetails&&configDetails.base&&configDetails.base.labelWidth"
        />
        <dee-form
          ref="addForm"
          :form="addData"
          :form-data="showFormData"
          :rules="configDetails.rules"
          :form-buttons="configDetails.formButtons"
          :border="configDetails&&configDetails.base&&configDetails.base.borderShow"
          :label-width="configDetails&&configDetails.base&&configDetails.base.labelWidth"
          :form-btn-position="configDetails&&configDetails.base&&configDetails.base.formBtnPosition"
          :label-position="configDetails&&configDetails.base&&configDetails.base.labelPosition"
          @on-submit="submitFun"
          @on-cancel="cancelFun"
        />
      </el-scrollbar>
    </div>
  </div>
</template>

<script>
import { getLayouts } from '@/api/config'
import { addDocWithRecursion, getSubTypeName } from '@/api/doc'

export default {
  name: 'DxDocumentAdd',
  displayName: '新建文档',
  modelRelationObjs: [],
  components: {},
  props: {
    sandboxId: {
      type: Number,
      default: () => 0
    }
  },
  data() {
    return {
      addData: {},
      appUrl: '',
      typeName: 'DxDocument',
      typeForm: { subTypeName: '' },
      configDetails: {
        formData: []
      },
      docTypes: [],
      layout: ''
    }
  },
  computed: {
    visitedViews() {
      return this.$store.state.tagsView.visitedViews
    },
    previousRouter() {
      return this.$store.state.tagsView.previousRouter.slice(-1)[0]
    },
    showFormData() {
      if (!this.configDetails || !this.configDetails.formData) {
        return []
      }
      return this.configDetails.formData
    },
    typeFormData() {
      return [
        {
          title: '',
          split: 3,
          data: [
            { key: 'subTypeName',
              title: '文档类型',
              component: {
                name: 'el-select',
                options: this.docTypes
              }
            }
          ]
        }
      ]
    }
  },
  watch: {
    'typeForm.subTypeName'(val) {
      this.getLayouts()
    },
    // 重新打开页签则刷新页面
    visitedViews(value) {
      if (value.some(x => x.name === 'docAdd')) {
        this.addData = {}
        this.$refs.addForm.$refs.form.clearValidate()
        this.getSubTypeName()
      }
    }
  },
  created() {
    if (window.location.hash.includes('?layout=')) {
      this.layout = window.location.hash.split('?layout=').slice(-1)[0]
      this.layout = this.layout ? this.layout.split('&').slice(-1)[0] : ''
    }
    this.getSubTypeName()
  },
  mounted() {},
  methods: {
    getSubTypeName() {
      if (this.typeName === null || this.typeName === '') {
        return
      }
      getSubTypeName('', this.typeName).then(res => {
        if (res.items) {
          this.docTypes = res.items.map(item => {
            return {
              label: item.displayName,
              value: item.name
            }
          })
          this.typeForm.subTypeName = this.docTypes[0].value
        }
      })
    },
    getLayouts() {
      if (!this.typeForm || !this.typeForm.subTypeName) {
        return
      }
      getLayouts(this.typeForm.subTypeName, this.layout || this.$enums.layout['新建']).then((res) => {
        const item = res.items.slice(-1)
        if (item[0] && item[0].configDetails) {
          this.configDetails = JSON.parse(item[0].configDetails)
          this.appUrl = this.configDetails.tableConfig && this.configDetails.tableConfig.serverUrl
        }
      })
    },
    submitFun() {
      // this.addData.state = '编制'
      this.addData.subTypeName = this.typeForm.subTypeName
      const params = this.$utils.saveDynamicAttr(this.addData, '.')
      params.operator = 'ADD'
      if (this.sandboxId !== 0) {
        params.sandboxId = this.sandboxId
        this.$emit('submitFun', params)
      } else {
        addDocWithRecursion(params, this.appUrl).then(res => {
          this.$utils.showMessage('操作成功!', 'success')
          this.$emit('submitFun', res.items)
        })
      }
    },
    cancelFun() {
      this.$emit('cancel')
    }
  }
}

</script>
<style lang='scss'>

</style>