package com.jwipc.tender.controller.pc;

import com.jwipc.tender.constant.ModuleConst;
import com.jwipc.tender.dto.TenderTemplateBaseDTO;
import com.jwipc.tender.logic.TenderTemplateLogic;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import static com.jwipc.tender.constant.ModuleConst.MODULE_ROOT;

/**
 * <p>招标模板相关页面</p>
 *
 * @author ZhangJie
 * @version 1.0
 * @since JDK 1.8
 */
@Controller
@RequiredArgsConstructor
@Slf4j
@RequestMapping(ModuleConst.MODULE_ROOT + "/template/page")
public class TenderTemplatePageController {
    private final TenderTemplateLogic tenderTemplateLogic;

    /**
     * 招标模板字段选择器 页面
     *
     * @return
     */
    @GetMapping("fieldSelector")
    public String fieldSelector() {
        return MODULE_ROOT + "/template/field_selector";
    }
    /**
     * 招标模板 列表页面
     *
     * @return
     */
    @GetMapping("index")
    public String index() {
        return MODULE_ROOT + "/template/index";
    }

    /**
     * 招标模板 新增和编辑页面
     *
     * @param type 0:正常;1复制;
     * @return
     */
    @GetMapping("detail")
    public String detail(@RequestParam(required = false, defaultValue = "0") Long id, Model model,
                         @RequestParam(required = false, defaultValue = "0") Integer type)
    {
        TenderTemplateBaseDTO dto=tenderTemplateLogic.getDetail(id);
        model.addAttribute("template", dto);
        model.addAttribute("type", type);
        return MODULE_ROOT + "/template/detail";
    }
}
