controlReportAdd.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  1. <template>
  2. <view class="appWrapper">
  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="supervision_title" required>
  11. <!-- <select name="" id="" filterable clearable v-model="supervision_title">
  12. <option value="">请选择</option>
  13. <option :value=item.supervision_name v-for="item in titleListData">{{ item.supervision_name}}</option>
  14. </select> -->
  15. </view>
  16. <view class="form-item">
  17. <view class="title"><text class="necessary">*</text>所属站点:</view>
  18. <select name="" id="" filterable clearable v-model="site_id">
  19. <option value="">请选择</option>
  20. <option :value=item.id v-for="item in siteListData">{{ item.site_name}}</option>
  21. </select>
  22. </view>
  23. <view class="form-item">
  24. <view class="title"><text class="necessary">*</text>监察内容:</view>
  25. <textarea maxlength="-1" width="250" v-model="supervision_content"></textarea>
  26. </view>
  27. <view class="form-item">
  28. <view class="title"><text class="necessary">*</text>上传图片:</view>
  29. <view style="width:500rpx">
  30. <!-- <uni-group title="只选择图片">
  31. <uni-file-picker limit="1"></uni-file-picker>
  32. </uni-group> -->
  33. <view ref="input" class="input">
  34. </view>
  35. <!-- <view class="cu-form-group" style="padding:0">
  36. <view class="grid col-4 grid-square flex-sub">
  37. <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage"
  38. :data-url="imgList[index]">
  39. <image :src="imgList[index]" mode="aspectFill"></image>
  40. <view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
  41. <text class='cuIcon-close'></text>
  42. </view>
  43. </view>
  44. <view class="solids" @tap="ChooseImage" v-if="imgList.length<4">
  45. <text class='cuIcon-cameraadd'></text>
  46. </view>
  47. </view>
  48. </view> -->
  49. </view>
  50. </view>
  51. <br>
  52. <view style="height:20rpx;background:#EDEDED"></view>
  53. <view class="form-item justify-between" style="border-bottom:1px solid #EDEDED;padding:20rpx 30rpx" @tap="goArchiveDetail()">
  54. <view >现场档案</view>
  55. <view><text class="icon iconfont margin-left-xs ">&#xe629;</text></view>
  56. </view>
  57. <view class="btn-area submitBottomBtn padding-lr-sm">
  58. <button class="bg-blue round margin-top" @click="$noMultipleClicks(addSubmit)">提 交 </button>
  59. </view>
  60. </form>
  61. </view>
  62. </template>
  63. <script>
  64. export default {
  65. data() {
  66. return {
  67. noClick:true,
  68. imgList: [],
  69. supervision_title: '',
  70. site_id: '',
  71. supervision_content: '',
  72. msg:'',
  73. img:'',
  74. titleListData: [],
  75. siteListData: [],
  76. }
  77. },
  78. onLoad: function(option) {
  79. this.getSiteList();
  80. },
  81. mounted(){
  82. // 创建附件上传
  83. var _self = this;
  84. var input = document.createElement('input');//创建元素
  85. input.type = 'file'//添加file类型
  86. input.onchange = (event) => {
  87. _self.upFile(input, event)
  88. }
  89. this.$refs.input.$el.appendChild(input)
  90. },
  91. methods: {
  92. goArchiveDetail(){
  93. if(this.site_id){
  94. uni.navigateTo({
  95. url: '/pages/siteArchive/archiveDetail/archiveDetail?siteId='+this.site_id+'&mark=control',
  96. });
  97. }else{
  98. uni.showToast({
  99. title: "请先选择所属站点",
  100. icon: "none"
  101. });
  102. }
  103. },
  104. upFile(input, event) {
  105. var _self = this;
  106. uni.uploadFile({
  107. url: _self.$BASE_URL+'MonitoringReporting/setUpload',
  108. files: [
  109. {
  110. file: input.files[0],
  111. uri: event.srcElement.value
  112. }
  113. ],
  114. success: (uploadFileRes) => {
  115. var data=JSON.parse(uploadFileRes.data)
  116. if(data.flag){
  117. this.img=data.img_url
  118. }else{
  119. uni.showToast({
  120. title: data.msg,
  121. icon: "none"
  122. });
  123. }
  124. // alert('上传成功')
  125. // alert(data.img_url)
  126. // console.log('data')
  127. // console.log(data.img_url)
  128. // console.log('uploadFileRes')
  129. },
  130. fail: (err) => {
  131. // alert('上传失败')
  132. // alert(err)
  133. console.log(err)
  134. // console.log('err'+err)
  135. // console.log('err.errMsg'+errMsg)
  136. }
  137. });
  138. },
  139. //新增提交
  140. async addSubmit() {
  141. if (!this.supervision_title.replace(/^\s*/g,'')) {
  142. uni.showToast({
  143. title: "请输入监察标题",
  144. icon: "none"
  145. });
  146. return
  147. }
  148. if (!this.site_id) {
  149. uni.showToast({
  150. title: "请选择站点",
  151. icon: "none"
  152. });
  153. return
  154. }
  155. if (!this.supervision_content.replace(/^\s*/g,'')) {
  156. uni.showToast({
  157. title: "请输入监察内容",
  158. icon: "none"
  159. });
  160. return
  161. }
  162. if (!this.img) {
  163. uni.showToast({
  164. title: "请上传图片",
  165. icon: "none"
  166. });
  167. return
  168. }
  169. // if (!this.msg ) {
  170. // uni.showToast({
  171. // title: "请上传图片",
  172. // icon: "none"
  173. // });
  174. // return
  175. // }
  176. let res = await this.addReport({
  177. "supervision_title": this.supervision_title,
  178. "site_id": this.site_id,
  179. "supervision_content": this.supervision_content,
  180. // "img":this.imgList[0]
  181. "img_url":this.img
  182. })
  183. if (!res.data.flag) {
  184. uni.showToast({
  185. title: "添加失败",
  186. icon: "none"
  187. });
  188. } else {
  189. uni.showToast({
  190. title: "添加成功",
  191. });
  192. }
  193. setTimeout(() => {
  194. uni.navigateTo({
  195. url: '/pages/eleControl/controlReport/controlReport',
  196. });
  197. }, 1000);
  198. },
  199. addReport(params = {}) {
  200. return this.$myRequest({
  201. url: 'MonitoringReporting/addMonitoringReporting',
  202. data: params
  203. })
  204. },
  205. //站带下拉数据请求
  206. async getSiteList(params = {}) {
  207. const res = await this.$myRequest({
  208. url: 'BlackoutPlan/getSiteBox',
  209. showLoading: true,
  210. data: params
  211. })
  212. this.siteListData = res.data.data
  213. },
  214. ChooseImage() {
  215. uni.chooseImage({
  216. count: 4, //默认9
  217. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  218. sourceType: ['album'], //从相册选择
  219. success: (res) => {
  220. if (this.imgList.length != 0) {
  221. this.imgList = this.imgList.concat(res.tempFilePaths)
  222. } else {
  223. this.imgList = res.tempFilePaths
  224. }
  225. }
  226. });
  227. },
  228. ViewImage(e) {
  229. uni.previewImage({
  230. urls: this.imgList,
  231. current: e.currentTarget.dataset.url
  232. });
  233. },
  234. DelImg(e) {
  235. uni.showModal({
  236. title: '删除',
  237. content: '确定要删除此图片吗?',
  238. cancelText: '取消',
  239. confirmText: '确定',
  240. success: res => {
  241. if (res.confirm) {
  242. this.imgList.splice(e.currentTarget.dataset.index, 1)
  243. }
  244. }
  245. })
  246. },
  247. submit() {
  248. uni.navigateTo({
  249. url: '/pages/accountManage/success/success',
  250. });
  251. },
  252. }
  253. }
  254. </script>
  255. <style lang="scss">
  256. select {
  257. background-size: 6%;
  258. }
  259. </style>