package com.ihaoin.hooloo.device.view;

import android.Manifest;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Rect;
import android.hardware.display.DisplayManager;
import android.os.Build;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.ihaoin.hooloo.device.HLApplication;
import com.ihaoin.hooloo.device.R;
import com.ihaoin.hooloo.device.adapter.GoodsAdapter;
import com.ihaoin.hooloo.device.adapter.RecommendAdapter;
import com.ihaoin.hooloo.device.component.NetworkHandler;
import com.ihaoin.hooloo.device.config.AppConfig;
import com.ihaoin.hooloo.device.config.Base;
import com.ihaoin.hooloo.device.data.MainData;
import com.ihaoin.hooloo.device.data.ScrollBean;
import com.ihaoin.hooloo.device.data.vo.Category;
import com.ihaoin.hooloo.device.data.vo.Goods;
import com.ihaoin.hooloo.device.data.vo.Recommend;
import com.ihaoin.hooloo.device.data.vo.Sku;
import com.ihaoin.hooloo.device.network.HttpUtil;
import com.ihaoin.hooloo.device.util.CollectionUtils;
import com.ihaoin.hooloo.device.util.JsonUtils;
import com.ihaoin.hooloo.device.util.SharedPreferencesUtils;
import com.ihaoin.hooloo.device.util.StringUtils;
import com.ihaoin.hooloo.device.util.Utils;

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

public class LauncherActivity extends Activity {

    private RadioGroup groupCategory;
    private RecyclerView recGoods;
    private RecyclerView recRecommends;
//    private TextView rightTitle;

    private List<ScrollBean> scrollRecommends;
    private List<ScrollBean> scrollGoods;

    private GridLayoutManager recommendManager;
    private LinearLayoutManager goodsLayoutManager;

    private RecommendAdapter recommendAdapter;
    private GoodsAdapter goodsAdapter;
    //右侧title在数据中所对应的position集合
    private List<Integer> tPosition = new ArrayList<>();
    //记录商品当前可见的第一个item的position
    private int first = 0;
    private Context mContext;
    private TrolleyView trolleyView;
    private MenuPresentation menu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(AppConfig.DEBUG_TAG, "onCreate");
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_launcher);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        mContext = this;

        requestPermissions();

        trolleyView = findViewById(R.id.view_trolley);
        groupCategory = findViewById(R.id.group_category);
        recGoods = findViewById(R.id.rec_right);
        recRecommends = findViewById(R.id.rec_recommend);

        initRecommends();
        setRecommendsData();

        initCategorys();

        initGoods();
        setGoodsData();

        registTrolleyGoodsChangedReceiver();
        registTrolleyStateChangedReceiver();
        registSettingChangedReceiver();
        showMenuView();

        startLoadDataThread();
    }

    private void setMachineCode() {
        AppConfig.MACHINE_CODE = SharedPreferencesUtils.getMachineCode(this);
        if (AppConfig.DEBUG) {
            Log.i(AppConfig.DEBUG_TAG, "machine code: " + AppConfig.MACHINE_CODE);
        }
        startLoadDataThread();
    }

    private void initRecommends() {
        recommendManager = new GridLayoutManager(mContext, 2);
        recommendManager.setSpanSizeLookup(new MySpanSizeLookup());
        recRecommends.addItemDecoration(new RecyclerView.ItemDecoration() {
            @Override
            public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
                outRect.left = Utils.getDimens(LauncherActivity.this, R.dimen.padding10);
                outRect.bottom = Utils.getDimens(LauncherActivity.this, R.dimen.padding10);
            }
        });

        if (recommendAdapter == null) {
            recommendAdapter = new RecommendAdapter(this, R.layout.item_recommend, R.layout.item_logo);
            recRecommends.setAdapter(recommendAdapter);
            recRecommends.setLayoutManager(recommendManager);
        } else {
            recommendAdapter.notifyDataSetChanged();
        }

    }

    private void setRecommendsData() {
        List<Recommend> recommends = HLApplication.getMainData().getRecommends();
        scrollRecommends = new ArrayList<>();
        ScrollBean header = new ScrollBean(true, null);
        scrollRecommends.add(header);
        recommendAdapter.setNewData(scrollRecommends);
        if (CollectionUtils.isEmpty(recommends)) {
            return;
        }
        recommends.forEach(x -> scrollRecommends.add(new ScrollBean(new ScrollBean.ScrollItemBean(x, null))));
        recommendAdapter.setNewData(scrollRecommends);
    }

    class MySpanSizeLookup extends GridLayoutManager.SpanSizeLookup {
        @Override
        public int getSpanSize(int position) {
            Log.d("TEST", "position:" + position);
            if (position == 0 || position == 1) {
                return 2;
            }
            return 1;
        }
    }

    private void initGoods() {
        goodsLayoutManager = new LinearLayoutManager(mContext);
        if (goodsAdapter == null) {
            goodsAdapter = new GoodsAdapter(this, R.layout.item_goods, R.layout.item_goods_category);
            recGoods.setAdapter(goodsAdapter);
            recGoods.setLayoutManager(goodsLayoutManager);
        } else {
            goodsAdapter.notifyDataSetChanged();
        }
        goodsAdapter.setNewData(scrollGoods);

        // 商品滚动时同时设置分类变化
        recGoods.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                // 商品滚动时获取当前显示的第一个商品的分类名称
                int firstPosition = goodsLayoutManager.findFirstVisibleItemPosition();
                String title = "";
                if (first != firstPosition && firstPosition >= 0) {
                    //给first赋值
                    first = firstPosition;

                    //判断如果右侧可见的第一个item是否是header,设置相应的值
                    if (scrollGoods.get(first).isHeader) {
                        title = scrollGoods.get(first).header;
                    } else {
                        title = scrollGoods.get(first).t.getType();
                    }
                }

                // 遍历分类列表，设置选中分类
                List<Category> categorys = HLApplication.getMainData().getCategorys();
                for (Category category : categorys) {
                    if (category.getName().equals(title)) {
                        if (groupCategory.getCheckedRadioButtonId() == category.getId()) {
                            break;
                        }
                        groupCategory.check(category.getId());
                    }
                }

                if (isSlideToBottom(recGoods)) {
                    // 滚动到最下，选中最后一个分类
                    groupCategory.check(CollectionUtils.lastItem(categorys).getId());
                }
            }
        });
    }

    /** 判断RecyclerView是否滚动到最下面 */
    private boolean isSlideToBottom(RecyclerView recyclerView) {
        if (recyclerView == null) {
            return false;
        }
        if (recyclerView.computeVerticalScrollExtent() + recyclerView.computeVerticalScrollOffset() >= recyclerView.computeVerticalScrollRange()) {
            return true;
        }
        return false;
    }

    private void initCategorys() {
        groupCategory.removeAllViews();
        List<Category> categorys = HLApplication.getMainData().getCategorys();
        if (CollectionUtils.isEmpty(categorys)) {
            return;
        }
        for (int i = 0; i < categorys.size(); i++) {
            Category category = categorys.get(i);
            if (CollectionUtils.isEmpty(category.getGoods())) {
                return;
            }
            RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.MATCH_PARENT, RadioGroup.LayoutParams.WRAP_CONTENT);
            RadioButton view = (RadioButton) this.getLayoutInflater().inflate(R.layout.item_category, null);
            view.setText(category.getName());
            view.setId(category.getId());
            view.setTag(category);
            if (i == 0) {
                view.setChecked(true);
                view.getPaint().setFakeBoldText(true);
            }
            groupCategory.addView(view, layoutParams);

            view.setOnClickListener(v -> {
                Integer checkedId = v.getId();
                Category category1 = (Category) groupCategory.findViewById(checkedId).getTag();
                int position = categorys.indexOf(category1);
                goodsLayoutManager.scrollToPositionWithOffset(tPosition.get(position), 0);
            });
        }
        groupCategory.setOnCheckedChangeListener((group, checkedId) -> {
            for (int i = 0; i < groupCategory.getChildCount(); i++) {
                View child = groupCategory.getChildAt(i);
                if (!(child instanceof RadioButton)) {
                    continue;
                }
                RadioButton butn = (RadioButton) child;
                if (butn.getId() == checkedId) {
                    butn.getPaint().setFakeBoldText(true);
                } else {
                    butn.getPaint().setFakeBoldText(false);
                }
            }
        });

        // 添加温馨提示
        RadioGroup.LayoutParams layoutParams = new RadioGroup.LayoutParams(RadioGroup.LayoutParams.MATCH_PARENT, RadioGroup.LayoutParams.WRAP_CONTENT);
        TextView view = (TextView) this.getLayoutInflater().inflate(R.layout.item_tips, null);
        groupCategory.addView(view, layoutParams);
        view.setOnClickListener(v -> Utils.showTips(LauncherActivity.this));
    }

    private void setGoodsData() {
        List<Category> categorys = HLApplication.getMainData().getCategorys();
        if (CollectionUtils.isEmpty(categorys)) {
            return;
        }

        scrollGoods = new ArrayList<>();
        categorys.forEach(category -> {
            if (CollectionUtils.isEmpty(category.getGoods())) {
                return;
            }
            scrollGoods.add(new ScrollBean(true, category.getName()));
            category.getGoods().forEach(goods -> {
                scrollGoods.add(new ScrollBean(new ScrollBean.ScrollItemBean(goods, category.getName())));
            });
        });

        for (int i = 0; i < scrollGoods.size(); i++) {
            if (scrollGoods.get(i).isHeader) {
                //遍历右侧列表,判断如果是header,则将此header在右侧列表中所在的position添加到集合中
                tPosition.add(i);
            }
        }
        goodsAdapter.setNewData(scrollGoods);
    }

    private void startLoadDataThread() {
        loadData();
//        new Thread(() -> {
//            try {
//                while (true) {
//                    runOnUiThread(() -> loadData());
//                    Thread.sleep(1000 * 10);
//                }
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
//        }).start();
    }

    private LoadDataHandler loadDataHandler;

    private void loadData() {
        loadDataHandler = new LoadDataHandler();
        HttpUtil.getMainDatas(loadDataHandler);
    }

    class LoadDataHandler extends NetworkHandler {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            try {
                Object obj = msg.obj;
                if (msg.what == 0 || obj == null) {
                    Toast.makeText(LauncherActivity.this, R.string.error_load_main_data, Toast.LENGTH_SHORT).show();
                    return;
                }
//                String s = "{\"images\":{\"left\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/1.jpg\",\"right\":{\"closeDown\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/1.jpg\",\"inProduction\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/3.jpg\",\"thereAOrder\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/3.jpg\",\"noOrder\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/4.jpg\"}},\"tips\":\"www.baidu.com3\",\"countOfOrder\":\"223\",\"categorys\":[{\"id\":0,\"name\":\"今日特惠\",\"goods\":[{\"goodsId\":\"21\",\"name\":\"樱花初绽拿铁\",\"price\":\"22.00\",\"skus\":[{\"skuId\":\"75\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"1\"},{\"skuId\":\"76\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"77\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"78\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"79\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"80\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"81\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"82\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"83\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"84\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"85\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"86\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"}],\"discount\":\"12.00\",\"pics\":null,\"desc\":\"樱花初绽拿铁\",\"remarks\":\"樱花初绽拿铁\",\"tags\":[],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"55\",\"ruleName\":\"不加糖\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"56\",\"ruleName\":\"半塘\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"57\",\"ruleName\":\"标准糖\"}],\"specId\":\"46\",\"specName\":\"糖度\"}]},{\"goodsId\":\"25\",\"name\":\"经典手冲咖啡\",\"price\":\"40.00\",\"skus\":[],\"discount\":\"20.00\",\"pics\":null,\"desc\":\"永远经典\",\"remarks\":\"永远经典\",\"tags\":[\"1\"],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"}]},{\"goodsId\":\"24\",\"name\":\"冷萃咖啡\",\"price\":\"13.00\",\"skus\":[],\"discount\":\"10.00\",\"pics\":null,\"desc\":\"冷翠永远的神\",\"remarks\":\"加入推荐\",\"tags\":[\"1\"],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"}]}]},{\"id\":9,\"name\":\"浓缩咖啡\",\"goods\":[{\"goodsId\":\"21\",\"name\":\"樱花初绽拿铁\",\"price\":\"22\",\"skus\":[{\"skuId\":\"75\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"1\"},{\"skuId\":\"76\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"77\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"78\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"79\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"80\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"81\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"82\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"83\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"84\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"85\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"86\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"}],\"discount\":\"12\",\"pics\":{\"thumbnail\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"introImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"],\"introImagesApplet\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"],\"detailImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"],\"thumbnailApplet\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"detailImagesApplet\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"]},\"desc\":\"樱花初绽拿铁\",\"remarks\":\"樱花初绽拿铁\",\"tags\":[],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"55\",\"ruleName\":\"不加糖\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"56\",\"ruleName\":\"半塘\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"57\",\"ruleName\":\"标准糖\"}],\"specId\":\"46\",\"specName\":\"糖度\"}]},{\"goodsId\":\"22\",\"name\":\"燕麦丝绒拿铁\",\"price\":\"60\",\"skus\":[{\"skuId\":\"87\",\"state\":\"1\",\"price\":\"30.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"1\"},{\"skuId\":\"88\",\"state\":\"1\",\"price\":\"31.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"89\",\"state\":\"1\",\"price\":\"30.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"90\",\"state\":\"1\",\"price\":\"31.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"}],\"discount\":\"30\",\"pics\":{\"thumbnail\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"introImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"],\"detailImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"]},\"desc\":\"燕麦丝绒拿铁\",\"remarks\":\"燕麦丝绒拿铁\",\"tags\":[\"1\"],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"}]},{\"goodsId\":\"23\",\"name\":\"燕麦焦糖玛奇朵\",\"price\":\"22\",\"skus\":[],\"discount\":\"11\",\"pics\":{\"thumbnail\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"introImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"],\"detailImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"]},\"desc\":\"yyds\",\"remarks\":null,\"tags\":[\"1\"],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"}]}]},{\"id\":10,\"name\":\"冷萃咖啡\",\"goods\":[{\"goodsId\":\"24\",\"name\":\"冷萃咖啡\",\"price\":\"13\",\"skus\":[],\"discount\":\"10\",\"pics\":{\"thumbnail\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"introImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"],\"detailImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"]},\"desc\":\"冷翠永远的神\",\"remarks\":\"加入推荐\",\"tags\":[\"1\"],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"}]}]},{\"id\":11,\"name\":\"冲煮咖啡\",\"goods\":[{\"goodsId\":\"25\",\"name\":\"经典手冲咖啡\",\"price\":\"40\",\"skus\":[],\"discount\":\"20\",\"pics\":{\"thumbnail\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"introImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"],\"detailImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"]},\"desc\":\"永远经典\",\"remarks\":\"永远经典\",\"tags\":[\"1\"],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"}]},{\"goodsId\":\"26\",\"name\":\"雅致手冲咖啡\",\"price\":\"30\",\"skus\":[],\"discount\":\"11\",\"pics\":{\"thumbnail\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"introImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"],\"detailImages\":[\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\"]},\"desc\":\"雅致手冲咖啡\",\"remarks\":\"雅致手冲咖啡\",\"tags\":[\"1\"],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"}]}]}],\"recommends\":[{\"goodsName\":\"樱花初绽拿铁\",\"pic\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"desc\":\"店家推荐\",\"goods\":{\"goodsId\":\"21\",\"name\":\"樱花初绽拿铁\",\"price\":\"22.00\",\"skus\":[{\"skuId\":\"75\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"1\"},{\"skuId\":\"76\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"77\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"78\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"79\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"80\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"81\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"82\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"83\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"84\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"85\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"86\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"}],\"discount\":\"12.00\",\"pics\":null,\"desc\":\"樱花初绽拿铁\",\"remarks\":\"樱花初绽拿铁\",\"tags\":[],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"55\",\"ruleName\":\"不加糖\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"56\",\"ruleName\":\"半塘\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"57\",\"ruleName\":\"标准糖\"}],\"specId\":\"46\",\"specName\":\"糖度\"}]}},{\"goodsName\":\"经典手冲咖啡\",\"pic\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"desc\":\"店家推荐\",\"goods\":{\"goodsId\":\"21\",\"name\":\"樱花初绽拿铁\",\"price\":\"22.00\",\"skus\":[{\"skuId\":\"75\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"1\"},{\"skuId\":\"76\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"77\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"78\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"79\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"80\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"81\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"82\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"83\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"84\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"85\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"86\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"}],\"discount\":\"12.00\",\"pics\":null,\"desc\":\"樱花初绽拿铁\",\"remarks\":\"樱花初绽拿铁\",\"tags\":[],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"55\",\"ruleName\":\"不加糖\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"56\",\"ruleName\":\"半塘\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"57\",\"ruleName\":\"标准糖\"}],\"specId\":\"46\",\"specName\":\"糖度\"}]}},{\"goodsName\":\"冷萃咖啡\",\"pic\":\"https://hooloo-saas-test.oss-cn-beijing.aliyuncs.com/hooloo/2022/05/14/a.jpg\",\"desc\":\"店家推荐\",\"goods\":{\"goodsId\":\"21\",\"name\":\"樱花初绽拿铁\",\"price\":\"22.00\",\"skus\":[{\"skuId\":\"75\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"1\"},{\"skuId\":\"76\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"77\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"78\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"79\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"80\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"2\",\"ruleId\":\"51\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"81\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"82\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"83\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"0\",\"ruleId\":\"53\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"84\",\"state\":\"1\",\"price\":\"12.00\",\"rules\":[{\"price\":\"0\",\"ruleId\":\"55\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"85\",\"state\":\"1\",\"price\":\"13.00\",\"rules\":[{\"price\":\"1\",\"ruleId\":\"56\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"},{\"skuId\":\"86\",\"state\":\"1\",\"price\":\"14.00\",\"rules\":[{\"price\":\"2\",\"ruleId\":\"57\",\"specId\":\"46\"},{\"price\":\"1\",\"ruleId\":\"54\",\"specId\":\"45\"},{\"price\":\"1\",\"ruleId\":\"52\",\"specId\":\"44\"}],\"isDefault\":\"0\"}],\"discount\":\"12.00\",\"pics\":null,\"desc\":\"樱花初绽拿铁\",\"remarks\":\"樱花初绽拿铁\",\"tags\":[],\"specs\":[{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"51\",\"ruleName\":\"冰\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"52\",\"ruleName\":\"热\"}],\"specId\":\"44\",\"specName\":\"温度\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"53\",\"ruleName\":\"不加奶\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"54\",\"ruleName\":\"正常奶\"}],\"specId\":\"45\",\"specName\":\"加奶\"},{\"rules\":[{\"isDefault\":\"1\",\"isRecommend\":\"0\",\"price\":\"0\",\"ruleId\":\"55\",\"ruleName\":\"不加糖\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"1\",\"ruleId\":\"56\",\"ruleName\":\"半塘\"},{\"isDefault\":\"0\",\"isRecommend\":\"0\",\"price\":\"2\",\"ruleId\":\"57\",\"ruleName\":\"标准糖\"}],\"specId\":\"46\",\"specName\":\"糖度\"}]}}]}";
                MainData mainData = JsonUtils.getMapper().readValue(obj.toString(), MainData.class);
                HLApplication.setMainData(mainData);
                mainDataChanged();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    private void mainDataChanged() {
        setRecommendsData();
        initCategorys();
        setGoodsData();
        if (menu != null) {
            menu.mainDataChanged();
        }
    }

    @Override
    protected void onDestroy() {
        Log.d(AppConfig.DEBUG_TAG, "onDestroy");
        super.onDestroy();
        exit();
    }

    private void exit() {
        Log.d(AppConfig.DEBUG_TAG, "exit");
        this.unregistTrolleyGoodsChangedReceiver();
        this.unregistTrolleyStateChangedReceiver();
        this.unregistSettingChangedReceiver();
        System.exit(0);
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
        exit();
    }

    private TrolleyGoodsChangedReceiver trolleyGoodsChangedReceiver = null;
    private TrolleyStateChangedReceiver trolleyStateChangedReceiver = null;
    private SettingChangedReceiver settingChangedReceiver;

    /** 注册购物车广播 */
    private void registTrolleyGoodsChangedReceiver() {
        if (trolleyGoodsChangedReceiver == null) {
            trolleyGoodsChangedReceiver = new TrolleyGoodsChangedReceiver();
            IntentFilter intentFilter = new IntentFilter();
            intentFilter.addAction(Base.BROADCAST_ACTION_ADD_GOODS);
            intentFilter.addAction(Base.BROADCAST_ACTION_GOODS_CHANGED);
            intentFilter.addAction(Base.BROADCAST_ACTION_CLEAR_GOODS);
            this.registerReceiver(trolleyGoodsChangedReceiver, intentFilter);
        }
    }

    private void unregistTrolleyGoodsChangedReceiver() {
        if (trolleyGoodsChangedReceiver != null) {
            this.unregisterReceiver(trolleyGoodsChangedReceiver);
            trolleyGoodsChangedReceiver = null;
        }
    }

    /** 购物车操作广播接收器 */
    class TrolleyGoodsChangedReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Base.BROADCAST_ACTION_ADD_GOODS)) {
                Goods goods = (Goods) intent.getSerializableExtra("goods");
                Sku sku = (Sku) intent.getSerializableExtra("sku");
                Integer count = intent.getIntExtra("count", 1);
                trolleyView.prepareAddGoods(goods, sku, count);
            } else if (intent.getAction().equals(Base.BROADCAST_ACTION_GOODS_CHANGED)) {
                trolleyView.goodsChanged();
            } else if (intent.getAction().equals(Base.BROADCAST_ACTION_CLEAR_GOODS)) {
                trolleyView.clearTrolley();
            }
        }
    }

    private void registTrolleyStateChangedReceiver() {
        trolleyStateChangedReceiver = new TrolleyStateChangedReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Base.BROADCAST_ACTION_TROLLEY_SHOW);
        filter.addAction(Base.BROADCAST_ACTION_TROLLEY_HIDE);
        this.registerReceiver(trolleyStateChangedReceiver, filter);
    }

    private void unregistTrolleyStateChangedReceiver() {
        if (trolleyStateChangedReceiver != null) {
            mContext.unregisterReceiver(trolleyStateChangedReceiver);
            trolleyStateChangedReceiver = null;
        }
    }

    class TrolleyStateChangedReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (StringUtils.isEmpty(intent.getAction())) {
                return;
            }
            if (goodsAdapter == null) {
                return;
            }
            if (intent.getAction().equals(Base.BROADCAST_ACTION_TROLLEY_SHOW)) {
                goodsAdapter.setTrolleyState(true);
            } else {
                goodsAdapter.setTrolleyState(false);
            }
            goodsAdapter.notifyDataSetChanged();
        }
    }

    private void registSettingChangedReceiver() {
        settingChangedReceiver = new SettingChangedReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction(Base.BROADCAST_ACTION_MACHINE_CODE_CHANGED);
        filter.addAction(Base.BROADCAST_ACTION_MENU_STATE_CHANGED);
        filter.addAction(Base.BROADCAST_ACTION_LOGCAT_STATE_CHANGED);
        this.registerReceiver(settingChangedReceiver, filter);
    }

    private void unregistSettingChangedReceiver() {
        if (settingChangedReceiver != null) {
            mContext.unregisterReceiver(settingChangedReceiver);
            settingChangedReceiver = null;
        }
    }

    private class SettingChangedReceiver extends BroadcastReceiver {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(Base.BROADCAST_ACTION_MACHINE_CODE_CHANGED)) {
                setMachineCode();
            } else if (intent.getAction().equals(Base.BROADCAST_ACTION_MENU_STATE_CHANGED)) {
                if (SharedPreferencesUtils.getShowMenu(LauncherActivity.this)) {
                    showMenuView();
                } else {
                    hideMenuView();
                }
            } else if (intent.getAction().equals(Base.BROADCAST_ACTION_LOGCAT_STATE_CHANGED)) {
                if (SharedPreferencesUtils.getShowMenu(LauncherActivity.this)) {
                    Toast.makeText(LauncherActivity.this, "展示Logcat", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(LauncherActivity.this, "隐藏Logcat", Toast.LENGTH_SHORT).show();
                }
            }
        }
    }

    /** 显示菜单屏KDS */
    private void showMenuView() {
        if (AppConfig.DEBUG) {
            Toast.makeText(this, "展示菜单屏", Toast.LENGTH_SHORT).show();
        }
        if (menu != null) {
            return;
        }
        DisplayManager displayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
        Display[] displays = displayManager.getDisplays();
        if (CollectionUtils.isEmpty(displays) || displays.length < 2) {
            Toast.makeText(this, "未获取到菜单屏硬件", Toast.LENGTH_SHORT).show();
            return;
        }
        menu = new MenuPresentation(this, displays[1]);
        menu.show();
    }

    private void hideMenuView() {
        if (AppConfig.DEBUG) {
            Toast.makeText(this, "隐藏菜单屏", Toast.LENGTH_SHORT).show();
        }
        if (menu == null) {
            return;
        }
        menu.dismiss();
        menu = null;
    }

    private void requestPermissions() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            requestPermissions(new String[]{Manifest.permission.READ_PHONE_STATE, Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
        }
    }
}
