Blame view

antis-ncc-admin/src/views/basic/dynamicModel/list/detail/index.vue 7.31 KB
de2bd2f9   “wangming”   项目初始化
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
  <template>
    <div>
      <template v-if="formData.popupType==='general'">
        <el-dialog title="详情" :close-on-click-modal="false" :visible.sync="visible"
          class="NCC-dialog NCC-dialog_center" lock-scroll :width="formData.generalWidth"
          append-to-body>
          <div class="dynamicDetail" v-loading="loading || mainLoading"
            :element-loading-text="$t('common.loadingText')">
            <Parser :formConf="formData" :relationData="relationData" @toDetail="toDetail"
              v-if="!loading" />
          </div>
          <span slot="footer" class="dialog-footer">
            <template v-if="formData.hasPrintBtn && formData.printId">
              <el-button type="primary" @click="printBrowseVisible=true">
                {{formData.printButtonText||'打 印'}}
              </el-button>
            </template>
            <el-button @click="visible = false">{{$t('common.cancelButton')}}</el-button>
          </span>
        </el-dialog>
      </template>
      <template v-if="formData.popupType==='fullScreen'">
        <transition name="el-zoom-in-center">
          <div class="NCC-preview-main">
            <div class="NCC-common-page-header">
              <el-page-header @back="goBack" content="详情" />
              <div class="options">
                <template v-if="formData.hasPrintBtn && formData.printId">
                  <el-button type="primary" @click="printBrowseVisible=true">
                    {{formData.printButtonText||'打 印'}}
                  </el-button>
                </template>
                <el-button @click="goBack">{{$t('common.cancelButton')}}</el-button>
              </div>
            </div>
            <div class="dynamic-form-main dynamicDetail"
              :style="{margin: '0 auto',width:formData.fullScreenWidth}"
              v-loading="loading || mainLoading" :element-loading-text="$t('common.loadingText')">
              <Parser :formConf="formData" :relationData="relationData" @toDetail="toDetail"
                v-if="!loading" />
            </div>
          </div>
        </transition>
      </template>
      <Detail v-if="detailVisible" ref="Detail" @close="detailVisible = false" />
      <print-browse :visible.sync="printBrowseVisible" :id="formData.printId" :formId="dataForm.id" />
    </div>
  </template>
  
  <script>
  import { getDataChange, getConfigData } from '@/api/onlineDev/visualDev'
  import { deepClone } from '@/utils'
  import Parser from './Parser'
  import PrintBrowse from '@/components/PrintBrowse'
  export default {
    name: 'Detail',
    components: { Parser, PrintBrowse },
    data() {
      return {
        visible: false,
        dataForm: {
          id: '',
          data: ''
        },
        modelId: '',
        formData: {},
        formValue: {},
        loading: true,
        mainLoading: false,
        detailVisible: false,
        relationData: {},
        useFormPermission: false,
        printBrowseVisible: false,
        formOperates: []
      }
    },
    methods: {
      goBack() {
        this.$emit('close')
      },
      init(formData, modelId, id, useFormPermission) {
        this.formData = deepClone(formData)
        this.modelId = modelId
        this.useFormPermission = useFormPermission
        this.dataForm.id = id || ''
        this.getFormOperates()
        this.loading = true
        this.relationData = {}
        this.$nextTick(() => {
          if (this.dataForm.id) {
            getDataChange(modelId, this.dataForm.id).then(res => {
              this.dataForm = res.data
              if (!this.dataForm.data) return
              this.formValue = JSON.parse(this.dataForm.data)
              this.fillFormData(this.formData, this.formValue)
              this.visible = true
            })
          } else {
            this.formValue = {}
            this.loading = false
            this.visible = false
            this.$emit('close')
          }
        })
      },
      unique(arr, attrName) {
        const res = new Map()
        return arr.filter(o => !res.has(o[attrName]) && res.set(o[attrName], 1))
      },
      handleAttrList(list) {
        let realList = this.unique(list, 'relationField')
        for (let i = 0; i < realList.length; i++) {
          const item = realList[i];
          let modelId = '', id = "", field = ""
          const loop = list => {
            for (let i = 0; i < list.length; i++) {
              if (item.relationField === list[i].__vModel__) {
                modelId = list[i].modelId
                id = list[i].__config__.defaultValue
                field = list[i].__vModel__
                break
              }
              if (list[i].__config__ && list[i].__config__.nccKey !== 'table' && list[i].__config__.children && Array.isArray(list[i].__config__.children)) {
                loop(list[i].__config__.children)
              }
            }
          }
          loop(this.formData.fields)
          if (!id) {
            this.$set(this.relationData, field, "")
            continue
          }
          getDataChange(modelId, id).then(res => {
            if (!res.data || !res.data.data) {
              this.$set(this.relationData, field, "")
              return
            }
            let data = JSON.parse(res.data.data)
            this.$set(this.relationData, field, data)
          }).catch(() => { this.$set(this.relationData, field, "") })
        }
      },
      toDetail(item) {
        if (!item.__config__.defaultValue) return
        this.mainLoading = true
        getConfigData(item.modelId).then(res => {
          this.mainLoading = false
          if (!res.data) return
          if (!res.data.formData) return
          let formData = JSON.parse(res.data.formData)
          formData.popupType = this.formData.popupType
          this.detailVisible = true
          this.$nextTick(() => {
            this.$refs.Detail.init(formData, item.modelId, item.__config__.defaultValue)
          })
        }).catch(() => { this.mainLoading = false })
      },
      getFormOperates() {
        if (!this.useFormPermission) return
        const permissionList = this.$store.getters.permissionList
        const modelId = this.$route.meta.modelId
        const list = permissionList.filter(o => o.modelId === modelId)
        this.formOperates = list[0] && list[0].form ? list[0].form : []
      },
      fillFormData(form, data) {
        let relationFormAttrList = []
        const loop = list => {
          for (let i = 0; i < list.length; i++) {
            let item = list[i]
            if (item.__vModel__) {
              if (item.__config__.nccKey === 'relationForm') {
                let id = data[item.__vModel__ + '_id']
                if (id) item.__config__.defaultValue = id
                this.$set(item, 'name', data[item.__vModel__] || '')
              } else {
                const val = data[item.__vModel__]
                if (val) item.__config__.defaultValue = val
              }
              if (this.useFormPermission) {
                let noShow = true
                if (this.formOperates && this.formOperates.length) {
                  noShow = !this.formOperates.some(o => o.enCode === item.__vModel__)
                }
                noShow = item.__config__.noShow ? item.__config__.noShow : noShow
                this.$set(item.__config__, 'noShow', noShow)
              }
            }
            if (item.__config__.nccKey === 'relationFormAttr') relationFormAttrList.push(item)
            if (item.__config__ && item.__config__.nccKey !== 'table' && item.__config__.children && Array.isArray(item.__config__.children)) {
              loop(item.__config__.children)
            }
          }
        }
        loop(form.fields)
        this.handleAttrList(relationFormAttrList)
        this.loading = false
      }
    }
  }
  </script>