controlReportAdd.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  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">
  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. titleListData: [],
  67. siteListData: [],
  68. }
  69. },
  70. onLoad: function(option) {
  71. this.getSiteList();
  72. },
  73. mounted(){
  74. // 创建附件上传
  75. var _self = this;
  76. var input = document.createElement('input');//创建元素
  77. input.type = 'file';//添加file类型
  78. input.setAttribute("v-model", "msg");
  79. // input.onchange = (event) => {
  80. // _self.upFile(input, event)
  81. // }
  82. input.onchange = this.inputUpload;
  83. this.$refs.input.$el.appendChild(input)
  84. },
  85. methods: {
  86. // 处理文件上传
  87. inputUpload(e) {
  88. let file = e.target.files[0];
  89. let formData = new FormData();
  90. formData.append('file', file);
  91. // 请求文件上传接口
  92. // data.upload(formData).then((res) => {
  93. // console.log(res);
  94. // }).catch(() => {
  95. // this.$message.error(data.message || '操作失败')
  96. // });
  97. // this.$forceUpdate();
  98. },
  99. //新增提交
  100. async addSubmit() {
  101. if (!this.supervision_title) {
  102. uni.showToast({
  103. title: "请选择监察标题",
  104. icon: "none"
  105. });
  106. return
  107. }
  108. if (!this.site_id) {
  109. uni.showToast({
  110. title: "请选择站点",
  111. icon: "none"
  112. });
  113. return
  114. }
  115. if (!this.supervision_content) {
  116. uni.showToast({
  117. title: "请输入监察内容",
  118. icon: "none"
  119. });
  120. return
  121. }
  122. if (!this.imgList.length > 0) {
  123. uni.showToast({
  124. title: "请上传图片",
  125. icon: "none"
  126. });
  127. return
  128. }
  129. // if (!this.msg ) {
  130. // uni.showToast({
  131. // title: "请上传图片",
  132. // icon: "none"
  133. // });
  134. // return
  135. // }
  136. let res = await this.addReport({
  137. "supervision_title": this.supervision_title,
  138. "site_id": this.site_id,
  139. "supervision_content": this.supervision_content,
  140. "img":this.imgList[0]
  141. // "img":this.msg
  142. })
  143. if (!res.data.flag) {
  144. uni.showToast({
  145. title: "添加失败",
  146. icon: "none"
  147. });
  148. } else {
  149. uni.showToast({
  150. title: "添加成功",
  151. });
  152. }
  153. setTimeout(() => {
  154. uni.navigateTo({
  155. url: '/pages/eleControl/controlReport/controlReport',
  156. });
  157. }, 1000);
  158. },
  159. addReport(params = {}) {
  160. return this.$myRequest({
  161. url: 'MonitoringReporting/addMonitoringReporting',
  162. data: params
  163. })
  164. },
  165. //站带下拉数据请求
  166. async getSiteList(params = {}) {
  167. const res = await this.$myRequest({
  168. url: 'BlackoutPlan/getSiteBox',
  169. showLoading: true,
  170. data: params
  171. })
  172. this.siteListData = res.data.data
  173. },
  174. ChooseImage() {
  175. uni.chooseImage({
  176. count: 4, //默认9
  177. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  178. sourceType: ['album'], //从相册选择
  179. success: (res) => {
  180. if (this.imgList.length != 0) {
  181. this.imgList = this.imgList.concat(res.tempFilePaths)
  182. } else {
  183. this.imgList = res.tempFilePaths
  184. }
  185. }
  186. });
  187. },
  188. ViewImage(e) {
  189. uni.previewImage({
  190. urls: this.imgList,
  191. current: e.currentTarget.dataset.url
  192. });
  193. },
  194. DelImg(e) {
  195. uni.showModal({
  196. title: '删除',
  197. content: '确定要删除此图片吗?',
  198. cancelText: '取消',
  199. confirmText: '确定',
  200. success: res => {
  201. if (res.confirm) {
  202. this.imgList.splice(e.currentTarget.dataset.index, 1)
  203. }
  204. }
  205. })
  206. },
  207. submit() {
  208. uni.navigateTo({
  209. url: '/pages/accountManage/success/success',
  210. });
  211. },
  212. }
  213. }
  214. </script>
  215. <style lang="scss">
  216. select {
  217. background-size: 6%;
  218. }
  219. </style>