jinlin
2024-09-19 eb6ffb9bf2eb98e6ed749ebbc14f2f607b7090a9
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
<template>
  <zt-dialog ref="dialog" title="导入产品结构树" :hasConfirm="false" :editAble="false" append-to-body>
    <el-form>
      <zt-form-item style="width:100%;" label="" prop="remark">
        <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>
      <zt-form-item style="width:100%;" label="导入信息提示:" prop="text">
        <el-input style="width:80%;color:#000000;" v-model="dataForm.text" type="textarea" :rows="1"
                  placeholder="导入信息提示" readOnly></el-input>
      </zt-form-item>
      <el-table ref="table" v-adaptive="{bottomOffset:220}" height="100px" :resizable="false" :data="resultData"
                highlight-current-row :default-sort="{prop:'errCause',order:'ascending'}">
        <el-table-column prop="sheetName" label="excel工作表" width="150"/>
        <el-table-column :sortable="true" prop="errCause" label="错误原因" width="300"/>
        <el-table-column prop="lineNumber" label="错误行数"/>
      </el-table>
    </el-form>
  </zt-dialog>
</template>
 
<script>
  import Cookies from 'js-cookie'
  import qs from 'qs'
  import {guid} from "../../../commonJS/common";
 
  export default {
    name: 'product-import',
    props: {
      projectId: {
        type: String,
        required: true
      }
    },
    data() {
      return {
        dataForm: {
          result: ''
        },
        progress: {
          id: null,
          speed: 0,
          text: '',
          start: false,
          timer: null
        },
        fileType: ['xlsx', 'xls'],
        apiURL: '',
        start: 0,
        dialogVisible: false,
        dialogMsg: '',
        fileList: [],
        resultData: []
      }
    },
    computed: {
      importparam() {
        return {}
      }
    },
    created() {
      this.fileList = []
      this.resultData = []
    },
    methods: {
 
      // Array.sort(function(obj1, obj2) {
      //   let val1 = obj1.key
      //   let val2 = obj2.key
      //   return val1 - val2
      // }),
      init(row) {
        console.log(row,'ship')
        this.fileList = []
        this.resultData = []
        this.progress.id = guid()
        let params = qs.stringify({
          token: Cookies.get('token'),
          progressId: this.progress.id,
          pid: row.id
        })
        this.apiURL = `${window.SITE_CONFIG['apiURL']}/basicInfo/XhProductModel/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 = []
        if (res.code === 0) {
          this.dataForm.text = res.msg
        }
        if (res.code === 501) {
          this.dataForm.text = res.msg
          if (res.data) {
            this.resultData = res.data
          }
        }
        this.$emit('refreshDataList')
      },
      err(res, file, fileList) {
        clearInterval(this.timer)
        this.dataForm.speed = 0
        this.dataForm.text = '导入数据包格式有误'
        this.$tip.error(res.msg)
      },
      submitUpload() {
        this.dataForm.speed = 0
        this.dataForm.text = ''
        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的文件')
        }
        //clearInterval(this.timers)
      },
      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)
        }
      }
    }
  }
</script>
 
<style scoped>
 
</style>