material.vue 9.92 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.materialName"></el-input>
        </el-form-item>
        <el-form-item label="物料编码:">
          <el-input v-model="formInline.materialCode"></el-input>
        </el-form-item>
        <el-form-item label="物料类别:">
          <el-select v-model="formInline.materialType" placeholder="请选择">
            <el-option value="" label="全部">全部</el-option>
            <el-option v-for="(item,index) in materialList" :key="index" :value="item.materialType" :label="item.materialTypeName"></el-option>
            <!-- <el-option value="1">硬件</el-option>
            <el-option value="2">安装服务</el-option>
            <el-option value="3">运营服务</el-option>
            <el-option value="4">软件</el-option>
            <el-option value="5">原材料</el-option>
            <el-option value="6">配件</el-option>
            <el-option value="7">其他</el-option> -->
          </el-select>
        </el-form-item>
        <el-form-item label="设备类型:">
          <el-select v-model="formInline.deviceTypeId" placeholder="请选择">
            <el-option value="" label="全部">全部</el-option>
            <el-option v-for="(item,index) in deviceList" :key="index" :value="item.id" :label="item.name"></el-option>
            <!-- <el-option value="1">导航</el-option>
            <el-option value="2">后视镜</el-option>
            <el-option value="3">记录仪</el-option>
            <el-option value="4">OBD</el-option>
            <el-option value="5">记录仪</el-option>
            <el-option value="6">GPS</el-option>
            <el-option value="7">车充</el-option>
            <el-option value="8">电子辅助</el-option> -->
          </el-select>
        </el-form-item>
        <el-form-item label="是否扫码:">
          <el-select v-model="formInline.deviceScanType" placeholder="请选择">
            <el-option value="" label="全部">全部</el-option>
            <el-option value="Y" label="是"></el-option>
            <el-option value="N" label="否"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="创建人:">
          <el-input v-model="formInline.createdBy"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="success" plain icon="el-icon-search" :loading="tableLoading" @click="getList()">搜索</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-refresh" plain @click="rest()">重置</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-download" :loading="exportLoading" @click="exportInfo()">导出</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <!-- 按钮区域 开始 -->
    <div class="search_links_box">
      <el-button type="success" plain size="small" icon="el-icon-plus" class="" @click="openDialog()">新增物料</el-button>
    </div>
    <!-- 按钮区域 end -->

    <!-- 表格区域 开始 -->
    <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="materialCode" label="物料编码" show-overflow-tooltip />
        <el-table-column prop="materialName" label="物料名称" show-overflow-tooltip />
        <el-table-column prop="materialTypeName" label="物料类别" show-overflow-tooltip />
        <el-table-column prop="deviceTypeName" label="设备类型" show-overflow-tooltip />
        <el-table-column prop="deviceScanType" label="是否扫码" show-overflow-tooltip>
          <template slot-scope="scope">{{SCANTYPELIST[scope.row.deviceScanType]}}</template>
        </el-table-column>
        <el-table-column prop="firstLevelName" label="归属物料大类" show-overflow-tooltip />
        <el-table-column prop="createdBy" label="创建人" show-overflow-tooltip />
        <!-- <el-table-column prop="saleSum" label="操作" width="80">
          <template slot-scope="scope">
            <el-button type="success" plain size="mini" @click="openDialog(scope.row.operateCode)">修改</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="currentId?'修改物料':'新建物料'" width="600px" @closed="close">
      <div>
        <!-- <add-config ref="addConfigComponent" :id="currentId" v-if="showDialog" @change="onChange" /> -->
        <add-material ref="addMaterialComponent" v-if="showDialog" @change="onChange"></add-material>
      </div>
      <div slot="footer">
        <el-button type="success" size="small" @click="submit" :loading="ajaxLoading">确认</el-button>
        <el-button type="default" size="small" @click="close">取消</el-button>
      </div>
    </glsx-dialog>
    <!-- 弹框 end -->

  </d2-container>
</template>

<script>
import { PAGEMATERIALINFO, PAGEKCWAREHOUSE, EXPORTMATERIALINFO } from '@/http/interface'
import {
  GETJXCCOMMONLISTMATERIALTYPE,
  GETJXCCOMMONLISTDEVICETYPE,
} from '@/http/public'
import GlsxDialog from '@/components/dialog/index'
import AddMaterial from './addMaterial'
export default {
  components: {
    GlsxDialog,
    AddMaterial,
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      tableLoading: false,
      pageTotal: 0,
      currentPage: 1,
      pageSizes: [10, 20, 30, 40],
      pageSize: 10,
      tdWidth: 170,
      longWidth: 300,
      exportLoading: false,
      showServiceList: [],
      serviceList: [],
      showDialog: false,
      currentId: '',
      ajaxLoading: false,
      SCANTYPELIST: {
        Y: '是',
        N: '否',
      },
      materialList: [],
      deviceList: [],
    }
  },
  created() {},

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

    /**
     * 获取查询参数
     */
    getParams: function () {
      let _this = this;
      const oParams = JSON.parse(JSON.stringify(_this.formInline))
      if (oParams.materialCode) {
        oParams.materialName = oParams.materialCode
      };
      oParams.pageSize = this.pageSize
      return oParams
    },

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

    /**
     * 导出列表
     */
    exportInfo: function () {
      const _this = this
      const oParams = _this.getParams()
      _this.exportLoading = true
      EXPORTMATERIALINFO(oParams)
        .then((res) => {
          _this.exportLoading = false
        })
        .catch((error) => {
          _this.exportLoading = false
        })
    },

    /** 获取服务商列表 */
    getService: function () {
      let _this = this
      let oParams = {}
      oParams.pageNum = 1
      oParams.pageSize = 999999
      PAGEKCWAREHOUSE(oParams).then((res) => {
        console.log(res)
        if (res.returnCode != 0) {
          return false
        }
        let _obj = res.data
        let _list = _obj.list || []
        _this.showServiceList = _list.slice(0, 31)
        _this.serviceList = _list
      })
    },

    /** 本地搜索服务商 */
    onSearch: function (e) {
      console.log(e)
      let list = JSON.parse(JSON.stringify(this.serviceList))
      let n = list.filter((k) => {
        let m =
          k.merchantName.indexOf(e) > -1 ||
          k.merchantCode.toLocaleLowerCase().indexOf(e.toLocaleLowerCase()) > -1
        console.log(m)
        return m
      })
      console.log(n)
      this.showServiceList = n || []
    },

    /** 打开弹框 */
    openDialog: function (e) {
      console.log(e)
      this.showDialog = true
      this.currentId = e || ''
    },

    /** 关闭弹框 */
    close: function () {
      this.showDialog = false
      this.currentId = ''
    },

    /** 保存数据 */
    submit: function () {
      this.ajaxLoading = true
      this.$refs.addMaterialComponent.submit()
    },

    /** 监听组件 */
    onChange: function (e) {
      this.ajaxLoading = false
      if (e) {
        this.close()
        this.getList()
      }
    },

    /** 显示物料数量 */
    showTotal: function (row, id) {
      let list = row || []
      let o = list.find((k) => k.typeFlag == id)
      let m = ''
      m = o ? o.materialCode + '/' + o.materialName + ':' + o.total : ''
      return m
    },

    // 获取物料类型
    getMaterial: function () {
      let _this = this
      GETJXCCOMMONLISTMATERIALTYPE().then((res) => {
        _this.materialList = res.data || []
      })
    },

    // 获取设备类型
    getDevice: function () {
      let _this = this
      GETJXCCOMMONLISTDEVICETYPE().then((res) => {
        _this.deviceList = res.data || []
      })
    },

    // 重置
    rest: function () {
      this.formInline = {}
      this.getList()
    },
  },
}
</script>

<style lang="scss" scoped>
.table_box {
  margin: 10px 0;
}
</style>