import OHeader from '@/components/o-header'
import { defineComponent, onMounted, reactive, ref } from 'vue'
import iconStudent from '@common/images/icon_student.png'
import styles from './apply-withdrawal.module.less'
import { Button, Dialog, Field, Image } from 'vant'
import OSticky from '@/components/o-sticky'
import { useRoute } from 'vue-router'
import request from '@/helpers/request'
import { state } from '@/state'

export default defineComponent({
  name: 'apply-withdrawal',
  setup() {
    const route = useRoute()
    const headColor = reactive({
      headBg: 'transparent',
      textColor: '#fff'
    })
    const forms = reactive({
      status: false,
      reason: null,
      id: route.query.id
    })

    const getDetails = async () => {
      try {
        const { data } = await request.post('/api-student/student/getOrchestraDate/' + forms.id)
      } catch {
        //
      }
    }

    const onSubmit = async () => {
      // forms.status = true
      await request.post('/api-student/orchestra/leaveOrchestra', {
        data: {
          studentId: state.user.data.account.id,
          orchestraId: forms.id,
          reason: forms.reason
        }
      })
    }
    onMounted(() => {
      getDetails()
    })
    return () => (
      <>
        <div class={styles.headers}>
          <OHeader
            background={headColor.headBg}
            color={headColor.textColor}
            border={false}
            backIconColor="white"
          />

          <div class={styles.userInfo}>
            <Image src={iconStudent} class={styles.img} />
            <div class={styles.userName}>宋小泽 同学</div>
            <div class={styles.timer}>
              您已在武汉小学2022标小学2022标准团训练<span>142</span>天
            </div>
          </div>
        </div>
        <div class={styles.content}>
          <span>在乐团训练的日子里，</span>
          有付出有汗水，用从0到1的喜悦也有攻克难关的坚持。你的付出为你带来成长，你的成长让老师感到欣喜。
        </div>

        <div class={styles.resion}>
          <div class={styles.title}>
            <div class={styles.name}>
              <i></i>退团原因<span>*</span>
            </div>
            <div class={styles.nums}>0/400</div>
          </div>
          <Field v-model={forms.reason} placeholder="请输入退团详细原因" type="textarea" rows={3} />
        </div>

        <OSticky position="bottom">
          <div class={'btnGroup'}>
            <Button block round size="large" type="primary" onClick={onSubmit}>
              确定
            </Button>
          </div>
        </OSticky>

        <Dialog
          v-model:show={forms.status}
          message={'确定要提交退团申请吗？'}
          messageAlign="left"
          confirmButtonText="确定"
          cancelButtonText="取消"
          showCancelButton
          onConfirm={() => {
            console.log('223')
          }}
        >
          {{
            title: () => (
              <div class={styles.dialogTitle}>
                <i></i>
                提示
              </div>
            )
          }}
        </Dialog>
      </>
    )
  }
})
