|
@@ -0,0 +1,407 @@
|
|
|
+<template>
|
|
|
+ <div>
|
|
|
+
|
|
|
+ <ag-grid-layout
|
|
|
+ toolbar
|
|
|
+ :table-height="tableHeight"
|
|
|
+ theme="ag-theme-alpine"
|
|
|
+ :column-defs="columnDefs"
|
|
|
+ :row-data="rowData"
|
|
|
+ :locale-text="localeText"
|
|
|
+ :grid-options="gridOptions"
|
|
|
+ :default-col-def="defaultColDef"
|
|
|
+ :animate-rows="true"
|
|
|
+ :row-selection="rowSelection"
|
|
|
+ :framework-components="frameworkComponents"
|
|
|
+ @filterChanged="filterModifed"
|
|
|
+ @sortChanged="gridSortChange"
|
|
|
+ >
|
|
|
+
|
|
|
+ <div slot="toolbar" class="inner-toolbar">
|
|
|
+ <div class="toolbar-search">
|
|
|
+ <en-table-search :placeholder="this.$t('action.keywords')" @search="handlerSearch"/>
|
|
|
+ </div>
|
|
|
+ <div class="toolbar-btns">
|
|
|
+ <el-button type="primary" size="mini" @click="refreshUser">{{ this.$t('entraceguardUser.refreshUser') }}
|
|
|
+ </el-button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <el-pagination
|
|
|
+ v-if="pageData"
|
|
|
+ slot="pagination"
|
|
|
+ :current-page="pageData.page_no"
|
|
|
+ :page-sizes="[10, 20, 50, 100]"
|
|
|
+ :page-size="pageData.page_size"
|
|
|
+ layout="total, sizes, prev, pager, next, jumper"
|
|
|
+ :total="pageData.data_total"
|
|
|
+ @size-change="handlePageSizeChange"
|
|
|
+ @current-change="handlePageCurrentChange"
|
|
|
+ />
|
|
|
+ </ag-grid-layout>
|
|
|
+
|
|
|
+ <!-- 用户信息 -->
|
|
|
+ <el-dialog :visible.sync="customerFormVisible" :title="this.$t('customerManage.customerInfo')"
|
|
|
+ class="customer-dialog" width="50%">
|
|
|
+
|
|
|
+ <el-form ref="editForm" :model="formmodel" :rules="rules" label-width="145px">
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item :label="this.$t('entraceguardUser.named')" prop="name">
|
|
|
+ <el-input v-model="formmodel.name" clearable
|
|
|
+ :placeholder="this.$t('entraceguardUser.named')" :maxlength="20"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item :label="this.$t('entraceguardUser.idNo')">
|
|
|
+ <el-input v-model="formmodel.id_card" clearable
|
|
|
+ :placeholder="this.$t('entraceguardUser.idNo')" :maxlength="20"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item :label="this.$t('entraceguardUser.ic')" prop="name">
|
|
|
+ <el-input v-model="formmodel.ic" clearable
|
|
|
+ :placeholder="this.$t('entraceguardUser.ic')" :maxlength="20"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item :label="this.$t('entraceguardUser.phone')">
|
|
|
+ <el-input v-model="formmodel.phone" clearable
|
|
|
+ :placeholder="this.$t('entraceguardUser.phone')" :maxlength="13"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-row>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item :label="this.$t('entraceguardUser.password')" prop="name">
|
|
|
+ <el-input v-model="formmodel.password" clearable
|
|
|
+ :placeholder="this.$t('entraceguardUser.password')" :maxlength="20"/>
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ <el-col :span="12">
|
|
|
+ <el-form-item :label="this.$t('entraceguardUser.forbidden')">
|
|
|
+ <el-switch
|
|
|
+ v-model="formmodel.forbidden"
|
|
|
+ >
|
|
|
+ </el-switch>
|
|
|
+
|
|
|
+ </el-form-item>
|
|
|
+ </el-col>
|
|
|
+ </el-row>
|
|
|
+
|
|
|
+ <el-form-item>
|
|
|
+ <el-button type="primary" class="save" @click="handlerSubmit('editForm')">{{ this.$t('action.save')
|
|
|
+ }}
|
|
|
+ </el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+
|
|
|
+ </el-dialog>
|
|
|
+ <!-- 用户信息 -->
|
|
|
+
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+ import {AG_GRID_LOCALE_CN} from '@/utils/AgGridVueLocaleCn'
|
|
|
+ import ButtonCellRender from '@/components/AgGridCellRender/ButtonCellRender'
|
|
|
+ import ButtonCellRenderList from '@/components/AgGridCellRender/ButtonCellRenderList'
|
|
|
+ import ListFilter from '@/components/AgGridCustomFilter/ListFilter'
|
|
|
+ import RadioFilter from '@/components/AgGridCustomFilter/RadioFilter'
|
|
|
+ import * as API_Customer from '@/api/ncs_entrace_guard_user'
|
|
|
+ import {unix2Date, unixToDate} from '@/utils/Foundation'
|
|
|
+
|
|
|
+ export default {
|
|
|
+ name: "users",
|
|
|
+ components: {ButtonCellRenderList, ButtonCellRender, ListFilter, RadioFilter},
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ /** ag-grid参数 **/
|
|
|
+ pageData: {}, // 翻页数据
|
|
|
+ columnDefs: null,
|
|
|
+ rowData: null,
|
|
|
+ defaultColDef: null,
|
|
|
+ gridOptions: null,
|
|
|
+ gridApi: null,
|
|
|
+ columnApi: null,
|
|
|
+ localeText: AG_GRID_LOCALE_CN,
|
|
|
+ filterState: null,
|
|
|
+ rowSelection: null,
|
|
|
+ frameworkComponents: null,
|
|
|
+ formmodel: {},
|
|
|
+ customerFormVisible: false,
|
|
|
+ /** 列表参数 */
|
|
|
+ params: {
|
|
|
+ page_size: 20,
|
|
|
+ page_no: 1,
|
|
|
+ fixedCondition: 'partment_id=' + this.$store.getters.partId
|
|
|
+ },
|
|
|
+ booleanRender: [
|
|
|
+ {key: this.$t('entraceguardUser.yes'), value: true, color: 'green'},
|
|
|
+ {key: this.$t('entraceguardUser.nop'), value: false, color: 'red'}
|
|
|
+ ],
|
|
|
+ rules: {}
|
|
|
+ }
|
|
|
+ },
|
|
|
+ computed: {
|
|
|
+ tableHeight() {
|
|
|
+ return this.mainAreaHeight - 130
|
|
|
+ }
|
|
|
+ },
|
|
|
+ beforeMount() {
|
|
|
+ const _this = this
|
|
|
+ this.gridOptions = {
|
|
|
+ onCellDoubleClicked: function (row) {
|
|
|
+ _this.formmodel = {
|
|
|
+ ...row.data
|
|
|
+ }
|
|
|
+ _this.detailsVisible = true
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.columnDefs = [
|
|
|
+ {
|
|
|
+ headerName: '#',
|
|
|
+ headerCheckboxSelection: true,
|
|
|
+ headerCheckboxSelectionFilteredOnly: true,
|
|
|
+ checkboxSelection: true,
|
|
|
+ sortable: false, filter: false,
|
|
|
+ width: 50,
|
|
|
+ resizable: false,
|
|
|
+ valueGetter: this.hashValueGetter
|
|
|
+ },
|
|
|
+ {headerName: 'ID', field: 'id', sortable: true, filter: 'agNumberColumnFilter', width: 100},
|
|
|
+ {
|
|
|
+ headerName: this.$t('entraceguardUser.named'),
|
|
|
+ field: 'name',
|
|
|
+ sortable: true,
|
|
|
+ filter: 'agTextColumnFilter',
|
|
|
+ width: 160
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headerName: this.$t('entraceguardUser.idNo'),
|
|
|
+ field: 'id_card',
|
|
|
+ sortable: true,
|
|
|
+ filter: 'agNumberColumnFilter',
|
|
|
+ flex: 1
|
|
|
+ },
|
|
|
+
|
|
|
+ {
|
|
|
+ headerName: this.$t('entraceguardUser.ic'),
|
|
|
+ field: 'ic',
|
|
|
+ sortable: true,
|
|
|
+ filter: 'agTextColumnFilter',
|
|
|
+ width: 160
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headerName: this.$t('entraceguardUser.phone'),
|
|
|
+ field: 'phone',
|
|
|
+ sortable: true,
|
|
|
+ filter: 'agTextColumnFilter'
|
|
|
+ },
|
|
|
+ {
|
|
|
+ headerName: this.$t('entraceguardUser.password'),
|
|
|
+ field: 'password',
|
|
|
+ sortable: true,
|
|
|
+ filter: 'agTextColumnFilter',
|
|
|
+ width: 160
|
|
|
+ },
|
|
|
+ // lockPosition 锁定位置,会在第一列
|
|
|
+ // lockPinned = true 不能拖动然后固定
|
|
|
+ // resizeable 单元个大小是否可以调整
|
|
|
+ {
|
|
|
+ headerName: this.$t('entraceguardUser.forbidden'),
|
|
|
+ field: 'forbidden',
|
|
|
+ sortable: true,
|
|
|
+ filterFramework: 'RadioFilter',
|
|
|
+ filterParams: {
|
|
|
+ listData: this.booleanRender
|
|
|
+ },
|
|
|
+ width: 150,
|
|
|
+ cellRenderer: (para) => {
|
|
|
+ return this.radioFilterFormatter(para, this.booleanRender)
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ {
|
|
|
+ headerName: this.$t('action.handle'), field: 'id',
|
|
|
+ cellRendererFramework: 'ButtonCellRenderList',
|
|
|
+ cellRendererParams: param => {
|
|
|
+ return {
|
|
|
+ list: [
|
|
|
+ {
|
|
|
+ onClick: this.handleEdit,
|
|
|
+ label: this.$t('action.edit'),
|
|
|
+ buttonType: 'primary',
|
|
|
+ buttonSize: 'mini'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ },
|
|
|
+ filter: false,
|
|
|
+ pinned: 'right',
|
|
|
+ lockPinned: true,
|
|
|
+ minWidth: this.$i18n.locale === 'zh' ? 260 : 380,
|
|
|
+ resizable: false,
|
|
|
+ sortable: false
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ this.defaultColDef = {
|
|
|
+ // filter: 'agTextColumnFilter',
|
|
|
+ sortable: true,
|
|
|
+ resizable: true,
|
|
|
+ // comparator: this.dateCustomComparator,
|
|
|
+ filterParams: {
|
|
|
+ debounceMs: 500,
|
|
|
+ newRowsAction: 'keep',
|
|
|
+ textCustomComparator: this.textCustomComparator
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.rowSelection = 'multiple'
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ window.onresize = this.windowResize()
|
|
|
+ this.gridApi = this.gridOptions.api
|
|
|
+ this.gridColumnApi = this.gridOptions.columnApi
|
|
|
+ this.gridColumnApi.applyColumnState({
|
|
|
+ state: [
|
|
|
+ {
|
|
|
+ colId: 'id',
|
|
|
+ sort: 'asc'
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ methods: {
|
|
|
+ windowResize() {
|
|
|
+ this.$set(this, 'mainAreaHeight', Number(document.documentElement.clientHeight) - 84)
|
|
|
+ },
|
|
|
+ /** 分页大小发生改变 */
|
|
|
+ handlePageSizeChange(size) {
|
|
|
+ this.params.page_size = size
|
|
|
+ this.getList()
|
|
|
+ },
|
|
|
+
|
|
|
+ /** 分页页数发生改变 */
|
|
|
+ handlePageCurrentChange(page) {
|
|
|
+ this.params.page_no = page
|
|
|
+ this.getList()
|
|
|
+ },
|
|
|
+ /** 加载列表数据 */
|
|
|
+ getList() {
|
|
|
+ const param = this.MixinClone(this.params)
|
|
|
+ this.gridApi.showLoadingOverlay()
|
|
|
+ API_Customer.getList(param).then(response => {
|
|
|
+ this.rowData = [...response.data]
|
|
|
+ this.pageData = {
|
|
|
+ page_no: response.page_no,
|
|
|
+ page_size: response.page_size,
|
|
|
+ data_total: response.data_total
|
|
|
+ }
|
|
|
+ this.$nextTick(() => {
|
|
|
+ const node = this.gridApi.getDisplayedRowAtIndex(0)
|
|
|
+ if (node !== null && node !== undefined) {
|
|
|
+ node.setSelected(true)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ /**
|
|
|
+ * 过滤状态发生变化,发送到服务器检索数据
|
|
|
+ */
|
|
|
+ filterModifed(param) {
|
|
|
+ var model = param.api.getFilterModel()
|
|
|
+ this.params.filter = JSON.stringify(model)
|
|
|
+ this.getList()
|
|
|
+ },
|
|
|
+ gridSortChange(param) {
|
|
|
+ console.log('sortparam', param)
|
|
|
+ const columnState = param.columnApi.getColumnState()
|
|
|
+ // 排序状态
|
|
|
+ const sortState = columnState.filter(function (s) {
|
|
|
+ return s.sort != null
|
|
|
+ }).map(function (s) {
|
|
|
+ return {
|
|
|
+ colId: s.colId,
|
|
|
+ sort: s.sort,
|
|
|
+ sortIndex: s.sortIndex
|
|
|
+ }
|
|
|
+ }).sort(function (a, b) {
|
|
|
+ return a.sortIndex - b.sortIndex
|
|
|
+ })
|
|
|
+ if (sortState.length > 0) {
|
|
|
+ if (sortState.length === 1) {
|
|
|
+ this.params.sort = sortState[0].colId
|
|
|
+ this.params.dir = sortState[0].sort
|
|
|
+ } else {
|
|
|
+ let sortstring = ''
|
|
|
+ sortState.forEach(function (item) {
|
|
|
+ sortstring += item.colId + ' ' + item.sort + ','
|
|
|
+ })
|
|
|
+ this.params.sort = sortstring.substring(0, sortstring.length - 1)
|
|
|
+ this.params.dir = ' '
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ delete this.params.sort
|
|
|
+ delete this.params.dir
|
|
|
+ }
|
|
|
+
|
|
|
+ this.getList()
|
|
|
+ },
|
|
|
+ /** 处理搜索 */
|
|
|
+ handlerSearch(keywords) {
|
|
|
+ this.params.query = keywords
|
|
|
+ this.getList()
|
|
|
+ },
|
|
|
+
|
|
|
+ handleEdit(row) {
|
|
|
+ this.formmodel = {
|
|
|
+ ...row
|
|
|
+ }
|
|
|
+ this.customerFormVisible = true
|
|
|
+ },
|
|
|
+ refreshUser() {
|
|
|
+ API_Customer.refreshUser(this.$store.getters.partId).then(res => {
|
|
|
+ this.getList()
|
|
|
+ }).catch(err => {
|
|
|
+ this.$message.error(err.message)
|
|
|
+ })
|
|
|
+ },
|
|
|
+ radioFilterFormatter(params, array) {
|
|
|
+ const item = array.filter(p => p.value === params.value)[0]
|
|
|
+ if (item) {
|
|
|
+ if (item.color) {
|
|
|
+ return '<span style="color:' + item.color + '">' + item.key + '</span>'
|
|
|
+ } else {
|
|
|
+ return item.key
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return ''
|
|
|
+ }
|
|
|
+ },
|
|
|
+ handlerSubmit(formName){
|
|
|
+ this.$refs[formName].validate(valid => {
|
|
|
+ if (valid) {
|
|
|
+
|
|
|
+ API_Customer.update(this.formmodel.id,this.formmodel).then(res => {
|
|
|
+ this.getList()
|
|
|
+ this.$message.success(this.$t('action.editSuccess'))
|
|
|
+ this.customerFormVisible = false
|
|
|
+ })
|
|
|
+
|
|
|
+ } else {
|
|
|
+ this.$message.error(this.$t('action.fromError'))
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+
|
|
|
+</style>
|