addcont.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. <template>
  2. <view style="background-color: #fff;margin-top: 30rpx;">
  3. <view class="context_box">
  4. <view class="weatherbox">
  5. <u--form labelPosition="left" :model="weatherdatas" :rules="rules" ref="form1">
  6. <u-form-item label="监测事项" prop="temp" ref="item1" labelWidth="80">
  7. <u--input v-model="weatherdatas.temp" border="none"></u--input>
  8. </u-form-item>
  9. </u--form>
  10. </view>
  11. <view class="imgbox">
  12. <view class="title">
  13. 图像信息
  14. </view>
  15. <view class="imgbox_box">
  16. <view class="addimg" @click="gainimg">
  17. <u-icon size="20" name="plus" color="#409eff"></u-icon>
  18. </view>
  19. <view class="imgitem" v-for="item,index in urllist" :key="index">
  20. <view class="icon" @click="deleimg(index)">
  21. <u-icon name="close" color="#fff"></u-icon>
  22. </view>
  23. <image :src="baseUrl+item" mode="scaleToFill" class="img"></image>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="imgbox_tishi" v-if="urllist.length ==0 && imgtf">
  28. 请选择图片
  29. </view>
  30. <view class="describe_box">
  31. <view class="title">
  32. 内容
  33. </view>
  34. <view class="textarea">
  35. <u--textarea v-model="value1" placeholder="请输入内容" :maxlength="-1" :autoHeight="false" height="200">
  36. </u--textarea>
  37. </view>
  38. </view>
  39. <view class="imgbox_tishi" v-if="value1==''&&texttf">
  40. 请填写内容
  41. </view>
  42. <u-button type="primary" text="提交" @click="submit" style="margin-top: 30rpx;"></u-button>
  43. </view>
  44. <!-- <kps-image-cutter @ok="onok" @cancel="oncancle" :url="kpsurlL" :fixed="false" :blob="false" :maxWidth="500"
  45. :maxHeight="500"></kps-image-cutter> -->
  46. </view>
  47. </template>
  48. <script>
  49. import kpsImageCutter from "@/components/ksp-image-cutter/ksp-image-cutter.vue";
  50. export default {
  51. data() {
  52. return {
  53. weatherdatas: {
  54. temp: ""
  55. },
  56. rules: {
  57. 'temp': {
  58. type: 'string',
  59. max: 20,
  60. required: true,
  61. message: '请填写事项(字数最多20字)',
  62. trigger: ['blur', 'change'],
  63. },
  64. },
  65. urllist: [],
  66. value1: "",
  67. kpsurlL: "",
  68. imgtf: false,
  69. texttf: false
  70. }
  71. },
  72. components: {
  73. kpsImageCutter
  74. },
  75. watch: {
  76. urllist(newName, oldName) {
  77. console.log(this.urllist)
  78. if (this.urllist != 0) {
  79. this.imgtf = false
  80. }
  81. },
  82. value1() {
  83. if (this.value1 != '') {
  84. this.texttf = false
  85. }
  86. },
  87. videoData(news, old) {
  88. console.log('触发了2222222222222222222222')
  89. console.log(news)
  90. uni.switchTab({
  91. url: '../response/index'
  92. })
  93. // if (news) {
  94. // }
  95. },
  96. },
  97. computed: {
  98. // 视频消息
  99. videoData() {
  100. return this.$store.state.video
  101. },
  102. },
  103. methods: {
  104. gainimg() { //添加图片
  105. uni.chooseImage({
  106. count: 1, //默认9
  107. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  108. sourceType: ['camera', 'album'], //从相册选择
  109. success: (res) => {
  110. console.log(res)
  111. // this.urllist.push(res.tempFilePaths[0])
  112. // this.kpsurlL = res.tempFilePaths[0]
  113. this.onok({ path: res.tempFilePaths[0] })
  114. }
  115. });
  116. },
  117. oncancle() {
  118. this.kpsurlL = ""
  119. },
  120. onok(ev) {
  121. uni.uploadFile({
  122. url: this.baseUrl +
  123. '/api/api_gateway?method=monitor_manage.cbd_manage.add_img', //仅为示例,非真实的接口地址
  124. filePath: ev.path,
  125. name: 'img_file',
  126. success: (uploadFileRes) => {
  127. console.log(JSON.parse(uploadFileRes.data).data.src)
  128. this.urllist.push(JSON.parse(uploadFileRes.data).data.src)
  129. this.kpsurlL = ""
  130. }
  131. });
  132. },
  133. submit() {
  134. this.$refs.form1.validate().then(res => {
  135. // this.alterpass()
  136. if (this.urllist.length == 0) {
  137. this.imgtf = true
  138. } else if (this.value1 == '') {
  139. this.texttf = true
  140. } else {
  141. var objlist = JSON.parse(JSON.stringify(this.$store.state.addobj))
  142. var obj = {
  143. name: this.weatherdatas.temp,
  144. imglist: this.urllist,
  145. text: this.value1
  146. }
  147. // var arr = []
  148. console.log(objlist)
  149. objlist.push(obj)
  150. this.$store.state.addobj = objlist
  151. uni.navigateBack({
  152. delta: 1
  153. })
  154. // uni.setStorage({
  155. // key:"addobj",
  156. // data:JSON.stringify(obj),
  157. // success(res) {
  158. // uni.navigateBack({
  159. // delta:1
  160. // })
  161. // }
  162. // })
  163. }
  164. }).catch(errors => {
  165. uni.$u.toast('校验失败')
  166. })
  167. },
  168. deleimg(index) {
  169. this.urllist.splice(index, 1)
  170. }
  171. },
  172. onLoad() {
  173. console.log(this.baseUrl)
  174. }
  175. }
  176. </script>
  177. <style lang="less" scoped>
  178. page {
  179. background-color: #f7f7f7;
  180. }
  181. .context_box {
  182. width: 90%;
  183. margin: 0 auto;
  184. padding-bottom: 40rpx;
  185. /deep/.u-form-item__body {
  186. border-bottom: 1px solid #F6F6F6;
  187. margin-bottom: 20rpx;
  188. }
  189. .imgbox {
  190. width: 100%;
  191. display: flex;
  192. margin-top: 30rpx;
  193. .title {
  194. font-size: 30rpx;
  195. width: 160rpx;
  196. }
  197. .imgbox_box {
  198. display: flex;
  199. flex-wrap: wrap;
  200. width: 80%;
  201. // justify-content: space-around;
  202. .addimg {
  203. width: 140rpx;
  204. height: 140rpx;
  205. border: 1px dashed #409eff;
  206. // text-align: center;
  207. display: flex;
  208. justify-content: space-around;
  209. margin-right: 30rpx;
  210. margin-bottom: 30rpx;
  211. }
  212. .imgitem {
  213. width: 140rpx;
  214. height: 140rpx;
  215. margin-right: 30rpx;
  216. margin-bottom: 30rpx;
  217. position: relative;
  218. .icon {
  219. position: absolute;
  220. top: -20rpx;
  221. right: -20rpx;
  222. z-index: 9;
  223. width: 40rpx;
  224. height: 40rpx;
  225. border-radius: 50%;
  226. display: flex;
  227. justify-content: space-around;
  228. background-color: red;
  229. }
  230. .img {
  231. width: 100%;
  232. height: 100%;
  233. // border: 1px solid #409eff;
  234. }
  235. }
  236. }
  237. }
  238. .imgbox_tishi {
  239. padding-left: 160rpx;
  240. font-size: 24rpx;
  241. color: red;
  242. }
  243. .describe_box {
  244. width: 100%;
  245. display: flex;
  246. margin-top: 30rpx;
  247. margin-bottom: 30rpx;
  248. .title {
  249. font-size: 30rpx;
  250. width: 160rpx;
  251. }
  252. .textarea {
  253. width: 80%;
  254. }
  255. }
  256. }
  257. </style>