quanyawei
2023-10-07 0c70804c83d63f5dd1c29550aa6eac60bd8dac1a
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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<template>
  <div class="mainContent">
    <a-card :bordered="false" style="margin-top: 24px">
      <a-form layout="inline">
        <a-form-item label="名称:">
          <a-input v-model="serch.name" style="width: 200px" />
        </a-form-item>
        <a-form-item label="上级区域:">
          <a-cascader
            placeholder="请选择"
            labelInValue
            v-model="serch.parentCode"
            style="width: 200px"
            :options="parentListOptions"
            @change="positionLevel"
          />
        </a-form-item>
        <a-form-item label="所属区域:">
          <a-select
            ref="select"
            v-model="serch.areaCode"
            style="width: 200px"
            placeholder="请选择"
          >
            <a-select-option
              v-for="(item, index) in areaCodeList"
              :key="index"
              :value="item.areaCode"
            >
              {{ item.areaName }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item>
          <a-button type="primary" html-type="submit" @click="handleSearch">
            查询
          </a-button>
          <a-button type="primary" @click="() => this.handleModalVisible(true)">
            新建
          </a-button>
        </a-form-item>
      </a-form>
      <div style="margin-top: 24px">
        <av-standard-table
          :dataSource="dataSource"
          :selectedRows="selectedRows"
          :columns="columns"
          :loading="tableLoading"
          :paginationProps="pagination"
          @tableChange="handlerTableChange"
        ></av-standard-table>
      </div>
    </a-card>
    <a-modal
      :title="title"
      destroyOnClose
      :visible.sync="visibleCreateModal"
      @cancel="handleCreateModalCancel"
    >
      <!---->
      <a-form-model
        style="margin-top: 8px"
        :model="editForm"
        :rules="rules"
        ref="ruleForm"
      >
        <a-form-model-item v-bind="formLayout" prop="unitName" label="名称">
          <a-input
            placeholder="请输入"
            type="string"
            v-model="editForm.unitName"
            :disabled="pageState === 'view'"
          />
        </a-form-model-item>
        <a-form-model-item
          v-bind="formLayout"
          label="上级编码"
          prop="parentCode"
        >
          <a-cascader
            v-model="editForm.parentCode"
            placeholder="请选择"
            change-on-select
            :options="newParentListOptions"
            @change="positionLevel"
            :disabled="pageState === 'view'"
          />
        </a-form-model-item>
        <a-form-model-item v-bind="formLayout" prop="areaCode" label="行政区划">
          <a-select
            ref="select"
            placeholder="请选择"
            v-model="editForm.areaCode"
            :disabled="pageState === 'view'"
          >
            <a-select-option
              :value="item.areaCode"
              v-for="item in newAreaCodeList"
            >
              {{ item.areaName }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item v-bind="formLayout" label="是否生效" prop="state">
          <a-radio-group
            name="radioGroup"
            v-model="editForm.state"
            :disabled="pageState === 'view'"
          >
            <a-radio value="0">是</a-radio>
            <a-radio value="1">否</a-radio>
          </a-radio-group>
        </a-form-model-item>
      </a-form-model>
      <template slot="footer">
        <a-button key="cancel" @click="handleCreateModalCancel">
          取消
        </a-button>
        <a-button
          key="forward"
          type="primary"
          v-if="pageState === 'add' || pageState === 'edit'"
          @click="handleCreateModalOk"
        >
          提交
        </a-button>
      </template>
    </a-modal>
    <a-modal
      title="作废"
      destroyOnClose
      :visible="visibleInvalidityModal"
      @ok="handleInvalidityModalOk"
      @cancel="handleInvalidityModalCancel"
    >
      <!---->
      <a-form
        style="margin-top: 8px"
        :autoFormCreate="
          (form) => {
            this.createForm = form;
          }
        "
      >
        <a-form-item
          :labelCol="{ span: 5 }"
          :wrapperCol="{ span: 15 }"
          label="理由"
          fieldDecoratorId="code"
          :fieldDecoratorOptions="{
            rules: [{ required: true, message: '请输入理由!' }],
          }"
        >
          <a-input placeholder="请输入" type="string" />
        </a-form-item>
      </a-form>
    </a-modal>
  </div>
</template>
 
<script lang="tsx">
import {
    Component,
    Prop,
    Vue,
    Model,
    Watch,
} from 'vue-property-decorator';
import moment from 'moment';
import { get, post } from "@/util/request";
import * as _ from 'lodash';
@Component({
  components: {
  },
})
export default class QueryList extends Vue {
 //规则定义
  private rules: any = {
    unitName:[
      { required: true, message: '名称不能为空', trigger: 'blur' },
      { message: '名称字数不能超过20个!', max: 19 },
    ],
    parentCode:[{ required: true, message: '请选择!' }],
    areaCode:[{ required: true, message: '请选择!' }],
    state:[{ required: true, message: '请选择!' }]
  }
    private formLayout = {
      labelCol: {
        span: 5,
      },
      wrapperCol: {
        span: 15,
      },
    };
    private serch:any = {
        name:'',
        parentCode: [],
        areaCode:''
    }
    private editForm: any = {
        unitName:'',
        parentCode: [],
        areaCode:'',
        state:'0',
    }
 
  private pagination:any={
    total:0,
    current:1,
    pageSize:10,
    showSizeChanger: true,
    showQuickJumper: true,
    showTotal: (total:number) => `共有 ${this.pagination.total} 条数据`,  //分页中显示总的数据
  };
 
    @Watch('serch.name')
    private watchsearchInform(newVal:string,oldval:string){
      if (newVal !== '' && oldval === '') {
        this.pagination.current = 1
      }
        this.handleSearch()
    }
 
    private expandForm: boolean = false;
 
    private selectedRows: any[] = [];
    
    private parentListOptions: any[] = [];
    private newParentListOptions: any[] = [];
 
    private tableLoading: boolean = false;
    private visibleInvalidityModal: boolean = false;
 
    private moment: any = moment;
    private pageState: String = 'add';
 
    private dataSource: any[] = [];
    
    private areaCodeList: any[] = [];
    
    private newAreaCodeList: any[] = [];
 
    private visibleCreateModal: boolean = false;
 
  private createForm: any = null;
    
    private title: any = null;
 
    private columns: any[] = [{
            title: '名称',
            dataIndex: 'unitName',
        },
        {
            title: '上级区域',
            dataIndex: 'parentName',
        },
        {
            title: '所属区域',
            dataIndex: 'areaName',
        },
        {
            title: '操作时间',
            dataIndex: 'updateTime',
        },
        {
            title: '操作人',
            dataIndex: 'createName',
        },
        {
            title: '状态',
            dataIndex: 'state',
            customRender: this.progressStateRender,
        },
        {
            title: '操作',
            customRender: this.opRender,
        },
    ];
 
 
    private handleModalVisible(isVisible: boolean): void {
      this.visibleCreateModal = isVisible;
      this.pageState='add'
      this.title='新建责任单位'
    }
 
  private handleSearch(): void {
    console.log(this.serch)
       const data = this.serch.parentCode
        let code =data[data.length-1]
        get("unit/selectUint",{
            name:this.serch.name,
            parentCode:code,
            parentCodeList:this.serch.parentCode,
            areaCode:this.serch.areaCode,
            current: this.pagination.current,
            page:1,
            size: this.pagination.pageSize
        }).then(res=>{
          this.dataSource = res.data.data.item
          this.pagination.total = res.data.data.total
        })
        .catch(err=>{
            console.log(err);
        })
    }
 
  private handlerTableChange(pagination: any, filter: any, sorter: any): void {
      console.log(pagination)
      this.pagination.current = pagination.current
      this.pagination.pageSize = pagination.pageSize
      this.pagination.total = pagination.total
      this.handleSearch()
    }
 
  private handleCreateModalOk() {
    let api ='unit/insert'
    if (this.pageState === 'edit') {
      api='unit/update'
    }
    this.$refs.ruleForm.validate((valid: any) => {
      console.log(valid);
      if (valid) {
        const data = this.editForm.parentCode
        let code =data[data.length-1]
        console.log(this.editForm);
        // 插入角色
        post(api, {
            unitId: this.editForm.unitId,
            unitName:this.editForm.unitName,
            parentCode: code,
            parentCodeList:this.editForm.parentCode,
            areaCode: this.editForm.areaCode,
            state:parseInt(this.editForm.state)
        }).then((res: any) => {
           this.handleSearch()
          this.visibleCreateModal = false
          this.editForm = {
            unitName:'',
            parentCode: [],
            areaCode:'',
            state: '0',
            parentCodeList:[]
          }
        }).catch((err)=>{
            console.log(err);
        })
      } else {
        console.log('error submit!!');
        return false;
      }
    });
 
      console.log('editForm',this.editForm)
    }
 
    private handleCreateModalCancel(): any {
      this.visibleCreateModal = false;
      this.editForm = {
        unitName:'',
        parentCode: [],
        areaCode:'',
        state: '0',
        parentCodeList:[]
      }
    }
  private handleInvalidityModalCancel(): any {
      this.editForm = {
        unitName:'',
        parentCode: [],
        areaCode:'',
        state: '0',
        parentCodeList:[]
      }
      this.visibleInvalidityModal = false;
    }
 
    private cityData() {
        get("system/area/queryCity",{
          
        }).then(res => {
          console.log('00000000000000', res);
          let org = res.data.data;
          let lists = JSON.stringify(org);
 
          lists = lists.replace(/"areaCode"/g, '"value"');
 
          lists = lists.replace(/"areaName"/g, '"label"');
 
          const treeLists = JSON.parse(lists)
          this.parentListOptions = JSON.parse(JSON.stringify(treeLists))
          this.newParentListOptions = JSON.parse(JSON.stringify(treeLists))
        })
        .catch(err=>{
            console.log(err);
        })
    }
 
  private  positionLevel(val: any) {
    this.serch.areaCode = ''
    this.editForm.areaCode = ''
     let code =val[val.length-1]
        get("system/area/code",{
          code:code
        }).then(res => {
          console.log('00000000000000', res);
          this.areaCodeList= res.data.data;
          this.newAreaCodeList= res.data.data;
        })
        .catch(err=>{
            console.log(err);
        })
    }
 
    private mounted() {
        this.handleSearch();
        this.cityData()
    }
 
    private updatedAtRender(text: string) {
        return <span> {
            moment(text).format('YYYY-MM-DD HH:mm:ss')
        } </span>;
    }
 
    private handleAssert(record: any){
       get("unit/state",{
         unitId: record.unitId,
          
       }).then(res => {
           this.handleSearch()
           this.$message.success('操作成功')
        })
        .catch(err=>{
            console.log(err);
        })
    }
    private recordTableData: any = null;
    private handleInvalidity(record: any) {
      this.visibleInvalidityModal = true
       this.recordTableData=record
    }
  
  private handleInvalidityModalOk(record: any) {
       this.createForm.validateFields((err: any, fieldsValue: any) => {
            if (err) {
                return;
            }
            get("unit/invalid",{
              unitId: this.recordTableData.unitId,
              invalidReason:this.createForm.getFieldValue('code')
            }).then(res => { 
              this.$message.success('操作成功')
              this.visibleInvalidityModal = false
              this.handleSearch()
            })
            .catch(err=>{
                console.log(err);
            })
        });
  }
    
    private progressStateRender(text: string) {
        if (text === '0') {
            return <a-badge status = 'success' text = '生效' />;
        }
        return <a-badge status = 'processing' text = '未生效' />;
  }
    
    private async handleUpdateModalVisible(visible: boolean, record: any): void {
      this.visibleCreateModal = true;
      await this.positionLevel(record.parentCodeList)
      this.title = '编辑责任单位'
      let params = _.cloneDeep(record)
      console.log(params)
      params.parentCode=record.parentCodeList
      this.editForm = params 
      this.pageState='edit'
      console.log('editForm',record)
    }
    private async handleDetailModalVisible(visible: boolean, record: any): void {
      this.visibleCreateModal = true;
      await this.positionLevel(record.parentCodeList)
      this.title = '责任单位详情'
       let params = _.cloneDeep(record)
      console.log(params)
      params.parentCode=record.parentCodeList
      this.editForm = params 
      this.pageState='view'
    }
  private opRender(text: string, record: any, index: number) {
    // 生效console
    console.log('1111',text)
    console.log('2222',record)
    console.log('333', index)
       if (record.state ==='0') {
       return   <div>
              <a onClick = {
                () => this.handleDetailModalVisible(true, record)
            } > 详情 </a>
            <a-divider type = 'vertical' />
            <a v-show="record.isInvalid !=='0'" onClick = {
                () => this.handleInvalidity(record)
            } >作废</a>
            </div>
        } else {
           return   <div>
              <a onClick = {
                () => this.handleDetailModalVisible(true, record)
            } > 详情 </a>
            <a-divider type='vertical' />
             <a onClick = {
                () => this.handleUpdateModalVisible(true, record)
            } > 编辑 </a>
            </div>
        }
      this.handleSearch();
    }
 
}
</script>
 
<style lang="less" scoped>
</style>