package com.jwipc.order.controller.pc;

import cn.hutool.core.util.StrUtil;
import com.jwipc.security.LoginUtil;
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 static com.jwipc.order.constant.ModuleConst.MODULE_ROOT;

/**
 * <p>
 * 采购订单明细页面
 * </p>
 *
 * @author wt
 * @version 1.0
 * @since 2024/3/4
 */
@Controller
@RequestMapping(MODULE_ROOT + "/purchaseOrderDetail/page")
@RequiredArgsConstructor
@Slf4j
public class PurchaseOrderDetailPageController {

    /**
     * 通过采购订单id获取采购订单明细数据
     *
     * @return
     */
    @GetMapping("index")
    public String list(Model model) {
        model.addAttribute("isSupplier", LoginUtil.isSupplier());
        return MODULE_ROOT + "/purchaseOrderDetail/index";
    }

    /**
     * 送货单创建页面
     *
     * @return
     */
    @GetMapping("listForDeliveryCreate")
    public String listForDeliveryCreate(Model model) {
        model.addAttribute("isSupplier", LoginUtil.isSupplier() ? 1 : 0);
        if (LoginUtil.isSupplier()) {
            model.addAttribute("supplierCode", LoginUtil.getSupplierCode());
        } else {
            model.addAttribute("supplierCode", StrUtil.EMPTY);
        }

        return MODULE_ROOT + "/purchaseOrderDetail/list_for_delivery_create";
    }

    /**
     * 采购订单行选择器
     *
     * @param supplierCode 供应商编码
     * @param singleSelect 是否单选 0:否 1:是
     * @param orderCode    采购订单号
     * @param factoryCode  工厂编码
     * @return 页面
     */
    @GetMapping("chosePurchaseDetail")
    public String chosePurchaseDetail(Model model, String supplierCode, Integer singleSelect, String orderCode,
                                      String factoryCode)
    {
        model.addAttribute("supplierCode", supplierCode);
        model.addAttribute("singleSelect", singleSelect);
        model.addAttribute("orderCode", orderCode);
        model.addAttribute("factoryCode", factoryCode);
        return MODULE_ROOT + "/purchaseOrderDetail/selectDialog";
    }

    /**
     * 计划行组件数据页面
     *
     * @param row       订单行号
     * @param planLine  计划行号
     * @param orderCode 采购订单号
     * @return 页面
     */
    @GetMapping("componentList")
    public String componentList(Model model, String orderCode, String row, String planLine)
    {
        model.addAttribute("orderCode", orderCode);
        model.addAttribute("row", row);
        model.addAttribute("planLine", planLine);
        return MODULE_ROOT + "/purchaseOrderDetail/component_list";
    }


}
