<template>
  <div class="app-history">
    <div class="search">
      <el-date-picker v-model="table.getdataListParm.parammaps.date" type="date" :placeholder="$t('formulationEvaluation.lssjjl')":clearable="false" style="width: 230px;" format="yyyy-MM-dd" value-format="yyyy-MM-dd" @change="changeDate" />
    </div>

    <div class="table">
      <el-table
        id="table"
        :key="table.tableKey"
        ref="table"
        v-loading="table.listLoading"
        :element-loading-text="$t('common.tableMsg')"
        :data="table.list"
        border
        highlight-current-row
        style="width: 100%;"
        :height="height"
        :row-style="rowStyle"
        :cell-style="cellStyle"
        class="elTable table-fixed"
        row-key="id"
      >
        <el-table-column :label="$t('errorAnalysis.projname')" width="85px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.sort }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.tmrbh')"  width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.tmrname }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.ms')"width="110px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.display }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.sx')"  width="100px" align="center">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.sel" disabled active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" @change="handleTakeEffectChange(scope.$index, scope.row)" />
          </template>
        </el-table-column>
        <el-table-column :label="$t('errorAnalysis.isTrainNumber')"  width="100px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.timesstr }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.time')"   width="150px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.begintime }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.zdzl')" width="80px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.maxweight }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.hjzl')" width="80px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.sumweight }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.pfmb')"width="120px" align="center">
          <template slot-scope="scope">
            <span>{{ scope.row.ftname }}</span>
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.sftqcfxl')" width="100px" align="center">
          <template slot-scope="scope">
            <el-switch v-model="scope.row.issplit" :disabled="scope.row.NoEdit" active-color="#13ce66" inactive-color="#ff4949" :active-value="1" :inactive-value="0" disabled />
          </template>
        </el-table-column>
        <el-table-column :label="$t('premixedPlan.sl')"min-width="250px" align="left" header-align="center">
          <template slot-scope="scope">
            <div v-for="element in scope.row.arrList" :key="element.name" class="list">
              <el-tooltip placement="top" :open-delay="1000">
                <div slot="content">
                  <div> 栏舍全称：{{ element.barname }} </div>
                  <div> 饲料重量：{{ element.weight }} </div>
                  <!-- <div> 撒料车：{{ element.tmrname }} </div> -->
                </div>
                <div :style="{'background':element.background}" class="tmrname">{{ element.barname }}</div>
              </el-tooltip>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>

  </div>
</template>

<script>
import { GetDataByName, postJson } from '@/api/common'
import draggable from 'vuedraggable'
import Cookies from 'js-cookie'
import { parseTime } from '@/utils/index.js'
export default {
  name: 'MaterialIssuancePlan',
  display: 'Two list header slot',
  order: 14,
  components: { draggable },
  data() {
    return {
      table: {
        getdataListParm: {
          name: 'getLppListdate',
          name1: 'getLppdListdate',
          page: 1,
          offset: 1,
          returntype: 'Map',
          parammaps: {
            pastureid: Cookies.get('pastureid'),
            date: parseTime(new Date(), '{y}-{m}-{d}')
          }
        },
        list: [],
        total: 0,
        tableKey: 0,
        listLoading: false,
        temp: {},
        changeList: [],
        startObj: {}
      },
      requestParams2: {
        name: 'getTMRListEnable', offset: 0, parammaps: { pastureid: Cookies.get('pastureid'), eqtype: '1' }
      },
      equipmentList: [], // 撒料设备
      height: document.body.clientHeight - 255 - 50, // table高度
      rowStyle: { maxHeight: 30 + 'px', height: 30 + 'px' },
      cellStyle: { padding: 0 + 'px' }
    }
  },
  created() {
    this.getList()
    this.getDownList()
  },
  methods: {
    changeDate() {
      this.getList()
    },
    getDownList() {
      GetDataByName(this.requestParams2).then(response => {
        this.equipmentList = response.data.list
      })
    },
    getList() {
      this.table.listLoading = true
      const url = 'authdata/GetArrList'
      const data = this.table.getdataListParm
      postJson(url, data).then(response => {
        console.log('table数据', response.data.list)
        if (response.data.list !== null) {
          for (let i = 0; i < response.data.list.length; i++) {
            if (response.data.list[i].arrList == null) {
              this.$set(response.data.list[i], 'arrList', [])
            }
          }
          this.table.list = response.data.list
          this.table.changeList = []
          this.table.startObj = {}
          if (response.data.total) {
            this.table.total = response.data.total
          }
        } else {
          this.table.list = []
        }

        setTimeout(() => {
          this.table.listLoading = false
        }, 100)
      })
    }
  }
}
</script>

<style  lang="scss" scoped>
 .search{margin-bottom: 10px;}
 .list{width: 60px;display: inline-block;margin: 5px 5px;text-align: center;
    .tmrname{
      width:100%;padding: 5px 5px;overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
    }
 }
</style>
