operator.js 2.18 KB
import { mapGetters,mapActions} from 'vuex';
export default {
  data() {
    return {
      // listData: [], // 需页面组件自己注入列表并命名为 listData
      filters: {},
      selected: {},
      selectedList: [], // 带有选择框列表选中的列表项
      editType: 0, // 带有新增/编辑的页面区分编辑状态
      dialogEditVisible: false, // 带有新增/编辑的页面弹出框可/不可见
    };
  },

  computed: {
    ...mapGetters(['loading', 'operatorList']),

  },
  created() {
    let operatorPromise = null;
    if (this.operatorList && this.operatorList.length) {
      operatorPromise = new Promise(resolve => resolve());
    } else {
      operatorPromise = this.getOperatorList();
    }
    operatorPromise.then(() => {
      if (this.operatorId) {
        this.filters.operatorId = this.operatorId;
      } else if (this.operatorList.length === 1) {
        this.filters.operatorId = this.operatorList[0].operatorId;
      }
    });
  },

  methods:{
    ...mapActions(['getOperatorList']),
      // 页面组件需自己实现获取列表数据的方法
      fetchList() {},
      // 点击搜索时处理函数
      searchList() {
        this.changePage(1);
      },
      // 获取过滤条件方法 组件可自己实现
      getFilters() {
        let filters = this.$getFilters(this.filters);
        return filters;
      },
      // 页码改变时处理函数
      changePage(index) {
        const filters = this.getFilters();
        this.fetchList({
          ...filters,
          pageNum: index,
        });
      },
      // 分页大小改变时处理函数
      changeSizeHandle(pageSize) {
        const filters = this.getFilters();
        this.fetchList({
          ...filters,
          pageNum: 1,
          pageSize: pageSize,
        });
        this.updatePagination({
          pageNum: 1,
          pageSize: pageSize,
        });
      },
      // 当列表可选时 处理选择函数
      handleSelectionChange(val) {
        this.selectedList = val;
      },
      resetEditDialog(done) {
        this.selected = {};
        done && typeof done == 'function'
          ? done()
          : (this.dialogEditVisible = false);
      },

  }
};