register.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <view class="container">
  3. <form>
  4. <view class="cu-form-group margin-top-sm">
  5. <view class="title">维修状态</view>
  6. <picker @change="pickerChange" :value="statusIndex" :range="statusPicker">
  7. <view class="picker">
  8. {{statusPicker[statusIndex]}}
  9. </view>
  10. </picker>
  11. </view>
  12. <view class="cu-form-group margin-top-sm">
  13. <view class="title">故障原因</view>
  14. <picker @change="causeChange" :value="causeIndex" :range="causePicker">
  15. <view class="picker">
  16. {{causePicker[causeIndex]}}
  17. </view>
  18. </picker>
  19. </view>
  20. <view class="cu-form-group align-start margin-top-sm">
  21. <view class="title">维修说明</view>
  22. <textarea maxlength="-1" @input="textareaInput" placeholder="维修情况说明"></textarea>
  23. </view>
  24. <view class="cu-bar bg-white margin-top-sm">
  25. <view class="action">
  26. 现场照片
  27. </view>
  28. </view>
  29. <view class="cu-form-group">
  30. <view class="grid col-4 grid-square flex-sub">
  31. <view class="bg-img" @tap="viewImage" :data-url="imgList.fullurl" v-if="imgUpload">
  32. <image :src="imgList.fullurl" mode="aspectFill"></image>
  33. <view class="cu-tag bg-red" @tap.stop="delImg">
  34. <text class='cuIcon-close'></text>
  35. </view>
  36. </view>
  37. <view class="solids" @tap="chooseImage" v-if="!imgUpload">
  38. <text class='cuIcon-cameraadd'></text>
  39. </view>
  40. </view>
  41. </view>
  42. </form>
  43. <view class="cu-bar bg-white tabbar flex flex-wrap" @click="submit()">
  44. <button class="bg-black submit basis-sm" style="border-radius: 0;">确认提交</button>
  45. </view>
  46. </view>
  47. </template>
  48. <script>
  49. import Config from '@/utils/config.js'
  50. var _self
  51. var repair_id = 0
  52. var flag = false
  53. export default {
  54. data() {
  55. return {
  56. content: '',
  57. imgList: {
  58. fullurl: '',
  59. url: ''
  60. },
  61. imgUpload: false,
  62. statusIndex: 0,
  63. statusPicker: ['已维修', '停机报废'],
  64. statusArr: ['repaired', 'scrapped'],
  65. causePicker: [],
  66. causeIdArr: [],
  67. causeIndex: 0
  68. };
  69. },
  70. onLoad(e) {
  71. _self = this
  72. if (!e.repair_id) {
  73. _self.tui.toast("未知维修工单")
  74. setTimeout(function() {
  75. uni.navigateBack()
  76. }, 1500)
  77. return
  78. }
  79. repair_id = e.repair_id
  80. _self.failureCause()
  81. },
  82. methods: {
  83. failureCause() {
  84. _self.$api.failureCause().then((res) => {
  85. var lists = res.data
  86. var causeIdArr = [];
  87. var causePicker = [];
  88. lists.forEach(function(item, index) {
  89. causeIdArr.push(item.id)
  90. causePicker.push(item.name)
  91. })
  92. _self.causeIdArr = causeIdArr
  93. _self.causePicker = causePicker
  94. })
  95. },
  96. pickerChange(e) {
  97. this.statusIndex = e.detail.value
  98. },
  99. causeChange(e) {
  100. this.causeIndex = e.detail.value
  101. },
  102. chooseImage() {
  103. uni.chooseImage({
  104. count: 1,
  105. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  106. success: (chooseImageRes) => {
  107. const tempFilePaths = chooseImageRes.tempFilePaths
  108. uni.uploadFile({
  109. url: Config.host + 'api/common/upload',
  110. filePath: tempFilePaths[0],
  111. name: 'file',
  112. header: {
  113. 'token': uni.getStorageSync('equipment_token')
  114. },
  115. success: (uploadFileRes) => {
  116. let result = JSON.parse(uploadFileRes.data)
  117. _self.imgUpload = true
  118. _self.imgList = result.data
  119. },
  120. fail: () => {
  121. _self.imgUpload = false
  122. _self.tui.toast('图片上传失败')
  123. }
  124. })
  125. }
  126. })
  127. },
  128. viewImage(e) {
  129. uni.previewImage({
  130. urls: [_self.imgList.fullurl],
  131. current: e.currentTarget.dataset.url
  132. });
  133. },
  134. delImg() {
  135. uni.showModal({
  136. title: '提示',
  137. content: '确定要删除这张照片吗?',
  138. cancelText: '再看看',
  139. confirmText: '确定',
  140. cancelColor: '#8799a3',
  141. confirmColor: '#333333',
  142. success: res => {
  143. if (res.confirm) {
  144. _self.imgList = {}
  145. _self.imgUpload = false
  146. }
  147. }
  148. })
  149. },
  150. textareaInput(e) {
  151. _self.content = e.detail.value
  152. },
  153. submit() {
  154. if (flag) return
  155. if (!repair_id) {
  156. _self.tui.toast('未知报修记录')
  157. return
  158. }
  159. if (_self.content == "") {
  160. _self.tui.toast('维修说明不能为空')
  161. return
  162. }
  163. uni.showLoading({
  164. title: '提交中...'
  165. })
  166. _self.$api.register({
  167. repair_id,
  168. failure_cause_id: _self.causeIdArr[_self.causeIndex],
  169. repair_content: _self.content,
  170. repair_image: _self.imgList.url,
  171. repair_status: _self.statusArr[_self.statusIndex]
  172. }).then((res) => {
  173. flag = false
  174. uni.hideLoading()
  175. _self.tui.toast('登记成功', '', 'success')
  176. setTimeout(function() {
  177. uni.$emit('repairChange', {
  178. ischange: true,
  179. type: 'repair'
  180. })
  181. uni.navigateBack({
  182. delta: 2
  183. })
  184. }, 1500)
  185. }).catch((err) => {
  186. flag = false
  187. uni.hideLoading()
  188. _self.tui.toast(err.msg)
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss">
  195. page {
  196. background-color: #f1f1f1;
  197. }
  198. .cu-bar.tabbar {
  199. position: fixed;
  200. width: 100%;
  201. left: 0;
  202. bottom: 0;
  203. }
  204. </style>