<template>
  <el-card shadow="never" class="aui-card--fill">
    <div class="mod-points__activepointlog}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item label="积分操作类型" prop="operationType">
          <el-select v-model="dataForm.operationType" placeholder="积分操作类型" clearable>
            <el-option v-for="item in operationTypeArr" :key="item.dictValue" :label="item.dictName" :value="item.dictValue">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="用户姓名" prop="userName" label-width="100px">
          <el-input v-model="dataForm.userName" placeholder="用户姓名" clearable @keyup.native="btKeyUpuserName"></el-input>
        </el-form-item>
        <el-form-item label="用户部门" label-width="90px">
          <el-cascader
                  v-model="ids"
                  :options="options"
                  :props="{ checkStrictly: true }"
                  clearable
          >
          </el-cascader>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('points:activepointlog:save')" type="primary" @click="addOrUpdateHandle()">{{ $t('add') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button v-if="$hasPermission('points:activepointlog:delete')" type="danger" @click="deleteHandle()">{{ $t('deleteBatch') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%;">
        <!--<el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>-->
        <el-table-column label="序号" width="50px" align="center">
          <template slot-scope="scope">
            {{scope.$index+1}}
          </template>
        </el-table-column>
        <el-table-column prop="userName" label="用户姓名" header-align="center" align="center"></el-table-column>
        <el-table-column prop="deptName" label="用户部门" header-align="center" align="center"></el-table-column>
        <el-table-column prop="mobile" label="用户电话" header-align="center" align="center"></el-table-column>
        <el-table-column prop="operationTypeName" label="积分操作类型" header-align="center" align="center"></el-table-column>
        <el-table-column prop="points" label="积分" header-align="center" align="center"></el-table-column>
        <!--<el-table-column prop="operationCode" label="操作编码" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="operationDesc" label="操作描述" header-align="center" align="center"></el-table-column>
        <el-table-column prop="operationTime" label="操作时间" header-align="center" align="center"></el-table-column>
        <el-table-column prop="lavePoints" label="剩余积分" header-align="center" align="center"></el-table-column>
        <el-table-column prop="createdTime" label="创建时间" header-align="center" align="center"></el-table-column>
        <el-table-column v-if="false" :label="$t('handle')" fixed="right" header-align="center" align="center" width="150">
          <template slot-scope="scope">
            <el-button v-if="$hasPermission('points:activepointlog:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button v-if="$hasPermission('points:activepointlog: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>
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from '@/mixins/view-module'
import AddOrUpdate from './activepointlog-add-or-update'
export default {
  mixins: [mixinViewModule],
  data () {
    return {
      mixinViewModuleOptions: {
        getDataListURL: '/points/activepointlog/page',
        getDataListIsPage: true,
        deleteURL: '/points/activepointlog',
        deleteIsBatch: true
      },
      dataForm: {
        id: '',
        operationType: '',
        userName: '',
        deptId: ''
      },
      operationTypeArr: [
        { dictValue: '1', dictName: '加积分' },
        { dictValue: '0', dictName: '减积分' }
      ],
      ids: [],
      options: []
    }
  },
  components: {
    AddOrUpdate
  },
  created: function () {
    this.getOptions()
  },
  watch: {
    ids: function (val) {
      if (val.length === 0) {
        this.dataForm.deptId = ''
      } else {
        this.dataForm.deptId = this.ids[val.length - 1]
      }
    }
  },
  methods: {
    getOptions () {
      this.$http
        .get(`/sys/user/deptOptions/getByLoginUser`)
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg)
          }
          this.options = res.data.options
        })
        .catch(() => {})
    },
    btKeyUpuserName (e) {
      e.target.value = e.target.value.replace(/[`~!@#$%^&*()_+=<>?:"{}|·~！@#￥%……&*（）——+={}|《》？：“”【】、；‘’，。、]/g, '')
      this.dataForm.userName = e.target.value
    }
  }
}
</script>
