userInfo.vue 8.4 KB

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