package com.bohuikeji.delivery.backstage.controller.views;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.bohuikeji.delivery.backstage.entity.discount.*;
import com.bohuikeji.frame.module.admin.base.PageTemplateControllerBase;
import com.bohuikeji.frame.module.admin.entity.back.PageEntity;
import com.bohuikeji.frame.module.admin.entity.web.TableModel;
import com.bohuikeji.frame.module.admin.entity.web.block.ButtonBlock;
import com.bohuikeji.frame.module.admin.entity.web.template.TableTemplate;
import com.bohuikeji.frame.module.admin.enums.ButtonBlockEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.ArrayList;
import java.util.List;

/**
 * 代金券模块
 * @author 10552
 */
@Slf4j
@Controller
@RequestMapping("/views")
public class VoucherPage extends PageTemplateControllerBase {

    /**
     * 创建代金券
     *.setOnClick("sendAjax('"+ StaticComponent.ctx +"/discount/createCoupon','POST',getTableSelectOne())") c直接通过接口传参
     * @return
     */
    @GetMapping("/table/craete/voucher")
    public PageEntity craeteVoucher() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TDiscountMall> queryWrapper = getFranQueryWrapper();
        queryWrapper.notIn("dis_state","已过期");
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"新增优惠卷"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改优惠卷"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"开始发放").setOnClick("setColumn('dis_state','发放中')"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"暂停发放").setOnClick("setColumn('dis_state','已暂停')"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"结束").setOnClick("setColumn('dis_state','已结束')"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除优惠卷"));
        TableModel model= pageTemplate.getTableModel();
        model.setUrl("/discount/table/dis/mall/add");
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 优惠卷领取记录
     *
     * @return
     */
    @GetMapping("/table/receive/record")
    public PageEntity releaseVoucher() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TDiscountRecord> queryWrapper = getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.DELETE,"删除领取记录"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }
    /**
     * 客户下单使用优惠券记录
     *
     * @return
     */
    @GetMapping("/table/order/dis/record")
    public PageEntity recordList() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TDiscountOrder> queryWrapper = getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        //buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"创建规则"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }
    /**
     * 客户下单使用优惠券记录
     *
     * @return
     */
    @GetMapping("/table/order/dis/pattern/info")
    public PageEntity pattTnfo() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TDiscountPattern> queryWrapper = getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper);
        List<ButtonBlock> buts = new ArrayList<>(0);
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"添加优惠卷样式"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改优惠卷样式"));
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

    /**
     * 优惠卷购买记录
     * @return
     */
    @GetMapping("/table/dis/mall/pay")
    public PageEntity disPay() {
        TableTemplate pageTemplate = (TableTemplate) createPage(TableTemplate.class);
        QueryWrapper<TDiscountPay> queryWrapper = getFranQueryWrapper();
        pageTemplate.setQueryWrapper(queryWrapper.notIn("pay_status","已超时"));
        List<ButtonBlock> buts = new ArrayList<>(0);
        /*buts.add(ButtonBlock.createButton(ButtonBlockEnum.ADD,"添加优惠卷样式"));
        buts.add(ButtonBlock.createButton(ButtonBlockEnum.EDIT,"修改优惠卷样式"));*/
        pageTemplate.setBatchButton(buts);
        session.setAttribute("pageTemplate", pageTemplate);
        return PageEntity.page("/table/index");
    }

}
