addData.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. <template>
  2. <view class="content">
  3. <view>
  4. <view class="form-data">
  5. <u-form :model="form" ref="uForm" :label-width="140" :error-type="['toast']">
  6. <u-form-item prop="gatherNum_other" label="其他垃圾:" >
  7. <u-input :disabled="isView" type="number" placeholder="请输入" v-model="form.gatherNum_other" />
  8. <text slot="right" style="color: #000000;">桶(约{{form.gatherNum_other*240}}kg)</text>
  9. </u-form-item>
  10. <u-form-item prop="gatherNum_chuyu" label="厨余垃圾:" >
  11. <u-input :disabled="isView" placeholder="请输入" type="number" v-model="form.gatherNum_chuyu" />
  12. <text slot="right" style="color: #000000;">桶(约{{form.gatherNum_chuyu*240}}kg)</text>
  13. </u-form-item>
  14. <u-form-item prop="gatherNum_jianzhu" label="建筑垃圾:" >
  15. <u-input :disabled="isView" placeholder="请输入" type="number" v-model="form.gatherNum_jianzhu" />
  16. <text slot="right" style="color: #000000;">吨(约{{form.gatherNum_jianzhu*1000}}kg)</text>
  17. </u-form-item>
  18. </u-form>
  19. </view>
  20. <view class="form-data remark">
  21. <text>信息备注</text>
  22. <textarea :disabled="isView" :auto-height="true" :maxlength="500" v-model="form.remark" class="receiveAddress"/>
  23. </view>
  24. <view class="form-data qyImg">
  25. <text>清运照片</text>
  26. <view class="info-main">
  27. <view v-if="photograph.length<3" class="camera-btn">
  28. <view @click="goPhotograph" class="photograph-camera">
  29. <u-icon name="camera" color="#bfbfbf" size="60" ></u-icon>
  30. </view>
  31. <view >
  32. (最多3张)
  33. </view>
  34. </view>
  35. <view v-show="photograph.length" v-for="(item,index) in photograph" :key="index" class="photograph-con">
  36. <u-icon v-show="!isView" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph(index)"></u-icon>
  37. <u-image width="100%" height="100%" :src="item" @click="previewPictures(item)"></u-image>
  38. </view>
  39. </view>
  40. </view>
  41. <u-button v-if="isView" @click="isView = false" class="submitBtn" type="waring" shape="circle">修改</u-button>
  42. <u-button v-else @click="submit" :loading="loading" class="submitBtn" type="success" shape="circle">提交</u-button>
  43. <uni-popup ref="openModal" type="center">
  44. <uni-popup-dialog content="确认提交吗?" @confirm="onOk" :title="title"></uni-popup-dialog>
  45. </uni-popup>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import uniPopup from '@/components/uni-popup/uni-popup.vue'
  51. import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
  52. import {gatherSave} from '@/api/index.js'
  53. export default {
  54. components: {
  55. uniPopup,uniPopupDialog
  56. },
  57. data() {
  58. return {
  59. title:'',
  60. loading:false, // 提交按钮加载圈
  61. photograph: [], // 图片路径
  62. form: {
  63. gatherNum_other: '', // 其它垃圾
  64. gatherNum_chuyu: '', // 厨余垃圾
  65. gatherNum_jianzhu: '', // 建筑垃圾
  66. remark: '' // 备注
  67. },
  68. isView: false // 是否是查看详情
  69. };
  70. },
  71. onLoad(option) {
  72. console.log(option,option.id,'ppppppppp')
  73. // 查看
  74. if(option && option.id){
  75. this.isView = true
  76. }else {
  77. console.log('--------新增')
  78. this.photograph = []
  79. this.$refs.uForm.resetFields()
  80. }
  81. },
  82. onUnload() {
  83. },
  84. methods: {
  85. // 签到拍照
  86. goPhotograph() {
  87. uni.chooseImage({
  88. count: 3, //默认9
  89. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  90. sourceType: ['album','camera'], //从相册选择
  91. success: (res) =>{
  92. console.log(JSON.stringify(res.tempFilePaths));
  93. this.photograph = this.photograph.concat(res.tempFilePaths)
  94. console.log(this.photograph.length,'this.photograph')
  95. }
  96. });
  97. },
  98. // 预览图片
  99. previewPictures(item) {
  100. const photograph = [item];
  101. uni.previewImage({
  102. urls: photograph,
  103. });
  104. },
  105. // 删除图片
  106. cancelPhotograph(index) {
  107. setTimeout(() => {
  108. this.photograph.splice(index,1)
  109. }, 500);
  110. },
  111. // 提交
  112. submit(){
  113. if(!this.form.gatherNum_other && !this.form.gatherNum_chuyu && !this.form.gatherNum_jianzhu) {
  114. uni.showToast({
  115. title: '请至少输入一项垃圾分类的数量!',
  116. icon: 'none'
  117. })
  118. return false
  119. } else {
  120. this.$refs.openModal.open()
  121. }
  122. },
  123. // 确认提交
  124. onOk() {
  125. this.$refs.openModal.close()
  126. let params = {
  127. rubbishEntityList: [],
  128. imageUrlList: this.photograph
  129. }
  130. if(this.form.gatherNum_other) {
  131. params.rubbishEntityList.push({
  132. "rubbishType":"GATHER_OTHER",
  133. "rubbishWeight": this.form.gatherNum_other*240,
  134. "gatherNum": this.form.gatherNum_other,
  135. "unit":"BUCKET"
  136. })
  137. }
  138. if(this.form.gatherNum_chuyu) {
  139. params.rubbishEntityList.push({
  140. "rubbishType":"GATHER_KITCHEN",
  141. "rubbishWeight": this.form.gatherNum_chuyu*240,
  142. "gatherNum": this.form.gatherNum_chuyu,
  143. "unit":"BUCKET"
  144. })
  145. }
  146. if(this.form.gatherNum_jianzhu) {
  147. params.rubbishEntityList.push({
  148. "rubbishType":"GATHER_BUILDING",
  149. "rubbishWeight": this.form.gatherNum_jianzhu*1000,
  150. "gatherNum": this.form.gatherNum_jianzhu,
  151. "unit":"TON"
  152. })
  153. }
  154. this.loading=true
  155. gatherSave(params).then(res=>{
  156. if(res.status == 200) {
  157. uni.showToast({
  158. title: res.message,
  159. icon: 'none'
  160. })
  161. setTimeout(()=>{
  162. uni.navigateBack()
  163. },300)
  164. } else {
  165. uni.showToast({
  166. title: res.message,
  167. icon: 'none'
  168. })
  169. }
  170. this.loading= false
  171. })
  172. },
  173. },
  174. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  175. onReady() {
  176. this.$refs.uForm.setRules(this.rules);
  177. }
  178. }
  179. </script>
  180. <style lang="scss">
  181. .content{
  182. width: 100%;
  183. height: 100vh;
  184. padding: 0;
  185. background: #F5F5F5;
  186. // .buttons{
  187. // font-size: 32upx;
  188. // display: block;
  189. // height: 80upx;
  190. // line-height: 80upx;
  191. // margin: 0 auto;
  192. // background-color: #0DC55F;
  193. // color: #fff;
  194. // border-radius: 50upx;
  195. // }
  196. .receiveAddress{
  197. width: 100%;
  198. line-height: 1.5em;
  199. box-sizing: border-box;
  200. font-style: normal;
  201. }
  202. .form-data{
  203. padding: 0 40upx;
  204. margin-bottom: 20upx;
  205. background-color: #fff;
  206. }
  207. .remark{
  208. padding: 40upx ;
  209. }
  210. .qyImg{
  211. padding: 40upx ;
  212. }
  213. .info-main {
  214. margin-top: 14upx;
  215. border-radius: 12upx;
  216. background-color: #fff;
  217. display: flex;
  218. .location-icon {
  219. padding-left: 10upx;
  220. vertical-align: sub;
  221. }
  222. .photograph-camera {
  223. border: 2upx dashed #bfbfbf;
  224. border-radius: 12upx;
  225. width: 140upx;
  226. height: 140upx;
  227. display: flex;
  228. align-items: center;
  229. justify-content: center;
  230. }
  231. .camera-btn{
  232. display: flex;
  233. flex-direction: column;
  234. align-items: center;
  235. color: #999999;
  236. }
  237. .photograph-con {
  238. margin: 0 20upx;
  239. width: 140upx;
  240. height: 140upx;
  241. text-align: center;
  242. position: relative;
  243. .photograph-icon {
  244. display: inline-block;
  245. padding-top: 48upx;
  246. }
  247. .close-circle-icon {
  248. background-color: #fff;
  249. border-radius: 50%;
  250. position: absolute;
  251. right: -23upx;
  252. top: -23upx;
  253. z-index: 9;
  254. }
  255. }
  256. }
  257. .submitBtn{
  258. font-size: 32upx;
  259. display: block;
  260. width: 670upx;
  261. height: 80upx;
  262. line-height: 80upx;
  263. margin: 0 auto;
  264. color: #fff;
  265. border-radius: 50upx;
  266. }
  267. }
  268. </style>