<template>
  <div 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>
          <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="500px">
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="80px">
          <el-form-item label="物料编码">
            <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="物料规格">
            <el-input v-model="form.material_spec" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="物料分类标识">
            <el-input v-model="form.class_id" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="静置时间(分钟)">
            <el-input v-model="form.standing_time" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="车间编码">
            <el-input v-model="form.workshop_code" style="width: 370px;" />
          </el-form-item>
          <el-form-item label="备注">
            <el-input v-model="form.remark" 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="material_spec" label="物料规格" :min-width="flexWidth('material_spec',crud.data,'物料规格')" />
        <el-table-column prop="class_id" label="物料分类标识" :min-width="flexWidth('class_id',crud.data,'物料分类标识')" />
        <el-table-column prop="standing_time" label="静置时间(分钟)" :min-width="flexWidth('standing_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 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,
  material_name: null,
  material_spec: null,
  class_id: null,
  standing_time: null,
  workshop_code: null,
  remark: null,
  is_used: true,
  is_delete: false
}
export default {
  name: 'MdBaseMaterial',
  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: {
      },
      workShopList: []
    }
  },
  created() {
    this.getWorkShopList()
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    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>
