index.vue 7.36 KB
<!-- 物料管理 -->
<template>
  <d2-container>
    <el-form
      :inline="true"
      :model="searchForm"
      label-width="85px"
    >
      <el-form-item label="物料">
         <el-input v-model="searchForm.keyWord" placeholder="请输入物料代码/编码/名称" clearable></el-input>
      </el-form-item>
      <el-form-item label="所在地">
         <el-select v-model="searchForm.stationCode" placeholder="请选择所在地" clearable filterable>
             <el-option value="1" label="仓库"></el-option>
             <el-option value="2" label="广州站"></el-option>
         </el-select>
      </el-form-item>
      <el-form-item label="责任人">
         <el-select v-model="searchForm.responsible" placeholder="请选择责任人" clearable filterable>
             <el-option value="1" label="张三"></el-option>
             <el-option value="2" label="李四"></el-option>
         </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="handleSearch">查询</el-button>
      </el-form-item>
    </el-form>
    <el-row style="height: 40px; line-height: 40px">
      <el-col :span="12">物料列表</el-col>
      <el-col :span="12" style="text-align: right">
        <el-button class="import-button" style="">导入
          <input
            type="file"
            class="import-input"
            accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
            @change="importFile($event)" />
        </el-button>
        <el-button>导出</el-button>
      </el-col>
    </el-row>
    <el-table
      :data="tableData"
      v-loading="tableLoading"
      border
      style="margin: 20px 0;"
    >
      <el-table-column
        align="center"
        width="60px"
        label="序号"
        type='index'
      ></el-table-column>
      <el-table-column
        v-for="(item, index) in tableColumns"
        :key="index"
        :label="item.label"
        :prop="item.prop"
        :width="item.width"
        align="center"
      >
        <!-- <template slot-scope="scope">
          <template v-if="item.formatter">
            {{item.formatter(scope.row)}}
          </template>
          <template v-else>
            {{tableData[scope.$index][item.prop]}}
          </template>
        </template> -->
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
      >
        <template slot-scope="scope">
          <el-button
            type="text"
            @click="handleEdit(scope.row, scope.$index)"
          >编辑</el-button>
          <el-button
            type="text"
            @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage"
      :page-sizes="[10,20,30,40]"
      :page-size="pageSize"
      :total="total"
      layout="sizes,total,->,prev,pager,next,jumper"
    >
    </el-pagination>
    <edit-dialog
      :isVisible="editVisible"
      :editForm="editForm"
      @closeDialog="handleEditClose"
      @confirmDialog="handleEditConfirm"
    ></edit-dialog>
  </d2-container>
</template>

<script>
import EditDialog from './editDialog'
import { getListApi, editApi, removeApi, importApi, exportApi } from '@api/deviceManagement'
import notice from '@/common/notice'
export default {
  name: 'deviceManagement',
  components: {
    EditDialog
  },
  data () {
    return {
      // 编辑弹窗
      editVisible: false,
      editForm: {
        id: '',
        deviceNum: '',
        deviceCode: '',
        crcCode: '',
        drawNum: '',
        deviceName: '',
        specifications: '',
        stationCode: '',
        stationName: '',
        stockCount: '',
        responsible: ''
      },
      // 搜索
      searchForm: {
        keyWord: '',
        stationCode: '',
        responsible: ''
      },
      // 表格
      tableLoading: false,
      tableData: [],
      tableColumns: [{
        label: '物料代码',
        prop: 'deviceNum'
      }, {
        label: '物料编码',
        prop: 'deviceCode'
      }, {
        label: 'CRC物料号',
        prop: 'crcCode'
      }, {
        label: '图号',
        prop: 'drawNum'
      }, {
        label: '物料名称',
        prop: 'deviceName'
      }, {
        label: '规格',
        prop: 'specifications'
      }, {
        label: '所在地',
        prop: 'stationName'
      }, {
        label: '库存',
        prop: 'stockCount'
      }, {
        label: '责任人',
        prop: 'responsible'
      }],
      // 页码
      currentPage: 1,
      pageSize: 10,
      total: 30
    }
  },

  mounted () {
    this.loadingGetList()
  },

  methods: {
    loadingGetList () {
      this.tableLoading = true
      this.getList()
    },
    /* 接口请求-start */
    getParams () {
      return {
        pageCount: this.pageSize,
        pageSize: this.currentPage,
        ...this.searchForm
      }
    },

    getList () {
      const params = this.getParams()
      getListApi(params).then(res => {
        this.tableData = res
        this.tableLoading = false
      }).catch(err => {
        notice.errorTips(err)
        this.tableLoading = false
      })
    },

    editDevice (params) {
      editApi(params).then(res => {
        // console.log(res)
        this.handleEditClose()
        notice.okTips()
        this.loadingGetList()
      }).catch(err => {
        notice.errorTips()
      })
    },

    // 导入
    importFile (e) {
      const params = {
        file: e.target.files[0]
      }
      console.log(params)
      importApi(params).then(res => {
        notice.okTips()
      }).catch(err => {
        notice.errorTips()
      })
    },
    /* 接口请求-end */
    // 搜索
    handleSearch () {
      console.log(this.searchForm)
      this.loadingGetList()
    },

    // 页码
    handleSizeChange (value) {
      // console.log(value)
      this.pageSize = value
      // 调接口
      this.loadingGetList()
    },

    handleCurrentChange (value) {
      // console.log(value)
      this.currentPage = value
      // 调接口
      this.loadingGetList()
    },

    handleEditClose () {
      this.editVisible = !this.editVisible
    },

    handleEditConfirm () {
      // console.log(JSON.parse(JSON.stringify(this.editForm)))
      var editParams = JSON.parse(JSON.stringify(this.editForm))
      this.editDevice(editParams)
    },

    // 表格-编辑
    handleEdit (row, index = -1) {
      // console.log(index)
      // console.log(row)
      console.log(row)
      this.editForm = JSON.parse(JSON.stringify(row))
      this.editVisible = !this.editVisible
    },

    handleDelete (index, row) {
      this.$confirm('确认删除?', '删除', {
        comfirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        console.log(index)
        console.log(row)
        this.$message({
          type: 'success',
          message: '删除成功'
        })
      }).catch(err => {})
    }
  }
}

</script>
<style scoped>
.import-button {
  width: 70px;
  height: 40px;
  overflow: hidden;
  position: relative;
  cursor: pointer;
}
.import-input {
  opacity: 0;
  position: absolute;
  left: 0;
  top: 0;
  width: 70px;
  height: 100%;
  cursor: pointer;
  font-size:0
}
</style>