<!--
 * @Author: zhp
 * @Date: 2024-04-18 15:49:48
 * @LastEditTime: 2024-04-18 16:30:42
 * @LastEditors: zhp
 * @Description:
-->
<template>
  <div>
    <el-row style="float: right; margin-bottom: 5px">
      <el-button v-if="!edit && this.$auth.hasPermi('base:report-auto-original-glass:update')" :disabled="noData"
        size="small" @click="edit = true">编辑</el-button>
      <el-button v-if="edit" size="small" @click="handleReturn()">返回</el-button>
      <el-button v-if="edit" size="small" @click="updateData">保存</el-button>
    </el-row>
    <el-table :id="id" :data="data" border style="width: 100%">
      <el-table-column v-for="(item, index) in cols" :key="index" :prop="item.prop" :label="item.label"
        :align="item.align ? item.align : 'left'">
        <el-table-column v-for="(it, index1) in item.children" :key="index1" :prop="it.prop" :label="it.label"
          :align="item.align ? item.align : 'left'">
          <el-table-column v-for="(y, index2) in it.children" :key="index2" :prop="y.prop" :label="y.label">
            <template slot-scope="scope">
              <span v-if="!edit">{{ scope.row[y.prop] }}</span>
              <el-input type="number" @change="handleChange" :disabled="y.prop == 'dailyOutputTrend' || y.prop === 'originalGlassStatisticsTrend'
                 || y.prop === 'actualProductTrend' || y.prop === 'originalGlassPassTrend' || y.prop === 'originalGlassPassNow' || y.prop === 'originalGlassPassHis'
              " v-else v-model="scope.row[y.prop]"></el-input>
            </template>
          </el-table-column>
        </el-table-column>
      </el-table-column>
    </el-table>
    <!-- <el-input type="textarea" v-model="remark" placeholder="备注" :disabled="!edit" :autosize="{ minRows: 2, maxRows: 6}">
    </el-input> -->
  </div>
</template>

<script>
import { updateGlass, updateGlassRemark } from '@/api/report/glass';

const cols = [
  {
		prop: 'xc',
    label: '许昌安彩新能科技有限公司2024年4月份生产日报',
		align: 'center',
		children: [
			{
				prop: 'lineName',
				label: '生产线',
			},
			{
				prop: 'm',
        label: '尺寸(长、宽、厚)毫米',
        align: 'center',
        children: [
          {
            prop: 'length',
            label: '长',
          },
          {
            prop: 'width',
            label: '宽',
          },
          {
            prop: 'thick',
            label: '高',
          }
        ]
      },
      {
        prop: 'm',
        label: '良品数',
        align: 'center',
        children: [
          {
            prop: 'earlyNum',
            label: '早班',
          },
          {
            prop: 'nightNum',
            label: '晚班',
          },
          {
            prop: 'num',
            label: '合计',
          }
        ]
      },
      {
        prop: 'weight',
        label: '良品重量(吨)',
      },
      {
				prop: 'y',
        label: '良品玻璃面积(㎡)',
        align: 'center',
        children: [
          {
            prop: 'earlyArea',
            label: '早班',
          },
          {
            prop: 'nightArea',
            label: '晚班',
          },
          {
            prop: 'area',
            label: '合计',
          }
        ]
      },
      {
        prop: 'y',
        label: '原片良品率',
        align: 'center',
        children: [
          {
            prop: 'earlyRate',
            label: '早班',
          },
          {
            prop: 'nightRate',
            label: '晚班',
          },
          {
            prop: 'rate',
            label: '合计',
          }
        ]
      },
      {
        prop: 'monthArea',
        label: '月累计面积',
      },
      {
        prop: 'remark',
        label: '备注',
      }
		]
	}
]
  export default {
    props: {
      data: {
        type: Array,
        default: () => [],
      },
      id: {
        type: String,
        default:'exportTable'
      },
      time: {
        type: Array,
        default: () => [],
      },
      date: {
        type: String,
        default:''
      },
      sum: {
        type: Object,
        default: () => {},
      },
      type: {
        type: Number,
        default: 3,
      }
    },
    data() {
      return {
        cols,
        remark:null,
        edit: false,
        noData:false,
      };
    },
  watch: {
    data: {
      handler(newv, oldv) {
        if (newv.length != 0) {
          this.noData = false
        } else {
          this.noData = true
        }
      }
      },
      time: {
        immediate: true,
        handler(newv, oldv) {
          if (newv[0] !== '') {
            this.cols[0].label = this.date + '(' + newv[0] + '-' + newv[1] + ')'
          } else {
            this.cols[0].label = this.date
          }
        }
      },
      // type: {
      //   immediate: true,
      //   handler(newv, oldv) {
      //     let text1 = '', text2 = '', text3 = ''
      //     if (newv === 3) {
      //       text1 = '本周'
      //       text2 = '上周'
      //       text3 = '原片合计(片/周)'
      //     } else if (newv === 4) {
      //       text1 = '本月'
      //       text2 = '上月'
      //       text3 = '原片合计(片/月)'
      //     } else if (newv === 2) {
      //       text1 = '今日'
      //       text2 = '昨日'
      //       text3 = '原片合计(片/日)'
      //     } else {
      //       text1 = '本年'
      //       text2 = '上年'
      //       text3 = '原片合计(片/年)'
      //     }
      //     this.cols[0].children[1].children[0].label = text1
      //     this.cols[0].children[1].children[1].label = text2
      //     this.cols[0].children[2].children[0].label = text1
      //     this.cols[0].children[2].children[1].label = text2
      //     this.cols[0].children[3].children[0].label = text1
      //     this.cols[0].children[3].children[1].label = text2
      //     this.cols[0].children[4].children[0].label = text1
      //     this.cols[0].children[4].children[1].label = text2
      //     this.cols[0].children[2].label = text3
      //   }
      // }
    },
  methods: {
    handleReturn() {
      this.edit = false
      console.log(this.$parent.getDataList());
    },
    handleChange(e) {
    },
      updateData() {
        // let obj = {}
        // this.data.forEach((ele, index) => {
        //   if (ele.det === false) {
        //     this.data[index].lineId = ''
        //     this.data[index].remark = this.remark
        //     obj = ele
        //     delete this.data[index].dailyOutputTrend
        //     delete this.data[index].originalGlassStatisticsTrend
        //     delete this.data[index].actualProductTrend
        //     delete this.data[index].originalGlassPassTrend
        //     this.data.splice(index, 1)
        //   }
        // })
        // let updateArr = this.data
        // updateArr.forEach((ele, index) => {
        //   delete ele.dailyOutputTrend
        //   delete ele.originalGlassStatisticsTrend
        //   delete ele.actualProductTrend
        //   delete ele.originalGlassPassTrend
        // });
        // this.data.forEach((ele, index) => {
        //   delete ele.dailyOutputTrend
        //   delete ele.originalGlassStatisticsTrend
        //   delete ele.actualProductTrend
        //   delete ele.originalGlassPassTrend
        // });
        updateGlass(updateArr).then(response => {
          updateGlassRemark(obj).then(res => {
            this.$modal.msgSuccess("修改成功");
            this.edit = false;
            this.$emit("refreshDataList");
          });
        });
      }
    }
  };
</script>