import request from '@/utils/request';

export default {
  //列表
  list: async (params) => {
    const res = await request.get('/main/producerouting/page', { params });
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //厂房列表
  Flist: async (params) => {
    const res = await request.get('/main/factoryarea/page', { params });
    if (res.data.code == 0) {
      return res.data.data;
    }
  },

  //工艺路线工序参数实例-分页
  taskinstanceParamList: async (params) => {
    const res = await request.get('/main/producerouting/param/page', {
      params
    });
    if (res.data.code == 0) {
      return res.data.data;
    }
  },

  //工艺路线工序参数实例-保存
  taskinstanceParamSave: async (data) => {
    const res = await request.post('/main/producerouting/param/save', data);
    if (res.data.code == 0) {
      return res.data.message;
    }
  },

  //工艺路线工序实例-分页
  taskinstanceList: async (data) => {
    const res = await request.post(
      '/main/producerouting/taskinstance/page',
      data
    );
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //工艺路线工序实例-保存
  taskinstanceSave: async (data) => {
    const res = await request.post(
      '/main/producerouting/taskinstance/save',
      data
    );
    if (res.data.code == 0) {
      return res.data.message;
    }
  },
  //工艺路线工序实例-删除
  taskinstanceDelete: async (data) => {
    const res = await request.delete(
      '/main/producerouting/taskinstance/delete',
      { data }
    );
    if (res.data.code == 0) {
      return res.data.message;
    }
  },
  //获取工艺所属参数列表
  paramList: async (params) => {
    const res = await request.get('/main/producetask/param/page', { params });
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //保存工艺所属参数列表
  paramSave: async (data) => {
    const res = await request.post('/main/producetask/param/save', data);
    if (res.data.code == 0) {
      return res.data.message;
    }
  },
  //详情
  getById: async (id) => {
    const res = await request.get(`/main/producerouting/getById/${id}`);
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //详情
  getCode: async () => {
    const res = await request.get(`/main/codemanage/getCode/process_route`);
    if (res.data.code == 0) {
      return res.data.data;
    }
  },
  //保存
  save: async (data) => {
    const res = await request.post('/main/producerouting/save', data);
    if (res.data.code == 0) {
      return res.data.message;
    }
  },
  //删除
  delete: async (data) => {
    const res = await request.delete('/main/producerouting/delete/' + data);
    if (res.data.code == 0) {
      return res.data.message;
    }
  },
  
  syncRouting: async () => {
    const res = await request.get(`/sap/sync/syncRouting`);
    if (res.data.code == 0) {
      return res.data.code;
    }
    return Promise.reject(new Error(res.data.message));
  },
};
