<template>
  <div class="stock-order">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item label="出入库类型">
        <el-select v-model="dataForm.recordType" placeholder="请选择">
          <el-option
            v-for="item in recordTypeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="申请人姓名">
        <user-component v-model="dataForm.userId"/>
      </el-form-item>
      <el-form-item label="申请日期">
        <el-date-picker
          v-model="dataForm.date"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('wh:in-out-bound-ctl:inbound')" type="primary" @click="inBound()">入库申请</el-button>
        <el-button v-if="isAuth('wh:in-out-bound-ctl:outbound')" type="primary" @click="outBound()">出库申请</el-button>
<!--        <el-button v-if="isAuth('sys:user:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>-->
<!--        <el-button v-if="isAuth('sys:user:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>-->
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>
      <el-table-column
        label="序号"
        type="index"
        width="50"
        align="center">
      </el-table-column>
      <el-table-column
        prop="-"
        header-align="center"
        align="center"
        label="编码">
      </el-table-column>
      <el-table-column
        prop="recordType"
        header-align="center"
        align="center"
        label="申请单类别">
      </el-table-column>
      <el-table-column
        prop="state"
        header-align="center"
        align="center"
        label="申请状态">
      </el-table-column>
      <el-table-column
        prop="approver"
        header-align="center"
        align="center"
        label="当前审批员">
      </el-table-column>
      <el-table-column
        prop="-"
        header-align="center"
        align="center"
        label="申请时间">
      </el-table-column>
      <el-table-column
        prop="recordTime"
        header-align="center"
        align="center"
        label="入库时间">
      </el-table-column>
      <el-table-column
        prop="-"
        header-align="center"
        align="center"
        label="申请人">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="isAuth('wh:inbound-record-ctl:info')" type="text" size="small" @click="details(scope.row.id)">查看</el-button>
          <el-button type="text" size="small" @click="exportItem(scope.row.id)">导出</el-button>
          <el-button type="text" size="small" @click="cancelItem(scope.row.id)">撤回</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>
    <!--    入库-->
    <stock-order-inbound v-if="inboundVisible" ref="inbound" @refreshDataList="getDataList"></stock-order-inbound>
  </div>
</template>

<script>
  import UserComponent from '../common/user-component'
  import StockOrderInbound from './stock-order-inbound'
  export default {
    name: 'stock-order',
    components: {StockOrderInbound, UserComponent},
    data () {
      return {
        inboundVisible: false,
        dataForm: {
          userId: '',
          date: '',
          recordType: null
        },
        recordTypeOptions: [
          {
            value: null,
            label: '请选择'
          },
          {
            value: '0',
            label: '入库'
          },
          {
            value: '1',
            label: '出库'
          }
        ],
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: []
      }
    },
    methods: {
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/biz-service/inbound-record-ctl/list'),
          method: 'get',
          params: this.$http.adornParams({
            'current': this.pageIndex,
            'size': this.pageSize,
            'userId': this.dataForm.userId,
            'beginTime': this.dataForm.date[0],
            'endTime': this.dataForm.date[1],
            'recordType': this.dataForm.recordType
          })
        }).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
      },
      // 入库申请
      inBound () {
        this.inboundVisible = true
        this.$nextTick(() => {
          this.$refs.inbound.init()
        })
      }
    }
  }
</script>

<style scoped>

</style>
