userInfo.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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" class="houseAddress" type="textarea"/>
  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. this.getDetailData()
  89. },
  90. onUnload() {
  91. },
  92. methods: {
  93. // 获取详情数据
  94. getDetailData(){
  95. userDetail().then(res=>{
  96. if(res.status==200){
  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. this.photograph=res.tempFilePaths
  160. uni.hideLoading()
  161. })
  162. }
  163. });
  164. },
  165. // 预览图片
  166. previewPictures(item) {
  167. const photograph = [item];
  168. uni.previewImage({
  169. urls: photograph,
  170. });
  171. },
  172. // 删除图片
  173. cancelPhotograph(index) {
  174. setTimeout(() => {
  175. this.photograph.splice(index)
  176. }, 500);
  177. },
  178. // 提交
  179. submit(){
  180. this.$refs.uForm.validate(valid => {
  181. if (valid) {
  182. console.log('验证通过');
  183. if (this.form.addressType =='') {
  184. uni.showToast({
  185. title: '请选择用户类型',
  186. icon: 'none'
  187. })
  188. return false
  189. }
  190. const testVal=/^1[34578]\d{9}$/
  191. if (!testVal.test(this.form.contactMobile)) {
  192. uni.showToast({
  193. title: '请输入正确的联系电话',
  194. icon: 'none'
  195. })
  196. return false
  197. }
  198. if (this.form.contactName==='') {
  199. uni.showToast({
  200. title: '请输入用户名称',
  201. icon: 'none'
  202. })
  203. return false
  204. }
  205. if (this.form.contactAddress ==='') {
  206. uni.showToast({
  207. title: '请选择通信地址',
  208. icon: 'none'
  209. })
  210. return false
  211. }
  212. if (this.form.houseAddress ==='') {
  213. uni.showToast({
  214. title: '请输入详细地址',
  215. icon: 'none'
  216. })
  217. return false
  218. }
  219. const params=Object.assign(this.form,{lat:this.form.lat,lng:this.form.lng})
  220. if(this.photograph){
  221. params.imageHeader=this.photograph[0]
  222. }
  223. userInfoSave(params).then(res=>{
  224. if(res.status==200){
  225. uni.$emit('pageType', {data: 'userInfo' })
  226. setTimeout(()=>{
  227. uni.navigateBack({
  228. })
  229. },300)
  230. }
  231. })
  232. } else {
  233. console.log('验证失败');
  234. }
  235. });
  236. },
  237. },
  238. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  239. onReady() {
  240. this.$refs.uForm.setRules(this.rules);
  241. }
  242. }
  243. </script>
  244. <style lang="scss">
  245. .content{
  246. width: 100%;
  247. height: 100vh;
  248. padding: 0;
  249. background: #F5F5F5;
  250. display: flex;
  251. flex-direction: column;
  252. .content-form{
  253. flex: 1;
  254. overflow-y: scroll;
  255. }
  256. .receiveAddress{
  257. width: 100%;
  258. line-height: 1.5em;
  259. box-sizing: border-box;
  260. font-style: normal;
  261. }
  262. .form-data{
  263. padding: 0 30upx 0 50upx;
  264. margin-bottom: 20upx;
  265. background-color: #fff;
  266. }
  267. .qyImg{
  268. padding: 40upx ;
  269. }
  270. .info-main {
  271. margin-top: 14upx;
  272. border-radius: 12upx;
  273. background-color: #fff;
  274. display: flex;
  275. .location-icon {
  276. padding-left: 10upx;
  277. vertical-align: sub;
  278. }
  279. .photograph-camera {
  280. border: 2upx dashed #bfbfbf;
  281. border-radius: 12upx;
  282. width: 140upx;
  283. height: 140upx;
  284. display: flex;
  285. align-items: center;
  286. justify-content: center;
  287. }
  288. .camera-btn{
  289. display: flex;
  290. flex-direction: column;
  291. align-items: center;
  292. color: #999999;
  293. font-size: 24upx;
  294. }
  295. .photograph-con {
  296. margin: 0 20upx;
  297. width: 140upx;
  298. height: 140upx;
  299. text-align: center;
  300. position: relative;
  301. .photograph-icon {
  302. display: inline-block;
  303. padding-top: 48upx;
  304. }
  305. .close-circle-icon {
  306. background-color: #fff;
  307. border-radius: 50%;
  308. position: absolute;
  309. right: -23upx;
  310. top: -23upx;
  311. z-index: 9;
  312. }
  313. }
  314. }
  315. .houseAddress{
  316. display: flex;
  317. flex-wrap: wrap;
  318. }
  319. .btns{
  320. padding: 30upx 30upx 50upx;
  321. background-color: #fff;
  322. }
  323. }
  324. </style>