<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="600px"
      >
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="160px" label-suffix="：">
          <el-form-item label="物料编码" prop="material_code">
            <el-input v-model="form.material_code" :disabled="crud.status.edit" placeholder="物料编码" style="width: 300px;" />
          </el-form-item>
          <el-form-item label="物料名称" prop="material_name">
            <el-input v-model="form.material_name" placeholder="物料名称" style="width: 300px;" />
          </el-form-item>
          <el-form-item label="炉型" prop="furnace">
            <el-select
              v-model="form.furnace"
              placeholder="炉型"
              style="width: 300px"
              clearable
              filterable
            >
              <el-option
                v-for="item in dict.furnace"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="物料砖类型" prop="material_brick_type">
            <el-select
              v-model="form.material_brick_type"
              placeholder="物料砖类型"
              style="width: 300px"
              clearable
              filterable
            >
              <el-option
                v-for="item in dict.material_brick_type"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="BOM编码" prop="bom_code">
            <el-input v-model="form.bom_code" placeholder="BOM编码" style="width: 300px;" />
          </el-form-item>
          <el-form-item label="订单编码" prop="order_code">
            <el-input v-model="form.order_code" placeholder="订单编码" style="width: 300px;" />
          </el-form-item>
          <el-form-item label="客户编码" prop="customer_code">
            <el-input v-model="form.customer_code" placeholder="客户编码" style="width: 300px;" />
          </el-form-item>
          <el-form-item label="牌号" prop="product_grade">
            <el-select
              v-model="form.product_grade"
              placeholder="物料砖类型"
              style="width: 300px"
              clearable
              filterable
            >
              <el-option
                v-for="item in dict.product_grade"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="砖型" prop="brick_type">
            <el-input v-model="form.brick_type" placeholder="砖型" style="width: 300px;" />
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="info" @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%;"
      >
        <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="furnace_name"
          label="炉型"
          :min-width="flexWidth('furnace_name',crud.data,'炉型')"
        />
        <el-table-column
          prop="material_brick_type_name"
          label="物料砖类型"
          :min-width="flexWidth('material_brick_type_name',crud.data,'物料砖类型')"
        />
        <el-table-column
          prop="bom_code"
          label="BOM编码"
          :min-width="flexWidth('bom_code',crud.data,'BOM编码')"
        />
        <el-table-column
          prop="order_code"
          label="订单编码"
          :min-width="flexWidth('order_code',crud.data,'订单编码')"
        />
        <el-table-column
          prop="customer_code"
          label="客户编码"
          :min-width="flexWidth('customer_code',crud.data,'客户编码')"
        />
        <el-table-column
          prop="product_grade_name"
          label="牌号"
          :min-width="flexWidth('product_grade_name',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="create_time" label="创建时间" :min-width="flexWidth('create_time',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
              :is-visiable-del="false"
              :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 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,
  furnace: null,
  material_brick_type: null,
  bom_code: null,
  order_code: null,
  customer_code: 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,
  is_delete: '0'
}
export default {
  name: 'MaterialDetail',
  dicts: ['furnace', 'material_brick_type', 'product_grade'],
  components: { pagination, crudOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '物料详情',
      url: 'api/materialDetail',
      idField: 'material_id',
      sort: 'material_id,desc',
      crudMethod: { ...crudMaterialDetail },
      optShow: {
        add: false,
        edit: false,
        del: false,
        download: false,
        reset: true
      }
    })
  },
  data() {
    return {
      permission: {},
      rules: {
        material_code: [
          { required: true, message: '物料编码不能为空', trigger: 'blur' }
        ],
        furnace: [
          { required: true, message: '炉型不能为空', trigger: 'blur' }
        ],
        material_brick_type: [
          { required: true, message: '物料砖类型不能为空', trigger: 'blur' }
        ],
        bom_code: [
          { required: true, message: 'BOM编码不能为空', trigger: 'blur' }
        ],
        order_code: [
          { required: true, message: '订单编码不能为空', trigger: 'blur' }
        ],
        customer_code: [
          { 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>
