mixin.js 2.53 KB
import { getDetailById } from "@api/notice"
import { httpStatus } from "@api/config"
let mixin = {
    data() {
      return {
        // 表格选择数据
        selectionChangeList:[]
      }
    },
    methods: {
        tableRowClassName({row, rowIndex}) {
          if ((rowIndex+1) % 2  === 0) {
              return 'success-row';
          }
          return '';
        },
        handleSelectionChange(value) {
            this.selectionChangeList.length = 0
            value.map((item,index)=>{
                this.selectionChangeList[index] = item.id
            })
        },
        // 导出数据
        getExportList (url,name='列表数据') {
          this.$confirm('此操作将进行文件导出, 是否继续?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning'
          }).then(() => {
            let loading = this.$loading({
                lock: true,
                text: '生在生成请稍后',
                spinner: 'el-icon-loading',
                background: 'rgba(0, 0, 0, 0.7)'
            })
            require.ensure([], () => {
                let { export_json_to_excel } = require('../../../vendor/Export2Excel');
                let tHeader = ['id', '名称', '开始时间', '结束时间']
                let filterVal = ['id', 'title', 'startTime', 'endTime'];
                let data = this.formatJson(filterVal, this.PageData.records)
                export_json_to_excel(tHeader, data, name)
                loading.close();
            })
          }).catch(() => {
            this.$message({
              type: 'info',
              message: '已取消'
            })
          })
        },
        formatJson(filterVal, jsonData) {
          return jsonData.map(v => filterVal.map(j => v[j]))
        },
        // 编辑
        getIdDetail(data) {
          getDetailById(data.id)
            .then(res => {
              if(res.code = httpStatus.OK.code){
                this.detailsData = res.data
              }
            })
            .catch(error => {
              reject(error)
            })
        },
        // 表格索引得问题
        indexMethod(index) {
          return index + 1 + (this.PageData.current - 1) * this.PageData.size;
        },
        handleCurrentChange(val) {
          this.initData.currentPage = val
          this._initData()
        },
        handleSizeChange(val) {
          console.log(val)
          this.initData.pageSize = val
          this._initData()
        }
    }
}
export default mixin