controlReportAdd.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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. <view class="btn-area submitBottomBtn padding-lr-sm">
  52. <button class="bg-blue round margin-top" @click="addSubmit()">提 交 </button>
  53. </view>
  54. </form>
  55. </view>
  56. </template>
  57. <script>
  58. export default {
  59. data() {
  60. return {
  61. imgList: [],
  62. supervision_title: '',
  63. site_id: '',
  64. supervision_content: '',
  65. msg:'',
  66. img:'',
  67. titleListData: [],
  68. siteListData: [],
  69. }
  70. },
  71. onLoad: function(option) {
  72. this.getSiteList();
  73. },
  74. mounted(){
  75. // 创建附件上传
  76. var _self = this;
  77. var input = document.createElement('input');//创建元素
  78. input.type = 'file'//添加file类型
  79. input.onchange = (event) => {
  80. _self.upFile(input, event)
  81. }
  82. this.$refs.input.$el.appendChild(input)
  83. },
  84. methods: {
  85. upFile(input, event) {
  86. var _self = this;
  87. uni.uploadFile({
  88. url: 'https://wx.ewoogi.com/wx/USKYOF/USKYOF.php/Home/MonitoringReporting/setUpload',
  89. files: [
  90. {
  91. file: input.files[0],
  92. uri: event.srcElement.value
  93. }
  94. ],
  95. success: (uploadFileRes) => {
  96. var data=JSON.parse(uploadFileRes.data)
  97. // alert('上传成功')
  98. // alert(data.img_url)
  99. // console.log('data')
  100. // console.log(data.img_url)
  101. // console.log('uploadFileRes')
  102. this.img=data.img_url
  103. },
  104. fail: (err) => {
  105. // alert('上传失败')
  106. console.log(err)
  107. }
  108. });
  109. },
  110. //新增提交
  111. async addSubmit() {
  112. if (!this.supervision_title.replace(/^\s*/g,'')) {
  113. uni.showToast({
  114. title: "请输入监察标题",
  115. icon: "none"
  116. });
  117. return
  118. }
  119. if (!this.site_id) {
  120. uni.showToast({
  121. title: "请选择站点",
  122. icon: "none"
  123. });
  124. return
  125. }
  126. if (!this.supervision_content.replace(/^\s*/g,'')) {
  127. uni.showToast({
  128. title: "请输入监察内容",
  129. icon: "none"
  130. });
  131. return
  132. }
  133. if (!this.img) {
  134. uni.showToast({
  135. title: "请上传图片",
  136. icon: "none"
  137. });
  138. return
  139. }
  140. // if (!this.msg ) {
  141. // uni.showToast({
  142. // title: "请上传图片",
  143. // icon: "none"
  144. // });
  145. // return
  146. // }
  147. let res = await this.addReport({
  148. "supervision_title": this.supervision_title,
  149. "site_id": this.site_id,
  150. "supervision_content": this.supervision_content,
  151. // "img":this.imgList[0]
  152. "img_url":this.img
  153. })
  154. if (!res.data.flag) {
  155. uni.showToast({
  156. title: "添加失败",
  157. icon: "none"
  158. });
  159. } else {
  160. uni.showToast({
  161. title: "添加成功",
  162. });
  163. }
  164. setTimeout(() => {
  165. uni.navigateTo({
  166. url: '/pages/eleControl/controlReport/controlReport',
  167. });
  168. }, 1000);
  169. },
  170. addReport(params = {}) {
  171. return this.$myRequest({
  172. url: 'MonitoringReporting/addMonitoringReporting',
  173. data: params
  174. })
  175. },
  176. //站带下拉数据请求
  177. async getSiteList(params = {}) {
  178. const res = await this.$myRequest({
  179. url: 'BlackoutPlan/getSiteBox',
  180. showLoading: true,
  181. data: params
  182. })
  183. this.siteListData = res.data.data
  184. },
  185. ChooseImage() {
  186. uni.chooseImage({
  187. count: 4, //默认9
  188. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  189. sourceType: ['album'], //从相册选择
  190. success: (res) => {
  191. if (this.imgList.length != 0) {
  192. this.imgList = this.imgList.concat(res.tempFilePaths)
  193. } else {
  194. this.imgList = res.tempFilePaths
  195. }
  196. }
  197. });
  198. },
  199. ViewImage(e) {
  200. uni.previewImage({
  201. urls: this.imgList,
  202. current: e.currentTarget.dataset.url
  203. });
  204. },
  205. DelImg(e) {
  206. uni.showModal({
  207. title: '删除',
  208. content: '确定要删除此图片吗?',
  209. cancelText: '取消',
  210. confirmText: '确定',
  211. success: res => {
  212. if (res.confirm) {
  213. this.imgList.splice(e.currentTarget.dataset.index, 1)
  214. }
  215. }
  216. })
  217. },
  218. submit() {
  219. uni.navigateTo({
  220. url: '/pages/accountManage/success/success',
  221. });
  222. },
  223. }
  224. }
  225. </script>
  226. <style lang="scss">
  227. select {
  228. background-size: 6%;
  229. }
  230. </style>