aaa
doum
2026-06-08 cf2da3b2a63840888815c6a81cbd7948faf93533
company_admin/src/views/business/goods.vue
@@ -63,8 +63,9 @@
        <ul class="toolbar" v-permissions="['business:goods:create', 'business:goods:delete']">
          <li><el-button type="primary" @click="$refs.operaGoodsWindow.open('新建商品')" icon="el-icon-plus" v-permissions="['business:goods:create']">新建</el-button></li>
          <el-button type="primary" :loading="isWorking.export" @click="$refs.selectProduct.open('选择平台商品')">选择平台商品</el-button>
          <el-button type="primary" :loading="isWorking.export" v-permissions="['business:goods:exportExcel']" @click="importFile">导入</el-button>
          <el-button type="primary" :loading="uploading" v-permissions="['business:goodsImportTask:create']" @click="pickImportFile">提交异步导入</el-button>
          <el-button type="primary" :loading="isWorking.export" @click="downloadFile">下载模板</el-button>
          <el-button type="primary" plain v-permissions="['business:goodsImportTask:query']" @click="$router.push('/business/goodsImportTask')">导入任务</el-button>
          <el-button type="primary" :loading="isWorking.export" @click="bulkOperation(0)">批量上架</el-button>
          <el-button type="primary" :loading="isWorking.export" @click="bulkOperation(1)">批量下架</el-button>
@@ -98,6 +99,7 @@
          </el-table-column>
          <el-table-column prop="brandName" label="品牌" min-width="100px"></el-table-column>
          <el-table-column prop="categoryName" label="类别" min-width="100px"></el-table-column>
          <el-table-column prop="subCategoryName" label="二级类别" min-width="100px"></el-table-column>
          <el-table-column prop="categoryName" label="类型" min-width="100px">
            <template slot-scope="{row}">
              <span v-if="row.type == 0">自建</span>
@@ -137,7 +139,7 @@
            </template>
          </el-table-column>
        </el-table>
        <input type="file" ref="upload" style="display: none;" @change="uplaodFile" />
        <input type="file" ref="upload" accept=".xlsx,.xls" style="display: none;" @change="uploadImportFile" />
        <pagination
          @size-change="handleSizeChange"
          @current-change="handlePageChange"
@@ -157,8 +159,9 @@
import Pagination from '@/components/common/Pagination'
import OperaGoodsWindow from '@/components/business/OperaGoodsWindow'
import selectProduct from '@/components/business/selectProduct'
import { brand, category, importExcel } from '@/api/system/common.js'
import { updateDisableById, queryById, exportDoc, batchUpdateDisableById } from '@/api/business/goods.js'
import { brand, category } from '@/api/system/common.js'
import { updateDisableById, queryById, batchUpdateDisableById } from '@/api/business/goods.js'
import { exportImportTemplate, importExcelAsync, hasUnfinishedTask } from '@/api/business/goodsImportTask'
export default {
  name: 'Goods',
  extends: BaseTable,
@@ -184,7 +187,8 @@
      typeList: [
        { name: '自建', id: 0 },
        { name: '拉取', id: 1 }
      ]
      ],
      uploading: false
    }
  },
  created () {
@@ -220,34 +224,46 @@
        this.handlePageChange()
      })
    },
    downloadFile() {
      exportDoc({})
    downloadFile () {
      this.isWorking.export = true
      exportImportTemplate({})
        .then(response => {
          this.download(response)
        })
        .catch(e => {
          this.$tip.apiFailed(e)
        })
        .finally(() => {
          this.isWorking.export = false
        })
    },
    rowStyle() {
      return "text-align:center";
    },
    importFile() {
      this.$refs.upload.click()
    },
    uplaodFile(e) {
      const FORMDATE = new FormData()
      FORMDATE.append('file', e.target.files[0])
      // 请求接口
      importExcel(FORMDATE)
    pickImportFile () {
      hasUnfinishedTask()
        .then(res => {
          console.log(res)
          this.search()
          if (res) {
            this.$message.warning('当前存在未完成的导入任务,请等待完成后再提交')
            return
          }
          this.$refs.upload.click()
        })
        .catch ((err) => {
          this.$message.error(err.message)
        })
        .catch(e => this.$tip.apiFailed(e))
    },
    uploadImportFile (e) {
      const file = e.target.files && e.target.files[0]
      this.$refs.upload.value = null
      if (!file) return
      const formData = new FormData()
      formData.append('file', file)
      this.uploading = true
      importExcelAsync(formData)
        .then(() => {
          this.$message.success('导入任务已提交,请前往「导入任务」查看进度')
        })
        .catch(err => this.$message.error(err.message || '提交失败'))
        .finally(() => { this.uploading = false })
    },
    edit(id) {
      queryById(id)
@@ -256,6 +272,7 @@
            id: res.id,
            name: res.name,
            categoryId: res.categoryId,
            subCategoryId: res.subCategoryId != null ? res.subCategoryId : '',
            brandId: res.brandId,
            zdPrice: res.zdPrice,
            price: res.price,