userInfo.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <view class="content">
  3. <view class="content-form">
  4. <view class="form-data">
  5. <u-form :model="form" ref="uForm" :label-width="140" :error-type="['toast']">
  6. <u-form-item prop="time" label="用户类型:" >
  7. <u-select v-model="show" mode="mutil-column-auto" :list="list" @confirm="confirm"></u-select>
  8. <u-input placeholder="请选择用户类型" v-model="form.time" @click="selectTime" :disabled="true"/>
  9. <u-icon name="arrow-right" slot="right" @click="selectTime"></u-icon>
  10. </u-form-item>
  11. <u-form-item prop="info" label="用户名称:" >
  12. <u-input placeholder="请输入用户名称" v-model="form.info"/>
  13. </u-form-item>
  14. <u-form-item prop="info" label="联系电话:" >
  15. <u-input placeholder="请输入联系电话" v-model="form.info"/>
  16. </u-form-item>
  17. </u-form>
  18. </view>
  19. <view class="form-data">
  20. <u-form :model="form" ref="uForm" :label-width="140" :error-type="['toast']">
  21. <u-form-item prop="address" label="通讯地址:" >
  22. <u-input placeholder="请选择通讯地址" v-model="form.address" @click="selectAddress" :disabled="true"/>
  23. <u-icon name="arrow-right" slot="right"></u-icon>
  24. </u-form-item>
  25. <u-form-item prop="info" label="详细信息:" >
  26. <u-input placeholder="请输入详细信息" v-model="form.info"/>
  27. </u-form-item>
  28. </u-form>
  29. </view>
  30. <view class="form-data qyImg">
  31. <view> 上传图片 <text style="color: #a6a6a6;">(仅可上传1张,10MB以内)</text></view>
  32. <view class="info-main">
  33. <view v-if="photograph.length<1 && !isView" class="camera-btn">
  34. <view @click="goPhotograph" class="photograph-camera">
  35. <u-icon name="camera" color="#bfbfbf" size="60" ></u-icon>
  36. </view>
  37. </view>
  38. <view v-show="photograph.length" v-for="(item,index) in photograph" :key="index" class="photograph-con">
  39. <u-icon v-show="!isView" name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph(index)"></u-icon>
  40. <u-image width="100%" height="100%" :src="item" @click="previewPictures(item)"></u-image>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. <view class="btns">
  46. <u-button @click="submit" :loading="loading" :custom-style="submitBtn">提交</u-button>
  47. </view>
  48. <!-- <uni-popup ref="openModal" type="center">
  49. <uni-popup-dialog content="确认提交吗?" @confirm="onOk" :title="title"></uni-popup-dialog>
  50. </uni-popup> -->
  51. </view>
  52. </template>
  53. <script>
  54. // import uniPopup from '@/components/uni-popup/uni-popup.vue'
  55. // import uniPopupDialog from '@/components/uni-popup/uni-popup-dialog.vue'
  56. import {gatherSave,gatherDetail} from '@/api/index.js'
  57. import {saveImgToAliOss} from '@/libs/tools.js'
  58. export default {
  59. // components: {
  60. // uniPopup,uniPopupDialog
  61. // },
  62. data() {
  63. return {
  64. title:'',
  65. loading:false, // 提交按钮加载圈
  66. photograph: [], // 图片路径
  67. form: {
  68. time: '', // 其它垃圾
  69. info: '', // 厨余垃圾
  70. address:'' // 通讯地址
  71. },
  72. isView: false ,// 是否是查看详情
  73. itemId:'',
  74. submitBtn:{
  75. backgroundColor: '#4F88F7',
  76. color: '#fff',
  77. borderRadius: '12px'
  78. },
  79. show: false,
  80. list: [
  81. {
  82. value: 1,
  83. label: '今天',
  84. children: [
  85. {
  86. value: 2,
  87. label: '上午(08-13点)',
  88. },
  89. {
  90. value: 3,
  91. label: '下午(13-18点)',
  92. }
  93. ]
  94. },
  95. {
  96. value: 4,
  97. label: '明天',
  98. children: [
  99. {
  100. value: 5,
  101. label: '上午(08-13点)',
  102. },
  103. {
  104. value: 6,
  105. label: '下午(13-18点)',
  106. }
  107. ]
  108. },
  109. {
  110. value: 7,
  111. label: '后天',
  112. children: [
  113. {
  114. value: 8,
  115. label: '上午(08-13点)',
  116. },
  117. {
  118. value: 9,
  119. label: '下午(13-18点)',
  120. }
  121. ]
  122. },
  123. ],
  124. rules: {
  125. time: [
  126. {
  127. required: true,
  128. message: '请选择时间',
  129. trigger: ['blur', 'change']
  130. }
  131. ],
  132. info:[{required:true,message:'请选择用户信息',trigger:['change']}]
  133. }
  134. };
  135. },
  136. onLoad(option) {
  137. console.log(option,option.id,'ppppppppp')
  138. // 查看
  139. if(option && option.id){
  140. this.isView = true
  141. this.itemId=option.id
  142. this.getDetailData()
  143. }else {
  144. console.log('--------新增')
  145. this.photograph = []
  146. this.form.remarks = ''
  147. this.$refs.uForm.resetFields()
  148. }
  149. },
  150. onUnload() {
  151. },
  152. methods: {
  153. // 保留几位小数
  154. // numberToFixed: function (key, num, max) {
  155. // let val = this.form[key]
  156. // let ret = numberToFixed(val, num, max)
  157. // this.$nextTick(() => {
  158. // this.form[key] = ret
  159. // })
  160. // },
  161. selectAddress(){
  162. wx.chooseLocation({
  163. success: function(res) {
  164. if(res){
  165. this.form.address=res,address
  166. }
  167. console.log(res,'-----------dizhi --------------')
  168. },
  169. })
  170. },
  171. // 选择用户类型
  172. selectTime(){
  173. wx.hideKeyboard()
  174. setTimeout(()=>{
  175. this.show=true
  176. },500)
  177. },
  178. confirm(e) {
  179. console.log(e);
  180. this.form.time=e[0].label + e[1].label
  181. },
  182. // 选择用户信息
  183. selectUserInfo(){
  184. uni.navigateTo({
  185. url: '/pages/index/userInfo'
  186. })
  187. },
  188. // 获取详情数据
  189. getDetailData(){
  190. gatherDetail({id:this.itemId}).then(res=>{
  191. if(res.status==200){
  192. console.log(res)
  193. const a = res.data.gatherRubbishList.find(item=>item.rubbishType=='GATHER_BUILDING')
  194. const b = res.data.gatherRubbishList.find(item=>item.rubbishType=='GATHER_OTHER')
  195. const c = res.data.gatherRubbishList.find(item=>item.rubbishType=='GATHER_KITCHEN')
  196. this.form.gatherNum_jianzhu= a ? a.gatherNum.toString() : '0'
  197. this.form.gatherNum_chuyu= c ? c.gatherNum.toString() : '0'
  198. this.form.gatherNum_other= b ? b.gatherNum.toString() : '0'
  199. this.form.remarks=res.data.remarks
  200. this.photograph=res.data.imageUrlList || []
  201. console.log(this.form,'this.form')
  202. }
  203. })
  204. },
  205. // 拍照或从相册选图片
  206. goPhotograph() {
  207. uni.chooseImage({
  208. count: 1, //默认9
  209. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  210. sourceType: ['album','camera'], //从相册选择
  211. success: (res) =>{
  212. console.log(res,'rrrrrrrrrrr')
  213. console.log(JSON.stringify(res.tempFilePaths));
  214. console.log(this.photograph.length,'this.photograph')
  215. if(res.tempFiles[0].size>10485760){
  216. uni.showToast({
  217. title: '图片过大无法上传!',
  218. icon: 'none'
  219. })
  220. return
  221. }
  222. uni.showLoading({
  223. title:'正在保存图片...',
  224. mask: true
  225. })
  226. saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
  227. // console.log(ret,'----------ret')
  228. this.photograph.push(ret.data)
  229. // _this.photograph = ret.data
  230. uni.hideLoading()
  231. })
  232. }
  233. });
  234. },
  235. // 预览图片
  236. previewPictures(item) {
  237. const photograph = [item];
  238. uni.previewImage({
  239. urls: photograph,
  240. });
  241. },
  242. // 删除图片
  243. cancelPhotograph(index) {
  244. setTimeout(() => {
  245. this.photograph.splice(index,1)
  246. }, 500);
  247. },
  248. // 提交
  249. submit(){
  250. this.$refs.uForm.validate(valid => {
  251. if (valid) {
  252. console.log('验证通过');
  253. } else {
  254. console.log('验证失败');
  255. }
  256. });
  257. },
  258. // 确认提交
  259. // onOk() {
  260. // this.$refs.openModal.close()
  261. // let params = {
  262. // rubbishEntityList: [],
  263. // imageUrlList: this.photograph,
  264. // remarks: this.form.remarks
  265. // }
  266. // if(this.itemId){
  267. // params.id=this.itemId
  268. // }
  269. // if(this.form.gatherNum_other) {
  270. // params.rubbishEntityList.push({
  271. // "rubbishType":"GATHER_OTHER",
  272. // "rubbishWeight": this.form.gatherNum_other*240,
  273. // "gatherNum": this.form.gatherNum_other,
  274. // "unit":"BUCKET"
  275. // })
  276. // }
  277. // if(this.form.gatherNum_chuyu) {
  278. // params.rubbishEntityList.push({
  279. // "rubbishType":"GATHER_KITCHEN",
  280. // "rubbishWeight": this.form.gatherNum_chuyu*240,
  281. // "gatherNum": this.form.gatherNum_chuyu,
  282. // "unit":"BUCKET"
  283. // })
  284. // }
  285. // if(this.form.gatherNum_jianzhu) {
  286. // params.rubbishEntityList.push({
  287. // "rubbishType":"GATHER_BUILDING",
  288. // "rubbishWeight": this.form.gatherNum_jianzhu*1000,
  289. // "gatherNum": this.form.gatherNum_jianzhu,
  290. // "unit":"TON"
  291. // })
  292. // }
  293. // this.loading=true
  294. // gatherSave(params).then(res=>{
  295. // if(res.status == 200) {
  296. // uni.showToast({
  297. // title: res.message,
  298. // icon: 'none'
  299. // })
  300. // setTimeout(()=>{
  301. // uni.navigateBack()
  302. // },300)
  303. // } else {
  304. // uni.showToast({
  305. // title: res.message,
  306. // icon: 'none'
  307. // })
  308. // }
  309. // this.loading= false
  310. // })
  311. // },
  312. },
  313. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  314. onReady() {
  315. this.$refs.uForm.setRules(this.rules);
  316. }
  317. }
  318. </script>
  319. <style lang="scss">
  320. .content{
  321. width: 100%;
  322. height: 100vh;
  323. padding: 0;
  324. background: #F5F5F5;
  325. display: flex;
  326. flex-direction: column;
  327. .content-form{
  328. flex: 1;
  329. overflow-y: scroll;
  330. }
  331. .receiveAddress{
  332. width: 100%;
  333. line-height: 1.5em;
  334. box-sizing: border-box;
  335. font-style: normal;
  336. }
  337. .form-data{
  338. padding: 0 30upx;
  339. margin-bottom: 20upx;
  340. background-color: #fff;
  341. }
  342. .qyImg{
  343. padding: 40upx ;
  344. }
  345. .info-main {
  346. margin-top: 14upx;
  347. border-radius: 12upx;
  348. background-color: #fff;
  349. display: flex;
  350. .location-icon {
  351. padding-left: 10upx;
  352. vertical-align: sub;
  353. }
  354. .photograph-camera {
  355. border: 2upx dashed #bfbfbf;
  356. border-radius: 12upx;
  357. width: 140upx;
  358. height: 140upx;
  359. display: flex;
  360. align-items: center;
  361. justify-content: center;
  362. }
  363. .camera-btn{
  364. display: flex;
  365. flex-direction: column;
  366. align-items: center;
  367. color: #999999;
  368. font-size: 24upx;
  369. }
  370. .photograph-con {
  371. margin: 0 20upx;
  372. width: 140upx;
  373. height: 140upx;
  374. text-align: center;
  375. position: relative;
  376. .photograph-icon {
  377. display: inline-block;
  378. padding-top: 48upx;
  379. }
  380. .close-circle-icon {
  381. background-color: #fff;
  382. border-radius: 50%;
  383. position: absolute;
  384. right: -23upx;
  385. top: -23upx;
  386. z-index: 9;
  387. }
  388. }
  389. }
  390. .btns{
  391. padding: 30upx 30upx 50upx;
  392. background-color: #fff;
  393. }
  394. }
  395. </style>