<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />
      <!--表单组件-->
      <el-dialog
        :close-on-click-modal="false"
        :before-close="crud.cancelCU"
        :visible.sync="crud.status.cu > 0"
        :title="crud.status.title"
        width="500px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
          <el-form-item label="物料编码" prop="material_code">
            <el-input v-model="form.material_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="物料名称">
            <el-input v-model="form.material_name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="订单编号" prop="order_number">
            <el-input v-model="form.order_number" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="客户名称" prop="customer_name">
            <el-input v-model="form.customer_name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="产品名称" prop="product_name">
            <el-input v-model="form.product_name" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="产品牌号" prop="product_grade">
            <el-input v-model="form.product_grade" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="砖型" prop="brick_type">
            <el-input v-model="form.brick_type" style="width: 370px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--表格渲染-->
      <el-table
        ref="table"
        v-loading="crud.loading"
        :data="crud.data"
        size="mini"
        style="width: 100%;"
        @selection-change="crud.selectionChangeHandler"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column
          prop="material_code"
          label="物料编码"
          :min-width="flexWidth('material_code',crud.data,'物料编码')"
        />
        <el-table-column
          prop="material_name"
          label="物料名称"
          :min-width="flexWidth('material_name',crud.data,'物料名称')"
        />
        <el-table-column
          prop="order_number"
          label="订单编号"
          :min-width="flexWidth('order_number',crud.data,'订单编号')"
        />
        <el-table-column
          prop="customer_name"
          label="客户名称"
          :min-width="flexWidth('customer_name',crud.data,'客户名称')"
        />
        <el-table-column
          prop="product_name"
          label="产品名称"
          :min-width="flexWidth('product_name',crud.data,'产品名称')"
        />
        <el-table-column
          prop="product_grade"
          label="产品牌号"
          :min-width="flexWidth('product_grade',crud.data,'产品牌号')"
        />
        <el-table-column prop="brick_type" label="砖型" :min-width="flexWidth('brick_type',crud.data,'砖型')" />
        <el-table-column prop="create_name" label="创建人" :min-width="flexWidth('create_name',crud.data,'创建人')" />
        <el-table-column prop="update_optname" label="修改人" :min-width="flexWidth('update_optname',crud.data,'创建人')" />
        <el-table-column prop="update_time" label="最后修改时间" :min-width="flexWidth('update_time',crud.data,'创建人')" />
        <el-table-column v-permission="[]" label="操作" width="120px" align="center" fixed="right">
          <template slot-scope="scope">
            <udOperation
              :data="scope.row"
              :permission="permission"
            />
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>

<script>
import crudMaterialDetail from '@/api/wms/basedata/materialDetail'
import CRUD, { crud, form, header, presenter } from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'

const defaultForm = {
  material_id: null,
  material_code: null,
  material_name: null,
  order_number: null,
  customer_name: null,
  product_name: null,
  product_grade: null,
  brick_type: null,
  create_id: null,
  create_name: null,
  create_time: null,
  update_optid: null,
  update_optname: null,
  update_time: null
}
export default {
  name: 'MaterialDetail',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '物料详情',
      url: 'api/materialDetail',
      idField: 'material_id',
      sort: 'material_id,desc',
      crudMethod: { ...crudMaterialDetail }
    })
  },
  data() {
    return {
      permission: {},
      rules: {
        material_code: [
          { required: true, message: '物料编码不能为空', trigger: 'blur' }
        ],
        order_number: [
          { required: true, message: '订单编号不能为空', trigger: 'blur' }
        ],
        customer_name: [
          { required: true, message: '客户名称不能为空', trigger: 'blur' }
        ],
        product_name: [
          { required: true, message: '产品名称不能为空', trigger: 'blur' }
        ],
        product_grade: [
          { required: true, message: '产品牌号不能为空', trigger: 'blur' }
        ],
        brick_type: [
          { required: true, message: '砖型不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
