fuliqi
2024-01-24 29c1e7eb5ac16e90d8991a86c1c071bc312ec8d9
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
<template>
  <el-dialog :visible.sync="isShow" :title="title" width="700px" :modal-append-to-body="false"
             :close-on-click-modal="false">
    <div id="exportCondition-style">
      <el-form ref="form" :model="form" label-width="120px" class="currentFormStyle">
        <el-row>
          <el-col :span="12">
            <el-form-item label="入库日期:" class="start-time-style">
              <el-date-picker v-model="form.inTimeStart" type="date" placeholder="请选择入库日期"
                              value-format="yyyy-MM-dd HH:mm:ss" :clearable="true">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="-" class="end-time-style">
              <el-date-picker v-model="form.inTimeEnd" type="date" placeholder="请选择入库日期"
                              value-format="yyyy-MM-dd 23:59:59" :clearable="true">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="分发日期:" class="start-time-style">
              <el-date-picker v-model="form.timeStart" type="date" placeholder="请选择分发日期"
                              value-format="yyyy-MM-dd HH:mm:ss" :clearable="true">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="-" class="end-time-style">
              <el-date-picker v-model="form.timeEnd" type="date" placeholder="请选择分发日期"
                              value-format="yyyy-MM-dd 23:59:59" :clearable="true">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="save('form')" type="primary"
                 v-customLoading="{ isLoading: isLoading, percentage: percentage }">保存
      </el-button>
      <el-button size="mini" @click="isShow = false">取消</el-button>
    </div>
  </el-dialog>
</template>
 
<script>
import { downloadFile } from '@/utils/downloadFile'
export default {
  name: "exportConditionDialog",
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: ''
    }
  },
  data() {
    return {
      isShow: false,
      form: {
        inTimeStart: null,
        inTimeEnd: null,
        timeStart: null,
        timeEnd: null
      },
      queryCon: {},//列表页查询条件
      percentage: 0,
      isLoading: false,
    }
  },
  watch: {
    /**
     * 监控外部显示变量变化
     * 传递到dialog组件
     */
    dialogVisible: function (newShow, oldShow) {
      this.isShow = newShow
    },
    /**
     * 监控内部显示属性变化
     * 传递到外部调用变量
     */
    isShow: function (newDialogShow, oldDialogShow) {
      this.$emit('update:dialogVisible', newDialogShow)
      if (!newDialogShow) {
        this.initData();
      }
    }
  },
  methods: {
    initData() {
      Object.keys(this.form).forEach((key) => {
        this.form[key] = null;
      })
      this.queryCon = {};
    },
    /**
      *保存
    */
    save(formName) {
      let _this = this;
      _this.$refs[formName].validate((valid) => {
        if (valid) {
          _this.handleExport();
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    /**
      *获取查询条件
    */
    getQueryCon(obj) {
      this.queryCon = obj;
    },
    async handleExport() {
      let [bool, flag] = [false, false];
      let _exportQuery = JSON.parse(JSON.stringify(this.form));
      for (var key in _exportQuery) {
        if (_exportQuery[key]) {
          bool = true;
          break;
        }
      }
      if (!bool) {
        this.$message({
          message: '请选择入库日期/分发日期!',
          type: 'info'
        })
        return
      } else {
        _exportQuery = this.handleExportCon(_exportQuery);
      }
      //是否有查询关键字----存在关键字、导出日期清空
      for (let key in this.queryCon) {
        if (this.queryCon[key]) {
          flag = true;
          break;
        }
      }
      if (flag) {
        _exportQuery = {};
      }
      //拆选
      let params = { ..._exportQuery, ...this.queryCon };
      const config = {
        onUploadProgress: (ProgressEvent) => {
          const progressPercent = Math.round(
            ((ProgressEvent.loaded / ProgressEvent.total) * 100) | 0
          )
          this.percentage = progressPercent === 100 ? 99 : progressPercent
          this.isLoading = true
        },
        onDownloadProgress: (ProgressEvent) => { },
        url: 'wly-warehouse-service/stock/query/exportFlowExcel',
        data: params,//导出条件
        fileName: "商品库存明细",
        type: '.xlsx'
      }
      const res = await downloadFile(config)
      if (res) {
        this.percentage = 100
        this.isLoading = false
      } else {
        this.percentage = 0
        this.isLoading = false
      }
    },
    /**
      * 文件名称处理
      */
    // exportFileName(exportQuery) {
    //   let _fileName = "";
    //   if (exportQuery.timeStart) {
    //     _fileName = exportQuery.timeStart
    //   }
    //   if (exportQuery.timeStart && exportQuery.timeEnd) {
    //     _fileName = `${_fileName}~`
    //   }
    //   if (exportQuery.timeEnd) {
    //     _fileName = `${_fileName}${exportQuery.timeEnd}`
    //   }
    //   return _fileName;
    // },
    /**
      *导出条件处理
    */
    handleExportCon(obj) {
      //其中一项未选择的情况中-给另一项赋值
      if (!obj.timeStart && !obj.timeEnd) {
        if (obj.inTimeStart) {
          obj.timeStart = obj.inTimeStart;
        }
        if (obj.inTimeEnd) {
          obj.timeEnd = obj.inTimeEnd;
        }
      }
      if (!obj.inTimeStart && !obj.inTimeEnd) {
        if (obj.timeStart) {
          obj.inTimeStart = obj.timeStart;
        }
        if (obj.timeEnd) {
          obj.inTimeEnd = obj.timeEnd;
        }
      }
      return obj;
    }
  }
}
</script>
 
<style lang="scss" scoped>
</style>