userInfo.vue 9.7 KB

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