import { loginByUsername, logout, getUserInfo } from '@/api/login'
import { getToken, setToken, removeToken } from '@/utils/auth'
import panelApi from '@/api/panel'
const user = {
  state: {
    panelVisible:false,
    panelType:'OB',//OB呼出，IB呼入
    ticketType:0,
    customerPhone:'',
    customerId:'',
    builtId:'',//电访任务id
    callId:0, //电访记录列表页 新增工单时 传递此参数
    startTime:'',//开始处理电访任务时 赋值当前时间 保存电访任务时 传递此参数
    user:{

    },
    fns:[],
    calllogList:[],//通话列表
    callList:[],//电访列表
    jzBookOrders:[],//订单列表
    ticketList:[],//工单列表
    tickets:[],//选中的关联工单
   
  },

  mutations: {
    togglePanel:(state,payload)=>{
      console.log(state);
      state.panelVisible=!state.panelVisible;
    },
    updatePanel:(state,value)=>{
      state.panelVisible=value;
    },
    showPanel:(state,payload)=>{
      state.panelVisible=true;
      state.customerId=payload.customerId;
      state.panelType=payload.panelType;
      state.customerPhone=payload.phone;
      state.builtId=payload.builtId;
      state.callId=payload.callId;
      state.startTime=payload.startTime;
      state.ticketType=payload.ticketType;
      console.log(state);
    },
    customerInfo:(state,payload)=>{
      state.user=payload.user;
      state.customerPhone=payload.user.tel;
      state.fns=payload.fns;
      state.callList=payload.jzCalllogs;
      state.calllogList=payload.jzCalllogRecords;
      state.ticketList=payload.ticketList;
      state.jzBookOrders=payload.jzOrders;
      state.tickets=[];
    },
    setCallList:(state,payload)=>{
      state.callList=payload.list;
    },
    updateJzBookOrders:(state,payload)=>{
      state.jzBookOrders=payload.jzBookOrders;
    }
 
  },

  actions: {
    CUSTOMER_DETAIL({commit},payload){
      console.log(payload);
      panelApi.customerDetail( payload)
      .then(res => {
          console.log(res.data.data);
          commit('customerInfo',res.data.data);

      })
      .catch((error) => {
          console.log(error)
      })

    },
    CALLLOG_RECORD({commit},payload){
      panelApi.calllogRecord( payload)
      .then(res => {
          console.log(res.data.data);
          commit('setCallList',res.data.data);

      })
      .catch((error) => {
          console.log(error);

      })
    }
    
  
    
  }
}

export default user
