userInfo.vue 9.3 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. <!-- <u-select v-model="show" mode="mutil-column-auto" :list="list" @confirm="confirm"></u-select> -->
  8. <v-select ref="addressType" placeholder="请选择用户类型" @itemChange="chooseType" code="ORDER_ADDRESS_TYPE" style="width: 100%"></v-select>
  9. <!-- <u-input placeholder="请选择用户类型" v-model="form.addressType" @click="selectTime" :disabled="true"/> -->
  10. <!-- <u-icon name="arrow-right" slot="right" @click="selectTime"></u-icon> -->
  11. </u-form-item>
  12. <u-form-item prop="contactName" label="用户名称:" required>
  13. <u-input placeholder="请输入用户名称" v-model="form.contactName"/>
  14. </u-form-item>
  15. <u-form-item prop="contactMobile" label="联系电话:" required>
  16. <u-input placeholder="请输入联系电话" v-model="form.contactMobile"/>
  17. </u-form-item>
  18. </u-form>
  19. </view>
  20. <view class="form-data">
  21. <u-form :model="form" ref="uForm" :label-width="140" :error-type="['toast']">
  22. <u-form-item prop="contactAddress" label="通讯地址:" required>
  23. <u-input placeholder="请选择通讯地址" v-model="form.contactAddress" @click="selectAddress" :disabled="true"/>
  24. <u-icon name="arrow-right" slot="right"></u-icon>
  25. </u-form-item>
  26. <u-form-item prop="houseAddress" label="详细信息:" >
  27. <u-input placeholder="请输入详细信息" v-model="form.houseAddress"/>
  28. </u-form-item>
  29. </u-form>
  30. </view>
  31. <view class="form-data qyImg">
  32. <view> 上传图片 <text style="color: #a6a6a6;">(仅可上传1张,10MB以内)</text></view>
  33. <view class="info-main">
  34. <view class="camera-btn" v-if="photograph.length<1">
  35. <view @click="goPhotograph" class="photograph-camera">
  36. <u-icon name="camera" color="#bfbfbf" size="60" ></u-icon>
  37. </view>
  38. </view>
  39. <view v-show="photograph.length" v-for="(item,index) in photograph" :key="index" class="photograph-con">
  40. <u-icon name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph(index)"></u-icon>
  41. <u-image width="100%" height="100%" :src="item" @click="previewPictures(item)"></u-image>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="btns">
  47. <u-button @click="submit" :loading="loading" :custom-style="submitBtn">提交</u-button>
  48. </view>
  49. </view>
  50. </template>
  51. <script>
  52. import {userInfoSave,userDetail} from '@/api/data.js'
  53. import {saveImgToAliOss} from '@/libs/tools.js'
  54. import vSelect from '@/components/select/v-select.vue'
  55. export default {
  56. components: {vSelect},
  57. data() {
  58. return {
  59. title:'',
  60. loading:false, // 提交按钮加载圈
  61. photograph:[],
  62. imageHeader:'', // 图片路径
  63. userDetailInfo:{}, // 用户信息
  64. form: {
  65. addressType:'', // 用户类型
  66. contactMobile: '', //联系人手机
  67. contactAddress:'' ,// 通讯地址
  68. contactName:'', // 联系人名称
  69. lat:'', // 通讯地址的经度
  70. lng:'', // 通讯地址的纬度
  71. houseAddress:'', // 详细地址
  72. // imageHeader:'', // 门头照片
  73. },
  74. contactAddress:'' ,// 通讯地址
  75. isView: false ,// 是否是查看详情
  76. itemId:'',
  77. submitBtn:{
  78. backgroundColor: '#4F88F7',
  79. color: '#fff',
  80. borderRadius: '12px'
  81. },
  82. show: false,
  83. };
  84. },
  85. onLoad(option) {
  86. console.log(option,option.id,'ppppppppp')
  87. this.getDetailData()
  88. uni.$emit()
  89. // 查看
  90. // if(option && option.id){
  91. // this.isView = true
  92. // this.itemId=option.id
  93. // // this.getDetailData()
  94. // }else {
  95. // console.log('--------新增')
  96. // this.photograph = []
  97. // // this.form.remarks = ''
  98. // this.$refs.uForm.resetFields()
  99. // }
  100. },
  101. onUnload() {
  102. },
  103. methods: {
  104. // 获取详情数据
  105. getDetailData(){
  106. userDetail().then(res=>{
  107. if(res.status==200){
  108. this.userDetailInfo=res.data
  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)
  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. this.$refs.uForm.validate(valid => {
  202. if (valid) {
  203. console.log('验证通过');
  204. if (this.form.addressType =='') {
  205. uni.showToast({
  206. title: '请选择用户类型',
  207. icon: 'none'
  208. })
  209. return false
  210. }
  211. const testVal=/^1[34578]\d{9}$/
  212. if (!testVal.test(this.form.contactMobile)) {
  213. uni.showToast({
  214. title: '请输入正确的联系电话',
  215. icon: 'none'
  216. })
  217. return false
  218. }
  219. if (this.form.contactName==='') {
  220. uni.showToast({
  221. title: '请输入用户名称',
  222. icon: 'none'
  223. })
  224. return false
  225. }
  226. if (this.form.contactAddress ==='') {
  227. uni.showToast({
  228. title: '请输入通讯地址',
  229. icon: 'none'
  230. })
  231. return false
  232. }
  233. const params=this.form
  234. if(this.photograph){
  235. params.imageHeader=this.imageHeader
  236. }
  237. console.log(params,'--------用户信息')
  238. userInfoSave(params).then(res=>{
  239. if(res.status==200){
  240. uni.$emit('add', {data: 'userInfo' })
  241. setTimeout(()=>{
  242. uni.navigateBack({
  243. })
  244. },300)
  245. }
  246. console.log(res,'------------res')
  247. })
  248. } else {
  249. console.log('验证失败');
  250. }
  251. });
  252. },
  253. },
  254. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  255. onReady() {
  256. this.$refs.uForm.setRules(this.rules);
  257. }
  258. }
  259. </script>
  260. <style lang="scss">
  261. .content{
  262. width: 100%;
  263. height: 100vh;
  264. padding: 0;
  265. background: #F5F5F5;
  266. display: flex;
  267. flex-direction: column;
  268. .content-form{
  269. flex: 1;
  270. overflow-y: scroll;
  271. }
  272. .receiveAddress{
  273. width: 100%;
  274. line-height: 1.5em;
  275. box-sizing: border-box;
  276. font-style: normal;
  277. }
  278. .form-data{
  279. padding: 0 30upx 0 50upx;
  280. margin-bottom: 20upx;
  281. background-color: #fff;
  282. }
  283. .qyImg{
  284. padding: 40upx ;
  285. }
  286. .info-main {
  287. margin-top: 14upx;
  288. border-radius: 12upx;
  289. background-color: #fff;
  290. display: flex;
  291. .location-icon {
  292. padding-left: 10upx;
  293. vertical-align: sub;
  294. }
  295. .photograph-camera {
  296. border: 2upx dashed #bfbfbf;
  297. border-radius: 12upx;
  298. width: 140upx;
  299. height: 140upx;
  300. display: flex;
  301. align-items: center;
  302. justify-content: center;
  303. }
  304. .camera-btn{
  305. display: flex;
  306. flex-direction: column;
  307. align-items: center;
  308. color: #999999;
  309. font-size: 24upx;
  310. }
  311. .photograph-con {
  312. margin: 0 20upx;
  313. width: 140upx;
  314. height: 140upx;
  315. text-align: center;
  316. position: relative;
  317. .photograph-icon {
  318. display: inline-block;
  319. padding-top: 48upx;
  320. }
  321. .close-circle-icon {
  322. background-color: #fff;
  323. border-radius: 50%;
  324. position: absolute;
  325. right: -23upx;
  326. top: -23upx;
  327. z-index: 9;
  328. }
  329. }
  330. }
  331. .btns{
  332. padding: 30upx 30upx 50upx;
  333. background-color: #fff;
  334. }
  335. }
  336. </style>