import $http from "@/utils/httpRequest.js";
import city_data from "@/utils/country-level2-data.js";
import qs from "qs";

export const mer_admin = {
  /**
   * 登录
   * @param {object} params LoginParam
   * @param {number} params.type
   * @param {string} params.role
   * @param {string} params.username
   * @param {string} params.password
   * @param {string} params.mobile
   * @param {string} params.code
   * @returns
   */
  loginByAccount: params => {
    return $http.post(`/merchant-api/auth/login`, {
      ...params
    });
  },
  loginByMobile: params => {
    return $http.post(`/merchant-api/auth/sms/login`, {
      ...params,
      type: 2
    });
  },
  getYZM(mobile) {
    return $http.get(`/merchant-api/auth/login/code?mobile=${mobile}`);
  },
  getInfo() {
    return $http.get(`/merchant-api/auth/info`);
  },
  //商品管理
  //保存商品信息
  saveProduct: data => {
    return $http.post(`/merchant-api/product/save`, data);
  },
  //保存商品基本信息
  saveProductBase: data => {
    return $http.post(`/merchant-api/product/save/basic`, data);
  },
  //返回商品分类以及列表(聚合)
  getPolyProduct: data => {
    return $http.post(`/merchant-api/product/polymerization/list`, data);
  },
  //商品分页
  getProductPage: data => {
    return $http.post(
      `/merchant-api/product/page?pageNumber=${data.p.pageNumber}&pageSize=${data.p.pageSize}`,
      data
    );
  },
  //商品规格分页
  getProductSpecificationPage: data => {
    return $http.post(`/merchant-api/product/specification/page`, data);
  },
  //商品概况
  getProductOverview: data => {
    return $http.post(`/merchant-api/product/overview`, data);
  },
  //商户商品分类
  getProductCategory: data => {
    return $http.request({
      url: `/merchant-api/product/category/list`,
      method: "get",
      params: data
    });
  },
  //上架或下架
  putOnShelvesProducts: data => {
    return $http.post(`/merchant-api/product/batch/update/status`, data);
  },
  //批量删除商品
  BatchDeleteProducts: data => {
    return $http.post(`/merchant-api/product/batch/delete`, data);
  },
  //打折扣
  setDiscounts: data => {
    return $http.post(`merchant-api/activity/save`, data);
  },
  //获取销售单位
  getSaleUnit: data => {
    return $http.request({
      url: `/merchant-api/product/unit/list`,
      method: "get",
      params: data
    });
  },
  //文件上传
  uploadFile: () => {
    return `${window.SITE_CONFIG["baseUrl"]}/merchant-api/file/upload`;
  },
  //直接获取城市数据
  getCityOptions: () => {
    return city_data;
  },
  //省市县数据
  getCity: () => {
    return $http.get(`/merchant-api/common/pca`);
  },
  //添加运费模板
  addShippingTemplate: data => {
    return $http.post(`/merchant-api/shippingTemplates/add`, data);
  },
  //删除模板
  removeShippingTemplate: id => {
    return $http.post(
      `/merchant-api/shippingTemplates/delete`,
      qs.stringify({
        id
      }),
      {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
    );
  },
  //更新模板
  updateShippingTemplate: data => {
    return $http.post(`/merchant-api/shippingTemplates/update`, data);
  },
  //获取模板分页
  getShippingTemplatePage: data => {
    return $http.request({
      method: "get",
      url: "/merchant-api/shippingTemplates/page",
      params: data
    });
  },
  //获取配送模板列表
  getShippingTemplateList: data => {
    return $http.request({
      method: "get",
      url: "/merchant-api/shippingTemplates/list",
      params: data
    });
  },
  //获取模板详情
  getShippingTemplateInfo: id => {
    return $http.request({
      method: "get",
      url: "/merchant-api/shippingTemplates/detail",
      hidemsg: true,
      params: { id }
    });
  },
  //银行卡分页
  bankCardPage: data => {
    return $http.request({
      method: "get",
      url: "/merchant-api/bank/page",
      params: data
    });
  },
  //添加商家端私账银行卡
  bankCardAdd: data => {
    return $http.post(`/merchant-api/bank/pri-create`, data);
  },
  //添加商家端公账银行卡
  publicAccountBankCardAdd: data => {
    return $http.post(`/merchant-api/bank/pub-create`, data);
  },
  //删除银行卡
  bankCardDelete: data => {
    return $http.post(`/merchant-api/bank/delete?id=${data}`);
  },
  //设置默认银行卡
  defaultBank: data => {
    return $http.post(
      `/merchant-api/bank/default-bank?linkId=${data.linkId}&bankId=${data.bankId}`
    );
  },
  //获取银行卡详情
  bankCardDetail: id => {
    return $http.request({
      method: "get",
      url: "/merchant-api/bank/detail",
      params: { id }
    });
  },
  //市场下的店铺列表
  storeList: data => {
    return $http.request({
      method: "get",
      url: `/merchant-api/market/shop_list`,
      params: data
    });
  },
  //获取品牌信息
  getBrandInfo: () => {
    return $http.request({
      method: "get",
      url: `/merchant-api/brand/info`,
      params: {}
    });
  },
  //编辑品牌信息
  editBrandInfo: data => {
    return $http.put(`/merchant-api/brand/edit`, data);
  },
  //修改密码
  changePassword: data => {
    return $http.put(`/merchant-api/auth/change/pwd`, data);
  },
  //修改简单密码
  simplePassword: data => {
    return $http.put(`/merchant-api/auth/update_password`, data);
  },
  //修改管理员
  editAdmin: data => {
    return $http.put(`/merchant-api/brand/change/administrator`, data);
  },
  //获取验证码
  getCaptcha: data => {
    return $http.request({
      method: "get",
      url: `/merchant-api/brand/sms_code`,
      params: data
    });
  },
  //全部订单管理
  orderPage: data => {
    return $http.request({
      method: "get",
      url: `/merchant-api/manager/order/page`,
      params: data
    });
  },
  //根据店铺查询订单
  shopOrderPage: data => {
    return $http.request({
      method: "get",
      url: `/merchant-api/manager/merchant/order/page`,
      params: data
    });
  },
  // 轮播图分页
  bannerPage: data => {
    return $http.request({
      method: "get",
      url: `/admin-api/banner/page`,
      params: data
    });
  },
  // 轮播图添加
  bannerAdd: data => {
    return $http.post(`/admin-api/banner/add`, data);
  },
  //编辑轮播图
  bannerUpdate: data => {
    return $http.post(`/admin-api/banner/update`, data);
  },
  //删除轮播图
  bannerDelete: data => {
    return $http.post(`/admin-api/banner/delete`, data);
  },
  //排序轮播图
  sortBanner: data => {
    return $http.post(`/admin-api/banner/update/sort`, data);
  },
  // 公告分页
  noticePage: data => {
    return $http.request({
      method: "get",
      url: `/admin-api/notice/page`,
      params: data
    });
  },
  // 公告添加
  noticeAdd: data => {
    return $http.post(`/admin-api/notice/add`, data);
  },
  //编辑公告
  noticeUpdate: data => {
    return $http.post(`/admin-api/notice/update`, data);
  },
  //删除公告
  noticeDelete: data => {
    return $http.post(`/admin-api/notice/delete`, data);
  },
  //排序公告
  sortnotice: data => {
    return $http.post(`/admin-api/notice/update/sort`, data);
  },
  //品牌和分销商的订单
  distributorOrBrandOrderPage: data => {
    return $http.request({
      method: "get",
      url: `/merchant-api/backend/order/page`,
      params: data
    });
  },
  //订单概述
  orderOverview: data => {
    return $http.request({
      method: "get",
      url: `/merchant-api/backend/order/overview`,
      params: data
    });
  },
  /**
   * 获取申请记录
   * @param {object} data 查询参数
   * @returns {Promise}
   */
  getApplyRecord: data => {
    return $http.request({
      method: "get",
      url: "/merchant-api/distribution/apply_record",
      params: data
    });
  },
  /**
   * 审核申请记录
   * @param {object} data 审核参数
   * @returns {Promise}
   */
  auditApplyRecord: data => {
    return $http.request({
      method: "put",
      url: "/merchant-api/distribution/audit",
      params: data
    });
  },
  /**
   * 审核一键通过
   * @param {object} data 审核参数
   * @returns {Promise}
   */
  passAllApplyRecord: data => {
    return $http.request({
      method: "put",
      url: "/merchant-api/distribution/pass_all",
      params: data
    });
  },
  membershipEnableList: data => {
    return $http.post(`/merchant-api/membershipEnable/list`, data);
  },
  membershipEnableChange: data => {
    return $http.post(`/merchant-api/membershipEnable/changeEnable`, data);
  },
  membershipEnableGetSettings: data => {
    return $http.post(`/merchant-api/membershipEnable/getSettings`, data);
  },
  membershipEnableSaveSettings: data => {
    return $http.post(`/merchant-api/membershipEnable/saveSettings`, data);
  }
};
