<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-form
          :inline="true"
          class="demo-form-inline"
          label-position="right"
          label-width="80px"
          label-suffix=":"
          size="mini"
        >

          <el-form-item label="仓库">
            <label slot="label">仓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;库:</label>
            <el-select
              v-model="query.stor_id"
              size="mini"
              placeholder="单据状态"
              class="filter-item"
              @change="crud.toQuery"
            >
              <el-option
                v-for="item in storlist"
                :key="item.stor_id"
                :label="item.stor_name"
                :value="item.stor_id"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="日期">
            <label slot="label">日&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;期:</label>
            <el-date-picker
              v-model="query.createTime"
              type="daterange"
              value-format="yyyy-MM-dd"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :clearable="false"
              @input="onInput()"
              @change="mytoQuery"
            />
          </el-form-item>

          <el-form-item label="物料编码">
            <el-input
              v-model="query.material_code"
              clearable
              size="mini"
              placeholder="请输入物料编码、名称、规格"
              style="width: 230px;"
              class="filter-item"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <rrOperation />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission"/>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="mini"
        show-summary
        :max-height="590"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column show-overflow-tooltip min-width="120" prop="material_code" label="物料编码" />
        <el-table-column show-overflow-tooltip min-width="120" prop="material_name" label="物料名称" />
        <el-table-column show-overflow-tooltip min-width="120" prop="material_spec" label="物料规格" />
        <el-table-column show-overflow-tooltip min-width="120" prop="qty_unit_name" label="单位" />
        <el-table-column show-overflow-tooltip min-width="120" prop="begin_qty" label="期初" :formatter="crud.formatNum3" />
        <el-table-column show-overflow-tooltip min-width="120" prop="in_qty" label="入库" :formatter="crud.formatNum3" />
        <el-table-column show-overflow-tooltip min-width="120" prop="out_qty" label="出库" :formatter="crud.formatNum3" />
        <el-table-column show-overflow-tooltip min-width="120" prop="canuse_qty" label="结存" :formatter="crud.formatNum3" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudPhyivt from '@/views/wms/stata_manage/phyivt/phyivt'
import CRUD, { presenter, header, crud } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker/index'
import Date from '@/utils/datetime'
import crudStorattr from '@/views/wms/storage_manage/basedata/basedata'

export default {
  name: 'Phyivt',
  components: { pagination, crudOperation, rrOperation, udOperation, DateRangePicker },
  mixins: [presenter(), header(), crud()],
  cruds() {
    return CRUD({
      title: '收发存',
      url: 'api/phyivt',
      idField: 'id',
      sort: 'id,desc',
      crudMethod: { ...crudPhyivt },
      props: {
        // 每页数据条数
        size: 10
      },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: true
      }
    })
  },
  data() {
    return {
      storlist: [],
      query_flag: true,
      permission: {
      },
      rules: {
      }}
  },
  created() {
    crudStorattr.getStor({ 'stor_type': '' }).then(res => {
      this.storlist = res.content
    })
    this.crud.query.createTime = [new Date().daysAgo(6), new Date()]
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      if (this.query_flag) {
        this.crud.query.begin_time = (new Date().daysAgo(6)).strftime('%F', 'zh')
        this.crud.query.end_time = (new Date()).strftime('%F', 'zh')
        this.crud.query.stor_id = '1528627995269533696'
        this.query_flag = false
      }
    },
    hand(value) {
      this.crud.toQuery()
    },
    onInput() {
      this.$forceUpdate()
    },
    mytoQuery(array1) {
      if (array1 === null) {
        this.crud.query.begin_time = ''
        this.crud.query.end_time = ''
      } else {
        this.crud.query.begin_time = array1[0]
        this.crud.query.end_time = array1[1]
      }
      this.crud.toQuery()
    }
  }
}
</script>

<style scoped>

</style>
