111
lkk
2025-04-09 e4717b437f7b4ef27c9801508f252f811fc65b3e
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
<template>
  <el-drawer
    :class="fullscreen ? 't-dialog--fullscreen' : 't-dialog'"
    :fullscreen="fullscreen"
    :visible.sync="dialogVisible"
    custom-class="view-dialog"
    width="75%"
  >
    <div slot="title" class="t__dialog__header">
      <span class="el-dialog__title">{{ dialogTitle }}</span>
      <!-- <div class="t__dialog__menu">
        <i
          :class="fullscreen ? 'el-icon-news' : 'el-icon-full-screen'"
          class="el-dialog__close"
          @click="handleFullScreen"
        />
      </div> -->
    </div>
    <div style="margin: 10px 10px;">
      <el-scrollbar>
          <generate-form
            v-if="formConf.fields.length && formModel && isEditMode"
            :key="formParseKey"
            ref="generateForm"
            :form-conf="formConf"
            :page-form-model="formModel"
            style="margin-bottom: 40px"
          />
          <view-data v-else id="printForm" :fields="fields" :page-form-model="formModel" :is-print.sync="isPrint" />
        </el-scrollbar>
    </div>
        
    
 
    <span slot="footer" class="t-dialog__footer">
      <!-- <el-button v-if="isEditMode" type="primary" @click="handleUpdate"> 确 定 </el-button>
      <el-button v-if="!isEditMode && canUpdate" icon="el-icon-edit" type="primary" @click="handleEditMode">
        修 改
      </el-button> -->
      <!-- <el-button v-if="checkBtnPerms('delete')" type="danger" plain @click="handleDelete"> 删 除 </el-button> -->
      <el-button @click="handleCancel">取 消</el-button>
    </span>
  </el-drawer>
</template>
 
<script>
import { GenerateForm } from 'tduck-form-generator'
import ViewData from './ViewData'
import "tduck-form-generator/dist/TduckForm.css";
// import { deleteFormDataRequest, updateFormDataRequest } from '@/api/project/data'
import { jsonSimpleClone } from '@/utils'
// import { getSettingRequest } from '@/api/project/setting'
import { removeHtmlTag } from '@/utils'
 
export default {
  name: 'ViewOrUpdate',
  components: {
    GenerateForm,
    ViewData
  },
  directives: {
    print
  },
  props: ['fields', 'fixedFields', 'formModel', 'formKey', 'canUpdate'],
  data() {
    return {
      activeName: 'info',
      isEditMode: false,
      formParseKey: new Date().getTime(),
      formConf: {
        fields: [],
        formKey: '',
        disabled: true,
        span: 24,
        size: 'small',
        labelPosition: 'top',
        labelWidth: 100,
        formRules: 'rules',
        gutter: 15,
        formBtns: false,
        resetBtn: false,
        theme: {
          backgroundImg: '',
          showTitle: true,
          showDescribe: true,
          showNumber: false,
          btnsColor: null
        }
      },
      dialogVisible: false,
      dialogTitle: '查看',
      fullscreen: false,
      openReply: false,
      isPrint: false,
      dialogHeight: 700
    }
  },
  watch: {
    fields: {
      handler: function (val, oldVal) {
        this.formConf.fields = val
          .filter((item) => {
            return item.scheme
          })
          .map((item) => {
            if (item.scheme != null) {
              item.scheme.viewMode = true
              // 去除标签中富文本
              item.scheme.config.label = removeHtmlTag(item.scheme.config.label)
            }
            return item.scheme
          })
      },
      immediate: true
    }
  },
  created() {
    // this.queryUserProjectSetting()
  },
  methods: {
    // checkBtnPerms(btn) {
    //   return this.$parent.checkBtnPerms(btn)
    // },
    showDialog() {
      this.formConf.disabled = true
      this.dialogTitle = '查看'
      this.formParseKey = new Date().getTime()
      this.isEditMode = false
      this.dialogVisible = true
      this.remarkEditDisable = true
      this.remarkButton = '编辑'
      this.activeName = 'info'
    },
    handleCancel() {
      if (this.isEditMode) {
        this.isEditMode = false
        this.formConf.disabled = true
        return
      }
      this.dialogVisible = false
      this.$emit('reload')
    },
    handleEditMode() {
      this.isEditMode = true
      this.dialogTitle = '编辑'
      this.formConf.disabled = false
    },
    handleFullScreen() {
      this.fullscreen = !this.fullscreen
    },
    // 查询操作按钮
    // queryUserProjectSetting() {
    //   console.log(1111)
    //   getSettingRequest(this.formKey).then((res) => {
    //     if (res.data) {
    //       this.openReply = res.data.openReply
    //     }
    //   })
    // },
    handleDelete() {
      this.$alert('删除后不可恢复,是否确认删除该数据?', '删除表单数据', {
        confirmButtonText: '确定',
        callback: (action) => {
          if (action === 'confirm')
            deleteFormDataRequest([this.formModel.id], this.formKey).then((res) => {
              this.msgSuccess('删除成功')
              this.dialogVisible = false
              this.$emit('reload')
            })
        }
      })
    },
    handleUpdate() {
      let formModel = jsonSimpleClone(this.$refs.generateForm.formModel)
      // 表单中字段名规则为字段类型时间戳 移除不符合规则的数据 不然会有其他的比如提交时间等数据
      let tempFormModel = {}
      // 保留formModel中包含数字的属性
      for (let key in formModel) {
        let bool = /.*\d+.*/g.test(key)
        if (bool) {
          tempFormModel[key] = formModel[key]
        }
      }
      updateFormDataRequest({
        id: this.formModel.id,
        completeTime: null,
        formKey: this.formKey,
        submitOs: '',
        submitBrowser: '',
        submitUa: null,
        wxUserInfo: null,
        wxOpenId: '',
        originalData: tempFormModel
      }).then((res) => {
        this.msgSuccess('修改成功')
        this.dialogVisible = false
        setTimeout(() => {
          this.$emit('reload')
        }, 1000)
      })
    }
  }
}
</script>
 
<style lang="scss" scoped>
.dialog-form {
  overflow: hidden;
  height: 563px;
 
  .left {
    overflow: auto;
    height: 100%;
    border-right: var(--color-bg) solid 1px;
    padding: 10px;
    box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  }
 
  .right {
    height: 100%;
    padding: 10px;
  }
}
 
.operate-btns {
  border-bottom: 1px solid #f0f0f0;
}
 
::v-deep .el-dialog__body {
  padding: 0 !important;
  margin-bottom: 0 !important;
  overflow-y: hidden !important;
}
 
.t-dialog .left {
  //height: 700px !important;
}
 
.t-dialog--fullscreen .left {
  padding: 50px;
  height: 80vh !important;
}
 
.view-dialog {
  height: 500px;
}
</style>