package com.sifang.modules.supply.setting.controller;


import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sunshine.SystemSetting.utils.StringUtil;
import com.sifang.modules.supply.setting.service.CrmSupplyDeliveryMethodService;
import com.sifang.modules.sys.util.LayuiPage;
import com.sifang.modules.sys.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@Controller
@RequestMapping(value = "${adminPath}/deliveryMethodSetting")
public class CrmSupplyDeliveryMethodController extends BaseController {

    @Autowired
    private CrmSupplyDeliveryMethodService deliveryMethodService;


    @RequestMapping(value = "deliveryMethodPage")
    public String deliveryMethodPage(){
        return "modules/yangguang/systemSetting/supplySetting/deliveryMethodPage";
    }

    @ResponseBody
    @RequestMapping(value = "deliveryMethodList")
    public Object deliveryMethodList(HttpServletRequest request) {
        Map<String, String> map = getParams(request);
        LayuiPage page = new LayuiPage(request);
        deliveryMethodService.deliveryMethodList(page,map);
        return page.renderJson();
    }

    @RequestMapping(value = "addDeliveryMethod")
    public String addDeliveryMethod(HttpServletRequest request, Model model){
        String id=request.getParameter("id");
        if(StringUtil.isNotBlank(id)){
            model.addAttribute("deliveryMethod",deliveryMethodService.getTypeDetai(id));
        }
        return "modules/yangguang/systemSetting/supplySetting/addDeliveryMethod";
    }

    @ResponseBody
    @RequestMapping(value = "saveDeliveryMethod")
    public Result saveDeliveryMethod(HttpServletRequest request){
        String id=request.getParameter("id");
        String name=request.getParameter("name");
        deliveryMethodService.saveDeliveryMethod(name,id);
        return Result.ok();
    }

    @ResponseBody
    @RequestMapping(value="deleteDeliveryMethod")
    public Result deleteDeliveryMethod(HttpServletRequest request){
        String ids=request.getParameter("ids");
        deliveryMethodService.deleteDeliveryMethod(ids);
        return Result.ok();
    }

}
