userInfo.vue 8.7 KB

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