package com.sifang.modules.customer.controller;

import com.sifang.modules.customer.Service.CrmReasonForApplicationService;
import com.sifang.modules.sunshine.SystemSetting.utils.Result;
import com.sifang.modules.sunshine.SystemSetting.utils.StringUtil;
import com.sifang.modules.supply.setting.service.CrmSupplyMaterialSettingService;
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}/crmReasonForApplication")
public class CrmReasonForApplicationController extends BaseController {

    @Autowired
    CrmReasonForApplicationService reasonForApplicationService;

    @RequestMapping(value = "findReasonForApplicationPage")
    public String materialTypePage(){
        return "modules/yangguang/customer/entry/reasonForApplicationPage";
    }

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

    @RequestMapping(value = "addReasonForApplication")
    public String addReasonForApplication(HttpServletRequest request, Model model){
        String id=request.getParameter("id");
        if(StringUtil.isNotBlank(id)){
            model.addAttribute("materialType",reasonForApplicationService.getTypeDetai(id));
        }
        return "modules/yangguang/customer/entry/addReasonForApplication";
    }

    @ResponseBody
    @RequestMapping(value = "saveReasonForApplication")
    public Result saveMReasonForApplication(HttpServletRequest request){
       String id=request.getParameter("id");
       String name=request.getParameter("name");
        reasonForApplicationService.saveMaterialType(name,id);
       return Result.ok();
    }

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



}
