diff --git a/src/assets/api.js b/src/assets/api.js index f6499e68..020c38a0 100644 --- a/src/assets/api.js +++ b/src/assets/api.js @@ -1,86 +1,86 @@ -import { Notify } from "zent"; +import { Notify } from "zent" //镜像环境 // export const baseurl = 'http://pre.marketapi.1688sup.com' // const Version = "v1.3.0"; // window.baseurl = 'http://pre.marketapi.1688sup.com' -let baseurl = ""; +let baseurl = "" if (process.env.NODE_ENV == "test" || process.env.NODE_ENV == "development") { // 测试环境 - baseurl = "http://192.168.6.75"; - window.baseurl = "http://192.168.6.75"; + baseurl = "http://192.168.6.75" + window.baseurl = "http://192.168.6.75" } if (process.env.NODE_ENV == "production") { // 生成环境 - baseurl = "https://marketapi.1688sup.com"; - window.baseurl = "https://marketapi.1688sup.com"; + baseurl = "https://marketapi.1688sup.com" + window.baseurl = "https://marketapi.1688sup.com" } const upload = (method, url, params, responseType) => { let obj = { method: method, headers: new Headers({ - authorization: sessionStorage.getItem("authorization"), + authorization: sessionStorage.getItem("authorization") // Version: Version, }), - body: params, - }; + body: params + } let http = fetch(url, obj).then((res) => { if (res.status == 200) { - return res.json(); + return res.json() } else { switch (res.status) { // 401: 未登录 case 401: - res + res .json() .then((response) => { if (response.code == 403) { - Notify.clear(); - Notify.error(response.message); + Notify.clear() + Notify.error(response.message) setTimeout(() => { - window.location.href = "/"; - }, 2000); + window.location.href = "/" + }, 2000) } else if (response.code == 401) { - Notify.clear(); - Notify.error(response.message); + Notify.clear() + Notify.error(response.message) } }) - .catch(); - break; + .catch() + break default: - return; + return } } - }); + }) return http .then((response) => response) - .catch((error) => console.error("Error:", error)); -}; + .catch((error) => console.error("Error:", error)) +} const derive = (method, url, params, responseType) => { var obj = { responseType: "blob", headers: new Headers({ - authorization: sessionStorage.getItem("authorization"), + authorization: sessionStorage.getItem("authorization") // Version: Version, - }), - }; + }) + } if (method == "get") { if (params) { - let paramsArray = []; + let paramsArray = [] //拼接参数 Object.keys(params).forEach((key) => paramsArray.push(key + "=" + params[key]) - ); + ) if (url.search(/\?/) === -1) { - url += "?" + paramsArray.join("&"); + url += "?" + paramsArray.join("&") } else { - url += "&" + paramsArray.join("&"); + url += "&" + paramsArray.join("&") } } } let http = fetch(url, obj).then((res) => { if (res.status == 200) { - return res.blob(); + return res.blob() } else { switch (res.status) { // 401: 未登录 @@ -89,57 +89,57 @@ const derive = (method, url, params, responseType) => { .json() .then((response) => { if (response.code == 403) { - Notify.clear(); - Notify.error(response.message); + Notify.clear() + Notify.error(response.message) setTimeout(() => { - window.location.href = "/"; - }, 2000); + window.location.href = "/" + }, 2000) } else if (response.code == 401) { - Notify.clear(); - Notify.error(response.message); + Notify.clear() + Notify.error(response.message) } }) - .catch(); - break; + .catch() + break default: - return; + return } } - }); + }) return http .then((response) => response) - .catch((error) => console.error("Error:", error)); -}; + .catch((error) => console.error("Error:", error)) +} const getData = (method, url, params, responseType) => { - var obj = null; + var obj = null if (method == "get") { obj = { headers: new Headers({ - authorization: sessionStorage.getItem("authorization"), + authorization: sessionStorage.getItem("authorization") // Version: Version, - }), - }; + }) + } if (params) { - let paramsArray = []; + let paramsArray = [] //拼接参数 Object.keys(params).forEach((key) => paramsArray.push(key + "=" + params[key]) - ); + ) if (url.search(/\?/) === -1) { - url += "?" + paramsArray.join("&"); + url += "?" + paramsArray.join("&") } else { - url += "&" + paramsArray.join("&"); + url += "&" + paramsArray.join("&") } } } let http = fetch(url, obj).then((res) => { - window.timeshow = res.headers.get("Date-Time"); + window.timeshow = res.headers.get("Date-Time") if (res.status == 200) { - console.log("当前返回", res.body); + console.log("当前返回", res.body) - return res.text(); + return res.text() } else { switch (res.status) { // 401: 未登录 @@ -148,48 +148,48 @@ const getData = (method, url, params, responseType) => { .json() .then((response) => { if (response.code == 403) { - Notify.clear(); - Notify.error(response.message); + Notify.clear() + Notify.error(response.message) setTimeout(() => { - window.location.href = "/"; - }, 2000); + window.location.href = "/" + }, 2000) } else if (response.code == 401) { - Notify.clear(); - Notify.error(response.message); + Notify.clear() + Notify.error(response.message) } }) - .catch(); + .catch() - break; + break default: - return; + return } } - }); + }) return http .then((response) => response) - .catch((error) => console.error("Error:", error)); -}; + .catch((error) => console.error("Error:", error)) +} const req = (method, url, params, responseType) => { - var obj = null; + var obj = null if (method == "get") { obj = { headers: new Headers({ - authorization: sessionStorage.getItem("authorization"), + authorization: sessionStorage.getItem("authorization") // Version: Version, - }), - }; + }) + } if (params) { - let paramsArray = []; + let paramsArray = [] //拼接参数 Object.keys(params).forEach((key) => paramsArray.push(key + "=" + params[key]) - ); + ) if (url.search(/\?/) === -1) { - url += "?" + paramsArray.join("&"); + url += "?" + paramsArray.join("&") } else { - url += "&" + paramsArray.join("&"); + url += "&" + paramsArray.join("&") } } } @@ -198,10 +198,10 @@ const req = (method, url, params, responseType) => { method: "post", body: JSON.stringify(params), headers: new Headers({ - "Content-Type": "application/json", + "Content-Type": "application/json" // Version: Version, - }), - }; + }) + } } if (method == "post" || method == "put" || method == "delete") { @@ -210,18 +210,18 @@ const req = (method, url, params, responseType) => { body: JSON.stringify(params), headers: new Headers({ "Content-Type": "application/json", - authorization: sessionStorage.getItem("authorization"), + authorization: sessionStorage.getItem("authorization") // Version: Version, - }), - }; + }) + } } let http = fetch(url, obj).then((res) => { - window.timeshow = res.headers.get("Date-Time"); + window.timeshow = res.headers.get("Date-Time") if (res.status == 200) { - console.log("当前返回", res.body); + console.log("当前返回", res.body) - return res.json(); + return res.json() } else { switch (res.status) { // 401: 未登录 @@ -230,488 +230,488 @@ const req = (method, url, params, responseType) => { .json() .then((response) => { if (response.code == 403) { - Notify.clear(); - Notify.error(response.message); + Notify.clear() + Notify.error(response.message) setTimeout(() => { - window.location.href = "/"; - }, 2000); + window.location.href = "/" + }, 2000) } else if (response.code == 401) { // Notify.clear() // Notify.error(response.message) } }) - .catch(); + .catch() - break; + break default: - return; + return } } - }); + }) return http .then((response) => response) - .catch((error) => console.error("Error:", error)); -}; + .catch((error) => console.error("Error:", error)) +} export const handelResponse = (res, cb, errCb) => { if (res && res.code == 200) { - cb(res.data, res.message); + cb(res.data, res.message) } else { if (res && typeof errCb == "function") { - Notify.clear(); + Notify.clear() // Notify.error(res.message); - errCb(res.message); + errCb(res.message) } } -}; +} //营销计划列表 export const getPlanList = (params) => { - return req("get", baseurl + "/plan", params); -}; + return req("get", baseurl + "/plan", params) +} //获取key批次列表 export const getKeyList = (params) => { - return req("get", baseurl + "/keys", params); -}; + return req("get", baseurl + "/keys", params) +} //获取营销计划下拉菜单 export const getReSellerOption = (params) => { - return req("get", baseurl + "/reseller/choice", params); -}; + return req("get", baseurl + "/reseller/choice", params) +} //获取分销商下拉菜单 export const getPlanChoseOption = (params) => { - return req("get", baseurl + "/plan/chose_list", params); -}; + return req("get", baseurl + "/plan/chose_list", params) +} //新建营销计划 export const addPlanStep = (id, params) => { - let str = id ? "/" + id : ""; + let str = id ? "/" + id : "" if (str) { - return req("put", baseurl + "/plan/step" + str, params); + return req("put", baseurl + "/plan/step" + str, params) } - return req("post", baseurl + "/plan/step" + str, params); -}; + return req("post", baseurl + "/plan/step" + str, params) +} //获取营销计划草稿信息 export const getDraftInfo = (id, params) => { - return req("get", baseurl + "/plan/draft/" + id, params); -}; + return req("get", baseurl + "/plan/draft/" + id, params) +} //启用停用 营销计划 export const startOrStopPlan = (id, params) => { - return req("put", baseurl + "/plan/status/" + id, params); -}; + return req("put", baseurl + "/plan/status/" + id, params) +} //创建key批次信息 export const addKeysBatchInfo = (id, params) => { - return req("post", baseurl + "/plan/" + id + "/keys", params); -}; + return req("post", baseurl + "/plan/" + id + "/keys", params) +} //编辑修改 export const putPlanStep = (id, params) => { - return req("put", baseurl + "/plan/edit/" + id, params); -}; + return req("put", baseurl + "/plan/edit/" + id, params) +} //获取key批次信息 export const getKeysBatchInfo = (id, params) => { - return req("get", baseurl + "/keys", params); -}; + return req("get", baseurl + "/keys", params) +} //启用停用key批次信息 export const startOrStopKeybatch = (id, params) => { - return req("put", baseurl + "/keys/status/" + id, params); -}; + return req("put", baseurl + "/keys/status/" + id, params) +} //获取key批次详细信息 export const getKeyBatchDetail = (id, params) => { - return req("get", baseurl + "/keys/" + id, params); -}; + return req("get", baseurl + "/keys/" + id, params) +} //更新key批次详细信息 export const putKeyBatchDetail = (id, params) => { - return req("put", baseurl + "/keys/" + id, params); -}; + return req("put", baseurl + "/keys/" + id, params) +} //发送key批次压缩包和压缩包密码 export const planSend = (id, params) => { - return req("put", baseurl + "/plan/send/" + id, params); -}; + return req("put", baseurl + "/plan/send/" + id, params) +} //是否已经发送过邮件 export const planIsSend = (id) => { - return req("get", baseurl + "/plan/is_send/" + id); -}; + return req("get", baseurl + "/plan/is_send/" + id) +} //重新修改手机号邮箱 export const planReceive = (id, params) => { - return req("put", baseurl + "/plan/receive/" + id, params); -}; + return req("put", baseurl + "/plan/receive/" + id, params) +} //重新发送key批次压缩包和压缩包密码 export const planResend = (id, params) => { - return req("put", baseurl + "/plan/resend/" + id, params); -}; + return req("put", baseurl + "/plan/resend/" + id, params) +} export const keysIsSend = (id, params) => { - return req("get", baseurl + "/keys/is_send/" + id, params); -}; + return req("get", baseurl + "/keys/is_send/" + id, params) +} //作废key批次 export const cancelKey = (id, params) => { - return req("put", baseurl + "/keys/cancel/" + id, params); -}; + return req("put", baseurl + "/keys/cancel/" + id, params) +} //删除草稿key批次 export const deldraftCode = (id) => { - return req("delete", baseurl + "/plan/delete/" + id); -}; + return req("delete", baseurl + "/plan/delete/" + id) +} //发送密钥邮件 export const postKeyEmail = (id, params) => { - return req("put", baseurl + "/keys/send/" + id, params); -}; + return req("put", baseurl + "/keys/send/" + id, params) +} //修改密钥邮件 export const putKeyEmail = (id, params) => { - return req("put", baseurl + "/keys/receive/" + id, params); -}; + return req("put", baseurl + "/keys/receive/" + id, params) +} export const resKeyEmail = (id, params) => { - return req("put", baseurl + "/keys/resend/" + id, params); -}; + return req("put", baseurl + "/keys/resend/" + id, params) +} // 兑换码管理 //兑换码管理列表 export const getCodesList = (params) => { - return getData("get", baseurl + "/codes", params); -}; + return getData("get", baseurl + "/codes", params) +} //获取兑换码明细 export const getCodesDetail = (id) => { - return req("get", baseurl + "/codes/" + id); -}; + return req("get", baseurl + "/codes/" + id) +} //修改兑换码批次 export const putCodesBatch = (id, params) => { - return req("put", baseurl + "/codes/edit/" + id, params); -}; + return req("put", baseurl + "/codes/edit/" + id, params) +} //作废本批次兑换码 export const delCode = (id) => { - return req("delete", baseurl + "/codes/discard/" + id); -}; + return req("delete", baseurl + "/codes/discard/" + id) +} //作废本批次兑换码 export const putCodeStatus = (id, params) => { - return req("put", baseurl + "/codes/status/" + id, params); -}; + return req("put", baseurl + "/codes/status/" + id, params) +} //兑换码商品列表 export const getCodeProductList = (params) => { - return req("get", baseurl + "/codes/products", params); -}; + return req("get", baseurl + "/codes/products", params) +} //删除商品库存信息 export const delCodeProduct = (id) => { - return req("delete", baseurl + "/codes/products/" + id); -}; + return req("delete", baseurl + "/codes/products/" + id) +} //更新单个商品信息 export const putCodeProduct = (batch_id, id, params) => { - return req("put", baseurl + "/codes/products/" + batch_id + "/" + id, params); -}; + return req("put", baseurl + "/codes/products/" + batch_id + "/" + id, params) +} //获取商品库存明细 export const getCodeProduct = (batch_id, id) => { - return req("get", baseurl + "/codes/products/" + batch_id + "/" + id); -}; + return req("get", baseurl + "/codes/products/" + batch_id + "/" + id) +} //获取商品库存明细 export const getIsRequireApproval = (id, data) => { - return req("post", baseurl + "/codes/" + id + "/is_require_approval", data); -}; + return req("post", baseurl + "/codes/" + id + "/is_require_approval", data) +} // //蓝色兄弟映射商品 export const getProductInfoSelect = (params) => { - return req("get", baseurl + "/product/market/products", params); -}; + return req("get", baseurl + "/product/market/products", params) +} // 上传 export const uploadImg = (params) => { - return upload("post", baseurl + "/upload/simple", params); -}; + return upload("post", baseurl + "/upload/simple", params) +} // 订单管理 //订单管理列表 export const getOrderList = (params) => { - return req("get", baseurl + "/order", params); -}; + return req("get", baseurl + "/order", params) +} //订单管理详情 export const getOrderDetails = (id) => { - return req("get", baseurl + "/order/" + id); -}; + return req("get", baseurl + "/order/" + id) +} //订单导出 export const getOrderExport = (params) => { - return derive("get", baseurl + "/order/export", params); -}; + return derive("get", baseurl + "/order/export", params) +} //订单改为成功 export const putOrderSuccess = (id) => { - return req("put", baseurl + "/order/success/" + id); -}; + return req("put", baseurl + "/order/success/" + id) +} //订单日志 export const getOrderLog = (orderId, params) => { - return req("get", baseurl + "/order/" + orderId + "/log", params); -}; + return req("get", baseurl + "/order/" + orderId + "/log", params) +} //订单作废 export const putOrderCancel = (id) => { - return req("put", baseurl + "/order/cancel/" + id); -}; + return req("put", baseurl + "/order/cancel/" + id) +} // 分销商管理 //分销商管理列表 export const getResellerList = (params) => { - return req("get", baseurl + "/reseller", params); -}; + return req("get", baseurl + "/reseller", params) +} //新建分销商异步校验分销商名称是否重复 export const getExistName = (name) => { - return req("get", baseurl + "/reseller/exist_name?name=" + name); -}; + return req("get", baseurl + "/reseller/exist_name?name=" + name) +} //编辑分销商异步校验分销商名称是否重复 export const geteditExistName = (name, params) => { - return req("get", baseurl + "/reseller/exist_name?name=" + name, params); -}; + return req("get", baseurl + "/reseller/exist_name?name=" + name, params) +} //新建分销商异步校验分销商登陆账号是否重复 export const getExistAccount = (name) => { - return req("get", baseurl + "/reseller/exist_account/" + name); -}; + return req("get", baseurl + "/reseller/exist_account/" + name) +} //编辑分销商异步校验分销商登陆账号是否重复 export const geteditExistAccount = (name, params) => { - return req("get", baseurl + "/reseller/exist_account/" + name, params); -}; + return req("get", baseurl + "/reseller/exist_account/" + name, params) +} //新建分销商-销售人员 export const getPersonnel = () => { - return req("get", baseurl + "/auth/admin/all"); -}; + return req("get", baseurl + "/auth/admin/all") +} //新建分销商-签约公司 export const getCompany = () => { - return req("get", baseurl + "/auth/company/all"); -}; + return req("get", baseurl + "/auth/company/all") +} //删除分销商 export const delReseller = (id) => { - return req("delete", baseurl + "/reseller/" + id); -}; + return req("delete", baseurl + "/reseller/" + id) +} //修改分销商状态 export const putResellerStatus = (id, data) => { - return req("put", baseurl + "/reseller/status/" + id, data); -}; + return req("put", baseurl + "/reseller/status/" + id, data) +} //新建分销商 export const postCreateReseller = (data) => { - return req("post", baseurl + "/reseller/create", data); -}; + return req("post", baseurl + "/reseller/create", data) +} //获取分销商详情 export const getReseller = (id) => { - return req("get", baseurl + "/reseller/" + id); -}; + return req("get", baseurl + "/reseller/" + id) +} //编辑分销商 export const putResellerInfo = (id, data) => { - return req("put", baseurl + "/reseller/" + id, data); -}; + return req("put", baseurl + "/reseller/" + id, data) +} //重置分销商密码 export const putResellerPwd = (id, data) => { - return req("put", baseurl + "/reseller/password/" + id, data); -}; + return req("put", baseurl + "/reseller/password/" + id, data) +} //重置分销商密码 export const getResellerSelect = (data) => { - return req("get", baseurl + "/reseller/exist_account/name", data); -}; + return req("get", baseurl + "/reseller/exist_account/name", data) +} // 账号管理 //账号管理列表 export const getAccountList = (params) => { - return req("get", baseurl + "/auth/admin", params); -}; + return req("get", baseurl + "/auth/admin", params) +} //修改账号状态 export const putAccountStatus = (id, params) => { - return req("put", baseurl + "/auth/admin/status/" + id, params); -}; + return req("put", baseurl + "/auth/admin/status/" + id, params) +} // 删除账号 export const delAccount = (id) => { - return req("delete", baseurl + "/auth/admin/" + id); -}; + return req("delete", baseurl + "/auth/admin/" + id) +} // 重置账号密码 export const putModifypwd = (id, data) => { - return req("put", baseurl + "/auth/admin/password/" + id, data); -}; + return req("put", baseurl + "/auth/admin/password/" + id, data) +} //添加账号-获取部门 export const getDepartment = (params) => { - return req("get", baseurl + "/auth/department", params); -}; + return req("get", baseurl + "/auth/department", params) +} //添加账号-获取岗位 export const getDepartmentJob = (params) => { - return req("get", baseurl + "/auth/departmentJob", params); -}; + return req("get", baseurl + "/auth/departmentJob", params) +} //添加账号-获取角色 export const getRole = (params) => { - return req("get", baseurl + "/auth/adminRole", params); -}; + return req("get", baseurl + "/auth/adminRole", params) +} //添加账号-新增账号 export const postAddAcc = (params) => { - return req("post", baseurl + "/auth/admin", params); -}; + return req("post", baseurl + "/auth/admin", params) +} //添加账号-编辑账号 export const putAddAcc = (id, params) => { - return req("put", baseurl + "/auth/admin/" + id, params); -}; + return req("put", baseurl + "/auth/admin/" + id, params) +} //子账号 //获取子账号权限 export const getsubAccount = (id) => { - return req("get", baseurl + "/auth/admin/adminRoleRules/" + id); -}; + return req("get", baseurl + "/auth/admin/adminRoleRules/" + id) +} //新增子账号 export const postAddSubAcc = (params) => { - return req("post", baseurl + "/auth/admin/createSon", params); -}; + return req("post", baseurl + "/auth/admin/createSon", params) +} //修改子账号 export const putAddSubAcc = (id, data) => { - return req("put", baseurl + "/auth/admin/editSon/" + id, data); -}; + return req("put", baseurl + "/auth/admin/editSon/" + id, data) +} //子账号列表 export const getSubAccList = (params) => { - return req("get", baseurl + "/auth/admin/sonIndex", params); -}; + return req("get", baseurl + "/auth/admin/sonIndex", params) +} //获取指定账号下的子账号列表 export const getsubAppoint = (id, params) => { - return req("get", baseurl + "/auth/admin/accountSonIndex/" + id, params); -}; + return req("get", baseurl + "/auth/admin/accountSonIndex/" + id, params) +} // 数据迁移获取角色下主账号(平级) export const getLevelSubList = (id) => { - return req("get", baseurl + "/auth/admin/roleAccounts/" + id); -}; + return req("get", baseurl + "/auth/admin/roleAccounts/" + id) +} //主账号数据向下迁移 export const putAcctransfer = (data) => { - return req("put", baseurl + "/auth/admin/downMigration", data); -}; + return req("put", baseurl + "/auth/admin/downMigration", data) +} // 主账号数据平行迁移 export const putequalMigration = (data) => { - return req("put", baseurl + "/auth/admin/equalMigration", data); -}; + return req("put", baseurl + "/auth/admin/equalMigration", data) +} // 角色管理 //角色管理列表 export const getRoleList = (params) => { - return req("get", baseurl + "/auth/adminRole", params); -}; + return req("get", baseurl + "/auth/adminRole", params) +} //角色获取权限列表 export const getMenuList = (params) => { - return req("get", baseurl + "/auth/menu/tree", params); -}; + return req("get", baseurl + "/auth/menu/tree", params) +} //角色删除 export const delRole = (id) => { - return req("delete", baseurl + "/auth/adminRole/" + id); -}; + return req("delete", baseurl + "/auth/adminRole/" + id) +} //角色添加 export const postRole = (data) => { - return req("post", baseurl + "/auth/adminRole", data); -}; + return req("post", baseurl + "/auth/adminRole", data) +} //角色编辑 export const putEditRole = (id, data) => { - return req("put", baseurl + "/auth/adminRole/" + id, data); -}; + return req("put", baseurl + "/auth/adminRole/" + id, data) +} //岗位列表 //新建公司 export const postCompany = (data) => { - return req("post", baseurl + "/auth/company", data); -}; + return req("post", baseurl + "/auth/company", data) +} //删除公司 export const delCompany = (id) => { - return req("delete", baseurl + "/auth/company/" + id); -}; + return req("delete", baseurl + "/auth/company/" + id) +} //编辑公司 export const postCompanyEdit = (id, data) => { - return req("put", baseurl + "/auth/company/" + id, data); -}; + return req("put", baseurl + "/auth/company/" + id, data) +} //新建部门 export const postDepartment = (data) => { - return req("post", baseurl + "/auth/department", data); -}; + return req("post", baseurl + "/auth/department", data) +} //删除部门 export const delDepartment = (id) => { - return req("delete", baseurl + "/auth/department/" + id); -}; + return req("delete", baseurl + "/auth/department/" + id) +} //编辑部门 export const postDepartmentEdit = (id, data) => { - return req("put", baseurl + "/auth/department/" + id, data); -}; + return req("put", baseurl + "/auth/department/" + id, data) +} //新建岗位 export const postDepartmentJob = (data) => { - return req("post", baseurl + "/auth/departmentJob", data); -}; + return req("post", baseurl + "/auth/departmentJob", data) +} //删除岗位 export const delDepartmentJob = (id) => { - return req("delete", baseurl + "/auth/departmentJob/" + id); -}; + return req("delete", baseurl + "/auth/departmentJob/" + id) +} //编辑岗位 export const postDepartmentJobEdit = (id, data) => { - return req("put", baseurl + "/auth/departmentJob/" + id, data); -}; + return req("put", baseurl + "/auth/departmentJob/" + id, data) +} //枚举 export const getAllEnum = (data) => { - return req("get", baseurl + "/enum", data); -}; + return req("get", baseurl + "/enum", data) +} //菜单维护 //新建菜单 export const postCreateMenu = (data) => { - return req("post", baseurl + "/auth/menu", data); -}; + return req("post", baseurl + "/auth/menu", data) +} //编辑菜单 export const putmodifyMenu = (id, data) => { - return req("put", baseurl + "/auth/menu/" + id, data); -}; + return req("put", baseurl + "/auth/menu/" + id, data) +} //删除菜单 export const delMenu = (id) => { - return req("delete", baseurl + "/auth/menu/" + id); -}; + return req("delete", baseurl + "/auth/menu/" + id) +} //添加定制化模板 export const postThemecustom = (data) => { - return upload("post", baseurl + "/plan/theme/custom", data); -}; + return upload("post", baseurl + "/plan/theme/custom", data) +} //添加定制化模板 export const copyThemecustom = (id, data) => { - return upload("put", baseurl + "/plan/theme/clone/" + id, data); -}; + return upload("put", baseurl + "/plan/theme/clone/" + id, data) +} //登录 export const postLogin = (data) => { - return req("login", baseurl + "/auth/login", data); -}; + return req("login", baseurl + "/auth/login", data) +} // logout退出登录 //连续输入三次,需验证码校验 export const getVerify = (params) => { - return req("post", baseurl + "/auth/login/verify", params); -}; + return req("post", baseurl + "/auth/login/verify", params) +} //获取用户信息接口 export const getUserinfo = (params) => { - return req("get", baseurl + "/auth/admin/userinfo", params); -}; + return req("get", baseurl + "/auth/admin/userinfo", params) +} //设置登录密码 export const putmodifySelf = (data) => { - return req("put", baseurl + "/auth/admin/setPassword", data); -}; + return req("put", baseurl + "/auth/admin/setPassword", data) +} //验证码登录发送验证码 export const postsendLoginCode = (data) => { - return req("post", baseurl + "/sms/sendLoginCode", data); -}; + return req("post", baseurl + "/sms/sendLoginCode", data) +} // 短信验证码登录 export const postLoginCode = (data) => { - return req("post", baseurl + "/auth/login/mobile", data); -}; + return req("post", baseurl + "/auth/login/mobile", data) +} // { // "mobile": "15184345039", // "code": "04593" @@ -719,122 +719,122 @@ export const postLoginCode = (data) => { //获取落地页下拉菜单 export const getThemeSel = (id) => { - return req("get", baseurl + "/plan/choice_theme"); -}; + return req("get", baseurl + "/plan/choice_theme") +} //获取落地页列表 export const getThemeList = (data) => { - return req("get", baseurl + "/plan/plan_theme", data); -}; + return req("get", baseurl + "/plan/plan_theme", data) +} //删除落地页 export const delTheme = (id) => { - return req("delete", baseurl + "/plan/theme/" + id); -}; + return req("delete", baseurl + "/plan/theme/" + id) +} //编辑模板 export const putMyTheme = (id, data) => { - return req("put", baseurl + "/plan/theme/" + id, data); -}; + return req("put", baseurl + "/plan/theme/" + id, data) +} export const getThemeChoice = (data) => { - return req("get", baseurl + "/plan/theme/choice", data); -}; + return req("get", baseurl + "/plan/theme/choice", data) +} //新增落地页模板 export const addTheme = (data) => { - return req("post", baseurl + "/plan/theme", data); -}; + return req("post", baseurl + "/plan/theme", data) +} //编辑落地页模板 export const putTheme = (id, data) => { - return req("put", baseurl + "/plan/plan_theme/" + id, data); -}; + return req("put", baseurl + "/plan/plan_theme/" + id, data) +} //我的模板列表查询 export const getTheme = (data) => { - return req("get", baseurl + "/plan/theme", data); -}; + return req("get", baseurl + "/plan/theme", data) +} //克隆落地页模板 export const cloneTheme = (data) => { - return req("put", baseurl + "/plan/theme/clone", data); -}; + return req("put", baseurl + "/plan/theme/clone", data) +} //获取系统模板 export const getSystemTemplate = (data) => { - return req("get", baseurl + "/plan/theme/system", data); -}; + return req("get", baseurl + "/plan/theme/system", data) +} //编辑系统模板 export const putSystemTemplate = (id, data) => { - return req("put", baseurl + "/plan/theme/system/" + id, data); -}; + return req("put", baseurl + "/plan/theme/system/" + id, data) +} //新增系统模板 export const addSystemTemplate = (data) => { - return req("post", baseurl + "/plan/theme/system", data); -}; + return req("post", baseurl + "/plan/theme/system", data) +} //删除系统模板 export const delSystemTemplate = (id) => { - return req("delete", baseurl + "/plan/theme/system/" + id); -}; + return req("delete", baseurl + "/plan/theme/system/" + id) +} //获取系统模板分类 export const getThemeType = () => { - return req("get", baseurl + "/plan/theme/getThemeType"); -}; + return req("get", baseurl + "/plan/theme/getThemeType") +} //key码列表 export const getkeyDetailList = (id, data) => { - return req("get", baseurl + "/key/" + id, data); -}; + return req("get", baseurl + "/key/" + id, data) +} //提交审核 export const approvals = (id, data) => { - return req("post", baseurl + "/plan/" + id + "/approvals", data); -}; + return req("post", baseurl + "/plan/" + id + "/approvals", data) +} export const getApprovalsInfo = (id, data) => { return req( "get", baseurl + "/approvals/" + id + "/market_approval_data", data - ); -}; + ) +} export const terminateApprovals = (id, data) => { - return req("put", baseurl + "/approvals/" + id + "/terminate", data); -}; + return req("put", baseurl + "/approvals/" + id + "/terminate", data) +} export const getApprovalsStatus = (id, data) => { - return req("get", baseurl + "/approvals/" + id + "/status"); -}; + return req("get", baseurl + "/approvals/" + id + "/status") +} //作废 export const keyBatchCancel = (data) => { - return req("put", baseurl + "/key/batch_cancel", data); -}; + return req("put", baseurl + "/key/batch_cancel", data) +} //作废 export const keyCancel = (data) => { - return req("put", baseurl + "/key/cancel", data); -}; + return req("put", baseurl + "/key/cancel", data) +} //标记使用 export const keyBatchUsage = (data) => { - return req("put", baseurl + "/key/batch_usage", data); -}; + return req("put", baseurl + "/key/batch_usage", data) +} //标记使用 export const keyUsage = (data) => { - return req("put", baseurl + "/key/usage", data); -}; + return req("put", baseurl + "/key/usage", data) +} //获取日志 export const getKeyLog = (data) => { - return req("get", baseurl + "/key/log/list", data); -}; + return req("get", baseurl + "/key/log/list", data) +} //白名单数据校验 export const getAccessVerification = (data) => { - return req("post", baseurl + "/keys/mobileAccessVerification", data); -}; + return req("post", baseurl + "/keys/mobileAccessVerification", data) +} //计划作废 export const planCancel = (id) => { - return req("put", baseurl + "/plan/cancel/" + id); -}; + return req("put", baseurl + "/plan/cancel/" + id) +} //key审批 export const keyApproval = (plan_id, key_id, data) => { @@ -842,65 +842,75 @@ export const keyApproval = (plan_id, key_id, data) => { "post", baseurl + "/plan/" + plan_id + "/keys/" + key_id + "/approval", data - ); -}; + ) +} export const keyEditApproval = (key_id, data) => { - return req("post", baseurl + "/keys/" + key_id + "/approval", data); -}; + return req("post", baseurl + "/keys/" + key_id + "/approval", data) +} // logout退出登录 //退出登录接口 export const postLogOut = (data) => { - return req("get", baseurl + "/auth/logout", data); -}; + return req("get", baseurl + "/auth/logout", data) +} // 请求分销商 export const getDirectList = (data) => { - return req("get", baseurl + "/reseller/direct", data); -}; + return req("get", baseurl + "/reseller/direct", data) +} // 获取预警人 export const getVoucherWarningAccount = () => { - return req("get", baseurl + "/auth/admin/voucherWarningAccount"); -}; + return req("get", baseurl + "/auth/admin/voucherWarningAccount") +} // 加款 export const addFund = (data, id) => { - return req("post", baseurl + `/codes/voucher/fund/${id}`, data); -}; + return req("post", baseurl + `/codes/voucher/fund/${id}`, data) +} // key列表 export const getKeysList = (data) => { - return req("get", baseurl + "/key", data); -}; + return req("get", baseurl + "/key", data) +} export const bachUploadAll = (url, file) => { - return upload("post", baseurl + url, file); -}; + return upload("post", baseurl + url, file) +} export const batchUploadVoid = (data) => { - return req("post", baseurl + `/key/batchUploadVoid`, data); -}; + return req("post", baseurl + `/key/batchUploadVoid`, data) +} export const batchUploadUsed = (data) => { - return req("post", baseurl + `/key/batchUploadUsed`, data); -}; + return req("post", baseurl + `/key/batchUploadUsed`, data) +} //批量发送 export const batchSend = (data) => { - return req("post", baseurl + `/keys/batchSend`, data); -}; + return req("post", baseurl + `/keys/batchSend`, data) +} // 批量导出 export const exportKey = (data) => { - return derive("get", baseurl + "/key/export", data); -}; + return derive("get", baseurl + "/key/export", data) +} // 复制,获取计划详情 export const get_copy_data = (data) => { - return req("get", baseurl + "/plan/get_copy_data/" + data); -}; + return req("get", baseurl + "/plan/get_copy_data/" + data) +} -export { req }; +// 获取key批次select +export const queryKeyBatch = (data) => { + return req("get", baseurl + "/keys/queryKeyBatch", data) +} + +// 获取营销计划select +export const queryPlans = (data) => { + return req("get", baseurl + "/plan/queryPlan", data) +} + +export { req } diff --git a/src/pages/exchangecode/exchangecodeAdd/index.jsx b/src/pages/exchangecode/exchangecodeAdd/index.jsx index 2398f6ab..937d6033 100644 --- a/src/pages/exchangecode/exchangecodeAdd/index.jsx +++ b/src/pages/exchangecode/exchangecodeAdd/index.jsx @@ -1,4 +1,4 @@ -import React from "react" +import React, { Fragment } from "react" import Ipt from "@/components/input/main" import Form from "@/components/form/main" import FormItem from "@/components/form-item/main" @@ -27,7 +27,10 @@ import { getProductInfoSelect, handelResponse, getCodesDetail, - putCodesBatch + putCodesBatch, + keyEditApproval, + queryPlans, + queryKeyBatch } from "@/assets/api.js" import _ from "lodash" import ProductForm from "../product/add" /* 商品 */ @@ -51,22 +54,76 @@ export default class exchangeAdd extends React.Component { const isState = ~~sessionStorage.getItem("isState") /*复制1 编辑2 */ code_batch_id = ~~sessionStorage.getItem("code_id") /* 兑换码id */ this.setState({ isState }) - if (isState === 1) { - /* 复制 */ - this.copyFunction() - } else if (isState === 2) { - /* 编辑 */ - this.editFunction() + + /* 编辑和复制时才调用 */ + if (isState) { + this.getDetailFunction() } else { - /* 新增 */ + sessionStorage.setItem("productData", []) + sessionStorage.setItem("knockGoldData", []) + this.getPlanSelect() } } + /* 请求归属营销计划下拉框数据 */ + getPlanSelect() { + queryPlans({ status: "3,4,5" }).then((res) => { + handelResponse( + res, + (req, msg) => { + const select = req.map((o) => { + return { key: o.id, text: o.title, ...o } + }) + this.setState({ planSelectData: select }) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + + /* 请求归属key下拉框数据 */ + getKeyBatchSelect(key) { + queryKeyBatch({ + status: "4,5", + plan_id: key + }).then((res) => { + handelResponse( + res, + (req, msg) => { + const select = req.map((o) => { + return { key: o.id, text: o.batch_name, ...o } + }) + this.setState({ keyBatchSelectData: select }) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + + /* 获取分销商 */ + getResellerFunction(reseller_id) { + getReseller(reseller_id).then((res) => { + handelResponse(res, (req1, msg) => { + this.setState({ + direct_reseller_id: req1.direct_reseller_id, + reseller: req1, + phone_list: req1.contact_phone, + email_list: req1.contact_email[0] + }) + }) + }) + } + /* 编辑处理数据 */ - editFunction() { + getDetailFunction() { let approval_id = sessionStorage.getItem("approval_id") let approval_status = sessionStorage.getItem("approval_status") - if (Number(approval_id) > 0) { + /* 判断是否是在审批中、状态是否时编辑 */ + if (Number(approval_id) > 0 && this.state.isState === 2) { //此处为审核中 getApprovalsInfo(approval_id) .then((res) => { @@ -80,20 +137,8 @@ export default class exchangeAdd extends React.Component { receive_email: req.receive_email } - //获取分销商 - getReseller(req.reseller_id).then((res) => { - handelResponse(res, (req1, msg) => { - req1.receive_email = req1.contact_email[0] - this.setState({ reseller: req1 }) - this.setState({ phone_list: req1.contact_phone }) - this.setState({ email_list: req1.contact_email }) - this.setState({ - direct_reseller_id: req1.direct_reseller_id - }) - }) - }) - this.setState({ reseller: resller_obj }) + this.getResellerFunction(req.reseller_id) req.update_product = [...this.transFormData1(req.update_product)] req.new_product = [...this.transFormData1(req.new_product, true)] @@ -128,7 +173,9 @@ export default class exchangeAdd extends React.Component { res, (req, msg) => { codeInfo.stock = req.stock - this.setState({ plan_time: req.plan.end_time }) + this.setState({ + plan_time: [req.plan.start_time, req.plan.end_time] + }) let reqCopy = _.cloneDeep(req) const resData = this.transFormData(reqCopy) this.setState({ oldTable: resData }) @@ -227,20 +274,20 @@ export default class exchangeAdd extends React.Component { range: reqCopy.goods } - this.setState({ plan_time: reqCopy.plan.end_time }) - //获取分销商 - getReseller(reqCopy.plan.reseller_id).then((res) => { - handelResponse(res, (req1, msg) => { - req1.receive_email = req1.contact_email[0] - this.setState({ reseller: req1 }) - this.setState({ phone_list: req1.contact_phone }) - this.setState({ email_list: req1.contact_email }) - this.setState({ - direct_reseller_id: req1.direct_reseller_id - }) - }) + /* 复制状态改变code_name */ + if (this.state.isState === 1) { + codeInfo.code_name = `${reqCopy.title}_${ + reqCopy.copy_count + 1 + }` + } + + this.setState({ + plan_time: [reqCopy.plan.start_time, reqCopy.plan.end_time] }) + //获取分销商 + this.getResellerFunction(reqCopy.plan.reseller_id) + this.setState({ codeInfo: codeInfo }) this.setState({ isload: true }) _.map(reqCopy.goods, (res) => { @@ -279,74 +326,6 @@ export default class exchangeAdd extends React.Component { } } - /* 复制处理数据 */ - copyFunction() { - getCodesDetail(code_batch_id) - .then((res) => { - handelResponse( - res, - (req, msg) => { - let reqCopy = _.cloneDeep(req) - const resData = this.transFormData(reqCopy) - reqCopy.goods = resData - let codeInfo = { - code_name: reqCopy.title /* 兑换码名称 count++ */, - issued: reqCopy.quantity, - stock: reqCopy.stock, - describe: reqCopy.describe, - date_time: [reqCopy.begin_time, reqCopy.end_time], - range: reqCopy.goods - } - - this.setState({ plan_time: reqCopy.plan.end_time }) - //获取分销商 - getReseller(reqCopy.plan.reseller_id).then((res) => { - handelResponse(res, (req1, msg) => { - req1.receive_email = req1.contact_email[0] - this.setState({ - reseller: req1, - phone_list: req1.contact_phone, - email_list: req1.contact_email, - direct_reseller_id: req1.direct_reseller_id - }) - }) - }) - - this.setState({ isload: true, codeInfo: codeInfo }) - _.map(reqCopy.goods, (res) => { - res.checked = true - return res - }) - this.setState({ tempdata: reqCopy.goods || [] }) - - let a1 = reqCopy.goods.map((item) => { - let obj = { - ...item, - in: true - } - return obj - }) - sessionStorage.setItem("productData", JSON.stringify(a1)) - sessionStorage.setItem("knockGoldData", JSON.stringify(a1)) - - let arr = [] - _.map(reqCopy.goods, (res) => { - let obj = {} - obj.key = res.only - obj.text = res.product_name - obj.id = res.id - this.state.oldProduct.push(res.id) - arr.push(obj) - return obj - }) - this.setState({ rankoptions: arr, rank: arr }) - }, - (err) => {} - ) - }) - .catch((err) => {}) - } - // 立减金 加款后 商品范围列表数据进行变动 getTableList() { if (sessionStorage.getItem("addMoneyData")) { @@ -494,6 +473,7 @@ export default class exchangeAdd extends React.Component { }) } + /* 编辑状态 数据整合 */ buildData() { let range = [] _.map(this.state.rank, (o) => { @@ -597,6 +577,47 @@ export default class exchangeAdd extends React.Component { return { data, addProduct, updateProduct } } + /* 复制\新增状态 数据整合 */ + copyOrAddBuildData() { + let range = [] + _.map(this.state.rank, (o) => { + range.push(o.text) + }) + + let selection = this.refs.tempdata.getSelectData() + const newData = { + begin_time: this.state.codeInfo.date_time[0], + end_time: this.state.codeInfo.date_time[1], + describe: this.state.codeInfo.describe, + quantity: this.state.codeInfo.issued, + range, + title: this.state.codeInfo.code_name, + product: [ + { + legal: selection.filter((item2) => item2.type == 1), + reduce: selection + .filter((item3) => item3.type === 2) + .map((item4) => item4.origin) + } + ] + } + + if (this.state.isState === 1) { + newData.copy_code_batch_id = code_batch_id + } + + let data = { + code_batch: newData, + reseller_id: this.state.reseller.id, + reseller_name: this.state.reseller.name, + company_name: this.state.reseller.company_name, + receive_email: this.state.reseller.contact_email[0], + payment_direction: this.state.payment_direction[this.state.paytype - 1] + } + return data + } + + /* 编辑状态下数据提交 */ submitCodeData() { if (!this.state.reseller) { Notify.error("该兑换码对应分销商不存在") @@ -625,13 +646,34 @@ export default class exchangeAdd extends React.Component { }) } + /* 复制\新增状态下数据提交 */ + submitCopyOrAddCodeData() { + let data = this.copyOrAddBuildData() + let id = sessionStorage.getItem("keybatch_id") + + keyEditApproval(id, data).then((res) => { + handelResponse( + res, + (req, msg) => { + Notify.success("成功发起审批") + setTimeout(() => { + window.history.back() + }, 1000) + }, + (err) => { + Notify.error(err) + } + ) + }) + } + submit() { - // if (this.state.direct_reseller_id <= 0) { - // // 老数据不能进行新增商品操作 - // Notify.error(`请添加映射分销商`) - // return - // } - if (this.refs.code_info.validator() && this.refs.code_rule.validator()) { + if (!(this.refs.code_info.validator() && this.refs.code_rule.validator())) { + return + } + + /* 编辑状态 */ + if (this.state.isState === 2) { if (this.state.uploading) { Notify.error("还有图片上传中,不可提交") return @@ -694,12 +736,33 @@ export default class exchangeAdd extends React.Component { ) }) } + } else { + /* 复制和新增状态 */ + let selection = this.refs.tempdata.getSelectData() + + if (this.state.uploading) { + return Notify.error("还有图片上传中,不可提交") + } + + if (selection.length < 1) { + return Notify.error("请绑定对象") + } + + if (!this.state.reseller) { + return Notify.error("该兑换码对应分销商不存在") + } + + this.setState({ audit_visible: true }) } } onConfirm() { this.setState({ audit_visible: false }) - this.submitCodeData() + if (this.state.isState !== 2) { + this.submitCopyOrAddCodeData() /* 复制、新增 */ + } else { + this.submitCodeData() /* 编辑 */ + } } addProduct(type) { @@ -878,9 +941,14 @@ export default class exchangeAdd extends React.Component { let isdisabled = false let str = moment(date).format("YYYY-MM-DD HH:mm:ss") - if (type == "end") { - isdisabled = moment(str).isAfter(this.state.plan_time) + if (type === "start") { + isdisabled = moment(str).isBefore(this.state.plan_time[0]) } + + if (type === "end") { + isdisabled = moment(str).isAfter(this.state.plan_time[1]) + } + return isdisabled } @@ -984,34 +1052,54 @@ export default class exchangeAdd extends React.Component { rules={codeInfo} ref='code_info' className='addform'> - - this.handleChange(e, "keyBatchId")} - clearable - value={this.state.codeInfo.keyBatchId} - options={this.state.rankoptions} - placeholder={"请选择"} - labelWidth={"0px"} - height={"36px"} - width={"520px"} - disabled={this.state.isState} - alignment={"left"} - /> - + {!this.state.isState ? ( + + this.handleChange(e, "keyBatchSelect")} + clearable + value={this.state.codeInfo.keyBatchSelect} + options={this.state.keyBatchSelectData} + placeholder={"请选择"} + labelWidth={"0px"} + height={"36px"} + width={"520px"} + disabled={this.state.isState} + alignment={"left"} + /> + + ) : null} + { date_time: "", range: "", stock: "", - planId: "", - keyBatchId: "" + planSelect: [] /* 归属计划 */, + keyBatchSelect: [] /* 归属key */ }, isload: false, tempdata: [],