userInfo.vue 9.3 KB

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