userInfo.vue 11 KB

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