<template>
  <div>
    <el-table class="ctr-tec-table xg-ytg-line-hei" :span-method="params.spanMethod" :ref="'detailTable' + params.index" max-height="600" :data="params.data" v-loading="params.loading" border highlight-current-row>
      <el-table-column prop="PACT_INDEX" label="计划号" :show-overflow-tooltip="true" align="left" min-width="120"></el-table-column>
      <el-table-column prop="SLAB_SEQ" label="子坯序号" :show-overflow-tooltip="true" align="left" min-width="100"></el-table-column>
      <el-table-column prop="DESIGN_NO" label="短尺设计号" :show-overflow-tooltip="true" align="left" min-width="140" :filter-method="filterColumn"></el-table-column>
      <el-table-column prop="STEEL_NAME" label="牌号" :show-overflow-tooltip="true" align="left" min-width="80" :filter-method="filterColumn"></el-table-column>
      <el-table-column prop="SLAB_THK" label="厚(mm)" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
      <el-table-column prop="SLAB_WTH" label="宽(mm)" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
      <el-table-column prop="SLAB_LEN" label="长(mm)" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
      <el-table-column prop="SINGLE_WGT" label="单重(t)"  :show-overflow-tooltip="true"  align="right" min-width="60">
        <template slot-scope="scope">
          <span>{{scope.row.SINGLE_WGT | weightTrans}}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单序号" prop="PLATE_SEQ" align="center" show-overflow-tooltip min-width="60"></el-table-column>
      <el-table-column prop="ORDER_NO" label="订单号" white-space-nowrap :show-overflow-tooltip="true" align="left" min-width="100" :filter-method="filterColumn"></el-table-column>
      <el-table-column prop="PROD_ORDER_NO" label="生产订单号" :show-overflow-tooltip="true" align="left" min-width="100" :filter-method="filterColumn"></el-table-column>
      <el-table-column  label="设计子板规格(长度：mm 重量：t)">
          <el-table-column prop="CHILD_THK" label="厚" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
          <el-table-column prop="CHILD_WTH" label="宽" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
          <el-table-column prop="CHILD_LEN" label="长" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
          <el-table-column prop="CHILD_WGT" label="重" :show-overflow-tooltip="true" align="right" min-width="60">
            <template slot-scope="scope">
              <span>{{scope.row.CHILD_WGT | weightTrans}}</span>
            </template>
          </el-table-column>
      </el-table-column>
      <el-table-column  label="订单要求规格(长度：mm 重量：t)">
        <el-table-column prop="THICK" label="厚" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
        <el-table-column prop="WIDTH" label="宽" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
        <el-table-column prop="LENGTH" label="长" :show-overflow-tooltip="true" align="right" min-width="50"></el-table-column>
        <el-table-column prop="ESTIMATE_WEIGHT" label="重"  :show-overflow-tooltip="true" align="right" min-width="50">
          <template slot-scope="scope">
            <span>{{scope.row.ESTIMATE_WEIGHT | weightTrans}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="LENGTH_MAX" label="长度上限" :show-overflow-tooltip="true" align="right" min-width="60"></el-table-column>
        <el-table-column prop="LENGTH_MIN" label="长度下限" :show-overflow-tooltip="true" align="right" min-width="60"></el-table-column>
        <el-table-column prop="WIDTH_MAX" label="宽度上限" :show-overflow-tooltip="true" align="right" min-width="60"></el-table-column>
        <el-table-column prop="WIDTH_MIN" label="宽度下限" :show-overflow-tooltip="true" align="right" min-width="60"></el-table-column>
        <el-table-column prop="SINGLE_WEIGHT_MAX" label="单重上限"  :show-overflow-tooltip="true"  align="right" min-width="60">
          <template slot-scope="scope">
            <span>{{scope.row.SINGLE_WEIGHT_MAX | weightTrans}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="SINGLE_WEIGHT_MIN" label="单重下限" :show-overflow-tooltip="true" align="right" min-width="60">
          <template slot-scope="scope">
            <span>{{scope.row.SINGLE_WEIGHT_MIN | weightTrans}}</span>
          </template>
        </el-table-column>
      </el-table-column>
      <el-table-column prop="FIX_SIZE_DESC" label="定尺方式" :show-overflow-tooltip="true" align="left" min-width="80"></el-table-column>
      <el-table-column prop="CUT_EDGE_TYPE_NAME" label="切边方式" :show-overflow-tooltip="true" align="left" min-width="80"></el-table-column>
      <el-table-column prop="DELIVERY_ERROR_MIN" label="交货重量下限(t)" :show-overflow-tooltip="true" align="right" min-width="60">
        <template slot-scope="scope">
          <span>{{scope.row.DELIVERY_ERROR_MIN | weightTrans}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="DELIVERY_ERROR_MAX" label="交货重量上限(t)" :show-overflow-tooltip="true" align="right" min-width="60">
        <template slot-scope="scope">
          <span>{{scope.row.DELIVERY_ERROR_MAX | weightTrans}}</span>
        </template>
      </el-table-column>
      <el-table-column prop="SPECIAL" label="特殊要求" :show-overflow-tooltip="true" align="left" min-width="80">
        <template slot-scope="props">
          <el-button type="text" size="small" @click="showSpecialDetail(props.row)">{{props.row.SPECIAL}}</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="ADD_ASK_DESC" label="附加要求" :show-overflow-tooltip="true" align="left" min-width="80"></el-table-column>
      <el-table-column prop="ORG" label="检验机构" :show-overflow-tooltip="true" align="left" min-width="80"></el-table-column>
      <el-table-column prop="RECIVER_UNIT_NAME" label="收货单位" white-space-nowrap :show-overflow-tooltip="true" align="left" min-width="80" :filter-method="filterColumn"></el-table-column>
    </el-table>
  </div>
</template>
<script>
export default {
  props: {
    params: {
      type: Object,
      default: {}
    },
    isshow: {
      type: Boolean
    }
  },
  data () {
    return {}
  },
  mounted () {
    console.log('传过来的数据', this.params)
    this.getDetailData(this.params)
  },
  methods: {
    showSpecialDetail (row) {
      this.$emit('showdetail', row)
    },
    getDetailData (row) {
      let _this = this;
      let ldesignNo = row.ldesign_no || row.LDESIGN_NO || row.object_type
      if (ldesignNo) {
        let arr = [
          {
            object: {
              ldesign_no: ldesignNo
            }
          }
        ]
        _this.$set(row, 'loading', true)
        _this.axios.post('/PlnLslabdesignMainService/doQuaryMultinfoMain', arr).then(function (response) {
          if (response) {
            if (response.status === 200 || response.status === '200') {
              let arr = [];
              let len = response.data.data.length;
              let data = response.data.data
              for (let i = 0; i < len; i++) {
                data[i].index = i
                data[i].$index = row.index
                if (!arr[Number(data[i].SLAB_SEQ) - 1]) {
                  arr[Number(data[i].SLAB_SEQ) - 1] = []
                }
              }
              for (let i = 1; i <= arr.length; i++) {
                for (let item of data) {
                  if (Number(item.SLAB_SEQ) === i) {
                    arr[i - 1].push(item.SLAB_SEQ)
                  }
                }
              }
              _this.$set(row, 'data', response.data.data)
              _this.$refs['detailTable' + row.index].clearFilter();
              _this.setFilterDatas(_this.$refs['detailTable' + row.index].columns, row.data, ['ORDER_NO', 'PROD_ORDER_NO', 'DELIVERY_STATE_DESC', 'DESIGN_NO', 'STEEL_NAME', 'RECIVER_UNIT_NAME']);
              _this.$set(row, 'spanMethod', function ({ row, column, rowIndex, columnIndex }) {
                let index = 0;
                if (columnIndex === 0 || columnIndex === 1 || columnIndex === 2 || columnIndex === 3 || columnIndex === 4 || columnIndex === 5 || columnIndex === 6) {
                  if (rowIndex === 0) {
                    return {
                      rowspan: arr[0].length,
                      colspan: 1
                    }
                  } else {
                    for (let i = 0; i < arr.length; i++) {
                      index += arr[i].length
                      if (rowIndex === index) {
                        if (i < arr.length - 1) {
                          return {
                            rowspan: arr[i + 1].length,
                            colspan: 1
                          }
                        }
                      }
                    }
                  }
                  for (let i = 0; i < arr.length; i++) {
                    if (rowIndex !== 0 && rowIndex !== arr[i].length) {
                      return {
                        rowspan: 0,
                        colspan: 0
                      }
                    }
                  }
                }
              })
            }
          }
          _this.$set(row, 'loading', false)
        }).catch(function () {
          _this.$set(row, 'loading', false)
        })
      }
    }
  },
  watch: {
    isshow () {
      console.log('执行了监听')
      this.getDetailData(this.params)
    }
  }
}
</script>
