<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="80px"
          label-suffix=":"
        >
          <el-form-item label="保养项目">
            <el-input
              v-model="query.maint_item_code"
              clearable
              size="mini"
              placeholder="请输入编码或者名称"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="保养内容">
            <el-input
              v-model="query.contents"
              clearable
              size="mini"
              placeholder="请输入内容"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="保养要求">
            <el-input
              v-model="query.requirement"
              clearable
              size="mini"
              placeholder="请输入要求"
              @keyup.enter.native="crud.toQuery"
            />
          </el-form-item>
          <el-form-item label="保养等级">
            <el-select v-model="query.item_level" clearable placeholder="请选择" @change="changeQuery">
              <el-option
                v-for="item in itemLevelList"
                :label="item.label"
                :value="item.value"
              >
              </el-option>
            </el-select>
          </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="850px">
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="120px">
          <el-row>
            <el-col span="12">
              <el-form-item label="保养项目编码:" prop="maint_item_code">
                <el-input v-model="form.maint_item_code" style="width: 230px;" />
              </el-form-item>
            </el-col>
            <el-col span="12">
              <el-form-item label="保养项目名称:" prop="maint_item_name">
                <el-input v-model="form.maint_item_name" style="width: 230px;" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col span="12">
              <el-form-item label="保养等级:" prop="item_level">
                <el-select v-model="form.item_level" clearable placeholder="请选择" style="width: 230px">
                  <el-option
                    v-for="item in itemLevelList"
                    :label="item.label"
                    :value="item.value"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col span="12">
              <el-form-item label="备注:">
                <el-input v-model="form.remark" style="width: 230px;" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col span="24">
              <el-form-item label="保养内容:" prop="contents">
                <el-input v-model="form.contents" style="width: 600px;" rows="2" type="textarea" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col span="24">
              <el-form-item label="保养要求:" prop="requirement">
                <el-input v-model="form.requirement" style="width: 600px;" rows="2" type="textarea" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-row>
            <el-col span="24">
              <el-form-item label="验收标准:" prop="acceptancecriteria">
                <el-input v-model="form.acceptancecriteria" style="width: 600px;" rows="2" type="textarea" />
              </el-form-item>
            </el-col>
          </el-row>
        </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 v-if="false" prop="maint_item_id" label="设备保养项目标识" />
        <el-table-column prop="maint_item_code" label="保养项目编码" />
        <el-table-column prop="maint_item_name" label="保养项目名称" />
        <el-table-column prop="item_level" label="保养等级" :formatter="formatLevel"/>
        <el-table-column prop="contents" label="保养内容" show-overflow-tooltip />
        <el-table-column prop="requirement" label="保养要求" show-overflow-tooltip />
        <el-table-column prop="acceptancecriteria" label="验收标准" show-overflow-tooltip />
        <el-table-column prop="remark" label="备注" />
        <el-table-column prop="create_name" label="创建人姓名" />
        <el-table-column prop="create_time" label="创建时间" width="150px"/>
        <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 crudDevicemaintenanceitems from '@/api/wms/basedata/em/devicemaintenanceitems'
import CRUD, { presenter, header, form, crud } 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 = { maint_item_id: null, maint_item_code: null, maint_item_name: null, item_level: null, contents: null, requirement: null, acceptancecriteria: null, create_id: null, create_name: null, create_time: null, update_optid: null, update_optname: null, update_time: null, is_delete: null, remark: null }
export default {
  name: 'Devicemaintenanceitems',
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({
      title: '设备保养项目维护',
      url: 'api/devicemaintenanceitems',
      idField: 'maint_item_id',
      sort: 'maint_item_id,desc',
      crudMethod: { ...crudDevicemaintenanceitems },
      optShow: {
        add: true,
        edit: false,
        del: false,
        download: false,
        reset: true
      }})
  },
  data() {
    return {
      itemLevelList: [
        { 'label': '日常', 'value': '01' },
        { 'label': '一级', 'value': '02' },
        { 'label': '二级', 'value': '03' }
      ],
      permission: {
      },
      rules: {
        maint_item_code: [
          { required: true, message: '保养项目编码不能为空', trigger: 'blur' }
        ],
        maint_item_name: [
          { required: true, message: '保养项目名称不能为空', trigger: 'blur' }
        ],
        item_level: [
          { required: true, message: '保养等级不能为空', trigger: 'blur' }
        ],
        contents: [
          { required: true, message: '保养内容不能为空', trigger: 'blur' }
        ],
        requirement: [
          { required: true, message: '保养要求不能为空', trigger: 'blur' }
        ],
        acceptancecriteria: [
          { required: true, message: '验收标准不能为空', trigger: 'blur' }
        ]
      }}
  },
  methods: {
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    changeQuery() {
      this.crud.toQuery()
    },
    formatLevel(row, cloum) {
      if (row.item_level === '01') {
        return '日常'
      } else if (row.item_level === '02') {
        return '一级'
      } else if (row.item_level === '03') {
        return '二级'
      }
    }
  }
}
</script>

<style scoped>

</style>
