userInfo.vue 11 KB

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