<template>
  <div class="app-container">
    <div class="operation">
      <el-button class="import" style="float: right;margin-bottom: 10px;" @click="form_export">导出</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%;"
        :cell-style="cellStyle"
        class="elTable table-fixed"
        :row-style="rowStyle"
      >
        <el-table-column label="序号" align="center" type="index" width="50px" />
        <!-- <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.feedname }}</span>
          </template>
        </el-table-column>
        <el-table-column label="库存量（kg）" min-width="130px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.stockweight }}</span>
          </template>
        </el-table-column>
        <el-table-column label="近七天平均计划量（kg）" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.avgweight }}</span>
          </template>
        </el-table-column>
        <el-table-column label="剩余使用天数" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.ldays }}</span>
          </template>
        </el-table-column>
        <el-table-column label="最近预警日期" min-width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.lastdate }}</span>
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center" width="120" class-name="small-padding fixed-width" fixed="right">
          <template slot-scope="{row}">
            <el-button class="miniPrimary" :disabled="isokDisable" @click="form_see(row)">查看</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>

    <el-dialog :title="textMap[see.dialogStatus]" :visible.sync="see.dialogFormVisible" :close-on-click-modal="false" width="90%">
      <div class="app-see">
        <el-form ref="temp" :rules="see.rules" :model="see.temp" label-position="right" label-width="110px" style="width: 100%;margin:0 auto">
          <el-row>
            <el-col :span="8">
              <el-form-item label="饲料名称:" prop="feedname">
                <span> {{ see.temp.feedname }}</span>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
        <el-table
          :key="see.tableKey"
          v-loading="see.listLoading"
          element-loading-text="给我一点时间"
          :data="see.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 + (see.pageNum-1) * see.pageSize + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="库存量" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.stockweight }}</span>
            </template>
          </el-table-column>
          <el-table-column label="近七天平均计划量（kg）" min-width="130px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.avgweight }}</span>
            </template>
          </el-table-column>
          <el-table-column label="剩余使用天数" min-width="110px" align="center">
            <template slot-scope="scope">
              <span> {{ scope.row.ldays }}</span>
            </template>
          </el-table-column>
          <el-table-column label="预警日期" min-width="110px" align="center">
            <template slot-scope="scope">
              <span>{{ scope.row.date }}</span>
            </template>
          </el-table-column>
        </el-table>
        <pagination v-show="see.total>=0" style="margin-bottom: 50px;" :total="see.total" :page.sync="see.getdataListParm.offset" :limit.sync="see.getdataListParm.pagecount" @pagination="getSeeList" />
        <div slot="footer" class="dialog-footer">
          <el-button class="cancelClose" @click="see.dialogFormVisible = false; ">关闭</el-button>
        </div>
      </div>
    </el-dialog>
  </div>

</template>

<script>
import { GetDataByName } from '@/api/common'
import Pagination from '@/components/Pagination'
import Cookies from 'js-cookie'
export default {
  name: 'Warning',
  components: { Pagination },
  data() {
    return {
      table: {
        getdataListParm: {
          name: 'getFsWarnList',
          page: 1,
          offset: 1,
          pagecount: '',
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid')
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true
      },
      textMap: {
        see: '库存预警记录'
      },
      see: {
        dialogFormVisible: false,
        dialogStatus: '',
        temp: {},
        rules: {},
        getdataListParm: {
          name: 'getFsWarnListdate',
          page: 1,
          offset: 1,
          pagecount: 10,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            feedid: ''
          }
        },
        tableKey: 0,
        list: [],
        total: 0,
        listLoading: true
      },
      isokDisable: false,
      rowStyle: { maxHeight: 50 + 'px', height: 45 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },

  created() {
    this.get_table_data()
  },

  methods: {
    get_table_data() {
      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)
      })
    },
    form_see(row) {
      this.see.dialogStatus = 'see'
      this.see.dialogFormVisible = true
      this.see.temp = Object.assign({}, row)
      this.see.list = []
      this.see.getdataListParm.offset = 1
      this.see.getdataListParm.parammaps.feedid = row.feedid
      this.getSeeList()
    },
    getSeeList() {
      this.see.listLoading = true
      GetDataByName(this.see.getdataListParm).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          this.see.list = response.data.list
          this.see.pageNum = response.data.pageNum
          this.see.pageSize = response.data.pageSize
          this.see.total = response.data.total
        } else {
          this.see.list = []
        }
        setTimeout(() => {
          this.see.listLoading = false
        }, 100)
      })
    },
    form_export() {
      console.log('导出')
    }

  }
}
</script>
