userInfo.vue 9.4 KB

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