device.vue 10.2 KB
<template>
  <d2-container>
    <el-card shadow="never">
      <el-form :inline="true" :model="formInline" class="demo-form-inline" size="small">
        <el-form-item label="设备类型">
          <el-select v-model="formInline.typeId" placeholder="请选择">
            <el-option value label="全部">全部</el-option>
            <el-option
              v-for="item in deviceTypeList"
              :key="item.id"
              :value="item.id"
              :label="item.name"
            >{{ item.name }}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="设备编号">
          <el-input v-model="formInline.deviceCode" placeholder="请输入发货单号" />
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-search"
            :loading="tableLoading"
            @click="getList()"
          >搜索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            type="primary"
            icon="el-icon-download"
            :loading="exportLoading"
            @click="exportExcel()"
          >导出</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-plus" @click="add()">新建</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 表格区域 开始 -->
    <div class="table_box">
      <el-table
        v-loading="tableLoading"
        :data="tableData"
        stripe
        style="width: 100%"
        size="small"
        border
      >
        <el-table-column type="index" :index="index => {return index+1}" label="序号" width="80" />
        <el-table-column prop="deviceCode" label="设备编号" />
        <el-table-column prop="deviceName" label="设备名称" />
        <el-table-column prop="iccid" label="设备类型">
          <template slot-scope="scoped">{{ scoped.row.deviceType.name }}</template>
        </el-table-column>
        <el-table-column prop="merchantName" label="品牌定制商" />
        <el-table-column prop="imei" label="创建人" />
        <el-table-column prop="createdDate" label="创建时间">
          <template slot-scope="scoped">{{ DATEFORMATE(scoped.row.createdDate) }}</template>
        </el-table-column>
        <el-table-column prop="createdDate" label="操作" align="center">
          <template slot-scope="scope">
            <el-link type="primary" :underline="false" @click="openDialog()">入库</el-link>
            <el-link type="danger" :underline="false" @click="deleteDevice(scope.row)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination
          background
          layout="sizes, total,prev, pager, next, jumper"
          :total="pageTotal"
          :page-size="pageSize"
          :page-sizes="pageSizes"
          @current-change="getList"
          @size-change="changePageSize"
        />
      </div>
    </div>
    <!-- 表格区域 end -->

    <!-- 新增 开始 -->
    <add-device :device-type="deviceTypeList" :show="addShow" @closed="closeDialog" />
    <!-- 新增 end -->

    <!-- 弹框 开始 -->
    <glsx-dialog :show="showDialog" title="入库设备" width="30%" usefooter @closed="closePopup">
      <div class="upload_box">
        <h2 class="h2">
          请点击"
          <a :href="UNSTOCKDOWNLOADTEMPLATE" target="_blank">下载导入设备模版</a>", 并填写导入信息
        </h2>
        <h3 class="h3">*请先选择是否虚拟设备</h3>
        <div class=""><el-checkbox v-model="uploadForm.isOnlyimsi">虚拟设备</el-checkbox></div>
        <div class="upload_cell">
          <span class="name">导入设备:</span>
          <div class="content">
            <el-input type="text" class="a_input" :value="uploadFile.name" readonly />
            <el-upload
              class="upload-demo"
              ref="upload"
              :action="PREDEVICEFILEUNSTOCKIMPORT"
              multiple
              :limit="1"
              :data="uploadForm"
              :file-list="fileList"
              :show-file-list="false"
              :on-change="uploadChange"
              :on-success="uploadSuccess"
            >
              <el-button size="small" type="primary">选择文件</el-button>
            </el-upload>
          </div>
        </div>
        <div class="upload_cell cell_center" v-if="uploadError.totalCount || uploadError.totalCount==0">
          <span>检验成功{{uploadError.successCount}}条,失败{{uploadError.failCount}}条</span>
          <span>请下载</span>
          <a :href="uploadError.url" target="_blank">导出失败列表</a>
        </div>
      </div>
      <div slot="footer" class="btn_group">
        <el-button type="success" @click="uploadInfoToServer">导入</el-button>
        <el-button @click="closePopup">取消</el-button>
      </div>
    </glsx-dialog>
    <!-- 弹框 end -->

  </d2-container>
</template>

<script>
import {
  GETLISTDEVICECODE,
  GETDEVICETYPE,
  INSERTANDUPDATEDEVICE,
  EXPORTDEVICECODE,
  UNSTOCKDOWNLOADTEMPLATE,
  PREDEVICEFILEUNSTOCKIMPORT
} from '@/http/interface'
import addDevice from './addDevice'
import { exportExcel } from '@/common/common'
import GlsxDialog from '@/components/dialog/index'
export default {
  name: 'fimsTable3',
  components: {
    'add-device': addDevice,
    'glsx-dialog': GlsxDialog
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      dialogVisible: false,
      tableLoading: false,
      pageTotal: 0,
      userInfo: {},
      currentPage: 1,
      pageSizes: [10, 20, 30, 40],
      pageSize: 10,
      registerDate: [],
      tdWidth: 170,
      DATEFORMATE: (str) => {
        return this.$Util.dateFormate(str)
      },
      deviceTypeList: [],
      exportLoading: false,
      addShow: false,
      showDialog:false,
      uploadForm:{},
      uploadFile:{},
      uploadError:{},
      PREDEVICEFILEUNSTOCKIMPORT:PREDEVICEFILEUNSTOCKIMPORT
    }
  },
  created() {},

  mounted: function () {
    this.getList()
    this.getDeviceList()
  },
  methods: {
    /**
     * 查询列表
     */
    getList: function (current) {
      const _this = this
      const oParams = _this.getParams()
      oParams.pageNum = current || _this.currentPage
      _this.tableLoading = true
      GETLISTDEVICECODE(oParams).then((res) => {
        _this.tableLoading = false
        if (res.returnCode == 0) {
          const { data } = res
          const { total, list } = data
          _this.tableData = list || []
          _this.pageTotal = total
        }
      })
    },

    /**
     * 获取查询参数
     */
    getParams: function () {
      const oParams = this.formInline
      const m = this.registerDate
      if (m && m.length > 0) {
        n.startDate = m[0]
        n.endDate = m[1]
      } else {
        delete this.formInline.startDate
        delete this.formInline.endDate
      }
      oParams.pageSize = this.pageSize
      return oParams
    },

    /**
     * 每页展示
     */
    changePageSize: function (e) {
      this.pageSize = e
      this.getList()
    },

    /**
     * 获取设备类型列表
     */
    getDeviceList: function () {
      const _this = this
      GETDEVICETYPE().then((res) => {
        const { data } = res
        _this.deviceTypeList = data || []
      })
    },

    /**
     * 删除设备
     */
    deleteDevice: function (row) {
      const _this = this
      const oParams = {}
      oParams.deletedFlag = 'Y'
      oParams.id = row.id
      _this.$Util.msg({
        message: '确定是否要删除?',
        showCancelButton: true,
        type: 'warning',
        success: () => {
          INSERTANDUPDATEDEVICE(oParams).then((res) => {
            if (res.returnCode == 0) {
              _this.$Util.Info({
                message: '操作成功',
                type: 'success',
              })
              _this.getList()
            }
          })
        },
      })
    },

    /**
     * 新建设备
     */
    add: function () {
      this.addShow = true
    },

    /**
     * 关闭弹框
     */
    closeDialog: function (e) {
      this.addShow = false
      this.getList()
      if (e) {
        this.$Util.Info({
          message: 'success',
          type: '新增成功',
        })
      }
    },

    /**导出excel */
    exportExcel: function () {
      let _this = this
      let options = {}
      let _obj = this.formInline;
      options.url = EXPORTDEVICECODE;
      if (_obj.typeId) {
        options.url = EXPORTDEVICECODE + '?typeId=' + _obj.typeId
      }
      options.fileName = '设备分类列表.xlsx'
      options.success = function () {
        _this.exportLoading = false
      }
      _this.exportLoading = true
      exportExcel(options)
    },

    /**入库 */
    openDialog: function () {
      this.showDialog = true
      //this.getDeviceList()
    },

    /**监听文件改变 */
    uploadChange: function (file, fileList) {
      console.log(file)
      this.uploadFile = file
    },

    /**监听文件上传成功 */
    uploadSuccess: function (res, file, fileList) {
      console.log(res)
      //this.$refs.upload.submit();
      let o = res.data || []
      let m = o[0] || {}

      if (m.url) {
        this.$refs.upload.clearFiles()
        this.uploadError = m;
        return false
      }
      this.fileInfo = m.msg
    },

    /**手动上传文件 */
    uploadInfoToServer: function () {
      let o = this.fileInfo
      if (!o) {
        return false
      }
      let oParams = JSON.parse(o)
      DEVICEIMEISTOKEIMPORT(oParams).then((res) => {
        console.log(res)
      })
    },

    /**关闭弹框 */
    closePopup: function () {
      this.$refs.upload.clearFiles()
      this.uploadFile = {}
      this.showDialog = false
    }

  },
}
</script>

<style lang="scss" scoped>
.table_box {
  margin: 20px 0;
}
.upload_box {
  .h2 {
    font-size: 14px;
    font-weight: normal;
    a {
      color: #337ab7;
    }
  }
  .h3{
    font-size:14px;
    color:#f00;
    font-weight:normal;
  }
}
.upload_cell {
  display: flex;
  align-items: center;
  margin:10px 0;
  .name {
    width: 80px;
    font-weight: bold;
  }
  .content {
    flex: 1;
    display: flex;
    .a_input {
      margin: 0 8px 0 0;
      width:217px;
    }
  }
}
.cell_center{
  text-align:center;
}
</style>