userInfo.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328
  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. },
  89. onUnload() {
  90. },
  91. methods: {
  92. // 获取详情数据
  93. getDetailData(){
  94. userDetail().then(res=>{
  95. if(res.status==200){
  96. this.userDetailInfo=res.data
  97. this.$refs.addressType.setVal(res.data.addressType)
  98. this.form.addressType=res.data.addressType
  99. this.form.contactMobile=res.data.contactMobile
  100. this.form.contactName=res.data.contactName
  101. this.form.contactAddress=res.data.contactAddress
  102. this.form.houseAddress=res.data.houseAddress
  103. this.photograph=[res.data.imageHeader] ?res.data.imageHeader.split() :''
  104. this.form.lat=res.data.latitude
  105. this.form.lng=res.data.longitude
  106. }
  107. })
  108. },
  109. // 选择用户类型
  110. chooseType(v){
  111. wx.hideKeyboard()
  112. this.form.addressType = v
  113. },
  114. selectAddress(){
  115. wx.chooseLocation({
  116. success:(res)=>{
  117. if(res){
  118. console.log(res,'--------dizhi ')
  119. this.$nextTick(()=>{
  120. this.form.contactAddress=res.address
  121. this.form.lat=res.latitude
  122. this.form.lng=res.longitude
  123. console.log(res.address,'-----------res.address',this.form.contactAddress)
  124. })
  125. }
  126. }
  127. })
  128. },
  129. confirm(e) {
  130. console.log(e);
  131. this.form.time=e[0].label + e[1].label
  132. },
  133. // 选择用户信息
  134. selectUserInfo(){
  135. uni.navigateTo({
  136. url: '/pages/index/userInfo'
  137. })
  138. },
  139. // 拍照或从相册选图片
  140. goPhotograph() {
  141. uni.chooseImage({
  142. count: 1, //默认9
  143. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  144. sourceType: ['album','camera'], //从相册选择
  145. success: (res) =>{
  146. if(res.tempFiles[0].size>10485760){
  147. uni.showToast({
  148. title: '图片过大无法上传!',
  149. icon: 'none'
  150. })
  151. return
  152. }
  153. uni.showLoading({
  154. title:'正在保存图片...',
  155. mask: true
  156. })
  157. saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
  158. this.photograph=res.tempFilePaths
  159. uni.hideLoading()
  160. })
  161. }
  162. });
  163. },
  164. // 预览图片
  165. previewPictures(item) {
  166. const photograph = [item];
  167. uni.previewImage({
  168. urls: photograph,
  169. });
  170. },
  171. // 删除图片
  172. cancelPhotograph(index) {
  173. setTimeout(() => {
  174. this.photograph.splice(index)
  175. }, 500);
  176. },
  177. // 提交
  178. submit(){
  179. this.$refs.uForm.validate(valid => {
  180. if (valid) {
  181. console.log('验证通过');
  182. if (this.form.addressType =='') {
  183. uni.showToast({
  184. title: '请选择用户类型',
  185. icon: 'none'
  186. })
  187. return false
  188. }
  189. const testVal=/^1[34578]\d{9}$/
  190. if (!testVal.test(this.form.contactMobile)) {
  191. uni.showToast({
  192. title: '请输入正确的联系电话',
  193. icon: 'none'
  194. })
  195. return false
  196. }
  197. if (this.form.contactName==='') {
  198. uni.showToast({
  199. title: '请输入用户名称',
  200. icon: 'none'
  201. })
  202. return false
  203. }
  204. if (this.form.contactAddress ==='') {
  205. uni.showToast({
  206. title: '请选择通信地址',
  207. icon: 'none'
  208. })
  209. return false
  210. }
  211. if (this.form.houseAddress ==='') {
  212. uni.showToast({
  213. title: '请输入详细地址',
  214. icon: 'none'
  215. })
  216. return false
  217. }
  218. const params=Object.assign(this.form,{lat:this.form.lat,lng:this.form.lng})
  219. if(this.photograph){
  220. params.imageHeader=this.photograph[0]
  221. }
  222. userInfoSave(params).then(res=>{
  223. if(res.status==200){
  224. uni.$emit('pageType', {data: 'userInfo' })
  225. setTimeout(()=>{
  226. uni.navigateBack({
  227. })
  228. },300)
  229. }
  230. })
  231. } else {
  232. console.log('验证失败');
  233. }
  234. });
  235. },
  236. },
  237. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  238. onReady() {
  239. this.$refs.uForm.setRules(this.rules);
  240. }
  241. }
  242. </script>
  243. <style lang="scss">
  244. .content{
  245. width: 100%;
  246. height: 100vh;
  247. padding: 0;
  248. background: #F5F5F5;
  249. display: flex;
  250. flex-direction: column;
  251. .content-form{
  252. flex: 1;
  253. overflow-y: scroll;
  254. }
  255. .receiveAddress{
  256. width: 100%;
  257. line-height: 1.5em;
  258. box-sizing: border-box;
  259. font-style: normal;
  260. }
  261. .form-data{
  262. padding: 0 30upx 0 50upx;
  263. margin-bottom: 20upx;
  264. background-color: #fff;
  265. }
  266. .qyImg{
  267. padding: 40upx ;
  268. }
  269. .info-main {
  270. margin-top: 14upx;
  271. border-radius: 12upx;
  272. background-color: #fff;
  273. display: flex;
  274. .location-icon {
  275. padding-left: 10upx;
  276. vertical-align: sub;
  277. }
  278. .photograph-camera {
  279. border: 2upx dashed #bfbfbf;
  280. border-radius: 12upx;
  281. width: 140upx;
  282. height: 140upx;
  283. display: flex;
  284. align-items: center;
  285. justify-content: center;
  286. }
  287. .camera-btn{
  288. display: flex;
  289. flex-direction: column;
  290. align-items: center;
  291. color: #999999;
  292. font-size: 24upx;
  293. }
  294. .photograph-con {
  295. margin: 0 20upx;
  296. width: 140upx;
  297. height: 140upx;
  298. text-align: center;
  299. position: relative;
  300. .photograph-icon {
  301. display: inline-block;
  302. padding-top: 48upx;
  303. }
  304. .close-circle-icon {
  305. background-color: #fff;
  306. border-radius: 50%;
  307. position: absolute;
  308. right: -23upx;
  309. top: -23upx;
  310. z-index: 9;
  311. }
  312. }
  313. }
  314. .houseAddress{
  315. display: flex;
  316. flex-wrap: wrap;
  317. }
  318. .btns{
  319. padding: 30upx 30upx 50upx;
  320. background-color: #fff;
  321. }
  322. }
  323. </style>