<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">模糊搜索</label>
        <el-input v-model="query.blurry" clearable placeholder="项点名称" style="width: 185px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
        <rrOperation :crud="crud" />
      </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="475px">
        <el-form ref="form" :model="form" :rules="rules" size="mini" label-width="120px">
          <el-form-item label="项点名称" prop="name">
            <el-input v-model="form.name" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="标准值">
            <el-input v-model="form.standard" style="width: 250px;" />
          </el-form-item>
          <el-form-item label="项点类型" prop="inspectionType">
            <el-select
              v-model="form.inspectionType"
              placeholder=""
              style="width: 250px"
            >
              <el-option
                v-for="item in dict.INSPECTION_POINT_TYPE"
                :key="item.id"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>

          <el-form-item label="备注">
            <el-input v-model="form.remark" :rows="3" type="textarea" style="width: 250px;" />
          </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="inspectionCode" label="项点编码" />
        <el-table-column prop="name" label="项点名称" />
        <el-table-column prop="standard" label="标准值">
          <template slot-scope="scope">
            {{ is_or_no(scope.row.standard, scope.row.inspectionType) }}
          </template>
        </el-table-column>
        <el-table-column prop="inspectionType" label="项点类型">
          <template slot-scope="scope">
            {{ dict.label.INSPECTION_POINT_TYPE[scope.row.inspectionType] }}
          </template>
        </el-table-column>
        <el-table-column prop="remark" label="备注" />
        <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 crudInspection from '@/views/wms/ql/inspection/inspectionpoint'
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 = { inspectionType: '1', inspectionId: null, inspectionCode: null, name: null, standard: null, remark: null }
export default {
  name: 'InspectionPoint',
  dicts: ['INSPECTION_POINT_TYPE'],
  components: { pagination, crudOperation, rrOperation, udOperation },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '质检项点', url: 'api/mdQlInspectionpoint', idField: 'inspectionId', sort: 'id,desc',
      optShow: {
        add: true,
        edit: true,
        del: true,
        reset: true,
        download: false
      },
      crudMethod: { ...crudInspection }})
  },
  data() {
    return {
      permission: {
      },
      rules: {
        inspectionCode: [
          { required: true, message: '项点编码不能为空', trigger: 'blur' }
        ],
        name: [
          { required: true, message: '项点名称不能为空', trigger: 'blur' }
        ],
        inspectionType: [
          { required: true, message: '项点类型不能为空', trigger: 'blur' }
        ]
      },
      queryTypeOptions: [
        { key: 'inspection_code', display_name: '项点编码' }
      ]
    }
  },
  methods: {
    is_or_no(val, type) {
      if (type === '01' && val === '1') {
        return '是'
      } else if (type === '01' && val === '0') {
        return '否'
      } else {
        return val
      }
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return true
    }
  }
}
</script>

<style scoped>

</style>
