index.tsx 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. import OSticky from '@/components/o-sticky'
  2. import request from '@/helpers/request'
  3. import dayjs from 'dayjs'
  4. import {
  5. Button,
  6. Cell,
  7. CellGroup,
  8. DatePicker,
  9. Field,
  10. Picker,
  11. Popup,
  12. Radio,
  13. RadioGroup,
  14. showSuccessToast,
  15. showToast
  16. } from 'vant'
  17. import { defineComponent, onMounted, reactive } from 'vue'
  18. import styles from './index.module.less'
  19. import iconUpload from '../images/icon-upload.png'
  20. import iconUploadVideo from '../images/icon-upload-video.png'
  21. import iconUploadVideoCover from '../images/icon-upload-video-cover.png'
  22. import OUploadAll from '@/components/o-upload-all'
  23. import OHeader from '@/components/o-header'
  24. import ODialog from '@/components/o-dialog'
  25. import { useRoute, useRouter } from 'vue-router'
  26. export default defineComponent({
  27. name: 'story-operation',
  28. setup() {
  29. const router = useRouter()
  30. const route = useRoute()
  31. const forms = reactive({
  32. id: route.query.id || null,
  33. content: '',
  34. orchestraStatus: false,
  35. orchestraList: [] as any,
  36. selectOrchestra: {} as any,
  37. createTime: new Date() as any,
  38. createTimeStatus: false,
  39. currentDate: [dayjs().format('YYYY'), dayjs().format('MM'), dayjs().format('DD')],
  40. storyType: 'IMAGE',
  41. attachments: [] as any, //群发消息附件
  42. video: [] as any,
  43. videoCover: [] as any,
  44. delStatus: false
  45. })
  46. // 获取乐团列表
  47. const getOrchestras = async () => {
  48. try {
  49. const { data } = await request.post('/api-school/orchestra/page', {
  50. data: {
  51. page: 1,
  52. rows: 100
  53. }
  54. })
  55. const temps = data.rows || []
  56. const s = [] as any
  57. temps.forEach((item: any) => {
  58. s.push({
  59. text: item.name,
  60. value: item.id
  61. })
  62. })
  63. forms.orchestraList = [...s]
  64. // 判断是否有乐团
  65. if (s.length > 0) {
  66. forms.selectOrchestra = s[0]
  67. }
  68. } catch {
  69. //
  70. }
  71. }
  72. const getDetails = async () => {
  73. try {
  74. if (!forms.id) {
  75. return
  76. }
  77. const { data } = await request.get('/api-school/orchestraStory/detail/' + forms.id)
  78. console.log(data)
  79. forms.content = data.content
  80. forms.createTime = data.createTime
  81. forms.storyType = data.type
  82. forms.orchestraList.forEach((item: any) => {
  83. if (item.value === item.orchestraId) {
  84. forms.selectOrchestra = item
  85. }
  86. })
  87. if (data.type === 'IMAGE') {
  88. data.attachments &&
  89. data.attachments.forEach((item: any) => {
  90. forms.attachments.push(item.url)
  91. })
  92. } else {
  93. const temp = data.attachments ? data.attachments[0] : []
  94. forms.video.push(temp.url)
  95. forms.videoCover.push(temp.coverImage)
  96. }
  97. } catch {
  98. //
  99. }
  100. }
  101. const onSumbit = async () => {
  102. try {
  103. if (!forms.selectOrchestra.value) {
  104. showToast('请选择乐团')
  105. return
  106. }
  107. if (!forms.createTime) {
  108. showToast('请选择事迹日期')
  109. return
  110. }
  111. if (!forms.content) {
  112. showToast('请输入事迹内容')
  113. return
  114. }
  115. if (forms.storyType === 'IMAGE' && forms.attachments.length <= 0) {
  116. showToast('请上传照片')
  117. return
  118. }
  119. if (forms.storyType === 'VIDEO') {
  120. if (forms.video.length <= 0) {
  121. showToast('请上传视频')
  122. return
  123. }
  124. if (forms.videoCover.length <= 0) {
  125. showToast('请上传视频封面')
  126. return
  127. }
  128. }
  129. const attachments: any = []
  130. if (forms.storyType === 'IMAGE') {
  131. forms.attachments.forEach((item: any) => {
  132. const temp = {
  133. attachmentType: forms.storyType,
  134. url: item
  135. }
  136. attachments.push(temp)
  137. })
  138. } else {
  139. attachments.push({
  140. attachmentType: forms.storyType,
  141. url: forms.video[0],
  142. coverImage: forms.videoCover[0]
  143. })
  144. }
  145. console.log({
  146. createTime: dayjs(forms.createTime).format('YYYY-MM-DD HH:mm:ss'),
  147. orchestraId: forms.selectOrchestra.value,
  148. content: forms.content,
  149. type: forms.storyType,
  150. attachments
  151. })
  152. const params = {
  153. createTime: dayjs(forms.createTime).format('YYYY-MM-DD HH:mm:ss'),
  154. orchestraId: forms.selectOrchestra.value,
  155. content: forms.content,
  156. type: forms.storyType,
  157. attachments
  158. }
  159. if (forms.id) {
  160. await request.post('/api-school/orchestraStory/update', {
  161. data: {
  162. ...params,
  163. id: forms.id
  164. }
  165. })
  166. setTimeout(() => {
  167. showSuccessToast('修改成功')
  168. }, 100)
  169. } else {
  170. await request.post('/api-school/orchestraStory/save', {
  171. data: params
  172. })
  173. setTimeout(() => {
  174. showSuccessToast('添加成功')
  175. }, 100)
  176. }
  177. setTimeout(() => {
  178. router.back()
  179. }, 1100)
  180. } catch {
  181. //
  182. }
  183. }
  184. //
  185. const onConfirm = async () => {
  186. try {
  187. await request.post('/api-school/orchestraStory/remove', {
  188. requestType: 'form',
  189. data: {
  190. id: forms.id
  191. }
  192. })
  193. setTimeout(() => {
  194. showSuccessToast('删除成功')
  195. }, 100)
  196. setTimeout(() => {
  197. router.back()
  198. }, 1100)
  199. } catch {
  200. //
  201. }
  202. }
  203. onMounted(async () => {
  204. if (forms.id) {
  205. document.title = '修改事迹'
  206. }
  207. await getOrchestras()
  208. await getDetails()
  209. })
  210. return () => (
  211. <div class={styles.storyOperation}>
  212. <OHeader title={forms.id ? '修改事迹' : '添加事迹'}>
  213. {{
  214. right: () =>
  215. forms.id && (
  216. <span
  217. style={{ color: '#777777' }}
  218. onClick={() => {
  219. forms.delStatus = true
  220. }}
  221. >
  222. 删除
  223. </span>
  224. )
  225. }}
  226. </OHeader>
  227. <CellGroup inset class={styles.cellGroup}>
  228. <Field
  229. inputAlign="right"
  230. label="所属乐团"
  231. modelValue={forms.selectOrchestra.text}
  232. placeholder="请选择所属乐团"
  233. onClick={() => {
  234. forms.orchestraStatus = true
  235. }}
  236. readonly
  237. isLink
  238. />
  239. <Field
  240. inputAlign="right"
  241. label="事迹日期"
  242. modelValue={forms.createTime ? dayjs(forms.createTime).format('YYYY-MM-DD') : ''}
  243. placeholder="请选择事迹日期"
  244. onClick={() => {
  245. forms.createTimeStatus = true
  246. }}
  247. readonly
  248. isLink
  249. class={styles.inputForm}
  250. />
  251. </CellGroup>
  252. <CellGroup inset class={styles.cellGroup}>
  253. <Cell title="事迹内容">
  254. {{
  255. title: () => (
  256. <div class={styles.title}>
  257. <div class={styles.name}>事迹内容</div>
  258. <div class={styles.nums}>{forms.content.length || 0}/200</div>
  259. </div>
  260. ),
  261. label: () => (
  262. <Field
  263. style={{ padding: '0', marginTop: '12px' }}
  264. placeholder="请输入乐团事迹内容"
  265. type="textarea"
  266. rows={3}
  267. v-model={forms.content}
  268. maxlength={200}
  269. />
  270. )
  271. }}
  272. </Cell>
  273. </CellGroup>
  274. <CellGroup inset class={styles.cellGroup}>
  275. <Cell title="事迹资料类型" center>
  276. {{
  277. value: () => (
  278. <RadioGroup
  279. checked-color="#FF8057"
  280. v-model={forms.storyType}
  281. direction="horizontal"
  282. >
  283. <Radio class={styles.radioItem} name={'IMAGE'}>
  284. 图片
  285. </Radio>
  286. <Radio class={styles.radioItem} name={'VIDEO'}>
  287. 视频
  288. </Radio>
  289. </RadioGroup>
  290. )
  291. }}
  292. </Cell>
  293. {forms.storyType === 'IMAGE' && (
  294. <Cell center>
  295. {{
  296. title: () => (
  297. <OUploadAll
  298. style={{ marginBottom: '12px' }}
  299. v-model:modelValue={forms.attachments}
  300. maxCount={9}
  301. uploadIcon={iconUpload}
  302. />
  303. )
  304. }}
  305. </Cell>
  306. )}
  307. {forms.storyType === 'VIDEO' && (
  308. <Cell center titleStyle={{ display: 'flex' }}>
  309. {{
  310. title: () => (
  311. <>
  312. <OUploadAll
  313. style={{ marginBottom: '12px' }}
  314. v-model:modelValue={forms.video}
  315. accept="video/*"
  316. uploadType="VIDEO"
  317. uploadIcon={iconUploadVideo}
  318. deletable={false}
  319. />
  320. <OUploadAll
  321. deletable={false}
  322. style={{ marginBottom: '12px' }}
  323. v-model:modelValue={forms.videoCover}
  324. uploadIcon={iconUploadVideoCover}
  325. />
  326. </>
  327. )
  328. }}
  329. </Cell>
  330. )}
  331. </CellGroup>
  332. <OSticky position="bottom">
  333. <div class={'btnGroup'}>
  334. <Button round block type="primary" onClick={onSumbit}>
  335. 保存
  336. </Button>
  337. </div>
  338. </OSticky>
  339. <Popup v-model:show={forms.createTimeStatus} position="bottom" round>
  340. <DatePicker
  341. maxDate={new Date()}
  342. v-model={forms.currentDate}
  343. onConfirm={(val: any) => {
  344. const selectedValues = val.selectedValues.join('-')
  345. forms.createTime = dayjs(selectedValues).toDate()
  346. forms.createTimeStatus = false
  347. }}
  348. />
  349. </Popup>
  350. <Popup v-model:show={forms.orchestraStatus} position="bottom" round>
  351. <Picker
  352. columns={forms.orchestraList}
  353. onCancel={() => (forms.orchestraStatus = false)}
  354. onConfirm={(val: any) => {
  355. forms.selectOrchestra = val.selectedOptions[0]
  356. forms.orchestraStatus = false
  357. }}
  358. />
  359. </Popup>
  360. <ODialog
  361. v-model:show={forms.delStatus}
  362. title="删除事迹"
  363. messageAlign="left"
  364. message="删除后学生将无法再看到本条事迹确认要删除吗?"
  365. showCancelButton
  366. onConfirm={onConfirm}
  367. ></ODialog>
  368. </div>
  369. )
  370. }
  371. })