import { filterObj } from '@/utils/util';
import { deleteAction, getAction,downFile } from '@/api/manage'
import Vue from 'vue'
import { ACCESS_TOKEN } from "@/store/mutation-types"
import JEllipsis from '@/components/jeecg/JEllipsis'
import {tableList} from '@/api/api'
export const activitiMixin = {
  components: {
    JEllipsis
  },
  data(){
    return {
      //token header
      tokenHeader: {'X-Access-Token': Vue.ls.get(ACCESS_TOKEN)},
      tableListAll:[
      //   {
      //   text:'请假申请',
      //     routeName:'@/views/activiti/form/cdLeaveForm',
      //   component:() => import(`@/views/activiti/form/cdLeaveForm`),
      //   businessTable:'cd_leave'
      // },
      // {
      //   text:'报销申请',
      //   routeName:'@/views/activiti/form/cdReimbursementForm',
      //   component:() => import(`@/views/activiti/form/cdReimbursementForm`),
      //   businessTable:'cd_reimbursement'
      // }
    ]
    }
  },
  computed:{
    
    /*所有的流程表单，组件化注册，在此维护*/
    allFormComponent:function(){
      return this.tableListAll;
      // return [
      //   {
      //     text:'示例表单1',
      //     routeName:'@/views/activiti/form/demoForm1',
      //     component:() => import(`@/views/activiti/form/demoForm1`),
      //     businessTable:'test_demo1'
      //   },
      // {
      //   text:'请假申请',
      //     routeName:'@/views/activiti/form/cdLeaveForm',
      //   component:() => import(`@/views/activiti/form/cdLeaveForm`),
      //   businessTable:'cd_leave'
      // },
      // {
      //   text:'报销申请',
      //   routeName:'@/views/activiti/form/cdReimbursementForm',
      //   component:() => import(`@/views/activiti/form/cdReimbursementForm`),
      //   businessTable:'cd_reimbursement'
      // }
      // ]
    },
    historicDetail:function () {
      return () => import(`@/views/activiti/historicDetail`)
    }
  },
  methods:{
    getTableList(){
        getAction("/actBusiness/getTableInfoList").then((res)=>{
          let tableList=[]
          //获取其他项目表单
          tableList=res.result
          //获取固定表单
          let nowTableList=[
          //   {
          //   text:'请假申请',
          //     routeName:'@/views/activiti/form/cdLeaveForm',
          //   component:() => import(`@/views/activiti/form/cdLeaveForm`),
          //   businessTable:'cd_leave'
          // },
          // {
          //   text:'报销申请',
          //   routeName:'@/views/activiti/form/cdReimbursementForm',
          //   component:() => import(`@/views/activiti/form/cdReimbursementForm`),
          //   businessTable:'cd_reimbursement'
          // },
          // {
          //   text:'报销申请2',
          //   routeName:'@/views/activiti/form/demoForm2',
          //   component:() => import(`@/views/activiti/form/demoForm2`),
          //   businessTable:'test_demo2'
          // }
        ];
          //把其他表单中的表数据添加到原有的下拉数据中合并
          if(tableList!=null&&tableList.length>0){
            tableList.forEach(element => {
              nowTableList.push(element);
            });
          }
          getAction("/tbTableInfo/list").then((ress)=>{
            ress.result.forEach(w => {
              nowTableList.push(w);
            });
          })
          this.tableListAll=nowTableList;
        })
    },
    getCustomForm(){
      getAction("/actBusiness/getTableInfoList").then((res)=>{
        return res.result;
      })
    },
    getFormComponent(routeName){
      return _.find(this.allFormComponent,{routeName:routeName})||{};
    },
    millsToTime(mills) {
      if (!mills) {
        return "";
      }
      let s = mills / 1000;
      if (s < 60) {
        return s.toFixed(0) + " 秒"
      }
      let m = s / 60;
      if (m < 60) {
        return m.toFixed(0) + " 分钟"
      }
      let h = m / 60;
      if (h < 24) {
        return h.toFixed(0) + " 小时"
      }
      let d = h / 24;
      if (d < 30) {
        return d.toFixed(0) + " 天"
      }
      let month = d / 30
      if (month < 12) {
        return month.toFixed(0) + " 个月"
      }
      let year = month / 12
      return year.toFixed(0) + " 年"

    },
    handleTableChange(pagination, filters, sorter) {
      //分页、排序、筛选变化时触发
      //TODO 筛选
      if (Object.keys(sorter).length > 0) {
        this.isorter.column = sorter.field;
        this.isorter.order = "ascend" == sorter.order ? "asc" : "desc"
      }
      this.ipagination = pagination;
      // this.loadData();
    }
  }

}