Bookings.tsx 15.6 KB
Newer Older
1
import React, { useState, useEffect, useRef } from 'react';
maple's avatar
maple committed
2
import styles from './css/Bookings.less';
3 4 5 6 7 8 9 10 11 12 13 14
import './css/Bookings.less';
import {
  Spin,
  Input,
  DatePicker,
  Button,
  Form,
  Radio,
  TimePicker,
  Row,
  Col,
  message,
cellee's avatar
cellee committed
15
  Select,
16
} from 'antd';
maple's avatar
maple committed
17
const { RangePicker } = TimePicker;
maple's avatar
maple committed
18

19
import { DollarOutlined, ClockCircleOutlined } from '@ant-design/icons';
maple's avatar
maple committed
20

21
import { connect } from 'umi';
maple's avatar
maple committed
22 23

import TitleBack from '../../../components/TitleBack/TitleBack';
maple's avatar
maple committed
24 25 26
import SearchOptionsCommnity from '../../../components/SearchOptions/SearchOptionsCommnity';

import { numberToString } from '../../../utils/string';
maple's avatar
maple committed
27 28
import { checkData, checkInput } from '@/utils/method';
import { validateMessages } from '@/utils/params';
29 30 31 32

// 日期
import moment from 'moment';
import { BookingsTip } from '@/utils/tip';
cellee's avatar
cellee committed
33
// 自定义时间段
cellee's avatar
cellee committed
34
import OnTime from '@/components/OnTime/OnTime';
cellee's avatar
cellee committed
35
import { getNumber } from '@/utils/string'; // 正则
cellee's avatar
cellee committed
36

37
const Bookings = (props: any) => {
cellee's avatar
cellee committed
38
  const { dispatch, Data3, Result, DataSave, token, load, resultTime } = props;
39 40 41 42 43 44 45 46 47 48 49 50 51 52

  const RA = (index: any, values: any) => {
    dispatch({ type: 'FacilityBookings/RA', playload: { index: index, body: values } });
  };
  const IA = () => {
    dispatch({ type: 'FacilityBookings/IA' });
  };
  const SAClear = () => {
    dispatch({ type: 'FacilityBookings/SA', playload: null });
  };
  const ResultClear = () => {
    dispatch({ type: 'FacilityBookings/ResultClear' });
  };

maple's avatar
maple committed
53
  const [comminityValues, setComminityValues] = useState(null);
cellee's avatar
cellee committed
54
  // 已选设施列表信息
55 56 57 58 59
  const [curString, setCurString] = useState({
    communityManagerFee: null,
    communityMargin: null,
    categoriesOpenTime: null,
  } as any);
maple's avatar
maple committed
60
  const [loading, setLoading] = useState(false);
cellee's avatar
cellee committed
61 62

  const formRef = useRef(null as any);
maple's avatar
maple committed
63

cellee's avatar
cellee committed
64 65 66
  const [prohibit, setProhibit] = useState(true); // 输入框是否不可选
  const [result, setResultTime] = useState(resultTime); // 已预约时间段
  const [soltTime, setSoltTime] = useState(['', '']); // 已选时间
67

68 69
  const [bookTime, setBookTime] = useState(1); // 默认延后预订时间

maple's avatar
maple committed
70
  useEffect(() => {
71 72 73 74 75
    if (DataSave != null) {
      console.log('页面进入参数');
      console.log(DataSave);
      setComminityValues(DataSave.communityName);
      RA(1, { userToken: token, communityName: DataSave.communityName, facilitieId: DataSave.id });
maple's avatar
maple committed
76
    }
77
  }, [DataSave]);
maple's avatar
maple committed
78

maple's avatar
maple committed
79
  useEffect(() => {
80 81 82
    IA();
  }, []);

maple's avatar
maple committed
83
  useEffect(() => {
maple's avatar
maple committed
84
    if (Result != null) {
85
      console.log(Result);
maple's avatar
maple committed
86 87
      message.error(Result.msg);
      if (Result.index == 1) {
88
        IA();
maple's avatar
maple committed
89
      }
90 91
      setLoading(false);
      ResultClear();
maple's avatar
maple committed
92
    }
93 94
  }, [Result]);

cellee's avatar
cellee committed
95
  console.log(Data3);
96 97 98 99 100 101
  // 选择小区监听是不是有值
  useEffect(() => {
    setLoading(false);
    if (!Data3) {
      // 如果没有值 要把Data3 从 false  复原成  null   并提示
      dispatch({ type: 'FacilityBookings/returnPage3' });
cellee's avatar
cellee committed
102 103 104 105 106
      // 再次把下方判断条件清空 和 禁用
      setCurString({ communityManagerFee: null });
      setProhibit(true);
      setResultTime(null);
      setSoltTime([]);
maple's avatar
maple committed
107
    }
108
  }, [Data3]);
maple's avatar
maple committed
109

cellee's avatar
cellee committed
110 111 112 113 114 115 116
  // 监听 已选时间段
  useEffect(() => {
    if (resultTime != null) {
      setResultTime(resultTime);
    }
  }, [resultTime]);

117
  const format = 'HH:mm';
maple's avatar
maple committed
118 119

  const checkParam = (values: any) => {
120
    var flag = true;
maple's avatar
maple committed
121 122 123 124

    for (var i in values) {
      // console.log(values[i]);
      if (values[i] == null) {
125
        flag = false;
maple's avatar
maple committed
126
      } else {
127 128 129 130
        if (values[i].length == 0) {
          flag = false;
        }
      }
maple's avatar
maple committed
131
    }
132 133
    return flag;
  };
maple's avatar
maple committed
134

cellee's avatar
cellee committed
135
  // 保存提交
136 137
  const onFinish = (value: any) => {
    var tmp = value;
cellee's avatar
cellee committed
138 139 140
    // 判断时间选择
    if (soltTime.length < 2 || !soltTime[0]) {
      message.error('Please Fill In The Appointment Period!');
cellee's avatar
cellee committed
141 142 143 144 145 146
      return false;
    }
    // 手机判断
    if (tmp.accountPhone.length != 11 && tmp.accountPhone.length != 8) {
      message.error('Please Fill In The Contact Information Correctly!');
      return false;
cellee's avatar
cellee committed
147
    }
maple's avatar
maple committed
148 149 150 151 152
    // tmp.categoriesId = null
    // tmp.facilitiesId = null
    // tmp.communityName = null
    // tmp.communityManagerFee = null
    // tmp.communityMargin=null
maple's avatar
maple committed
153
    if (value.categoriesName != null) {
154 155 156
      tmp.categoriesId = value.categoriesName.categoriesId;
      tmp.facilitiesId = value.categoriesName.facilitiesId;
      tmp.categoriesName = value.categoriesName.categoriesName;
maple's avatar
maple committed
157
    }
158
    if (value.subscribeDate != null) {
cellee's avatar
cellee committed
159
      tmp.subscribeDate = value.subscribeDate.format('YYYY-MM-DD');
maple's avatar
maple committed
160 161 162
    }
    if (value.reservedTimeList != null) {
    }
163 164
    if (comminityValues != null) {
      tmp.communityName = comminityValues;
maple's avatar
maple committed
165
    }
maple's avatar
maple committed
166
    if (curString != null) {
167 168
      tmp.communityManagerFee = numberToString(curString.communityManagerFee);
      tmp.communityMargin = numberToString(curString.communityMargin);
maple's avatar
maple committed
169
    }
170 171
    if (tmp.accountName.length < 2) {
      message.error('User Name Should be limit 2~30!', 3);
maple's avatar
maple committed
172
    } else {
cellee's avatar
cellee committed
173 174
      tmp.reservedTimeList = soltTime; // 预约时间
      RA(11, tmp);
maple's avatar
maple committed
175
      //还差检测
cellee's avatar
cellee committed
176 177 178 179 180 181
      // if (checkParam(tmp)) {
      //   console.log(tmp);
      //   RA(11, tmp);
      // } else {
      //   message.error('Error,Please Finish It,Not Empty!', 3);
      // }
maple's avatar
maple committed
182
    }
183
    // console.log(checkParam(tmp))
maple's avatar
maple committed
184 185
    // console.log(comminityValues)
    // console.log(tmp)
186
  };
cellee's avatar
cellee committed
187
  // 选择设施
188
  const RadioChoose = (e: any) => {
maple's avatar
maple committed
189
    Data3.map((item: any, index: any) => {
190
      item.categorieList.map((thing: any, i: any) => {
cellee's avatar
cellee committed
191
        console.log(thing);
192
        if (thing.categoriesId == e.target.value.categoriesId) {
maple's avatar
maple committed
193
          setCurString({
194 195 196
            communityManagerFee: parseInt(item.communityManagerFee).toFixed(2),
            communityMargin: parseInt(item.communityMargin).toFixed(2),
            categoriesOpenTime: item.categoriesOpenTime,
cellee's avatar
cellee committed
197 198
            categoriesId: thing.categoriesId,
            facilitiesId: thing.facilitiesId,
199 200 201 202
          });

          // 选择后取消输入框禁止
          setProhibit(false);
203
          // 赋值给延后天数
cellee's avatar
cellee committed
204
          setBookTime(-item.canReservationDay + 1);
maple's avatar
maple committed
205 206 207
          // console.log(item.communityManagerFee)
          // console.log(item.communityMargin)
        }
208 209 210 211 212 213 214 215 216 217
      });
    });
  };

  // 选择小区名字发起请求
  const getFacility = (values: any) => {
    SAClear();
    setComminityValues(values);
    RA(1, { userToken: token, communityName: values });
    setLoading(true);
cellee's avatar
cellee committed
218 219 220 221 222 223 224
    // 如果切换了小区 再次把下方判断的内容清空 和 禁用
    setCurString({
      communityManagerFee: null,
    });
    setProhibit(true);
    setResultTime(null);
    setSoltTime([]);
cellee's avatar
cellee committed
225
    // formRef.current.resetFields({ accountName: null }); // 清空已填写的表单
226 227 228 229
  };

  // 设置之前时间不能选择
  function disabledDate(current: any) {
230
    return current && current <= moment().subtract(bookTime, 'days').endOf('day');
maple's avatar
maple committed
231
  }
232 233 234 235

  // 确认日期
  const confirmData = (value: any) => {
    console.log(value);
cellee's avatar
cellee committed
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
    let data = {
      categoriesId: curString.categoriesId,
      facilitiesId: curString.facilitiesId,
      subscribeDate: moment(value).format('YYYY-MM-DD'),
    };

    RA(50, data);
  };

  // 下拉选择
  const startTimes = (value: any) => {
    let s = soltTime;
    s[0] = value;
    setSoltTime(s);
  };
  // 结束时间
  const endTimes = (value: any) => {
    let s = soltTime;
    s[1] = value;
    setSoltTime(s);
256 257
  };

cellee's avatar
cellee committed
258 259 260 261 262 263 264 265 266 267
  // 正则手机号
  const keyup_tool = (value: any) => {
    return getNumber(value.replace(/[^\d^\.]+/g, ''));
  };

  // 手机号
  const keyup_communityManagerFee = (e: any) => {
    e.target.value = keyup_tool(e.target.value);
  };

maple's avatar
maple committed
268 269 270 271
  return (
    <div className={styles.base}>
      {/* 头部组件v1.2 */}
      <TitleBack title="Facility Bookings" />
272

maple's avatar
maple committed
273
      <div className={styles.box1}>
274
        <div className={styles.box1item1}>Project : </div>
maple's avatar
maple committed
275
        <div className={styles.box1item2}>
276 277 278 279 280
          <Spin spinning={loading} tip="Finding...">
            <SearchOptionsCommnity
              alone={true}
              placeholder={'Community Name'}
              opname={getFacility}
cellee's avatar
cellee committed
281
              defaultName={DataSave != null ? DataSave.communityName : null}
282 283
              // onSubmit={getFacility}
            />
maple's avatar
maple committed
284 285
          </Spin>
          {/* <Input.Search style={{ width: 200, height: 32 }} onSearch={getFacility} loading={loading} defaultValue={}/> */}
maple's avatar
maple committed
286 287
        </div>
      </div>
cellee's avatar
cellee committed
288
      {Data3 && Data3.length > 0 ? (
maple's avatar
maple committed
289
        <>
290
          <Form ref={formRef} name="basic" onFinish={onFinish} validateMessages={validateMessages}>
cellee's avatar
cellee committed
291
            <div className="box2 required">
292
              <div className={styles.box2item1}>Facility Bookings : </div>
maple's avatar
maple committed
293
              <div className={styles.box2item2}>
294 295 296 297 298 299 300 301 302 303 304
                <Form.Item name="categoriesName">
                  <Radio.Group defaultValue={1} onChange={RadioChoose}>
                    {Data3.map((item: any, index: any) => {
                      var tmp = new Array();
                      item.categorieList.map((thing: any, i: any) => {
                        tmp.push(
                          <Radio key={thing.categoriesId} value={thing}>
                            {thing.categoriesName}
                          </Radio>,
                        );
                      });
305

306 307
                      return tmp;
                    })}
maple's avatar
maple committed
308
                  </Radio.Group>
309 310
                </Form.Item>
              </div>
maple's avatar
maple committed
311
            </div>
312 313
            <div className={styles.line}></div>

cellee's avatar
cellee committed
314
            <div className="box3 required">
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
              <div className={styles.box3item1}>User Name : </div>
              <div className={styles.box3item2}>
                <Form.Item name="accountName" rules={BookingsTip[0]}>
                  <Input
                    style={{ width: 200 }}
                    placeholder="Name Of Subscriber"
                    disabled={prohibit}
                  />
                </Form.Item>
              </div>
              <div className={styles.box3item3}>Contact Details : </div>
              <div className={styles.box3item4}>
                <Form.Item name="accountPhone" rules={BookingsTip[1]}>
                  <Input
                    style={{ width: 200 }}
                    placeholder="Contact Information"
                    disabled={prohibit}
cellee's avatar
cellee committed
332 333
                    onKeyUp={keyup_communityManagerFee}
                    maxLength={11}
334 335 336
                  />
                </Form.Item>
              </div>
maple's avatar
maple committed
337
            </div>
338

cellee's avatar
cellee committed
339
            <div className="box4 required">
340 341 342
              <div className={styles.box4item1}>Unit : </div>
              <div className="divbox4">
                <Form.Item name="buildNumber" rules={BookingsTip[2]}>
cellee's avatar
cellee committed
343 344 345 346 347 348 349
                  <Input
                    placeholder="Blk"
                    style={{ width: 80 }}
                    disabled={prohibit}
                    onKeyUp={keyup_communityManagerFee}
                    maxLength={10}
                  />
350 351 352
                </Form.Item>
                <span className="jio">#</span>
                <Form.Item name="floorNumber" rules={BookingsTip[3]}>
cellee's avatar
cellee committed
353 354 355 356 357 358 359
                  <Input
                    placeholder="Floor"
                    style={{ width: 80 }}
                    disabled={prohibit}
                    onKeyUp={keyup_communityManagerFee}
                    maxLength={10}
                  />
360 361 362 363 364 365
                </Form.Item>
                <span className="heng">--</span>
                <Form.Item name="roomNumber" rules={BookingsTip[4]}>
                  <Input placeholder="Room" style={{ width: 80 }} disabled={prohibit} />
                </Form.Item>
              </div>
maple's avatar
maple committed
366
            </div>
367 368
            <div className={styles.line}></div>

cellee's avatar
cellee committed
369
            <div className="box5 required">
370 371 372 373 374 375 376 377 378 379 380 381 382 383
              <div className={styles.box5item1}>Booking Schedule : </div>
              <div className={styles.box5item2}>
                <Row gutter={8}>
                  <Col>
                    <Form.Item name="subscribeDate" rules={BookingsTip[5]}>
                      <DatePicker
                        placeholder="Select Date"
                        disabledDate={disabledDate}
                        onChange={confirmData}
                        disabled={prohibit}
                      />
                    </Form.Item>
                  </Col>
                  <Col>
cellee's avatar
cellee committed
384 385 386 387 388 389 390
                    <Form.Item label="Opening Hours" className="required">
                      <Form.Item name="startTime" noStyle>
                        <OnTime
                          placeholder={'Start Time'}
                          disabled={prohibit}
                          limit={curString.categoriesOpenTime}
                          openSelect={startTimes}
cellee's avatar
cellee committed
391
                          type={0}
cellee's avatar
cellee committed
392 393 394 395 396
                        />
                      </Form.Item>
                      <span className="diyspan">-</span>
                      <Form.Item name="endTime" noStyle>
                        <OnTime
cellee's avatar
cellee committed
397 398 399 400 401
                          placeholder={'Closing Time'} // 默认值
                          disabled={prohibit} // 是否禁止
                          limit={curString.categoriesOpenTime} // 禁止时间段
                          openSelect={endTimes} //  时间类型
                          type={1}
cellee's avatar
cellee committed
402 403
                        />
                      </Form.Item>
404 405 406
                    </Form.Item>
                  </Col>
                </Row>
maple's avatar
maple committed
407
              </div>
408
            </div>
cellee's avatar
cellee committed
409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426

            {/* 提示已选时间段 */}
            {result != null && result.length > 0 ? (
              <div className={styles.box3}>
                <div className={styles.box3item1}>Reserved Time Period:</div>
                <div className="boxdiyitem">
                  {result.map((item: any, index: any) => {
                    return (
                      <span className="diyspan3" key={index}>
                        {item}
                      </span>
                    );
                  })}
                </div>
              </div>
            ) : null}

            {curString.communityManagerFee != null && Data3 ? (
427 428 429 430 431 432 433
              <>
                <div className={styles.box6}>
                  <div className={styles.box6item1}>Management fee required : </div>
                  <div className={styles.box6item2}>
                    <DollarOutlined style={{ color: '#999' }} /> {curString.communityManagerFee}
                  </div>
                </div>
maple's avatar
maple committed
434

435 436 437 438 439 440
                <div className={styles.box6}>
                  <div className={styles.box6item1}>Deposit is required : </div>
                  <div className={styles.box6item2}>
                    <DollarOutlined style={{ color: '#999' }} /> {curString.communityMargin}
                  </div>
                </div>
maple's avatar
maple committed
441

442 443 444 445 446 447 448 449 450 451 452 453 454
                <div className={styles.box6}>
                  <div className={styles.box6item1}>Opening Hours : </div>
                  <div className={styles.box6item2}>
                    <ClockCircleOutlined style={{ color: '#999' }} /> {curString.categoriesOpenTime}
                  </div>
                </div>
              </>
            ) : null}

            <div className={styles.line}></div>
            <Button
              htmlType="submit"
              type="primary"
cellee's avatar
cellee committed
455 456
              loading={load}
              disabled={prohibit}
457 458 459 460
              style={{ width: 80, height: 32 }}
            >
              Submit
            </Button>
maple's avatar
maple committed
461
          </Form>
462 463
        </>
      ) : null}
maple's avatar
maple committed
464 465 466 467
    </div>
  );
};

468
function mapStateToProps(state: any) {
cellee's avatar
cellee committed
469 470 471 472 473 474
  const { Data3, Result, DataSave, resultTime } = state.FacilityBookings;
  const load =
    typeof state.loading.models.FacilityBookings == 'undefined'
      ? true
      : state.loading.models.FacilityBookings;
  console.log(Data3);
475
  const { token } = state.login;
maple's avatar
maple committed
476 477
  return {
    Data3,
maple's avatar
maple committed
478
    Result,
maple's avatar
maple committed
479 480
    DataSave,
    token,
cellee's avatar
cellee committed
481 482
    resultTime,
    load,
maple's avatar
maple committed
483 484 485
  };
}
export default connect(mapStateToProps)(Bookings);