addData.vue 7.8 KB

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