index.jsx 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import React, { useState, useEffect } from 'react'
  2. import Taro, { Current } from '@tarojs/taro'
  3. import { Input, Textarea } from '@tarojs/components'
  4. import request, { apis } from '@/utils/request'
  5. import { useModel } from '@/store'
  6. import '@/assets/css/reset.less'
  7. import '@/assets/css/iconfont.less'
  8. import './index.less'
  9. export default function WuYeXiuGaiBaoXiu () {
  10. const { user } = useModel('user')
  11. const [DataLock, setDataLock] = useState(false)
  12. const [DetailInfo, setDetailInfo] = useState(null)
  13. const [CurrnetId] = useState(Current.router.params.id)
  14. const [PhotoUrl, setPhotoUrl] = useState(null)
  15. useEffect(() => {
  16. Init()
  17. }, [CurrnetId])
  18. const Init = () => {
  19. request({ ...apis.getGongDanDetail, args: { orgId: user.orgId }, params: { ticketId: CurrnetId } }).then((res) => {
  20. setDetailInfo(res)
  21. setPhotoUrl(res.tdImagesList !== null && res.tdImagesList.length > 0 ? res.tdImagesList[0] : null)
  22. })
  23. }
  24. const TitleChange = (e) => {
  25. setDetailInfo({ ...DetailInfo, ticketTitle: e.detail.value })
  26. }
  27. const DescChange = (e) => {
  28. setDetailInfo({ ...DetailInfo, ticketContent: e.detail.value })
  29. }
  30. const CheckForm = () => { // 校验报修单
  31. if (DetailInfo.ticketTitle === '') {
  32. Taro.showToast({ title: `报修标题不能为空`, icon: 'none' })
  33. return false
  34. }
  35. if (DetailInfo.ticketContent === '') {
  36. Taro.showToast({ title: `报修描述不能为空`, icon: 'none' })
  37. return false
  38. }
  39. return true
  40. }
  41. const Send = () => { // 提交报修
  42. if (DataLock || !CheckForm()) return
  43. setDataLock(true)
  44. request({
  45. ...apis.editGongDan,
  46. args: { id: CurrnetId },
  47. data: {
  48. ticketTitle: DetailInfo.ticketTitle,
  49. ticketContent: DetailInfo.ticketContent,
  50. type: 2,
  51. imageUrl: PhotoUrl
  52. }
  53. }).then((res) => {
  54. Taro.showToast({ title: '报修修改成功', icon: 'none' })
  55. Taro.redirectTo({ url: `/pages/WuYe/BaoXiuDetail/index?id=${res.id}` })
  56. setDataLock(false)
  57. }).catch((res) => {
  58. Taro.showToast({ title: res, icon: 'none' })
  59. setDataLock(false)
  60. })
  61. }
  62. const AddImg = () => { // 添加图片
  63. Taro.chooseImage({
  64. count: 1,
  65. sizeType: ['compressed'],
  66. sourceType: ['album', 'camera'],
  67. success: (res) => {
  68. const tempFilePaths = res.tempFilePaths
  69. Taro.uploadFile({
  70. url: apis.uploadImage.url,
  71. filePath: tempFilePaths[0],
  72. name: 'file',
  73. formData: { user: 'upload' },
  74. header: { 'x-action': 'miniapp', 'authorization': `Bearer ${Taro.getStorageSync('token')}` },
  75. success: (res) => {
  76. setPhotoUrl(JSON.parse(res.data).data)
  77. }
  78. })
  79. }
  80. })
  81. }
  82. const DeleteItem = () => {
  83. setPhotoUrl(null)
  84. }
  85. return (
  86. <view className='WuYeXiuGaiBaoXiu'>
  87. <view className='Form'>
  88. <Input placeholder='简述你的想法' onInput={TitleChange} value={DetailInfo === null ? null : DetailInfo.ticketTitle}></Input>
  89. <Textarea placeholder='描述问题详情,以便我们更好的相处' onInput={DescChange} value={DetailInfo === null ? null : DetailInfo.ticketContent}></Textarea>
  90. </view>
  91. <view className='Photo'>
  92. <view className='Add' onClick={AddImg}>
  93. <view className='centerLabel'>
  94. <text className='iconfont iconxiangji'></text>
  95. <text>添加图片</text>
  96. </view>
  97. </view>
  98. {
  99. PhotoUrl !== null &&
  100. <view className='PhotoItem'>
  101. <text className='iconfont iconshanchu' onClick={DeleteItem}></text>
  102. <image mode='aspectFit' src={PhotoUrl}></image>
  103. </view>
  104. }
  105. </view>
  106. <view className='Btn'>
  107. <text onClick={Send}>确认修改</text>
  108. </view>
  109. </view>
  110. )
  111. }