Blame view

src/views/contract/printContractList.vue 3.96 KB
b25b036d   wuxw   v1.9 优化日期
1
  <template>
bc37d685   wuxw   开发完成合同功能
2
    <div class="print-contract-container">
d767b5e6   wuxw   v1.9 合同费用bug 修复
3
      <div class="box-card">
bc37d685   wuxw   开发完成合同功能
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
        <div slot="header" class="clearfix">
          <h2>{{ $t('printContract.title') }}</h2>
        </div>
  
        <el-row v-if="printContractInfo.context" class="margin-top">
          <el-col :span="24">
            <div v-html="printContractInfo.context"></div>
          </el-col>
        </el-row>
  
        <el-row v-else class="margin-top">
          <el-col :span="24" class="text-center">
            <div>{{ $t('printContract.noTemplate') }}</div>
          </el-col>
        </el-row>
  
        <div id="print-btn" class="button-group">
d767b5e6   wuxw   v1.9 合同费用bug 修复
21
          <el-button type="primary" class="float-right" @click="_printContractDiv">
bc37d685   wuxw   开发完成合同功能
22
23
            <i class="el-icon-printer"></i>&nbsp;{{ $t('printContract.print') }}
          </el-button>
d767b5e6   wuxw   v1.9 合同费用bug 修复
24
          <el-button type="warning" class="float-right" style="margin-right:20px;" @click="_closePage">
bc37d685   wuxw   开发完成合同功能
25
26
27
            {{ $t('printContract.close') }}
          </el-button>
        </div>
d767b5e6   wuxw   v1.9 合同费用bug 修复
28
      </div>
bc37d685   wuxw   开发完成合同功能
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
    </div>
  </template>
  
  <script>
  import { getPrintContractTemplate } from '@/api/contract/printContractApi'
  import { getCommunityId } from '@/api/community/communityApi'
  
  export default {
    name: 'PrintContractList',
    data() {
      return {
        templatecontent: '',
        contractdata: '',
        contractTypeSpec: '',
        baseRepalce: [],
        attrs: [],
        printContractInfo: {
          contractId: '',
          contractTypeId: '',
          context: ''
        },
        printFlag: '0',
        communityId: ''
      }
    },
    created() {
      this.communityId = getCommunityId()
      this.printContractInfo.contractTypeId = this.$route.query.contractTypeId
      this.printContractInfo.contractId = this.$route.query.contractId
      this._loadContract()
    },
    methods: {
      _loadContract() {
        const param = {
          page: 1,
          row: 1,
          contractId: this.printContractInfo.contractId,
          contractTypeId: this.printContractInfo.contractTypeId,
          communityId: this.communityId
        }
  
        getPrintContractTemplate(param)
          .then(res => {
            const _data = res.data
            this.templatecontent = _data.contractTypeTemplate[0].context
            this.contractdata = _data.contract[0]
            this.attrs = _data.contract[0].attrs
            this.contractTypeSpec = _data.contractTypeSpec
  
            this.contractTypeSpec.forEach(e => {
              const rname = e.specName
              const rspecCd = e.specCd
              this.attrs.forEach(ea => {
                if (rspecCd === ea.specCd) {
                  const reg = new RegExp('#' + rname + '#', 'g')
                  this.templatecontent = this.templatecontent.replace(reg, ea.value)
                }
              })
            })
  
            this.baseRepalce = _data.baseRepalce
            if (this.baseRepalce) {
              this.baseRepalce.forEach(e => {
                const rname = e.name
                const rkey = e.key
                const contractarr = Object.keys(this.contractdata)
                for (const a in contractarr) {
                  if (rkey === contractarr[a]) {
                    const reg = new RegExp('#' + rname + '#', 'g')
                    this.templatecontent = this.templatecontent.replace(reg, this.contractdata[contractarr[a]])
                  }
                }
              })
            }
  
            this.printContractInfo.context = this.templatecontent
          })
          .catch(error => {
            console.error('请求失败:', error)
          })
      },
  
      _printContractDiv() {
        this.printFlag = '1'
        document.getElementById('print-btn').style.display = 'none'
        window.print()
        window.opener = null
        window.close()
      },
  
      _closePage() {
        window.opener = null
        window.close()
      }
    }
  }
  </script>
  
  <style lang="scss" scoped>
  .print-contract-container {
    padding: 20px;
  
    .box-card {
      margin-bottom: 20px;
    }
  
    .margin-top {
      margin-top: 20px;
    }
  
    .text-center {
      text-align: center;
    }
  
    .float-right {
      float: right;
    }
  
    .button-group {
      margin-top: 20px;
      overflow: hidden;
    }
  }
  </style>