<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <el-input
          v-model="query.name"
          clearable
          size="small"
          placeholder="输入KML名称"
          style="width: 160px"
          class="filter-item"
          @keyup.enter.native="crud.toQuery"
        />
        <rrOperation />
      </div>
      <crudOperation :permission="permission"></crudOperation>
    </div>
    <!--表单组件-->
    <el-dialog
      append-to-body
      :close-on-click-modal="false"
      :before-close="crud.cancelCU"
      :visible="crud.status.cu > 0"
      :title="crud.status.title"
      width="500px"
    >
      <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
        <el-form-item label="名称" prop="name">
          <el-input v-model="form.name" style="width: 370px" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" style="width: 370px" />
        </el-form-item>
        <el-form-item label="KML文件" prop="path">
          <upload-attachment
            v-model="form.path"
            accept=".kml"
            :loading.sync="attUploading"
            :maxSize="100 * 1024 * 1024"
            :limit="1"
          />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="text" @click="crud.cancelCU">取消</el-button>
        <el-button
          :loading="crud.status.cu === 2 || attUploading"
          type="primary"
          @click="crud.submitCU"
          >确认</el-button
        >
      </div>
    </el-dialog>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      style="width: 100%"
      @selection-change="crud.selectionChangeHandler"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column
        v-for="item in kmlTableOptions"
        :key="item.prop"
        :label="item.label"
        :prop="item.prop"
        :width="item.width"
        :align="item.align"
        :fixed="item.fixed"
        :sortable="item.sortable"
      >
        <template slot-scope="scope">
          <download-attachment
            v-if="item.prop === 'path'"
            :attachments="scope.row.path"
          />
          <span v-else>{{ scope.row[item.prop] }}</span>
        </template>
      </el-table-column>
      <!--   编辑与删除   -->
      <el-table-column
        v-if="checkPer(['admin', 'route:kml:edit', 'route:kml:del'])"
        label="操作"
        width="130px"
        align="center"
        fixed="right"
      >
        <template slot-scope="scope">
          <udOperation :data="scope.row" :permission="permission" />
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
  </div>
</template>
  
  <script>
import permission from '@/directive/permission'
import crudKML from '@/api/route/kml'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
import UploadAttachment from '@/components/UploadAttachment'
import DownloadAttachment from '@/components/DownloadAttachment'

import crudComps from '@crud'
import { kmlTableOptions } from '../tableConfig'

const defaultForm = {
  id: '',
  name: '',
  remark: '',
  path: [],
}

export default {
  name: 'RouteKml',
  directives: { permission },
  mixins: [presenter(), header(), form(defaultForm), crud()],
  components: { ...crudComps, UploadAttachment, DownloadAttachment },
  cruds() {
    return CRUD({
      title: '路径KML文件',
      url: 'route/kml/getList',
      listOrder: [],
      crudMethod: { ...crudKML },
    })
  },
  computed: {
    crudCU() {
      return this.crud.status.cu > 0
    },
    VUE_APP_BASE_API() {
      return process.env.VUE_APP_BASE_API
    },
  },
  data() {
    return {
      kmlTableOptions,
      viewLoading: false,
      permission: {
        add: ['admin', 'route:kml:add'],
        edit: ['admin', 'route:kml:edit'],
        del: ['admin', 'route:kml:del'],
      },
      rules: {
        name: [{ required: true, message: '请输入KML名称', trigger: 'blur' }],
        path: [{ required: true, message: '请上传KML文件', trigger: 'blur' }],
      },
      attUploading: false,
    }
  },
  created() {},
  methods: {},
}
</script>
<style lang="scss" scoped>
</style>