MrShi
2025-02-07 7de835dea145fe8229f5f0100e2a90094e6d5b22
admin/src/views/stock/assetList.vue
@@ -3,8 +3,16 @@
    <QueryForm v-model="filters" :query-form-config="queryFormConfig" @handleQuery="getList(1)" @clear="clear" />
    <div class="mt20">
      <el-button type="primary" @click="$refs.newMaterial.open('新建物料')">添加</el-button>
      <el-button>导出</el-button>
      <el-button>导入</el-button>
      <el-button @click="exportExcel">导出</el-button>
      <el-popover
        placement="right"
        trigger="click">
        <div style="display: flex; align-items: center; justify-content: center;">
          <el-button type="primary" @click="$refs.uploadFile.click()">导入模板</el-button>
          <el-button type="text" @click="exportTemplate">点击下载模版.EXCEL</el-button>
        </div>
        <el-button style="margin-left: 10px;" slot="reference">导入</el-button>
      </el-popover>
    </div>
    <el-table v-loading="loading" :data="list" stripe>
      <el-table-column prop="code" label="物料编码" min-width="100" show-overflow-tooltip />
@@ -38,6 +46,7 @@
      <Pagination @size-change="handleSizeChange" @current-change="getList" :pagination="pagination" />
    </div>
    <newMaterial ref="newMaterial" @success="getList" />
    <input type="file" ref="uploadFile" @change="importTemplate" accept=".xlsx" style="position: fixed; top: -100px;" />
  </div>
</template>
@@ -48,7 +57,7 @@
import dayjs from 'dayjs'
import duration from 'dayjs/plugin/duration'
dayjs.extend(duration)
import { fetchList, updateStatus, deleteById } from '@/api/ywMaterial'
import { fetchList, updateStatus, deleteById, exportExcel, importMaterialBatch } from '@/api/ywMaterial'
export default {
  components: {
    Pagination,
@@ -87,6 +96,39 @@
    this.getList()
  },
  methods: {
    // 导出模板
    exportTemplate () {
      window.open('/template/material.xlsx')
    },
    // 导入模板
    importTemplate(e) {
      const FormDate = new FormData()
      FormDate.append('file', e.target.files[0])
      importMaterialBatch(FormDate)
        .then(res => {
          this.getList()
        })
        .finally(() => {
          this.$refs.uploadFile.value = null
        })
    },
    exportExcel () {
      this.$dialog.exportConfirm('确认导出吗?')
        .then(() => {
          exportExcel({
            page: this.pagination.page,
            capacity: 1000000,
            model: this.filters
          })
            .then(response => {
              this.download(response)
            })
            .catch(e => {
              this.$tip.apiFailed(e)
            })
        })
        .catch(() => {})
    },
    getList(page) {
      const { pagination, filters } = this
      this.loading = true