import OHeader from '@/components/o-header'
import OSticky from '@/components/o-sticky'
import { Collapse, CollapseItem } from 'vant'
import { defineComponent, reactive, onMounted, nextTick, ref } from 'vue'
import clockIcon from './images/clock-icon.png'
import styles from './index.module.less'
import request from '@/helpers/request'
import { addFormMinute, reduceFormMinute } from '@/helpers/date'
import { useRect } from '@vant/use'
import { Html5Event } from 'plyr'
export default defineComponent({
  name: 'attendance-rule',
  setup() {
    const state = reactive({
      activeNames: '',
      wrapHeight: 0
    })
    const divRef = ref()
    const forms = reactive({} as any)
    const getRules = async () => {
      try {
        const { data } = await request.post('/api-backend/sysParamConfig/page', {
          data: {
            page: 1,
            rows: 999,
            group: 'ATTENDANCE'
          }
        })
        if (data.rows) {
          data.rows.forEach((item: any) => {
            forms[item.id] = item.paramValue
          })
        }
        console.log(forms)
      } catch (e) {
        console.log(e)
      }
    }
    onMounted(() => {
      getRules()
      nextTick(() => {
        setTimeout(() => {
          console.log(divRef.value)
          const { height, top } = useRect(divRef.value as Element)
          state.wrapHeight = height + top + 45
        }, 100)
      })
    })
    return () => (
      <>
        {/* <OSticky position="top" background="#F8F8F8">
          <OHeader></OHeader>
        </OSticky> */}
        <div class={styles.attCollapseWrap} ref={divRef}>
          <Collapse v-model={state.activeNames} accordion>
            <CollapseItem
              name="1"
              border={false}
              v-slots={{
                title: () => (
                  <div class={styles.collapseTitle}>
                    <span class={styles.dot}></span>
                    签到规则
                  </div>
                )
              }}
            >
              <div
                class={styles.collapseWrap}
                style={{ height: `calc(100vh - ${state.wrapHeight}px)` }}
              >
                {state.wrapHeight}
                <div class={styles.mainMsg}>
                  <img src={clockIcon} alt="" class={styles.clockIcon} />
                  <p>以课程时间12:00:00 ~ 13:00:00为例</p>
                </div>
                <div class={styles.textWrap}>
                  <h4>可签到时间范围：</h4>
                  <p>
                    课程<span>开始前{forms[15] ? forms[15] : 0}分钟</span>至课程<span>结束前</span>
                  </p>
                  <p>时间段：{reduceFormMinute('12:00:00', forms[15])} ~13:00:00 </p>
                </div>

                <div class={styles.textWrap}>
                  <h4>正常签到：</h4>
                  <p>
                    课程<span>开始前{forms[15] ? forms[15] : 0}分钟</span>至课程
                    <span>开始前{forms[16] ? forms[16] : 0}分钟</span>
                    签到 <br />
                    GPS定位点在教学点<span>{forms[10] ? forms[10] : 0}米内</span>
                  </p>
                  <p>
                    时间段：{reduceFormMinute('12:00:00', forms[15])} ~{' '}
                    {reduceFormMinute('12:00:00', forms[16])}
                  </p>
                </div>

                <div class={styles.textWrap}>
                  <h4>异常签到：</h4>
                  <p>
                    课程<span>开始前{forms[17] ? forms[17] : 0}分钟</span>后至课程
                    <span>开始前</span>
                    签到
                    <br />
                    GPS定位点在教学点<span>{forms[10] ? forms[10] : 0}米内</span>
                  </p>
                  <p>时间段：{reduceFormMinute('12:00:00', forms[17])} ~ 12:00:00</p>
                  <p>
                    扣除训练补助：
                    <span>
                      -{forms[18] ? forms[18] : 0}
                      {forms[19] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>

                <div class={styles.textWrap}>
                  <h4>迟到：</h4>
                  <p>
                    课程<span>开始后{forms[20] ? forms[20] : 0}分钟</span>内签到
                  </p>
                  <p>时间段：12:00:00 ~ {addFormMinute('12:00:00', forms[20])}</p>
                  <p>
                    扣除训练补助：
                    <span>
                      -{forms[21] ? forms[21] : 0}
                      {forms[22] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>

                <div class={styles.textWrap}>
                  <h4>旷课：</h4>
                  <p>
                    课程<span>开始后{forms[23] ? forms[23] : 0}分钟</span>至课程<span>结束前</span>
                    签到
                  </p>
                  <p>
                    时间段：{addFormMinute('12:00:00', forms[23])}后签到（含
                    {addFormMinute('12:00:00', forms[23])}）
                  </p>
                  <p>
                    扣除训练补助：
                    <span>
                      -{forms[24] ? forms[24] : 0}
                      {forms[25] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>

                <div class={styles.textWrap}>
                  <h4>未签到：</h4>
                  <p>未进行【签到】操作</p>
                  <p>
                    扣除训练补助：
                    <span>
                      -{forms[26] ? forms[26] : 0} {forms[27] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>
              </div>
            </CollapseItem>
            <CollapseItem
              name="2"
              border={false}
              class={styles.sticky}
              v-slots={{
                title: () => (
                  <div class={styles.collapseTitle}>
                    <span class={styles.dot}></span>
                    签退规则
                  </div>
                )
              }}
            >
              <div
                class={styles.collapseWrap}
                style={{ height: `calc(100vh - ${state.wrapHeight}px)` }}
              >
                <div class={styles.mainMsg}>
                  <img src={clockIcon} alt="" class={styles.clockIcon} />
                  <p>以课程时间12:00:00 ~ 13:00:00为例</p>
                </div>
                <div class={styles.textWrap}>
                  <h4>可签退时间范围：</h4>
                  <p>
                    课程<span>结束后</span>至课程当天24点前
                  </p>
                  <p>时间段：12:00:00 ~ 23:59:59</p>
                </div>

                <div class={styles.textWrap}>
                  <h4>正常签退：</h4>
                  <p>
                    课程<span>结束后</span>至课程<span>结束后{forms[28] ? forms[28] : 0}分钟</span>
                    签退 <br />
                    GPS定位点在教学点<span>{forms[10] ? forms[10] : 0}米内</span>
                  </p>
                  <p>时间段：13:00:00 ~ {addFormMinute('13:00:00', forms[28])}</p>
                </div>
                <div class={styles.textWrap}>
                  <h4>早退：</h4>
                  <p>
                    课程<span>结束前{forms[32] ? forms[32] : 0}分钟</span>内签退
                  </p>
                  <p>
                    时间段：{reduceFormMinute('13:00:00', forms[32])}前签退（含
                    {reduceFormMinute('13:00:00', forms[32])}）{' '}
                  </p>
                  <p>
                    扣除训练补助：
                    <span>
                      -{forms[33] ? forms[33] : 0}
                      {forms[34] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>

                <div class={styles.textWrap}>
                  <h4>异常签退：</h4>
                  <p>
                    课程<span>结束前{forms[29] ? forms[29] : 0}分钟</span>至<span>课程结束前</span>
                    <br /> 或GPS定位点在教学点<span> {forms[10] ? forms[10] : 0}米内</span>
                  </p>
                  <p>时间段：{reduceFormMinute('13:00:00', forms[29])} ~ 12:59:59</p>
                  <p>
                    扣除训练补助：
                    <span>
                      -{forms[30] ? forms[30] : 0} {forms[31] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>

                <div class={styles.textWrap}>
                  <h4>未签退：</h4>
                  <p>未进行【签退】操作</p>
                  <p>
                    扣除训练补助：
                    <span>
                      -{forms[45] ? forms[45] : 0}
                      {forms[38] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>
              </div>
            </CollapseItem>
            <CollapseItem
              name="3"
              border={false}
              v-slots={{
                title: () => (
                  <div class={styles.collapseTitle}>
                    <span class={styles.dot}></span>
                    GPS定位
                  </div>
                )
              }}
            >
              <div
                class={styles.collapseWrap}
                style={{ maxHeight: `calc(100vh - ${state.wrapHeight}px)` }}
              >
                <div class={styles.textWrap}>
                  <p>
                    <span>
                      若签到时间在正常范围内
                      <br /> 但同时GPS定位在教学点{forms[10] ? forms[10] : 0}
                      米外
                    </span>
                  </p>
                  <p>
                    扣除训练补助：
                    <span>
                      - {forms[11] ? forms[11] : 0}
                      {forms[12] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>
                <div class={styles.textWrap}>
                  <p>
                    <span>
                      若签退时间在正常范围内 <br /> 但同时GPS定位在教学点{forms[10] ? forms[10] : 0}
                      米外
                    </span>
                  </p>
                  <p>
                    扣除训练补助：
                    <span>
                      - {forms[13] ? forms[13] : 0}
                      {forms[14] == 'MONEY' ? '元' : '%'}
                    </span>
                  </p>
                </div>
              </div>
            </CollapseItem>
          </Collapse>
        </div>
      </>
    )
  }
})
