<template>
  <el-dialog
          :visible.sync="visible"
          :close-on-click-modal="false"
          :close-on-press-escape="false"
          width="80%"
  >
    <el-card shadow="never" class="aui-card--fill">
      <div class="mod-news__resourcestotalrelation}">
        <el-form :inline="true" :model="dataForm" @keyup.enter.native="selectData()">
            <div>
                <el-form-item label="统计名称" prop="totalName">
                    <el-input v-model="dataForm.totalName" placeholder="统计名称" clearable></el-input>
                </el-form-item>
                <el-form-item label="统计类型" prop="totalType">
                    <el-input v-model="dataForm.totalType" placeholder="统计类型" clearable></el-input>
                </el-form-item>
            </div>
            <div>
                <el-form-item label="统计方式" prop="totalStyle">
                    <el-select v-model="dataForm.totalStyle" placeholder="统计方式" clearable>
                        <el-option label="其他" :value="0"></el-option>
                        <el-option label="统计次数" :value="1"></el-option>
                        <el-option label="统计人数" :value="2"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="自动计算" prop="autoFlag">
                    <el-select v-model="dataForm.autoFlag" placeholder="自动计算" clearable>
                        <el-option label="否" :value="0"></el-option>
                        <el-option label="是" :value="1"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button @click="selectData()">{{ $t('query') }}</el-button>
                </el-form-item>
                <el-form-item>
                    <el-button v-if="$hasPermission('workRecord:relation:save')" type="primary" @click="selectHandle()">{{ "新增" }}</el-button>
                </el-form-item>
            </div>
        </el-form>
        <el-table v-loading="dataListLoading" :data="dataList" max-height="500"
                  style="width: 100%;">
<!--        <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">-->
          <el-table-column label="序号" header-align="center" align="center" width="50px">
            <template slot-scope="scope">
              {{scope.$index+1}}
            </template>
          </el-table-column>
          <el-table-column prop="totalName" label="统计名称" header-align="center" align="center"></el-table-column>
          <el-table-column prop="totalType" label="统计类型" header-align="center" align="center"></el-table-column>
          <el-table-column prop="totalStyle" label="统计方式" :formatter="totalStyleFormatter" header-align="center" align="center"></el-table-column>
          <el-table-column prop="sort" label="排序" header-align="center" align="center"></el-table-column>
          <el-table-column prop="autoFlag" label="是否自动计算" :formatter="autoFlagFormatter" header-align="center" align="center"></el-table-column>
          <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
            <template slot-scope="scope">
              <el-button v-if="$hasPermission('workRecord:relation:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t('delete') }}</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
                :current-page="page"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="limit"
                :total="total"
                layout="total, sizes, prev, pager, next, jumper"
                @size-change="pageSizeChangeHandle"
                @current-change="pageCurrentChangeHandle">
        </el-pagination>
      </div>
    </el-card>
    <!-- 弹窗, 新增 / 修改 -->
    <select-list v-if="selectListVisible" ref="selectList" @refreshDataList="selectData"></select-list>
  </el-dialog>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import SelectList from './totalconfig-select-list'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/workRecord/resourcestotalrelation/page',
        getDataListIsPage: true,
        deleteURL: '/workRecord/resourcestotalrelation',
        deleteIsBatch: true
      },
      visible: false,
      selectListVisible : false,
      dataForm: {
        id: '',
        totalName: '',
        totalType: '',
        totalStyle: '',
        autoFlag: ''
      }
    }
  },
  components: {
    SelectList
  },
  methods: {
    init () {
      this.visible = true
      this.$nextTick(() => {
        if (this.dataForm.resourceId) {
          this.getDataList()
        }
      })
    },
    selectData(){
        this.page = 1
        this.getDataList()
    },
    totalStyleFormatter: function (row, column) {
      if (row.totalStyle === 0) {
        return '其他'
      } else if (row.totalStyle === 1) {
        return '统计次数'
      } else if (row.totalStyle === 2) {
        return '统计人数'
      }
    },
    autoFlagFormatter: function (row, column) {
      if (row.autoFlag === '0') {
        return '否'
      } else if (row.autoFlag === '1') {
        return '是'
      }
    },
    selectHandle () {
      this.selectListVisible = true
      this.$nextTick(() => {
        this.$refs.selectList.dataForm.resourceId = this.dataForm.resourceId
        this.$refs.selectList.init()
      })
    }
  }
}
</script>
