userInfo.vue 8.4 KB

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