陈力
2023-05-27 f8db5417fbb2fc1155e5c931605e3a6e06409475
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package com.lotaai.canguiayw;
 
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
 
import androidx.fragment.app.Fragment;
 
import com.bin.david.form.core.SmartTable;
import com.bin.david.form.core.TableConfig;
import com.bin.david.form.data.CellInfo;
import com.bin.david.form.data.column.Column;
import com.bin.david.form.data.format.bg.IBackgroundFormat;
import com.bin.david.form.data.format.draw.IDrawFormat;
import com.bin.david.form.data.style.FontStyle;
import com.bin.david.form.data.table.TableData;
import com.blankj.utilcode.util.ScreenUtils;
import com.lotaai.canguiayw.sqllitedb.Order;
 
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
 
public class CunCanFragment extends Fragment {
 
    private View root;
    private Context context;
    private EditText editText;
    private SmartTable orderDetailTable;
 
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
 
    @Override
    public void onDestroy() {
        super.onDestroy();
    }
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        if (root == null) {
            root = inflater.inflate(R.layout.framgment_cuncan, container, false);
        }
        context = container.getContext();
        editText = (EditText)root.findViewById(R.id.edt_borrow_case_number);
        editText.setInputType(InputType.TYPE_NULL); // 屏蔽软键盘
        View.OnClickListener clickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int index = editText.getSelectionEnd();
                Editable editable = editText.getText();
                int key = v.getId();
                if (key == R.id.borrow_bt_delete) {
                    if (0 != index) {
                        editable.delete(index - 1, index);
                    }
                } else if (key == R.id.borrow_bt_confirm) {
                    // 调用后台
                    String gridNo = editable.toString();
                    if (null == gridNo || "".equals(gridNo.trim())) {
                        Toast.makeText(context, "取餐码不能为空。", Toast.LENGTH_SHORT).show();
                        return;
                    } else {
                        if (gridNo.length() > 5) {
                            Toast.makeText(context, "取餐码输入错误,请重试。", Toast.LENGTH_SHORT).show();
                            return;
                        }
                    }
                } else {
                    Button button = (Button) v;
                    editable.insert(index, button.getText());
                }
            }
        };
 
        View view1 = root.findViewById(R.id.borrow_bt1);
        View view2 = root.findViewById(R.id.borrow_bt2);
        View view3 = root.findViewById(R.id.borrow_bt3);
        View view4 = root.findViewById(R.id.borrow_bt4);
        View view5 = root.findViewById(R.id.borrow_bt5);
        View view6 = root.findViewById(R.id.borrow_bt6);
        View view7 = root.findViewById(R.id.borrow_bt7);
        View view8 = root.findViewById(R.id.borrow_bt8);
        View view9 = root.findViewById(R.id.borrow_bt9);
        View view0 = root.findViewById(R.id.borrow_bt0);
        View view11 = root.findViewById(R.id.borrow_bt_delete);
        View view12 = root.findViewById(R.id.borrow_bt_confirm);
        view1.setOnClickListener(clickListener);
        view2.setOnClickListener(clickListener);
        view3.setOnClickListener(clickListener);
        view4.setOnClickListener(clickListener);
        view5.setOnClickListener(clickListener);
        view6.setOnClickListener(clickListener);
        view7.setOnClickListener(clickListener);
        view8.setOnClickListener(clickListener);
        view9.setOnClickListener(clickListener);
        view0.setOnClickListener(clickListener);
        view11.setOnClickListener(clickListener);
        view12.setOnClickListener(clickListener);
 
        //初始化ttable
        initOrderDetailTableView();
        return root;
    }
 
 
    public void initOrderDetailTableView(){
        Column<String> xuhaoCol = new Column<>("", "gridNo");
        xuhaoCol.setMinWidth(10);
        xuhaoCol.setComputeWidth(1);
        Column<String> nameCol = new Column<>("名称", "orderNo");
        nameCol.setComputeWidth(10);
        Column<String> numCol = new Column<>("量", "putInDate");
        numCol.setWidth(10);
        nameCol.setComputeWidth(1);
 
        List<Order> lists = new ArrayList<>();
//        for (int i = 1;i <= 20; i++) {
//            Order order = new Order();
//            order.setGridNo(Integer.toString(i));
//            order.setOrderNo("new year char grenn" );
//            Date dd = new Date();
//            order.setPutInDate(6);
//            order.setState(0);
//            order.setTakeCode("56897");
//            lists.add(order);
//        }
 
        TableData<Order> tableData = new TableData<Order>("订单详情",lists, xuhaoCol,nameCol, numCol);
        //设置数据
        orderDetailTable = root.findViewById(R.id.table);
        orderDetailTable.getConfig().setShowTableTitle(true);
        orderDetailTable.getConfig().setTableTitleStyle(new FontStyle(30,Color.WHITE));
//        // 设置表格标题名称文字样式
//        setTable.getConfig().setTableTitleStyle(new FontStyle(30, Color.GREEN));
        orderDetailTable.getConfig().setMinTableWidth(ScreenUtils.getScreenWidth()/2 -40);
        // 设置表格标题文字样式
        orderDetailTable.getConfig().setColumnTitleStyle(new FontStyle(30, Color.WHITE));
 
        IBackgroundFormat backgroundFormat = new IBackgroundFormat() {
            @Override
            public void drawBackground(Canvas canvas, Rect rect, Paint paint) {
                canvas.drawColor(getResources().getColor(R.color.DarkGray));
            }
        };
        orderDetailTable.getConfig().setColumnTitleBackground(backgroundFormat);
        // 设置表格主体内容文字样式
        orderDetailTable.getConfig().setContentStyle(new FontStyle(30, Color.WHITE));
//        setTable.setZoom(true,1,0.5f);                     //开启缩放功能
        orderDetailTable.getConfig().setShowXSequence(false);      //去掉表格顶部字母
        orderDetailTable.getConfig().setShowYSequence(false);      //去掉左侧数字
 
        // 设置表格主标题
        orderDetailTable.setTableData(tableData);
 
    }
}