package com.jwipc.shopping.controller.pc;

import com.jwipc.shopping.constant.ModuleConst;
import com.jwipc.shopping.entity.ShoppingReceivingAddress;
import com.jwipc.shopping.logic.OnlineMallLogic;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 功能描述:
 *
 * @Author: zx
 * @Date: 2024/3/14 0014 15:05
 */
@Controller
@RequestMapping(ModuleConst.MODULE_ROOT + "/address/page")
@RequiredArgsConstructor
@Slf4j
public class ShoppingReceivingAddressPageController {

    @Autowired
    OnlineMallLogic onlineMallLogic;

    /**
     * 收货地址维护页面
     *
     * @return 页面
     */
    @RequestMapping("/index")
    public String receivingAddressIndex(){
        return ModuleConst.MODULE_ROOT + "/receiving/index";
    }


    /**
     * 商城比价中选择收货地址弹框
     *
     * @param model model
     * @param supCodes 已选择的供应商编码
     * @param singleSelect 表格是否单选 0:多选 1:单选
     * @param parentFrameName 父级iFrame的name值
     * @return 页面
     */
    @RequestMapping("/chose/address/dialog")
    public String choseSupDialog(Model model, String supCodes, Integer singleSelect, String parentFrameName){
        model.addAttribute("supCodes", supCodes);
        model.addAttribute("singleSelect", singleSelect);
        model.addAttribute("parentFrameName", parentFrameName);
        return ModuleConst.MODULE_ROOT + "/shopping/chose_address";
    }


    /**
     * 详情页面
     */
    @RequestMapping("/detail")
    public String detail(Model model, Long id) {
        ShoppingReceivingAddress receivingAddress;
        if (0L == id) {
            receivingAddress = new ShoppingReceivingAddress();
            receivingAddress.setId(id);
        } else {
            receivingAddress = onlineMallLogic.selectDetailById(id);
        }
        model.addAttribute("data", receivingAddress);
        return ModuleConst.MODULE_ROOT+"/receiving/detail";
    }


}
