jinlin
2024-12-02 18f682f736914e427070b9bb769df538ad9f6d1c
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
<template>
  <zt-dialog ref="dialog" append-to-body @confirm="formSubmit" :hasConfirm="true">
    <el-form :model="dataForm" ref="dataForm" :disabled="dataForm.disabled" label-width="120px">
      <zt-form-item label="总体节点" prop="shipName">
        <el-input v-model="dataForm.shipName" :readonly="true"></el-input>
      </zt-form-item>
      <zt-form-item label="评定数据名称" prop="name" rules="required">
        <el-input v-model="dataForm.name"></el-input>
      </zt-form-item>
      <zt-form-item style="width:100%;" label="">
        <el-upload
          style="width: 600px"
          class="upload-demo"
          ref="upload"
          :action="apiURL"
          :on-success="succ"
          :on-exceed="uploadExceed"
          :on-error="err"
          :limit="1"
          :file-list="fileList"
          :auto-upload="false">
          <div style="display:inline-block;font-size: 14px;" class="el-upload__tip">&nbsp;&nbsp;&nbsp;只能上传.xlsx或.xls的文件,且不超过2G</div>
          <el-button slot="trigger" size="small" type="primary" style="font-size: 15px">选取文件</el-button>
          <el-button type="primary" size="small" style="margin-left:20px;font-size: 15px" @click="submitUpload()">提 交</el-button>
        </el-upload>
      </zt-form-item>
      <el-progress :text-inside="true" :stroke-width="30" :percentage="progress.speed"></el-progress>
    </el-form>
  </zt-dialog>
</template>
 
<script>
  import {guid} from "../../../commonJS/common";
  import qs from "qs";
  import Cookies from "js-cookie";
 
  export default {
    name:'assess-AddOrUpdate',
    data() {
      return {
        dataForm: {
          id:'',
          name:'',
          productId:''
        },
        progress: {
          id: null,
          speed: 0,
          text: '',
          start: false,
          timer: null
        },
        start: 0,
        fileType: ['xlsx', 'xls'],
        fileList:[],
        apiURL:'',
        itemId:''
      }
    },
    methods: {
      async init(id, param) {
        if(id){
          this.dataForm.itemId=id
          this.dataForm.id=id
          this.dataForm.name=param.name
        }else{
          let result = await this.$http.get(`/basicInfo/TyProductModel/getUuid`)
          this.dataForm.itemId = result.data
        }
        this.dataForm.productId = param.productId
        this.dataForm.shipName = param.shipName
        this.resultData = []
        this.progress.id = guid()
        let params = qs.stringify({
          token: Cookies.get('token'),
          progressId: this.progress.id,
          pid: this.dataForm.productId,
          itemId: this.dataForm.itemId,
        })
        this.apiURL = `${window.SITE_CONFIG['apiURL']}/taskReliability/ReliabilityAssess/importProductExcel?${params}`
      },
      uploadExceed(files, fileList) {
        this.$set(fileList[0], 'raw', files[0])
        this.$set(fileList[0], 'name', files[0].name)
        this.$refs.upload.clearFiles()
        this.$refs.upload.handleStart(files[0])
      },
      succ(res, file, fileList) {
        clearInterval(this.timer)
        this.dataForm.speed = 100
        this.$refs.upload.clearFiles()
        this.fileList = []
        this.$emit('refreshDataList')
      },
      err(res, file, fileList) {
        clearInterval(this.timer)
        this.dataForm.speed = 0
        this.$tip.error(res.msg)
      },
      submitUpload() {
        this.dataForm.speed = 0
        this.progress.speed = 0
        this.progress.start = true
        this.progress.timer = window.setInterval(this.getStroke, 1000)
        this.uploadQuery()
      },
      uploadQuery() {
        if (this.$refs.upload.uploadFiles.length === 1) {
          this.start = 1
          this.$refs.upload.submit()
        } else {
          this.$tip.error('请选择需要上传的.xlsx或.xls的文件')
        }
      },
      getStroke() {
        //console.log('getStroke:',this.progress.start,",",this.progress.speed)
        if (this.progress.start && this.progress.speed < 100) {
          //console.log('getStroke2')
          this.$http.get(`sys/common/stroke?progressId=${this.progress.id}`).then(
            res => {
              if (res.success) {
                this.progress.speed = parseFloat(res.data.speed)
                this.progress.text = res.data.text
              }
            }
          )
        } else {
          clearInterval(this.timer)
        }
      },
      // 表单提交
      async formSubmit() {
        let param={
          id:this.dataForm.itemId,
          name:this.dataForm.name,
          productId:this.dataForm.productId
        }
        let res
        if (this.dataForm.id){
          res = await this.$http.post('/taskReliability/ReliabilityAssess/update', param)
        }else{
          res = await this.$http.post('/taskReliability/ReliabilityAssess/add', param)
        }
        if (res.success) {
          await this.$tip.success()
          this.$refs.dialog.close()
          this.$emit('refreshDataList')
        }
      },
 
    }
  }
</script>