Kaynağa Gözat

增加是否在打卡区间判断

dev01 1 yıl önce
ebeveyn
işleme
71865b9639

+ 20 - 16
src/components/common/xx-calendar/xx-calendar.js

@@ -10,7 +10,6 @@ Component({
       value: [],
       observer(v) {
         let nowMonthDays = this.data.nowMonthDays
-        // let sel = this.data.dateSel.replace(/\-/g, "/")
         if (v.length > 0) {
           v.forEach(el => {
             let ele = el.dates.replace(/\-/g, "/")
@@ -22,21 +21,28 @@ Component({
             })
           })
         }
-        let date1 = new Date().getDate()
-        let time1 = ""
-        let obj1 = {}
-        for (var i = 0; i < nowMonthDays.length; i++) {
-          if (nowMonthDays[i].date == date1) {
-            time1 = nowMonthDays[i].time.replace(/\//g, "-")
-            obj1 = nowMonthDays[i]
-          }
-        }
-        if (!!time1) {
-          this.triggerEvent('selectdate', { selectDate: time1, obj: obj1 })
-        }
         this.setData({
           nowMonthDays
         })
+
+        let year1 = new Date().getFullYear()
+        let month1 = new Date().getMonth() + 1
+        let { year, month } = this.data
+        // 避免切换月份重复调用
+        if (year == year1 && month == month1) {
+          let date1 = new Date().getDate()
+          let time1 = ""
+          let obj1 = {}
+          for (var i = 0; i < nowMonthDays.length; i++) {
+            if (nowMonthDays[i].date == date1) {
+              time1 = nowMonthDays[i].time.replace(/\//g, "-")
+              obj1 = nowMonthDays[i]
+            }
+          }
+          if (!!time1) {
+            this.triggerEvent('selectdate', { selectDate: time1, obj: obj1 })
+          }
+        }
       }
     },
     year: {
@@ -60,7 +66,6 @@ Component({
       value: new Date().getDate(),
     },
   },
-
   /**
    * 组件的初始数据
    */
@@ -76,7 +81,6 @@ Component({
     nextMonthDays: [], //下一个月
     dateList: [],
   },
-
   /**
    * 组件的方法列表
    */
@@ -242,7 +246,7 @@ Component({
   ready() {
     let {
       year,
-      month
+      month,
     } = this.data
     this.createDays(year, month)
   }

+ 79 - 82
src/pages/punchClock/punchClocks.jsx

@@ -53,6 +53,7 @@ class PunchClocks extends Component {
       isCalendar: true,
       //isVacation: false, // 是否节假日
       isVopen: false, // 节假日提示
+      dayInfo: {},
 
       year: new Date().getFullYear(),
       month: new Date().getMonth() + 1,
@@ -229,6 +230,7 @@ class PunchClocks extends Component {
     let obj = val.detail.obj
     let date = dayjs(data)
     this.setState({
+      dayInfo: val.detail.obj,
       dateSel: data,
       year: date.year(),
       month: date.month() + 1,
@@ -245,7 +247,7 @@ class PunchClocks extends Component {
   }
 
   render() {
-    const { data, dateList, year, month, day, isVacation, isVopen } = this.state;
+    const { dayInfo, data, dateList, year, month, day, isVacation, isVopen } = this.state;
     return (
       <View className='punchClock'>
         <View className='header'>
@@ -317,92 +319,87 @@ class PunchClocks extends Component {
                       }}
                     />
                   }
-                  <View className='items'>
-                    <View className='ititle'><Text style={{ color: "red", width: "7px" }}>*</Text>研发工时:
-                      <Input value={this.state.duration} type='digit' className='input' placeholder='请输入'
-                        style={{ textAlign: "center", background: "#F5F5F5", borderRadius: "15px", padding: "3px 5px" }}
-                        // border: "1px solid #d6e4ef",
-                        onInput={e => {
-                          this.setState({
-                            duration: e.detail.value
-                          })
-                        }}
-                      />&nbsp;小时&nbsp;
-                      <Text style={{ color: "red", fontSize: "15px" }}>剩余打卡({this.state.hours}h)</Text>
-                    </View>
-                  </View>
+                  {
+                    (dayInfo.dayStatus != 1 && dayInfo.color != 3)
+                      ? <View>
+                        <View className='items'>
+                          <View className='ititle'><Text style={{ color: "red", width: "7px" }}>*</Text>研发工时:
+                            <Input value={this.state.duration} type='digit' className='input' placeholder='请输入'
+                              style={{ textAlign: "center", background: "#F5F5F5", borderRadius: "15px", padding: "3px 5px" }}
+                              // border: "1px solid #d6e4ef",
+                              onInput={e => {
+                                this.setState({
+                                  duration: e.detail.value
+                                })
+                              }}
+                            />&nbsp;小时&nbsp;
+                            <Text style={{ color: "red", fontSize: "15px" }}>剩余打卡({this.state.hours}h)</Text>
+                          </View>
+                        </View>
 
-                  <View className='item'>
-                    <View className='ititle'><Text style={{ color: "red", width: "7px" }}>*</Text>研发阶段:
-                      <Picker mode='selector' range={this.state.selector} rangeKey="lable"
-                        value={this.state.selectorChecked.value}
-                        onChange={e => {
-                          this.setState({
-                            selectorChecked: this.state.selector[e.detail.value]
-                          })
-                        }}>
-                        <View className='picker'>
-                          {!!this.state.selectorChecked.lable ? this.state.selectorChecked.lable : "请选择"}
+                        <View className='item'>
+                          <View className='ititle'><Text style={{ color: "red", width: "7px" }}>*</Text>研发阶段:
+                            <Picker mode='selector' range={this.state.selector} rangeKey="lable"
+                              value={this.state.selectorChecked.value}
+                              onChange={e => {
+                                this.setState({
+                                  selectorChecked: this.state.selector[e.detail.value]
+                                })
+                              }}>
+                              <View className='picker'>
+                                {!!this.state.selectorChecked.lable ? this.state.selectorChecked.lable : "请选择"}
+                              </View>
+                            </Picker>
+                          </View>
                         </View>
-                      </Picker>
-                    </View>
-                  </View>
 
-                  <View className='items'>
-                    <View className='ititles'><Text style={{ width: "7px" }}></Text>研发记录:
-                      <AtTextarea
-                        value={this.state.remark}
-                        onChange={value => {
-                          this.setState({
-                            remark: value,
-                          });
-                        }}
-                        maxLength={500}
-                        placeholder="请填写研发过程记录"
-                      />
-                      {/* 
-                      <Textarea
-                        value={this.state.remark}
-                        placeholder="请填写研发过程记录不能超过500字"
-                        style='background:#D7D7D7;width:66%;min-height:70px;padding:10px;border-radius: 10px'
-                        autoHeight
-                        maxlength={500}
-                        onInput={e => {
-                          this.setState({
-                            remark: e.detail.value
-                          })
-                        }}
-                      /> */}
-                    </View>
-                  </View>
+                        <View className='items'>
+                          <View className='ititles'><Text style={{ width: "7px" }}></Text>研发记录:
+                            <AtTextarea
+                              value={this.state.remark}
+                              onChange={value => {
+                                this.setState({
+                                  remark: value,
+                                });
+                              }}
+                              maxLength={500}
+                              placeholder="请填写研发过程记录"
+                            />
+                          </View>
+                        </View>
 
-                  <View className='items'>
-                    <View className='ititles'><Text style={{ width: "7px" }}></Text>上传附件:</View>
-                    <ImagePicker
-                      showAddBtn
-                      ref={(ref) => (this.imagePickerRef = ref)}
-                      url="/api/project/upload"
-                      onChange={this.onChange}
-                    />
-                    <View>
-                      <Text className='text'>注:包括研发日志、实验报告、实验记录、检测报告、会议纪要、会议照片等</Text>
-                    </View>
-                  </View>
+                        <View className='items'>
+                          <View className='ititles'><Text style={{ width: "7px" }}></Text>上传附件:</View>
+                          <ImagePicker
+                            showAddBtn
+                            ref={(ref) => (this.imagePickerRef = ref)}
+                            url="/api/project/upload"
+                            onChange={this.onChange}
+                          />
+                          <View>
+                            <Text className='text'>注:包括研发日志、实验报告、实验记录、检测报告、会议纪要、会议照片等</Text>
+                          </View>
+                        </View>
 
-                  <View className='content'>
-                    <View className='punchClockContent'
-                      onClick={() => {
-                        isVacation
-                          ? this.setState({ isVopen: true })
-                          : this.publicReleaseClockIn()
-                      }}
-                      style={{
-                        boxShadow: '1px 1px 15px 1px #acb8ad',
-                        background: '#009DD9',
-                      }}>
-                      <View className='punchClockTitle'>研发打卡</View>
-                    </View>
-                  </View>
+                        <View className='content'>
+                          <View className='punchClockContent'
+                            onClick={() => {
+                              isVacation
+                                ? this.setState({ isVopen: true })
+                                : this.publicReleaseClockIn()
+                            }}
+                            style={{
+                              boxShadow: '1px 1px 15px 1px #acb8ad',
+                              background: '#009DD9',
+                            }}>
+                            <View className='punchClockTitle'>研发打卡</View>
+                          </View>
+                        </View>
+                      </View>
+                      : <View style={{ color: "red" }}>
+                        当前时间不可打卡,请重新选择研发时间
+                      </View>
+                  }
                 </View>
             }
           </Skeleton>