<!-- 单位换算 -->
<template>
  <div class="stock-order">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="queryData()">
      <el-form-item label="换算后单位">
        <el-input v-model="dataForm.convertUnit" placeholder="换算后单位" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="queryData()">查询</el-button>
        <el-button @click="addOrUpdateHandle(0, false)"  type="primary">新增换算</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center">
      </el-table-column>
      <el-table-column
        prop="conversionCode"
        header-align="center"
        align="center"
        min-width="160"
        label="编码">
      </el-table-column>
      <el-table-column
        prop="convertUnitBefore"
        header-align="center"
        align="center"
        label="转换前单位">
      </el-table-column>
      <el-table-column
        prop="convertUnit"
        header-align="center"
        align="center"
        label="转换后单位">
      </el-table-column>
      <el-table-column
        prop="cnt"
        header-align="center"
        align="center"
        label="转换后数量">
      </el-table-column>
      <el-table-column
        prop="useNumber"
        header-align="center"
        align="center"
        label="使用次数">
      </el-table-column>
      <el-table-column
        prop="creatorName"
        header-align="center"
        align="center"
        label="创建人">
      </el-table-column>
      <el-table-column
        prop="createTime"
        header-align="center"
        align="center"
        min-width="160"
        label="创建时间">
      </el-table-column>
      <el-table-column
        prop="notes"
        header-align="center"
        align="center"
        width="100"
        :show-overflow-tooltip="true"
        label="备注">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="100"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.conversionId, true)">查看</el-button>
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.conversionId, false)">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!--    入库-->
    <unit-add v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></unit-add>
  </div>
</template>

<script>
  import unitAdd from './unit-add'
  import { getUnitConversionList } from '@/api/warehouse'
  export default {
    name: 'stock-order',
    components: {unitAdd},
    data () {
      return {
        inboundVisible: false,
        dataForm: {
          name: '',
          date: ''
        },
        recordTypeOptions: [
          {
            value: null,
            label: '请选择'
          },
          {
            value: '0',
            label: '入库'
          },
          {
            value: '1',
            label: '出库'
          }
        ],
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false
      }
    },
    created () {
      this.queryData()
    },
    methods: {
      // 查询
      queryData () {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        let params = {
          'current': this.pageIndex,
          'size': this.pageSize,
          'convertUnit': this.dataForm.convertUnit
        }
        getUnitConversionList(params).then(({data}) => {
          if (data && data.code === '200') {
            this.dataList = data.data.records
            this.totalPage = Number(data.data.total)
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 入库申请
      addOrUpdateHandle (id, display) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id, display)
        })
      }
    }
  }
</script>

<style scoped>

</style>
