userInfo.vue 9.1 KB

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