repair.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <view class="container">
  3. <form>
  4. <view class="cu-form-group align-start margin-top-sm">
  5. <view class="title">报修登记</view>
  6. <textarea maxlength="-1" @input="textareaInput" placeholder="报修问题描述"></textarea>
  7. </view>
  8. <view class="cu-bar bg-white margin-top-sm">
  9. <view class="action">
  10. 现场照片
  11. </view>
  12. </view>
  13. <view class="cu-form-group">
  14. <view class="grid col-4 grid-square flex-sub">
  15. <view class="bg-img" @tap="viewImage" :data-url="imgList.fullurl" v-if="imgUpload">
  16. <image :src="imgList.fullurl" mode="aspectFill"></image>
  17. <view class="cu-tag bg-red" @tap.stop="delImg">
  18. <text class='cuIcon-close'></text>
  19. </view>
  20. </view>
  21. <view class="solids" @tap="chooseImage" v-if="!imgUpload">
  22. <text class='cuIcon-cameraadd'></text>
  23. </view>
  24. </view>
  25. </view>
  26. </form>
  27. <view class="cu-bar bg-white tabbar flex flex-wrap" @click="submit()">
  28. <button class="bg-black submit basis-sm" style="border-radius: 0;">确认提交</button>
  29. </view>
  30. </view>
  31. </template>
  32. <script>
  33. import Config from '@/utils/config.js'
  34. var _self
  35. var equipment_id = 0
  36. var flag = false
  37. export default {
  38. data() {
  39. return {
  40. content: '',
  41. imgList: {
  42. fullurl: '',
  43. url: ''
  44. },
  45. imgUpload: false
  46. };
  47. },
  48. onLoad(e) {
  49. _self = this
  50. if (!e.equipment_id) {
  51. _self.tui.toast("未知设备")
  52. setTimeout(function() {
  53. uni.navigateBack()
  54. }, 1500)
  55. return
  56. }
  57. equipment_id = e.equipment_id
  58. },
  59. methods: {
  60. chooseImage() {
  61. uni.chooseImage({
  62. count: 1,
  63. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  64. sourceType: ['album'], //从相册选择
  65. success: (chooseImageRes) => {
  66. const tempFilePaths = chooseImageRes.tempFilePaths
  67. uni.uploadFile({
  68. url: Config.host + 'api/common/upload',
  69. filePath: tempFilePaths[0],
  70. name: 'file',
  71. header: {
  72. 'token': uni.getStorageSync('equipment_token')
  73. },
  74. success: (uploadFileRes) => {
  75. let result = JSON.parse(uploadFileRes.data)
  76. _self.imgUpload = true
  77. _self.imgList = result.data
  78. },
  79. fail: () => {
  80. _self.imgUpload = false
  81. _self.tui.toast('图片上传失败')
  82. }
  83. })
  84. }
  85. })
  86. },
  87. viewImage(e) {
  88. uni.previewImage({
  89. urls: [_self.imgList.fullurl],
  90. current: e.currentTarget.dataset.url
  91. });
  92. },
  93. delImg() {
  94. uni.showModal({
  95. title: '提示',
  96. content: '确定要删除这张照片吗?',
  97. cancelText: '再看看',
  98. confirmText: '确定',
  99. cancelColor: '#8799a3',
  100. confirmColor: '#333333',
  101. success: res => {
  102. if (res.confirm) {
  103. _self.imgList = {}
  104. _self.imgUpload = false
  105. }
  106. }
  107. })
  108. },
  109. textareaInput(e) {
  110. _self.content = e.detail.value
  111. },
  112. submit() {
  113. if (flag) return
  114. if (!equipment_id) {
  115. _self.tui.toast('未知设备')
  116. return
  117. }
  118. if (_self.content == "") {
  119. _self.tui.toast('报修登记不能为空')
  120. return
  121. }
  122. uni.showLoading({
  123. title: '提交中...'
  124. })
  125. _self.$api.repair({
  126. equipment_id,
  127. content: _self.content,
  128. register_image: _self.imgList.url
  129. }).then((res) => {
  130. flag = false
  131. uni.hideLoading()
  132. _self.tui.toast('报修成功', '', 'success')
  133. setTimeout(function() {
  134. const eventChannel = _self.getOpenerEventChannel()
  135. eventChannel.emit('doRefresh', {
  136. ischange: true,
  137. type: 'register'
  138. })
  139. uni.navigateBack()
  140. }, 1500)
  141. }).catch((err) => {
  142. flag = false
  143. uni.hideLoading()
  144. _self.tui.toast(err.msg)
  145. })
  146. }
  147. }
  148. }
  149. </script>
  150. <style lang="scss">
  151. page {
  152. background-color: #f1f1f1;
  153. }
  154. .cu-bar.tabbar {
  155. position: fixed;
  156. width: 100%;
  157. left: 0;
  158. bottom: 0;
  159. }
  160. </style>