MrShi
2024-11-22 ba5f8ce99b414a89d1e21a650321bf373773e7ae
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>
    <GlobalWindow
        :title="title"
        width="50%"
        :visible.sync="visible"
        :confirm-working="isWorking"
        @confirm="confirm"
    >
        <el-form :model="form" ref="form" :rules="rules">
            <el-form-item label="授权账号" prop="userId">
                <el-select v-model="form.userId" filterable placeholder="请选择">
                    <el-option
                        v-for="item in account"
                        :key="item.id"
                        :label="item.username"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="申请授权企业" prop="companyIds">
                <el-select
                    v-model="form.companyIds"
                    multiple
                    filterable
                    placeholder="请选择">
                    <el-option
                        v-for="item in company"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>
            <el-form-item label="申请说明" prop="content">
                <el-input
                    type="textarea"
                    placeholder="请输入申请说明"
                    v-model="form.content"
                    maxlength="300"
                    show-word-limit />
            </el-form-item>
            <el-form-item label="授权书" prop="multifileList">
                <UploadFile v-if="visible" @remove="deleFile" :limit="99" :uploadData="{ folder: 'companyUserApply', fileType:'.pdf' }" :fileList="fileList" @uploadSuccess="editFanganFile" />
            </el-form-item>
        </el-form>
    </GlobalWindow>
</template>
 
<script>
  import BaseOpera from '@/components/base/BaseOpera'
  import GlobalWindow from '@/components/common/GlobalWindow'
  import UploadFile from '@/components/common/UploadFile'
  import { findUserList } from '@/api/system/user'
  import { findAllCompanyList } from '@/api/business/company'
  export default {
    name: 'OperaCompanyUserApplyWindow',
    extends: BaseOpera,
    components: { GlobalWindow, UploadFile },
    data () {
      return {
        // 表单数据
        form: {
          id: null,
          userId: '',
          content: '',
          companyIds: [],
          multifileList: []
        },
        // 验证规则
        rules: {
          multifileList: [
            { required: true, message: '请上传授权书' }
          ],
          companyIds: [
            { required: true, message: '请选择授权企业' }
          ],
          userId: [
            { required: true, message: '请选择授权账号' }
          ]
        },
        account: [],
        fileList: [],
        company: []
      }
    },
    created () {
      this.config({
        api: '/business/companyUserApply',
        'field.id': 'id'
      })
    },
    methods: {
      __confirmCreate () {
        this.$refs.form.validate((valid) => {
          if (!valid) {
            return
          }
          let obj = JSON.parse(JSON.stringify(this.form))
          obj.companyIds = obj.companyIds.join(',')
          obj.companyNames = []
          this.form.companyIds.forEach(item => {
            this.company.forEach(row => {
              if (item === row.id) {
                obj.companyNames.push(row.name)
              }
            })
          })
          obj.companyNames = obj.companyNames.join(',')
          this.isWorking = true
          this.api.create(obj)
            .then(() => {
              this.visible = false
              this.$tip.apiSuccess('新建成功')
              this.$emit('success')
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isWorking = false
            })
        })
      },
      // 确认修改
      __confirmEdit () {
        this.$refs.form.validate((valid) => {
          if (!valid) {
            return
          }
          let obj = JSON.parse(JSON.stringify(this.form))
          obj.companyIds = obj.companyIds.join(',')
          obj.companyNames = []
          this.form.companyIds.forEach(item => {
            this.company.forEach(row => {
              if (item === row.id) {
                obj.companyNames.push(row.name)
              }
            })
          })
          obj.companyNames = obj.companyNames.join(',')
          this.isWorking = true
          this.api.updateById(obj)
            .then(() => {
              this.visible = false
              this.$tip.apiSuccess('修改成功')
              this.$emit('success')
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
            .finally(() => {
              this.isWorking = false
            })
        })
      },
      open (title, target) {
        this.title = title
        this.visible = true
        this.getAccount()
        this.getFindAllCompanyList()
        // 新建
        if (target == null) {
          this.$nextTick(() => {
            this.$refs.form.resetFields()
            this.form[this.configData['field.id']] = null
          })
          return
        }
        // 编辑
        this.$nextTick(() => {
          for (const key in this.form) {
            this.form[key] = target[key]
          }
        })
      },
      deleFile (imgaddr) {
        this.form.multifileList.forEach((item, index) => {
          if (item.imgaddr === imgaddr) {
            this.form.multifileList.splice(index, 1)
          }
        })
      },
      editFanganFile (data) {
        this.form.multifileList.push(data)
      },
      getAccount() {
        findUserList({})
          .then(res => {
            console.log(res)
            this.account = res
          })
      },
      getFindAllCompanyList() {
        findAllCompanyList({})
          .then(res => {
            console.log(res)
            this.company = res
          })
      }
    }
  }
</script>
 
<style lang="scss" scoped>
    .list {
        width: 100%;
        padding: 10px 16px;
        box-sizing: border-box;
        background: #F4F7FC;
        border-radius: 2px;
        border: 1px solid #DFE2E8;
        margin-top: 10px;
        .list_label {
            font-weight: 400;
            font-size: 13px;
            color: #333333;
        }
        .list_box {
            width: 100%;
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            .list_box_row {
                padding: 0 10px;
                box-sizing: border-box;
                background: #FFFFFF;
                border-radius: 2px;
                display: flex;
                align-items: center;
                margin-right: 10px;
                &:last-child {
                    margin: 0 !important;
                }
                span {
                    font-weight: 400;
                    font-size: 12px;
                    color: #3F4F69;
                    margin-right: 12px;
                }
                i {
                    color: #BFC3CB;
                    cursor: pointer;
                }
            }
        }
    }
</style>