index.tsx 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import { Field, CellGroup, Icon, Button, showToast, ActionSheet } from 'vant'
  4. import { defineComponent, reactive, ref, onMounted } from 'vue'
  5. import styles from './index.module.less'
  6. import { useRouter } from 'vue-router'
  7. import { state as globalState } from '@/state'
  8. // import locIcon from './images/loc-icon.png'
  9. import request from '@/helpers/request'
  10. export default defineComponent({
  11. name: 'unit-create',
  12. setup() {
  13. const router = useRouter()
  14. const state = reactive({
  15. actions: [] as any,
  16. classList: [] as any,
  17. showPopoverOrchestra: false,
  18. showPopoverClass: false
  19. })
  20. const forms = ref({
  21. orchestraId: '',
  22. orchestraName: '',
  23. classGroupName: '',
  24. classGroupId: '',
  25. emergencyContact: '',
  26. addressLongitudeLatitude: '',
  27. unitName: '',
  28. unitId: ''
  29. } as any)
  30. const schoolImageRef = ref()
  31. const submitInfo = async () => {
  32. sessionStorage.setItem('unit-create', JSON.stringify(forms.value))
  33. }
  34. const chioseLesson = () => {
  35. if (!forms.value.classGroupId) {
  36. showToast('请选择测验班级')
  37. return
  38. }
  39. sessionStorage.setItem('unit-create', JSON.stringify(forms.value))
  40. router.push({ path: '/unit-Lesson', query: { classGroupId: forms.value.classGroupId } })
  41. }
  42. onMounted(() => {
  43. forms.value = { ...JSON.parse(sessionStorage.getItem('unit-create') || '{}') } as any
  44. getOrchestraList()
  45. })
  46. const getOrchestraList = async () => {
  47. try {
  48. const res = await request.post('/api-school/orchestra/page', {
  49. data: { page: 1, rows: 9999, status: 'DONE' }
  50. })
  51. state.actions = res.data.rows.map((item) => {
  52. return {
  53. name: item.name,
  54. value: item.id as string
  55. }
  56. })
  57. } catch (e: any) {
  58. const message = e.message
  59. showToast(message)
  60. }
  61. }
  62. const checkOrchestra = async (val: any) => {
  63. forms.value.orchestraId = val.value
  64. forms.value.orchestraName = val.name
  65. forms.value.classGroupName = ''
  66. forms.value.classGroupId = ''
  67. if (val.value) {
  68. try {
  69. const res = await request.post('/api-teacher/classGroup/page', {
  70. data: { page: 1, rows: 9999, orchestraId: val.value }
  71. })
  72. state.classList = res.data.rows.map((item) => {
  73. return {
  74. name: item.name,
  75. value: item.id as string
  76. }
  77. })
  78. if (state.classList.length < 1) {
  79. showToast('当前乐团暂无班级')
  80. }
  81. } catch (e) {
  82. console.log(e, 'cuowu')
  83. }
  84. } else {
  85. state.classList = []
  86. }
  87. state.showPopoverOrchestra = false
  88. }
  89. const checkClass = async (val: any) => {
  90. forms.value.classGroupName = val.name
  91. forms.value.classGroupId = val.value
  92. state.showPopoverClass = false
  93. }
  94. return () => (
  95. <>
  96. <div class={styles.schoolEidtWrap}>
  97. <div class={styles.eidtWrap}>
  98. {/* onClick={() => setAddress()} */}
  99. <CellGroup inset>
  100. <Field
  101. v-model={forms.value.orchestraName}
  102. placeholder="选择乐团"
  103. disabled
  104. input-align="right"
  105. onClick={() => {
  106. state.showPopoverOrchestra = true
  107. }}
  108. >
  109. {{
  110. extra: () => (
  111. <div class={styles.loctionIconWrap}>
  112. <Icon name="arrow" color="#d8d8d8"></Icon>
  113. {/* <Image width={19} height={18} src={locIcon}></Image> */}
  114. </div>
  115. ),
  116. label: () => <p class={styles.addP}>选择乐团</p>
  117. }}
  118. </Field>
  119. <Field
  120. rows={3}
  121. v-model={forms.value.classGroupName}
  122. maxlength={50}
  123. placeholder="测验班级"
  124. disabled
  125. input-align="right"
  126. onClick={() => {
  127. if (!forms.value.orchestraId) {
  128. showToast('请先选择乐团')
  129. } else {
  130. state.showPopoverClass = true
  131. }
  132. }}
  133. >
  134. {{
  135. extra: () => (
  136. <div class={styles.loctionIconWrap}>
  137. <Icon name="arrow" color="#d8d8d8"></Icon>
  138. {/* <Image width={19} height={18} src={locIcon}></Image> */}
  139. </div>
  140. ),
  141. label: () => <p class={styles.addP}>测验班级</p>
  142. }}
  143. </Field>
  144. <Field
  145. rows={3}
  146. v-model={forms.value.unitName}
  147. maxlength={50}
  148. placeholder="测验内容"
  149. disabled
  150. input-align="right"
  151. onClick={chioseLesson}
  152. >
  153. {{
  154. extra: () => (
  155. <div class={styles.loctionIconWrap}>
  156. <Icon name="arrow" color="#d8d8d8"></Icon>
  157. {/* <Image width={19} height={18} src={locIcon}></Image> */}
  158. </div>
  159. ),
  160. label: () => <p class={styles.addP}>测验内容</p>
  161. }}
  162. </Field>
  163. </CellGroup>
  164. </div>
  165. <OSticky position="bottom">
  166. <div class={'btnGroup'}>
  167. <Button block round type="primary">
  168. 下一步
  169. </Button>
  170. </div>
  171. </OSticky>
  172. </div>
  173. <ActionSheet
  174. v-model:show={state.showPopoverOrchestra}
  175. title="选择乐团"
  176. actions={state.actions}
  177. onSelect={checkOrchestra}
  178. ></ActionSheet>
  179. <ActionSheet
  180. v-model:show={state.showPopoverClass}
  181. title="选择班级"
  182. actions={state.classList}
  183. onSelect={checkClass}
  184. ></ActionSheet>
  185. </>
  186. )
  187. }
  188. })