<template>
  <div class="app-container">
    <div class="operation">
      <el-button class="success" @click="handleCreate">新增入库单</el-button>
      <el-button class="success" @click="handleInitial">初始化库存</el-button>
    </div>
    <div class="search">
      <el-date-picker v-model="table.getdataListParm.parammaps.inputDatetime" class="inputDatetime" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="width: 250px;" />
      <el-select v-model="table.getdataListParm.parammaps.enable" placeholder="饲料名称" class="filter-item" style="width: 150px;" clearable>
        <el-option v-for="item in feedNameList" :key="item.id" :label="item.name" :value="item.name" />
      </el-select>
      <el-button class="successBorder" @click="handleSearch">查询</el-button>
      <el-button class="successBorder" @click="handleRefresh">重置</el-button>
    </div>

    <div class="table">
      <el-table
        :key="table.tableKey"
        v-loading="table.listLoading"
        element-loading-text="给我一点时间"
        :data="table.list"
        border
        fit
        highlight-current-row
        style="width: 100%;"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
      >
        <el-table-column label="序号" align="center" type="index" width="50px">
          <template slot-scope="scope">
            <span>{{ scope.$index + (table.pageNum-1) * table.pageSize + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="入库日期" min-width="130px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brandName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="饲料名称" min-width="130px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brandName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作重量(kg)" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brandName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="批号" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brandName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="金额(元)" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brandName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="备注" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brandName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建日期" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brandName }}</span>
          </template>
        </el-table-column>
        <el-table-column label="创建人" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.brandName }}</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination v-show="table.total>=0" :total="table.total" :page.sync="table.getdataListParm.offset" :limit.sync="table.getdataListParm.pagecount" @pagination="getList" />
    </div>

    <!-- 新增入库单 -->
    <el-dialog :title="textMap[create.dialogStatus]" :visible.sync="create.dialogFormVisible" :close-on-click-modal="false" width="90%">
      <div class="app-add">
        <el-form ref="createTemp" :rules="create.rules" :model="create.createTemp" label-position="right" label-width="160px" style="width: 90%;margin:0 auto 50px">
          <el-row>
            <el-col :span="8">
              <el-form-item label="入库日期:" prop="location">
                <el-date-picker v-model="create.createTemp.location" class="filter-item" type="date" placeholder="入库日期" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="饲料名称:" prop="location">
                <el-select v-model="create.createTemp.enable" placeholder="饲料名称" class="filter-item" style="width: 100%">
                  <el-option v-for="item in feedNameList" :key="item.id" :label="item.name" :value="item.name" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="操作重量(kg):" prop="location">
                <el-input ref="location" v-model="create.createTemp.location" class="filter-item" placeholder="单价" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="金额(元):" prop="location">
                <el-input ref="location" v-model="create.createTemp.location" class="filter-item" placeholder="允许误差数" type="text" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="批号:" prop="location">
                <el-input ref="location" v-model="create.createTemp.location" class="filter-item" placeholder="包装单位重量" type="text" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="备注:" prop="location">
                <el-input ref="location" v-model="create.createTemp.location" class="filter-item" placeholder="单价" type="text" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="8">
              <el-form-item label="创建日期:" prop="location">
                <el-date-picker v-model="create.createTemp.location" class="filter-item" type="date" placeholder="创建日期" disabled />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="创建人:" prop="location">
                <el-input ref="location" v-model="create.createTemp.location" class="filter-item" placeholder="创建人" type="text" disabled />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button class="cancel" @click="create.dialogFormVisible = false; ">关闭</el-button>
          <el-button class="success" :disabled="isokDisable" @click="createData()">确认</el-button>
        </div>
      </div>
    </el-dialog>

    <!-- 初始化库存 -->
    <el-dialog :title="textMap[initial.dialogStatus]" :visible.sync="initial.dialogFormVisible" :close-on-click-modal="false" width="30%" height="55%">
      <div class="app-add" style="height: 100%;margin: 0 auto 60px;">
        <h3 style="font:400 18px/36px '';padding: 0 60px;text-align: center;">初始化操作会将现有库存数量更改,是否确认进行操作:</h3>

        <div slot="footer" class="dialog-footer">
          <el-button class="cancel" @click="initial.dialogFormVisible = false; ">关闭</el-button>
          <el-button class="success" :disabled="isokDisable" @click="initialData()">确认</el-button>
        </div>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import { GetDataByName } from '@/api/common'
import Pagination from '@/components/Pagination'
import { MessageBox } from 'element-ui'
export default {
  name: 'Warehousing',
  components: { Pagination },
  data() {
    return {
      feedNameList: [{ id: 0, name: '羊草' }, { id: 1, name: '小苏打' }], // 饲料名称
      table: {
        getdataListParm: {
          name: 'getAssetList',
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: 'Map',
          parammaps: {
            enable: '',
            inputDatetime: ''
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true
      },
      create: {
        dialogFormVisible: false,
        dialogStatus: '',
        createTemp: {},
        rules: {}
      },
      initial: {
        dialogFormVisible: false,
        dialogStatus: '',
        createTemp: {},
        rules: {}
      },
      textMap: {
        create: '新增',
        initial: '提示'
      },
      isokDisable: false,
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },

  created() {
    this.getList()
  },

  methods: {
    getList() {
      this.table.listLoading = true
      GetDataByName(this.table.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.table.list = response.data.list
          this.table.pageNum = response.data.pageNum
          this.table.pageSize = response.data.pageSize
            this.table.total = response.data.total
        } else {
          this.table.list = []
        }
        setTimeout(() => {
          this.table.listLoading = false
        }, 100)
      })
    },
    handleSearch() {
      console.log('点击了查询')
      this.getList()
    },
    handleRefresh() {
      console.log('点击了重置')
    },
    resetCreateTemp() {

    },
    handleCreate() {
      console.log('点击了新增入库单')
      this.resetCreateTemp()
      this.create.dialogStatus = 'create'
      this.create.dialogFormVisible = true
    },
    createData() {
      MessageBox.confirm('是否确认保存当前内容', {
        confirmButtonText: '确认',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        console.log('点击了新增入库单保存')
      })
    },
    handleInitial() {
      console.log('点击了初始化库存')
      this.initial.dialogStatus = 'initial'
      this.initial.dialogFormVisible = true
    },
    initialData() {
      console.log('点击了初始化库存保存')
    }
  }
}
</script>
<style lang="scss" scoped>
  .search{margin-top:10px;}
  .table{margin-top:10px;}
</style>
<style>
  .inputDatetime .el-range-separator{ padding: 0; margin: 0 10px; }
</style>