planDetail.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <view>
  3. <form action="">
  4. <view style='height:30rpx'></view>
  5. <view class="form-item">
  6. <view class="title">
  7. <text class="necessary">*</text>
  8. 上报名称:
  9. </view>
  10. <input type="text" v-model="reportName">
  11. </view>
  12. <view class="form-item margin-top">
  13. <view class="title">
  14. <text class="necessary">*</text>
  15. 巡检状态:
  16. </view>
  17. <radio-group name="gender" @change="radioChange">
  18. <label class="">
  19. <radio value="0" checked /><text>正常</text>
  20. </label>
  21. <label class="">
  22. <radio value="1" /><text>异常</text>
  23. </label>
  24. <label class="">
  25. <radio value="2" /><text>故障</text>
  26. </label>
  27. <label>
  28. <radio value="3" /><text>其他</text>
  29. </label>
  30. </radio-group>
  31. </view>
  32. <view class="form-item margin-top">
  33. <view class="title">
  34. <text class="necessary">*</text>
  35. 上传图片:
  36. </view>
  37. <view class="unload-box" @tap="goCamera()">
  38. <image v-if="this.imgUrl" mode="aspectFit" style="width:70rpx;height:70rpx" :src="this.imgUrl"
  39. :data-src="this.imgUrl"></image>
  40. <view v-else style="background:rgb(223 215 215 / 63%);font-size:22rpx;line-height:40rpx;margin-top:20rpx;padding:0 20px;display:inline-block;border-radius:10rpx">请上传 + </view>
  41. </view>
  42. </view>
  43. <view class="form-item margin-top">
  44. <view class="title">
  45. <text class="necessary">*</text>
  46. 巡检描述:
  47. </view>
  48. <textarea maxlength="-1" @input="textareaAInput" placeholder="" v-model="msg"></textarea>
  49. </view>
  50. <view class="btn-area submitBottomBtn padding-lr-sm">
  51. <button class="bg-blue round margin-top" @click="$noMultipleClicks(addSubmit)">提 交 </button>
  52. </view>
  53. </form>
  54. </view>
  55. </template>
  56. <script>
  57. export default {
  58. data() {
  59. return {
  60. noClick: true,
  61. imgList: [],
  62. msg: '',
  63. id: '',
  64. img: '',
  65. imgUrl: '',
  66. reportName: '',
  67. radioOne: 0,
  68. zb_id: 0,
  69. hasRes:0
  70. }
  71. },
  72. onLoad: function(option) {
  73. this.id = option.id;
  74. this.zb_id = option.zb_id
  75. },
  76. mounted() {
  77. // 创建附件上传
  78. // var _self = this;
  79. // var input = document.createElement('input'); //创建元素
  80. // input.type = 'file' //添加file类型
  81. // input.onchange = (event) => {
  82. // _self.upFile(input, event)
  83. // }
  84. // this.$refs.input.$el.appendChild(input)
  85. },
  86. methods: {
  87. radioChange(e) {
  88. console.log('type:' + e.detail.value);
  89. this.radioOne = e.detail.value;
  90. },
  91. goCamera() {
  92. const that = this;
  93. uni.chooseImage({
  94. count: 1, // 最多可以选择的图片张数
  95. sizeType: ['original', 'compressed'], //original 原图,compressed 压缩图,默认二者都有
  96. sourceType: ['camera','album'],
  97. success: function(res) {
  98. console.log(res);
  99. that.imgUrl = res.tempFilePaths[0];
  100. var tempFilePaths = res.tempFilePaths[0];
  101. alert(1)
  102. alert(tempFilePaths)
  103. setTimeout(function(){
  104. uni.uploadFile({
  105. url: that.$BASE_URL + 'Inspection/setUpload',
  106. filePath: tempFilePaths,
  107. name: 'file',
  108. // header: {
  109. // 'content-type': 'multipart/form-data'
  110. // },
  111. formData: {
  112. // 'user': 'test'
  113. },
  114. success: (uploadFileRes) => {
  115. console.log('uploadFileRes')
  116. that.img = JSON.parse(uploadFileRes.data).img_url;
  117. alert(uploadFileRes.data)
  118. alert(that.img)
  119. that.hasRes=1
  120. }
  121. });
  122. },2000)
  123. }
  124. })
  125. },
  126. // upFile(input, event) {
  127. // var _self = this;
  128. // uni.uploadFile({
  129. // url:this.$BASE_URL+'Inspection/setUpload',
  130. // files: [{
  131. // file: input.files[0],
  132. // uri: event.srcElement.value
  133. // }],
  134. // success: (uploadFileRes) => {
  135. // var data = JSON.parse(uploadFileRes.data)
  136. // this.img = data.img_url;
  137. // alert(this.img)
  138. // },
  139. // fail: (err) => {
  140. // console.log(err)
  141. // }
  142. // });
  143. // },
  144. addSubmit() {
  145. if (!this.reportName.replace(/^\s*/g, '')) {
  146. uni.showToast({
  147. title: "请输入上报名称",
  148. icon: "none"
  149. });
  150. return
  151. }
  152. if (!this.img) {
  153. uni.showToast({
  154. title: "请上传图片",
  155. icon: "none"
  156. });
  157. return
  158. }
  159. if (!this.msg.replace(/^\s*/g, '')) {
  160. uni.showToast({
  161. title: "请输入巡检描述",
  162. icon: "none"
  163. });
  164. return
  165. }
  166. this.powerSubmitRes({
  167. "zb_id": this.zb_id,
  168. "spot_id": this.id,
  169. "report_name": this.reportName,
  170. "spot_abnormal": this.radioOne,
  171. "img": this.img,
  172. "dwsb_remarks": this.msg,
  173. })
  174. },
  175. async powerSubmitRes(params = {}) {
  176. const res = await this.$myRequest({
  177. url: 'Inspection/setInspection',
  178. data: params
  179. })
  180. if (res.data.flag) {
  181. uni.showToast({
  182. title: "提交成功",
  183. });
  184. setTimeout(() => {
  185. uni.navigateTo({
  186. url: '/pages/xunJian/planInnerList/planInnerList?id=' + this.zb_id,
  187. });
  188. }, 1000);
  189. }
  190. },
  191. textareaAInput(e) {
  192. this.textareaAValue = e.detail.value
  193. },
  194. }
  195. }
  196. </script>
  197. <style lang="scss">
  198. .unload-box {
  199. width: calc(100% - 200rpx)
  200. }
  201. .textarea {
  202. width: calc(100% - 200rpx)
  203. }
  204. </style>