<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <el-select v-model="query.type" clearable placeholder="请选择统计方式" class="filter-item" style="width: 185px" @keyup.enter.native="crud.toQuery">
          <el-option v-for="item in options" :key="item.name" :label="item.name" :value="item.id" />
        </el-select>
        <date-range-picker v-model="pjTime" class="date-item" />
        <!-- <rrOperation :crud="crud" /> -->
        <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="getData">搜索</el-button>
        <el-button class="filter-item" size="mini" type="warning" icon="el-icon-refresh-left" @click="resetDate">重置</el-button>
        <!-- <el-button class="filter-item" size="mini" type="warning" icon="el-icon-download" @click="doExport">导出</el-button> -->
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission" />

      <el-table ref="table" v-loading="crud.loading" :data="crud.data" size="small" style="width: 100%;" @row-dblclick="showInfo" @selection-change="crud.selectionChangeHandler">
        <el-table-column width="55" />
        <el-table-column prop="wdPoint" label="味道" />
        <el-table-column prop="pzPoint" label="品种" />
        <el-table-column prop="flPoint" label="分量" />
        <el-table-column prop="fwtdPoint" label="服务态度" />
        <el-table-column prop="hjwsPoint" label="环境卫生" />
        <el-table-column prop="zhfwPoint" label="综合服务" />
        <el-table-column prop="cxgjPoint" label="持续改进" />
        <el-table-column prop="totalPoint" label="综合评分" />
        <el-table-column prop="pjTime" label="统计时段">
          <template slot-scope="{ row }">
            <div v-if="query.type === 'month'">{{ row.pjTime ? row.pjTime.slice(0, 7) : '' }}</div>
            <div v-if="query.type === 'year'">{{ row.pjTime ? row.pjTime.slice(0, 4) : '' }}</div>
          </template>
        </el-table-column>
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
  </div>
</template>
<script>
import crudDmEvaluate from '@/api/dm/evaluate/dmEvaluate'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import DateRangePicker from '@/components/DateRangePicker'
import pagination from '@crud/Pagination'

const defaultForm = { type: 'month' }
export default ({
  name: 'DmEvaluate',
  components: { pagination, crudOperation, DateRangePicker }, //, rrOperation
  mixins: [presenter(), header(), crud(), form(defaultForm)],
  cruds() {
    return CRUD({ title: '整体评价报表', url: '/api/dmEvaluate', tempBtnShow: { user: false }, selectOne: true,
      crudMethod: { ...crudDmEvaluate }, optShow: { del: false, edit: false, add: false, download: true, reset: true }})
  },
  data() {
    return {
      type: 'month',
      pjTime: [],
      permission: {
        add: ['admin', 'dmEvaluate:add'],
        edit: ['admin', 'dmEvaluate:edit'],
        del: ['admin', 'dmEvaluate:del']
      },
      queryTypeOptions: [
        { key: 'wdPoint', display_name: '味道' },
        { key: 'pzPoint', display_name: '品种' },
        { key: 'flPoint', display_name: '分量' },
        { key: 'fwtdPoint', display_name: '服务态度' },
        { key: 'hjwsPoint', display_name: '环境卫生' },
        { key: 'zhfwPoint', display_name: '综合服务' },
        { key: 'cxgjPoint', display_name: '持续改进' },
        { key: 'totalPoint', display_name: '综合评分' },
        { key: 'pjTime', display_name: '统计时段' }
      ],
      options: [
        {
          id: 'month',
          name: '按月统计'
        },
        {
          id: 'year',
          name: '按年统计'
        }
      ]
    }
  },
  created() {
    // this.crud.query.type = 'month'
    this.$set(this.crud.query, 'type', 'month')
    this.getData()
  },
  methods: {
    // changeDate() {
    //   this.crud.query.stateDate = this.pjTime[0] || ''
    //   this.crud.query.endDate = this.pjTime[1] || ''
    //   this.getData()
    // },
    resetDate() {
      this.pjTime = []
      this.crud.query.type = 'month'
      this.getData()
    },
    getData() {
      this.crud.query.stateDate = this.pjTime[0] || ''
      this.crud.query.endDate = this.pjTime[1] || ''
      crudDmEvaluate.dmEvaluate({
        ... this.crud.form,
        ... this.crud.query
      }).then(res => {
        this.crud.page.total = res.totalElements
        this.crud.data = res.content
      })
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return false
    }
  }
})
</script>
