userInfo.vue 8.9 KB

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