<template>
  <el-dialog
    title="物料新增"
    append-to-body
    :visible.sync="dialogVisible"
    destroy-on-close
    width="1000px"
    @close="close"
    @open="open"
  >
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <date-range-picker v-model="query.createTime" class="date-item" value-format="yyyy-MM-dd" />
        <el-input
          v-model="query.bill_code"
          clearable
          size="mini"
          placeholder="单据号"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.package_box_sn"
          clearable
          size="mini"
          placeholder="箱号"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.container_name"
          clearable
          size="mini"
          placeholder="子卷号"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <el-input
          v-model="query.material_search"
          clearable
          size="mini"
          placeholder="物料编码"
          style="width: 200px;"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation />
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation />
      <!--表格渲染-->
      <el-table
        ref="multipleTable"
        v-loading="crud.loading"
        :data="crud.data"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column show-overflow-tooltip width="200" prop="sale_order_name" label="订单号" />
        <el-table-column show-overflow-tooltip width="150" prop="customer_name" label="客户编号" />
        <el-table-column prop="customer_name" label="客户名称" />
        <el-table-column show-overflow-tooltip prop="package_box_sn" width="250" label="箱号" />
        <el-table-column show-overflow-tooltip width="100" prop="quanlity_in_box" label="箱内子卷数" />
        <el-table-column show-overflow-tooltip width="150" prop="container_name" label="子卷号" />
        <el-table-column show-overflow-tooltip width="150" prop="product_name" label="物料编码" />
        <el-table-column show-overflow-tooltip width="150" prop="product_description" label="物料描述" />
        <el-table-column show-overflow-tooltip prop="width" label="幅宽" />
        <el-table-column show-overflow-tooltip prop="thickness" label="产品厚度" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>

    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>

import CRUD, { crud, header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import DateRangePicker from '@/components/DateRangePicker/index'

const start = new Date()
export default {
  name: 'AddDtl',
  components: { crudOperation, rrOperation, pagination, DateRangePicker },
  cruds() {
    return CRUD({
      title: '用户',
      url: '/api/in/rawAssist/getBillDtl',
      crudMethod: {},
      optShow: {
        reset: true
      },
      query: {
        createTime: [start.daysAgo(7), new Date()]
      }
    })
  },
  mixins: [presenter(), header(), crud()],
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    },
    opendtlParam: {
      type: Object
    }
  },
  data() {
    return {
      dialogVisible: false,
      rows: [],
      tableData: []
    }
  },
  watch: {
    dialogShow: {
      handler(newValue, oldValue) {
        this.dialogVisible = newValue
      }
    }
  },
  methods: {
    [CRUD.HOOK.beforeRefresh]() {
      this.crud.query.bill_type = '000101'
      return true
    },
    objectSpanMethod({ row, column, rowIndex, columnIndex }) {
      if (columnIndex === 0) {
        if (rowIndex % 2 === 0) {
          return {
            rowspan: 2,
            colspan: 1
          }
        } else {
          return {
            rowspan: 0,
            colspan: 0
          }
        }
      }
    },
    open() {
      this.crud.toQuery()
    },
    close() {
      this.$emit('update:dialogShow', false)
    },
    submit() {
      debugger
      this.$emit('update:dialogShow', false)
      this.rows = this.$refs.multipleTable.selection
      // this.form = this.$options.data().form
      this.$emit('tableChanged', this.rows)
    }
  }
}
</script>

