loginHistoryDialog.vue 5.47 KB
<!-- 设备登录历史 -->
<template>
  <baseDialog :dialog-config="dialogConfig"
              :is-show.sync="visible"
              class="accountDailog"
              @handleClick="handleAddConfirm">
    <div>
      <div class="header"
           slot="header"
           style="padding: 10px 20px;">
        <d2-search ref="showSearch"
                   class="show-search"
                   :search-form="searchForm"
                   :label-width="labelWidth"
                   :form-data="showFormData" />
        <div class="up-btns">
          <el-button @click="handleSearch"
                     size="small"
                     type="primary">
            查询
          </el-button>
          <el-button size="small"
                     @click="handleReset">
            重置
          </el-button>
        </div>
      </div>
      <div class="d2-container-content">
        <d2-table ref="recordTable"
                  :get-list-api="getListApi"
                  :search-form="searchFormSearch"
                  :table-params="tableParams"
                  :before-search-fn="beforeSearchFn">
        </d2-table>
      </div>
    </div>
  </baseDialog>
</template>

<script>
import { Util, deepClone } from '@/common/util'
import { merchantShopGoodsStockPage } from '@api/stockManage'
import { queryloginLog } from '@api/inStoreManage'
export default {
  name: 'LoginHistoryDialog',
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      labelWidth: '100px',
      dialogConfig: {
        title: '设备登录历史',
        width: '1500px'
      },
      // editChildRef: 'editChildRef',
      searchForm: {
        userName: '',
        loginTime: '',
        loginDeviceType: ''
      },
      searchFormSearch: {},
      showFormData: [{
        label: '员工姓名',
        name: 'userName',
        type: 'input',
        maxlength: '50',
        isClear: true
      }, {
        label: '日期',
        name: 'loginTime',
        type: 'datePicker',
        isClear: true,
        pickerOptions: 'rangePickerOptions'
      }, {
        label: '登录设备',
        name: 'loginDeviceType',
        type: 'select',
        optionList: [],
        optionId: 'confId',
        optionLabel: 'confValue',
        optionsName: 'loginDeviceTypeList'
      }],
      getListApi: queryloginLog,
      tableData: [],
      tableParams: {
        btnId: new Date().getTime() + parseInt(Math.random() * 1000),
        listName: 'list',
        // tableOption: false,
        tableColumns: [
          {
            label: '登录员工',
            prop: 'userName'
          },
          {
            label: '日期',
            prop: 'loginTime',
            formatter: (cellValue) => {
              return cellValue.loginTime ? Util.dateFormate(cellValue.loginTime, 'YYYY-MM-DD') : ''
            }
          },
          {
            label: '时间',
            prop: 'loginTime',
            formatter: (cellValue) => {
              return cellValue.loginTime ? Util.dateFormate(cellValue.loginTime, 'HH:ss') : ''
            }
          },
          {
            label: '登录设备',
            prop: 'loginDeviceType',
            formatter: (cellValue) => {
              return this.baseData.loginDeviceTypeList.find(item => item.confId == cellValue.loginDeviceType)?.confValue
            }
          }]
      },
      baseData: {
        loginDeviceTypeList: [
          { confId: '1', confValue: "pad端" },
          { confId: '2', confValue: "手机端" }
        ]
      },
    }
  },

  props: {
    loginHistoryVisible: {
      type: Boolean,
      default: false
    }
  },
  watch: {
  },
  computed: {
    visible: {
      get() {
        return this.loginHistoryVisible
      },
      set(newVal) {
        this.$emit('dialogClose', { flag: newVal, attrName: 'loginHistoryVisible' })
      }
    }
  },

  mounted() {
    console.log(this.userInfo);
    this.getOptionsList()
  },

  methods: {

    beforeSearchFn() {
      return new Promise(resolve => {
        this.searchFormSearch = deepClone(this.searchForm)
        console.log(this.searchFormSearch);
        if (this.searchFormSearch.loginTime) {
          this.searchFormSearch.startLoginTime = Util.dateFormate(this.searchFormSearch.loginTime[0], 'YYYY-MM-DD 00:00:00')
          this.searchFormSearch.endLoginTime = Util.dateFormate(this.searchFormSearch.loginTime[1], 'YYYY-MM-DD 23:59:59')
          delete this.searchFormSearch.loginTime
        }
        resolve()
      })
    },

    getOptionsList() {
      this.showFormData.forEach((item, index) => {
        if (item.type === 'select') {
          if (this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this.showFormData[index].optionLabel] !== '全部') {
            const temp = {}
            temp[this.showFormData[index].optionId] = ''
            temp[this.showFormData[index].optionLabel] = '全部'
            this.baseData[item.optionsName].unshift(temp)
          }
          this.$set(this.showFormData[index], 'optionList', this.baseData[item.optionsName])
        }
      })
    },

    handleSearch() {
      this.$refs.recordTable.refreshTable(false, true)
    },
    handleReset() {
      this.searchForm = {
        userName: '',
        loginTime: '',
        loginDeviceType: ''
      }
      this.$refs.recordTable.refreshTable(false, true)
    },

    handleAddConfirm() {
      this.visible = true
    }
  }
}
</script>
<style lang="scss" scoped>
.flagFrom.d2-container-content {
  margin-top: 0 !important;
}

.detail-dialog {
}
</style>