userInfo.vue 8.3 KB

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