index.vue 8.72 KB
<!-- 物料管理 -->
<template>
  <d2-container>
    <el-form
      :inline="true"
      :model="searchForm"
      label-width="85px"
      slot="header"
    >
      <el-form-item label="物料">
         <el-input v-model="searchForm.keyWord" placeholder="请输入物料代码/编码/名称" @clear="loadingGetList" clearable></el-input>
      </el-form-item>
      <el-form-item label="所在地">
         <el-select v-model="searchForm.stationCode" placeholder="请选择所在地" @clear="loadingGetList" clearable filterable>
           <el-option
            v-for="(item, index) in baseData.station"
            :key="index"
            :value="item.confCode"
            :label="item.confValue"
           ></el-option>
         </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary"  icon="el-icon-search" @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="position: relative; display: flex; justify-content: flex-end; ">
        <span style="margin-right: 10px;">
          <auth-button
            category="Button"
            label="导出"
          ></auth-button>
          </span>
          <auth-button
            category="Button"
            label="导入"
            >
            <input
              type="file"
              id="fileUpload"
              class="import-input"
              accept=".csv, application/vnd.ms-excel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
              @change="importFile($event)" />
          </auth-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"
      >
      </el-table-column>
      <el-table-column
        align="center"
        label="操作"
      >
        <template slot-scope="scope">
          <auth-button :data="scope.row"></auth-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 axios from 'axios'
import EditDialog from './editDialog'
import { BaseData } from '@/common/constants'
import { getListApi, editApi, removeApi, exportApi } from '@api/deviceManagement'
import notice from '@/common/notice'
import qs from 'qs'
import sign from '@api/sign'
export default {
  name: 'fimsDeviceManagement',
  components: {
    EditDialog
  },
  data() {
    return {
      // 编辑弹窗
      editVisible: false,
      editForm: {
        id: '',
        deviceNum: '',
        deviceCode: '',
        crcCode: '',
        drawNum: '',
        deviceName: '',
        specifications: '',
        stationCode: '',
        stationName: '',
        stockCount: '',
        responsible: ''
      },
      // 搜索
      searchForm: {
        keyWord: '',
        stationCode: ''
      },
      // 表格
      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,
      baseData: {
        station: []
      },
      fileInfo: { fileType: '', fileBase: '' }
    }
  },

  mounted() {
    this.loadingGetList()
    this.loadBaseData()
  },

  methods: {
    async loadBaseData() {
      const data = await this.$store.dispatch('d2admin/base/get', BaseData.STATION.KEY)
      this.baseData.station = data
    },

    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.deviceList
        this.total = res.pagination.totalCount
        this.tableLoading = false
      }).catch(() => {
        notice.errorTips()
        this.tableLoading = false
      })
    },

    delObjMutiAttr(obj, keys) {
      keys.map(key => delete obj[key])
      return obj
    },

    editDevice(params) {
      params = this.delObjMutiAttr(params, ['createTime', 'keyWord', 'pageCount', 'pageSize', 'updateTime', 'stationName', 'stationCode'])
      // console.log(params)
      editApi(params).then(res => {
        this.handleEditClose()
        notice.okTips()
        this.loadingGetList()
      }).catch(() => {
        notice.errorTips()
      })
    },

    // 导入
    importFile(e) {
      const name = e.target.files[0].name
      this.fileInfo.fileType = name.split('.')[1]
      // // 转码base64
      const reader = new FileReader()
      reader.readAsDataURL(e.target.files[0])
      reader.onload = event => {
        const imgFile = event.target.result
        const arrBase64 = imgFile.split(',')
        this.fileInfo.fileBase = arrBase64[1]
        var params = {
          file: this.fileInfo.fileType + '@' + this.fileInfo.fileBase
        }
        const noSignAttr = ['file']
        params.source = '1'
        params.app_key = '48e5e13229b82c1b4e6e8c96151f0637'
        params.timestamp = new Date().getTime()
        params.v = '1.0.0'
        params.format = 'json'
        params.method = 'fims.device.import'// params.method
        // console.log(params)
        params = sign(params, noSignAttr)
        axios.post(process.env.VUE_APP_API, qs.stringify({
          ...params
        }),
        {
          headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
          }
        }).then(res => {
          let url = res.data.data.url
          if (!url) {
            notice.okTips()
          } else {
            this.$open(url)
            notice.errorTips()
          }
          document.getElementById('fileUpload').value = null
        }).catch(() => {
          notice.errorTips()
          document.getElementById('fileUpload').value = null
        })
      }
    },

    exportFile() {
      const params = this.getParams()
      exportApi(params).then(res => {
        this.$open(res.url)
        notice.okTips()
      }).catch(() => {
        notice.errorTips()
      })
    },
    /* 接口请求-end */
    // 搜索
    handleSearch() {
      this.loadingGetList()
    },

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

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

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

    handleEditConfirm() {
      var editParams = _.cloneDeep(this.editForm)
      this.editDevice(editParams)
    },

    // 表格-编辑
    handleEdit(row) {
      // console.log(row)
      this.editForm = _.cloneDeep(row)
      this.editVisible = !this.editVisible
    },

    handleDelete(row) {
      this.$confirm('确认删除?', '删除', {
        comfirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        removeApi({
          id: row.id,
          usedStatus: 2
        }).then(res => {
          notice.okTips()
          this.loadingGetList()
        }).catch(() => {
          notice.errorTips()
        })
      }).catch(() => {})
    }
  }
}

</script>
<style scoped>
.import-input {
  opacity: 0;
  position: absolute;
  right: 0;
  top: 0;
  width: 70px;
  height: 36px;
  cursor: pointer;
  font-size:0
}
</style>