index.tsx 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. import OHeader from '@/components/o-header'
  2. import OSticky from '@/components/o-sticky'
  3. import { Field, CellGroup, Icon, Button, showToast, ActionSheet, Popup, Picker } from 'vant'
  4. import { defineComponent, reactive, ref, onMounted, nextTick } 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 showFirstloading = ref(false)
  32. const submitInfo = async () => {
  33. sessionStorage.setItem('unit-create', JSON.stringify(forms.value))
  34. }
  35. const chioseLesson = () => {
  36. if (!forms.value.classGroupId) {
  37. showToast('请选择测验班级')
  38. return
  39. }
  40. sessionStorage.setItem('unit-create', JSON.stringify(forms.value))
  41. router.push({ path: '/unit-Lesson', query: { classGroupId: forms.value.classGroupId } })
  42. }
  43. onMounted(async () => {
  44. forms.value = { ...JSON.parse(sessionStorage.getItem('unit-create') || '{}') } as any
  45. getOrchestraList()
  46. if (forms.value?.orchestraId) {
  47. try {
  48. const res = await request.post('/api-teacher/classGroup/page', {
  49. data: { page: 1, rows: 9999, orchestraId: forms.value?.orchestraId }
  50. })
  51. state.classList = res.data.rows.map((item) => {
  52. return {
  53. name: item.name,
  54. value: item.id as string
  55. }
  56. })
  57. if (state.classList.length < 1) {
  58. showToast('当前乐团暂无班级')
  59. }
  60. } catch (e) {
  61. console.log(e, 'cuowu')
  62. }
  63. }
  64. })
  65. const getOrchestraList = async () => {
  66. try {
  67. const res = await request.post('/api-school/orchestra/page', {
  68. data: { page: 1, rows: 9999, status: 'DONE' }
  69. })
  70. state.actions = res.data.rows.map((item) => {
  71. return {
  72. name: item.name,
  73. value: item.id as string
  74. }
  75. })
  76. nextTick(() => {
  77. showFirstloading.value = true
  78. })
  79. } catch (e: any) {
  80. showFirstloading.value = true
  81. const message = e.message
  82. showToast(message)
  83. }
  84. }
  85. const checkOrchestra = async (val: any) => {
  86. console.log(val.selectedOptions)
  87. forms.value.orchestraId = val.selectedOptions[0].value
  88. forms.value.orchestraName = val.selectedOptions[0].name
  89. forms.value.classGroupName = ''
  90. forms.value.classGroupId = ''
  91. if (val.selectedOptions[0].value) {
  92. try {
  93. const res = await request.post('/api-teacher/classGroup/page', {
  94. data: { page: 1, rows: 9999, orchestraId: val.selectedOptions[0].value }
  95. })
  96. state.classList = res.data.rows.map((item) => {
  97. return {
  98. name: item.name,
  99. value: item.id as string
  100. }
  101. })
  102. if (state.classList.length < 1) {
  103. showToast('当前乐团暂无班级')
  104. }
  105. } catch (e) {
  106. console.log(e, 'cuowu')
  107. }
  108. } else {
  109. state.classList = []
  110. }
  111. state.showPopoverOrchestra = false
  112. }
  113. const checkClass = async (val: any) => {
  114. forms.value.classGroupName = val.selectedOptions[0].name
  115. forms.value.classGroupId = val.selectedOptions[0].value
  116. state.showPopoverClass = false
  117. }
  118. return () => (
  119. <>
  120. {showFirstloading.value ? (
  121. <div class={styles.schoolEidtWrap}>
  122. <div class={styles.eidtWrap}>
  123. {/* onClick={() => setAddress()} */}
  124. <CellGroup inset>
  125. <Field
  126. // v-model={forms.value.orchestraName}
  127. placeholder="请选择乐团"
  128. readonly
  129. input-align="right"
  130. onClick={() => {
  131. state.showPopoverOrchestra = true
  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. input: () =>
  143. forms.value.orchestraName ? (
  144. <div class={[styles.orchestraName, 'van-ellipsis']}>
  145. {forms.value.orchestraName}
  146. </div>
  147. ) : (
  148. <div style={{ color: '#c8c9cc' }}>请选择乐团</div>
  149. )
  150. }}
  151. </Field>
  152. <Field
  153. rows={3}
  154. v-model={forms.value.classGroupName}
  155. maxlength={50}
  156. placeholder="请选择测验班级"
  157. readonly
  158. input-align="right"
  159. onClick={() => {
  160. if (!forms.value.orchestraId) {
  161. showToast('请先选择乐团')
  162. } else {
  163. state.showPopoverClass = true
  164. }
  165. }}
  166. >
  167. {{
  168. extra: () => (
  169. <div class={styles.loctionIconWrap}>
  170. <Icon name="arrow" color="#d8d8d8"></Icon>
  171. {/* <Image width={19} height={18} src={locIcon}></Image> */}
  172. </div>
  173. ),
  174. label: () => <p class={styles.addP}>测验班级</p>
  175. }}
  176. </Field>
  177. <Field
  178. rows={3}
  179. v-model={forms.value.unitName}
  180. maxlength={50}
  181. placeholder="请选择测验内容"
  182. readonly
  183. input-align="right"
  184. onClick={chioseLesson}
  185. >
  186. {{
  187. extra: () => (
  188. <div class={styles.loctionIconWrap}>
  189. <Icon name="arrow" color="#d8d8d8"></Icon>
  190. {/* <Image width={19} height={18} src={locIcon}></Image> */}
  191. </div>
  192. ),
  193. label: () => <p class={styles.addP}>测验内容</p>
  194. }}
  195. </Field>
  196. </CellGroup>
  197. </div>
  198. <OSticky position="bottom">
  199. {/* <div class={'btnGroup'}>
  200. <Button block round type="primary">
  201. 下一步
  202. </Button>
  203. </div> */}
  204. </OSticky>
  205. </div>
  206. ) : null}
  207. {/* <ActionSheet
  208. v-model:show={state.showPopoverOrchestra}
  209. title="选择乐团"
  210. actions={state.actions}
  211. onSelect={checkOrchestra}
  212. ></ActionSheet> */}
  213. <Popup v-model:show={state.showPopoverOrchestra} position="bottom" round>
  214. <Picker
  215. columns={state.actions}
  216. columnsFieldNames={{ text: 'name', value: 'value' }}
  217. onCancel={() => (state.showPopoverOrchestra = false)}
  218. onConfirm={checkOrchestra}
  219. />
  220. </Popup>
  221. <Popup v-model:show={state.showPopoverClass} position="bottom" round>
  222. <Picker
  223. columns={state.classList}
  224. columnsFieldNames={{ text: 'name', value: 'value' }}
  225. onCancel={() => (state.showPopoverOrchestra = false)}
  226. onConfirm={checkClass}
  227. />
  228. </Popup>
  229. {/*
  230. <ActionSheet
  231. v-model:show={state.showPopoverClass}
  232. title="选择班级"
  233. actions={state.classList}
  234. onSelect={checkClass}
  235. ></ActionSheet> */}
  236. </>
  237. )
  238. }
  239. })