<template>
  <div v-loading.fullscreen.lock="fullscreenLoading" class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-form
          :inline="true"
          class="demo-form-inline"
          label-position="right"
          label-width="90px"
          label-suffix=":"
        >
<!--          <el-form-item label="所属车间">-->
<!--            <el-select-->
<!--              v-model="query.workshop_code"-->
<!--              clearable-->
<!--              size="mini"-->
<!--              placeholder="所属车间"-->
<!--              class="filter-item"-->
<!--            >-->
<!--              <el-option-->
<!--                v-for="item in workShopList"-->
<!--                :label="item.workshop_name"-->
<!--                :value="item.workshop_code"-->
<!--              />-->
<!--            </el-select>-->
<!--          </el-form-item>-->
          <el-form-item label="模糊搜索">
            <el-input
              v-model="query.blurry"
              clearable
              size="mini"
              placeholder="编码名称"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="物料规格">
            <el-input
              v-model="query.material_spec"
              clearable
              size="mini"
              placeholder="物料规格"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <rrOperation />
        </el-form>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， 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="820px">
        <el-form
          ref="form"
          :inline="true"
          style="border: 1px solid #cfe0df;margin-top: 10px;padding-top: 10px;"
          :model="form"
          :rules="rules"
          size="mini"
          label-width="125px"
          label-suffix=":">
          <el-form-item label="原料编码" prop="raw_material_code">
            <el-input v-model="form.raw_material_code" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="物料名称 " prop="material_name">
            <el-input v-model="form.material_name" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="物料规格" prop="material_spec">
            <el-input v-model="form.material_spec" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="物料型号" prop="material_model">
            <el-input v-model="form.material_model" style="width: 240px;" />
          </el-form-item>
          <el-form-item label="A长边">
            <el-input-number
              v-model.number="form.a_long_side"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="B短边">
            <el-input-number
              v-model.number="form.b_short_side"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="H高度">
            <el-input-number
              v-model.number="form.h_height"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="W厚度">
            <el-input-number
              v-model.number="form.w_thickness"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="单重">
            <el-input-number
              v-model.number="form.single_weight"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="木托盘规格">
            <el-tooltip class="item" effect="dark" content="例如：950*1000" placement="top">
              <el-select
                v-model="form.pack_palletspec"
                clearable
                size="mini"
                placeholder="请选择"
                style="width: 240px;"
              >
                <el-option
                  v-for="item in dict.vehicle_type"
                  :label="item.label"
                  :value="item.label"
                  :disabled="item.value === 'LZ' || item.value === 'GTP'"
                />
              </el-select>
            </el-tooltip>
          </el-form-item>
          <el-form-item label="静置时间(分钟)">
            <el-input-number
              v-model.number="form.standing_time"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="冷却时间(分钟)">
            <el-input-number
              v-model.number="form.cooling_time"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="静置时间(下限)">
            <el-input-number
              v-model.number="form.standing_time_lower"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="静置时间(上限)">
            <el-input-number
              v-model.number="form.standing_time_upper"
              :min="0"
              style="width: 240px;"
            />
          </el-form-item>
          <el-form-item label="包装方式">
            <el-tooltip class="item" effect="dark" content="例如：3*6*6" placement="top">
              <el-input v-model="form.pack_method" style="width: 240px;" />
            </el-tooltip>
          </el-form-item>
          <el-form-item label="是否特殊" prop="is_needmove">
            <el-radio-group v-model="form.is_special" style="width: 240px">
              <el-radio :label="true">是</el-radio>
              <el-radio :label="false">否</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" type="textarea" style="width: 240px;" />
          </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%;" @selection-change="crud.selectionChangeHandler">
        <el-table-column type="selection" width="55" />
        <el-table-column prop="raw_material_code" label="泥料编码" :min-width="flexWidth('raw_material_code',crud.data,'物料编码')" />
        <el-table-column prop="half_material_code" label="半成品编码" :min-width="flexWidth('half_material_code',crud.data,'半成品编码')" />
        <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="material_spec" label="物料规格" :min-width="flexWidth('material_spec',crud.data,'物料规格')" />
        <el-table-column prop="material_model" label="物料型号" :min-width="flexWidth('material_model',crud.data,'物料分类标识')" />
        <el-table-column prop="standing_time" label="静置时间(分钟)" :min-width="flexWidth('standing_time',crud.data,'静置时间(分钟)')" />
        <el-table-column prop="cooling_time" label="冷却时间(分钟)" :min-width="flexWidth('cooling_time',crud.data,'静置时间(分钟)')" />
<!--        <el-table-column prop="workshop_code" label="车间编码" :min-width="flexWidth('workshop_code',crud.data,'车间编码')" />-->
        <el-table-column prop="remark" label="备注" :min-width="flexWidth('remark',crud.data,'备注')" />
        <el-table-column prop="is_used" label="是否启用" :min-width="flexWidth('is_used',crud.data,'是否启用')">
          <template slot-scope="scope">
            {{ scope.row.is_used?'是':'否' }}
          </template>
        </el-table-column>
        <el-table-column prop="is_delete" label="是否删除" :min-width="flexWidth('is_delete',crud.data,'是否删除')">
          <template slot-scope="scope">
            {{ scope.row.is_delete?'是':'否' }}
          </template>
        </el-table-column>
        <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_name" label="修改人" :min-width="flexWidth('update_name',crud.data,'修改人')" />
        <el-table-column prop="update_time" label="修改时间" :min-width="flexWidth('update_time',crud.data,'修改时间')" />
<!--        <el-table-column prop="ext_time" label="MES时间" :min-width="flexWidth('ext_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 crudMdBaseMaterial from './mdBaseMaterial'
import crudMdBaseWorkShop from '@/views/wms/basedata/workshop/mdBaseWorkshop'
import Treeselect, { LOAD_CHILDREN_OPTIONS } from '@riophae/vue-treeselect'
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,
  half_material_code: null,
  raw_material_code: null,
  material_name: null,
  material_spec: null,
  material_model: null,
  a_long_side: null,
  b_short_side: null,
  h_height: null,
  w_thickness: null,
  class_id: null,
  standing_time: 0,
  cooling_time: 0,
  single_weight: 0,
  standing_time_lower: 0,
  standing_time_upper: 0,
  workshop_code: null,
  pack_palletspec: null,
  pack_method: null,
  remark: null,
  is_used: true,
  is_special: false,
  is_delete: false
}
export default {
  name: 'MdBaseMaterial',
  dicts: ['vehicle_type'],
  components: { pagination, crudOperation, rrOperation, udOperation, Treeselect },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '物料基础信息',
      url: 'api/mdBaseMaterial',
      idField: 'material_id',
      sort: 'material_id,desc',
      crudMethod: { ...crudMdBaseMaterial }
    })
  },
  data() {
    return {
      classes1: [],
      permission: {
      },
      rules: {
        raw_material_code: [
          { required: true, message: '原料不能为空', trigger: 'blur' }
        ],
        material_name: [
          { required: true, message: '物料名称不能为空', trigger: 'blur' }
        ],
        material_spec: [
          { required: true, message: '物料规格不能为空', trigger: 'blur' }
        ],
        material_model: [
          { required: true, message: '砖型不能为空', trigger: 'blur' }
        ]
      },
      fullscreenLoading: false,
      workShopList: []
    }
  },
  created() {
    this.getWorkShopList()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    synchronize() {
      this.fullscreenLoading = true
      crudMdBaseMaterial.synchronize(this.crud.query).then(res => {
        this.fullscreenLoading = false
        this.crud.notify('同步成功！', CRUD.NOTIFICATION_TYPE.SUCCESS)
      }).catch(() => {
        this.fullscreenLoading = false
      })
    },
    getWorkShopList() { // 获取车间列表
      crudMdBaseWorkShop.getWorkShopList().then(res => {
        this.workShopList = res
      })
    },
    // 获取子节点数据
    loadChildNodes({ action, parentNode, callback }) {
      // if (action === LOAD_CHILDREN_OPTIONS) {
      //   crudClassstandard.getClass({ pid: parentNode.id }).then(res => {
      //     parentNode.children = res.content.map(function(obj) {
      //       if (obj.hasChildren) {
      //         obj.children = null
      //       }
      //       return obj
      //     })
      //     setTimeout(() => {
      //       callback()
      //     }, 100)
      //   })
      // }
    }
  }
}
</script>

<style scoped>

</style>
