<template>
  <el-card class="mb20">
    <div slot="header">
      <span class="card-title">
        材料汇总表
      </span>
    </div>
    <!-- 操作 -->
    <el-row :gutter="10" class="mb10">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          :disabled="updateDisable"
          @click="handleUpdate"
        >新增</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-check"
          size="mini"
          @click="handleSave"
        >保存</el-button>
      </el-col> -->
    </el-row>

    <!-- 列表 -->
    <el-table
      ref="multipleTable"
      v-loading="loading"
      :data="list"
      border
      max-height="400px"
      :row-key="getOnlyRowKey"
      @selection-change="tableSelected"
    >
      <el-table-column
        type="selection"
        width="39"
        fixed="left"
        :reserve-selection="true"
        align="center"
      />
      <el-table-column
        label="生产订单"
        align="center"
        fixed="left"
        prop="workOrderNo"
        width="100"
        show-overflow-tooltip
      >
        <template slot-scope="scope">
          <el-button type="text" @click="handleToProduct(scope.row)">
            <span>{{ scope.row.workOrderNo }}</span>
          </el-button>
        </template>
      </el-table-column>
      <el-table-column
        label="宽度(mm)"
        align="center"
        prop="width"
        width="60"
        show-overflow-tooltip
      />
      <el-table-column
        label="步长(mm)"
        align="center"
        prop="stepLength"
        width="60"
        show-overflow-tooltip
      />
      <el-table-column
        label="调机米数"
        align="center"
        prop="testScrapLength"
        width="80"
      />
      <el-table-column
        label="需求分切量"
        align="center"
        prop="needArea"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column label="已分切量" align="center" prop="slitArea" />
      <el-table-column
        label="损耗"
        align="center"
        prop="pcsScrap"
        width="80"
      />
      <el-table-column
        label="总长度"
        align="center"
        prop="sumLength"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="标准卷数"
        align="center"
        prop="volumeNumber"
        width="100"
        show-overflow-tooltip
      />
      <el-table-column
        label="穴数"
        align="center"
        prop="hillQty"
        width="80"
      />
      <el-table-column label="订单数" align="center" prop="productAmount" />
      <el-table-column
        label="物料编码"
        align="center"
        prop="materialNo"
        width="150"
        show-overflow-tooltip
      />
      <el-table-column
        label="物料名称"
        align="center"
        prop="materialName"
        width="130"
        show-overflow-tooltip
      />
      <el-table-column
        label="物料规格"
        align="center"
        prop="materialModels"
        show-overflow-tooltip
      />
      <el-table-column
        label="用料清单"
        align="center"
        prop="workOrderBomNo"
        show-overflow-tooltip
      />
      <el-table-column
        label="单位"
        align="center"
        prop="unitCode"
        width="60"
      />
      <el-table-column
        label="计划开工日期"
        align="center"
        prop="planStartTime"
        width="100"
      />
      <el-table-column
        label="计划完工日期"
        align="center"
        prop="planCompleteTime"
        width="100"
      />
      <el-table-column
        label="创建人"
        align="center"
        prop="creator"
        width="80"
      />
      <el-table-column
        label="创建时间"
        align="center"
        prop="createTime"
        width="100"
      />
      <el-table-column
        label="操作"
        align="center"
        width="80"
        fixed="right"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['wms:slitting-order-detail:delete']"
            type="text"
            class="text-danger"
            icon="el-icon-delete"
            size="mini"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNo"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 物料选择 -->
    <MultipleSelect ref="multipleSelect" @MultipleComplete="getList" />
  </el-card>
</template>

<script>
import { getSupportPage, deleteOrderDetail } from '@/api/wms/inLibrary/slittingOrder'
import MultipleSelect from './MultipleSelect.vue'

export default {
  name: 'SlittingOrder',
  components: {
    MultipleSelect
  },
  inject: ['paramsQuery'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 分切任务单列表
      list: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      drawer: false,
      updateDisable: false,

      direction: 'rtl',
      currentRows: [],
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        eBillNo: null,
        alitStatus: null,
        createTime: []
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      }
    }
  },
  created() {
    this.queryParams.eBillNo = this.$route.query.ebillNo
    this.getList()
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true
      // 执行查询
      getSupportPage(this.queryParams).then(response => {
        this.list = response.data.list
        this.total = response.data.total
        this.$emit('getSupportList', response.data)
      }).finally(() => {
        this.loading = false
      })
    },
    /** 取消按钮 */
    cancel() {
      this.open = false
      this.reset()
    },
    /** 表单重置 */
    reset() {
      this.form = {
        id: undefined,
        eBillNo: undefined,
        alitStatus: undefined
      }
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    handleClose(done) {
      done()
    },
    // 表格选中
    tableSelected(val) {
      this.currentRows = val
      this.$emit('materialList', val)
    },
    // 修改
    handleUpdate() {
      const { materialNo, ebillNo } = this.list[0]
      this.$refs.multipleSelect.queryParams.materialNo = materialNo
      this.$refs.multipleSelect.queryParams.eBillNo = ebillNo
      this.$refs.multipleSelect.selectDisabled = true
      this.$refs.multipleSelect.orderDisabled = false
      this.$refs.multipleSelect.open = true
    },
    getOnlyRowKey(row) {
      return row.id
    },
    handleToProduct(row) {
      const { workOrderNo } = row
      this.$router.push({ path: '/entry-exit/product-out-in/work-order-bom', query: { workOrderNo }})
    },
    // 删除
    handleDelete(row) {
      const { id, width } = row
      this.$modal.confirm('是否确认删除物料宽度为"' + width + '"的数据项?').then(function() {
        return deleteOrderDetail(id)
      }).then(() => {
        this.$modal.msgSuccess('删除成功')
        this.getList()
      }).catch(() => {})
    }
  }
}
</script>

<style scoped>
.card-title {
  font-size: 14px;
}
</style>
