黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
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
using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 底部时间选择控件
    /// </summary>
    public class BottomTimeSelectControl : BottomDialogCommon
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 结束事件(0:点击了取消  1:点击了确定,第二,三参数为时和分)
        /// </summary>
        public Action<int, int, int> FinishEvent = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 底部时间选择控件
        /// </summary>
        /// <param name="i_title">标题</param>
        /// <param name="clickBackClose">点击背景时,是否关闭弹窗</param>
        public BottomTimeSelectControl(string i_title = "", bool clickBackClose = true)
        {
            base.ClickBackClose = clickBackClose;
            base.StrTitle = i_title;
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="i_hour">默认选择时</param>
        /// <param name="i_minute">默认选择分</param>
        public void InitControl(int i_hour, int i_minute)
        {
            //已经初始化
            if (base.btnCancel != null) { return; }
 
            //初始化底层控件
            var frameWhiteBack = base.InitBaseControl();
            frameWhiteBack.Height = Application.GetRealHeight(297);
            frameWhiteBack.Y = frameWhiteBack.Parent.Height - Application.GetRealHeight(297 + 20);
 
            //选择的时与分
            int selectHour = 0;
            int selectMinute = 0;
 
            //取消
            base.btnCancel.ButtonClickEvent += (sender, e) =>
            {
                base.Close();
                this.FinishEvent?.Invoke(0, 0, 0);
                this.FinishEvent = null;
            };
            //确认
            base.btnConfirm.ButtonClickEvent += (sender, e) =>
            {
                //有选择了才能点确认
                if (selectHour != 0 || selectMinute != 0)
                {
                    base.Close();
                    this.FinishEvent?.Invoke(1, selectHour, selectMinute);
                    this.FinishEvent = null;
                }
            };
 
            //线
            var btnLine = new NormalViewControl(frameWhiteBack.Width, HdlControlResourse.BottomLineHeight, false);
            btnLine.BackgroundColor = CSS_Color.PromptingColor2;
            btnLine.Y = btnCancel.Bottom;
            frameWhiteBack.AddChidren(btnLine);
 
            //时间控件
            var pickerView = new UIPickerView();
            //时
            var strhour = Language.StringByID(StringId.h);
            //分
            var strMinute = Language.StringByID(StringId.m);
            //XX时
            var listHour = new List<string> { "00" + strhour };
            //XX分
            var listMinute = new List<string> { "00" + strMinute };
            for (int i = 1; i <= 23; i++)
            {
                listHour.Add(i.ToString().PadLeft(2, '0') + strhour);
            }
            for (int i = 1; i <= 58; i++)
            {
                listMinute.Add(i.ToString().PadLeft(2, '0') + strMinute);
            }
            pickerView.Height = frameWhiteBack.Height - btnLine.Bottom;
            pickerView.Width = frameWhiteBack.Width - Application.GetRealWidth(8) * 2;
            pickerView.Y = btnLine.Bottom;
            pickerView.Gravity = Gravity.CenterHorizontal;
            frameWhiteBack.AddChidren(pickerView);
            //默认索引
            var index1 = listHour.IndexOf(i_hour.ToString().PadLeft(2, '0') + strhour);
            if (index1 == -1) { index1 = 0; }
            var index2 = listMinute.IndexOf(i_minute.ToString().PadLeft(2, '0') + strMinute);
            if (index2 == -1) { index2 = 0; }
 
            pickerView.setNPicker(listHour, listMinute, null);
            pickerView.setCurrentItems(index1, index2, 0);
 
            pickerView.OnSelectChangeEvent = (value1, value2, value3) =>
            {
                //更改索引
                selectHour = Convert.ToInt32(listHour[value1].Substring(0, 2));
                selectMinute = Convert.ToInt32(listMinute[value2].Substring(0, 2));
            };
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 关闭界面
        /// </summary>
        public override void Close()
        {
            base.Close();
            this.FinishEvent = null;
        }
 
 
        #endregion
    }
}