initialize.vue 7.87 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-input v-model="formInline.dvSn" placeholder="设备号/设备IMEI/ICCID" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" :loading="tableLoading" plain @click="getList()">搜索</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 按钮操作区域 开始 -->
    <div class="links_group">
      <div class="left"></div>
      <div class="right">
        <el-button type="primary" plain icon="el-icon-upload2" @click="openDialog">导入</el-button>
      </div>
    </div>
    <!-- 按钮操作区域 开始 -->

    <!-- 表格区域 开始 -->
    <div class="table_box">
      <el-table class="el_table" v-loading="tableLoading" :data="tableData" stripe style="width: 100%" size="small" border>
        <el-table-column prop="seedTag" label="批次码" />
        <el-table-column prop="dvSn" label="设备号" />
        <el-table-column prop="dvImei" label="设备IMEI" />
        <el-table-column prop="dvIccid" label="流量卡ICCID" />
        <el-table-column prop="dvOperatorType" label="操作方式">
          <template slot-scope="scope">{{showType(scope.row.dvOperatorType)}}</template>
        </el-table-column>
        <el-table-column prop="dvRemark" label="备注" />
        <el-table-column prop="dvFailreason" label="失败原因" />
        <el-table-column prop="createdDate" label="发起时间" />
      </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 -->

    <!-- 弹框 开始 -->
    <glsx-dialog :show="showDialog" title="批量初始化" width="30%" usefooter @closed="closeDialog">
      <div class="upload_box">
        <h2 class="h2">
          请点击下载"
          <a :href="DEVICESNINITRECORDDOWNLOADTEMPLATE" target="_blank">批量初始化模版</a>"
        </h2>
        <el-form :model="uploadForm" :rules="uploadFormRules" label-width="120px">
          <el-form-item label="操作方式:" prop="operatorType">
            <el-select v-model="uploadForm.operatorType">
              <el-option v-for="item in DVOPERATORTYPE" :key="item.id" :label="item.name" :value="item.id"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="导入文件:" prop="msg">
            <div class="upload_cell">
              <el-input type="text" class="a_input" :value="uploadFile.name" readonly />
              <el-upload class="upload-demo" ref="upload" :action="CHECKDEVICESNINITRECORDIMPORT" multiple :limit="1" :data="uploadForm" :on-exceed="handleExceed" :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 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>
          </el-form-item>
        </el-form>
      </div>
      <div slot="footer" class="btn_group">
        <el-button type="success" @click="uploadInfoToServer">导入</el-button>
        <el-button @click="closeDialog">取消</el-button>
      </div>
    </glsx-dialog>
    <!-- 弹框 end -->
  </d2-container>
</template>

<script>
import { PAGEDEVICESNINITRECORD,DEVICESNINITRECORDDOWNLOADTEMPLATE,CHECKDEVICESNINITRECORDIMPORT,IMPORTDEVICESNINITRECORDIMPORT } from '@/http/device'
import GlsxDialog from '@/components/dialog/index'
import { deepClone, showToast } from '@/common/util'
export default {
  components: {
    'glsx-dialog': GlsxDialog,
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      tableLoading: false,
      pageTotal: 0,
      currentPage: 1,
      pageSizes: [10, 20, 30, 40],
      pageSize: 10,
      tdWidth: 170,
      showDialog: false,
      uploadFile: {},
      deviceList: [],
      DEVICESNINITRECORDDOWNLOADTEMPLATE: DEVICESNINITRECORDDOWNLOADTEMPLATE,
      CHECKDEVICESNINITRECORDIMPORT: CHECKDEVICESNINITRECORDIMPORT,
      uploadForm: {  },
      uploadError: {},
      DVOPERATORTYPE: [
        { id: 'I', name: '初始化' },
        { id: 'Q', name: '取消出库' },
        { id: 'P', name: '取消入库' },
      ],
      uploadFormRules:{
        operatorType:[{required:true,message:'请选择操作方式',trigger:'change'}]
      }
    }
  },
  created() {},

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

    /**
     * 获取查询参数
     */
    getParams: function () {
      let oParams = deepClone(this.formInline)
      oParams.dvIccid = oParams.dvSn
      oParams.dvImei = oParams.dvSn
      oParams.pageSize = this.pageSize
      return oParams
    },

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

    /**监听文件改变 */
    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] || {}
      this.$refs.upload.clearFiles()
      if (m.url) {
        this.uploadError = m
        return false
      }
      this.fileInfo = m.msg
    },

    /**手动上传文件 */
    uploadInfoToServer: function () {
      let _this = this
      let o = this.fileInfo
      let m = this.uploadForm
      if (!o) {
        return false
      }
      let oParams = {}
      oParams.msg = o;
      IMPORTDEVICESNINITRECORDIMPORT(oParams).then((res) => {
        console.log(res)
        _this.fileLoading = false
        if (res.returnCode == 0) {
          _this.closeDialog()
          showToast({
            message: '导入成功',
            type: 'success',
          })
          _this.getList()
        }
      })
    },

    // 打开弹框
    openDialog() {
      this.uploadFile = {}
      this.showDialog = true
    },

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

    // 展示操作方式
    showType(id) {
      let _list = this.DVOPERATORTYPE
      let o = _list.find((k) => k.id == id)
      if (o) {
        return o.name
      } else {
        return ''
      }
    },
  },
}
</script>

<style lang="scss" scoped>
.table_box {
  margin: 10px 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;
  }
  .a_input {
    margin: 0 8px 0 0;
    width: 217px;
  }
}
.cell_center {
  text-align: center;
}
</style>