imeiInventory.vue 7.81 KB
<template>
  <d2-container>
    <el-card shadow="never">
      <el-form :inline="true" :model="formInline" class="demo-form-inline" size="small">
        <el-form-item label="IMEI">
          <el-input v-model="formInline.imei" placeholder="请输入IMEI" />
        </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-upload2" @click="openDialog">入库</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="imei" label="IMEI" />
        <el-table-column prop="externalFlag" label="设备标识">
          <template slot-scope="scope">{{ EXTERNALFLAG[scope.row.externalFlag] }}</template>
        </el-table-column>
        <el-table-column prop="devTypeName" label="设备大类型" />
        <el-table-column prop="merchantNo" label="商户号" />
        <el-table-column prop="createdBy" label="创建人" />
        <el-table-column prop="createdDate" label="创建时间">
          <template slot-scope="scope">{{DATEFORMATE(scope.row.createdDate, 'YYYY-MM-DD HH:mm:ss')}}</template>
        </el-table-column>
        <el-table-column prop="updatedBy" label="修改人" />
        <el-table-column prop="sendMerchantNo" label="操作">
          <template slot-scope="scope">
            <el-button
              type="danger"
              size="mini"
              :id="scope.row.id"
              @click="deleteDevice(scope.row.id)"
            >删除</el-button>
          </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 -->

    <!-- 弹框 开始 -->
    <glsx-dialog :show="showDialog" title="IMEI入库设备" width="30%" usefooter @closed="closeDialog">
      <div class="upload_box">
        <h2 class="h2">
          请点击"
          <a :href="IMEIDOWNLOADTEMPLATE" target="_blank">下载导入设备模版</a>", 并填写导入信息
        </h2>
        <div class="upload_cell">
          <span class="name">导入设备:</span>
          <div class="content">
            <input type="text" :value="uploadFile.name" readonly />
            <el-upload
              class="upload-demo"
              ref="upload"
              :action="PREDEVICEIMEISTOKEIMPORT"
              multiple
              :limit="1"
              :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>
      </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 {
  GETLISTDEVICEIMEISTOCK,
  REMOVEDEVICEIMEISTOCK,
  IMEIDOWNLOADTEMPLATE,
  PREDEVICEIMEISTOKEIMPORT,
  DEVICEIMEISTOKEIMPORT
} from '@/http/interface'
import GlsxDialog from '@/components/dialog/index'
export default {
  components: {
    '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, type) => {
        return this.$Util.dateFormate(str, type)
      },
      deviceTypeList: [],
      EXTERNALFLAG: {
        IN: '内部设备',
        EX: '外部设备',
      },
      showDialog: false,
      IMEIDOWNLOADTEMPLATE: IMEIDOWNLOADTEMPLATE,
      PREDEVICEIMEISTOKEIMPORT:PREDEVICEIMEISTOKEIMPORT,
      uploadFile:{}
    }
  },
  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
      GETLISTDEVICEIMEISTOCK(oParams).then((res) => {
        console.log(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
      if (oParams.iccid) {
        oParams.imsi = oParams.iccid
      } else {
        delete oParams.imsi
      }
      oParams.pageSize = this.pageSize
      return oParams
    },

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

    /**
     * 删除
     */
    deleteDevice: function (id) {
      let _this = this
      let oParams = {}
      oParams.id = id
      _this.$Util.msg({
        message: '确定是否要删除',
        showCancelButton: true,
        success: () => {
          REMOVEDEVICEIMEISTOCK(oParams).then((res) => {
            console.log(res)
            if (res.returnCode == 0) {
              _this.$Util.Info({
                message: '删除成功',
                type: 'success',
              })
              _this.getList()
            }
          })
        },
      })
    },

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

    /**监听文件改变 */
    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.cause){
        this.$Util.Info({
          message:m.cause
        })
        this.$refs.upload.clearFiles();
        this.uploadFile = {};
        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);
      })

    },

    /**关闭弹框 */
    closeDialog: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;
    }
  }
}
.upload_cell {
  display: flex;
  align-items: center;
  .name {
    width: 80px;
    font-weight: bold;
  }
  .content {
    flex: 1;
    display: flex;
    input {
      margin: 0 8px 0 0;
    }
  }
}
</style>