123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322 |
- <template>
- <view class="content">
- <view class="content-form">
- <view class="form-data">
- <u-form :model="form" ref="uForm" :label-width="140" :error-type="['toast']">
- <u-form-item prop="addressType" label="用户类型:" required >
- <v-select ref="addressType" placeholder="请选择用户类型" @itemChange="chooseType" code="ORDER_ADDRESS_TYPE" style="width: 100%" :disabled="true"></v-select>
- </u-form-item>
- <u-form-item prop="contactName" label="用户名称:" required>
- <u-input placeholder="请输入用户名称" v-model="form.contactName" maxlength="15"/>
- </u-form-item>
- <u-form-item prop="contactMobile" label="联系电话:" required>
- <u-input placeholder="请输入联系电话" v-model="form.contactMobile" maxlength="11" type="number"/>
- </u-form-item>
- </u-form>
- </view>
- <view class="form-data">
- <u-form :model="form" ref="uForm" :label-width="140" :error-type="['toast']">
- <u-form-item prop="contactAddress" label="通信地址:" required>
- <u-input placeholder="请选择通信地址" v-model="form.contactAddress" @click="selectAddress" :disabled="true"/>
- <u-icon name="arrow-right" slot="right"></u-icon>
- </u-form-item>
- <u-form-item prop="houseAddress" label="详细信息:" required>
- <u-input placeholder="请输入详细信息" v-model="form.houseAddress" maxlength="30" class="houseAddress" type="textarea"/>
- </u-form-item>
- </u-form>
- </view>
- <view class="form-data qyImg">
- <view> 门头照片 <text style="color: #a6a6a6;">(仅可上传1张,10MB以内)</text></view>
- <view class="info-main">
- <view class="camera-btn" v-if="photograph.length<1">
- <view @click="goPhotograph" class="photograph-camera">
- <u-icon name="camera" color="#bfbfbf" size="60" ></u-icon>
- </view>
- </view>
- <view v-show="photograph.length" v-for="(item,index) in photograph" :key="index" class="photograph-con">
- <u-icon name="close-circle-fill" color="#fa3534" size="50" class="close-circle-icon" @click="cancelPhotograph(index)"></u-icon>
- <u-image width="100%" height="100%" :src="item" @click="previewPictures(item)"></u-image>
- </view>
- </view>
- </view>
- </view>
- <view class="btns">
- <u-button @click="submit" :loading="loading" :custom-style="submitBtn">提交</u-button>
- </view>
- </view>
- </template>
- <script>
- import {userInfoSave,userDetail} from '@/api/data.js'
- import {saveImgToAliOss} from '@/libs/tools.js'
- import vSelect from '@/components/select/v-select.vue'
- export default {
- components: {vSelect},
- data() {
- return {
- title:'',
- loading:false, // 提交按钮加载圈
- photograph: [],
- imageHeader:'', // 图片路径
- // userDetailInfo:{}, // 用户信息
- form: {
- addressType:'', // 用户类型
- contactMobile: '', //联系人手机
- contactAddress:'' ,// 通讯地址
- contactName:'', // 联系人名称
- lat:'', // 通讯地址的经度
- lng:'', // 通讯地址的纬度
- houseAddress:'', // 详细地址
- // imageHeader:'', // 门头照片
- },
- // contactAddress:'' ,// 通讯地址
- isView: false ,// 是否是查看详情
- itemId:'',
- submitBtn:{
- backgroundColor: '#4F88F7',
- color: '#fff',
- borderRadius: '12px'
- },
- show: false,
- };
- },
- onLoad(option) {
- console.log(option,option.id,'ppppppppp')
- this.getDetailData()
- },
- onShow() {
- },
- onUnload() {
- },
- methods: {
- // 获取详情数据
- getDetailData(){
- userDetail().then(res=>{
- if(res.status==200){
- console.log(res,res.data,'---------------详情数据')
- if(res.data){
- this.form=res.data
- this.$refs.addressType.setVal(res.data.addressType)
- this.photograph = res.data.imageHeader ? [res.data.imageHeader] : []
- this.form.lat=res.data.latitude
- this.form.lng=res.data.longitude
- }
- }
- })
- },
- // 选择用户类型
- chooseType(v){
- wx.hideKeyboard()
- this.form.addressType = v
- },
- selectAddress(){
- wx.chooseLocation({
- success:(res)=>{
- if(res){
- this.form.contactAddress=res.address
- this.form.lat=res.latitude
- this.form.lng=res.longitude
- console.log(res.address,'-----------res.address',this.form.contactAddress)
- }
- }
- })
- },
- confirm(e) {
- console.log(e);
- this.form.time=e[0].label + e[1].label
- },
- // 选择用户信息
- selectUserInfo(){
- uni.navigateTo({
- url: '/pages/index/userInfo'
- })
- },
- // 拍照或从相册选图片
- goPhotograph() {
- uni.chooseImage({
- count: 1, //默认9
- sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album','camera'], //从相册选择
- success: (res) =>{
- if(res.tempFiles[0].size>10485760){
- uni.showToast({
- title: '图片过大无法上传!',
- icon: 'none'
- })
- return
- }
- uni.showLoading({
- title:'正在保存图片...',
- mask: true
- })
- saveImgToAliOss(res.tempFilePaths[0],(ret)=>{
- this.photograph.push(ret.data)
- uni.hideLoading()
- })
- }
- });
- },
- // 预览图片
- previewPictures(item) {
- const photograph = [item];
- uni.previewImage({
- urls: photograph,
- });
- },
- // 删除图片
- cancelPhotograph(index) {
- setTimeout(() => {
- this.photograph.splice(index)
- }, 500);
- },
- // 提交
- submit(){
- this.$refs.uForm.validate(valid => {
- if (valid) {
- console.log('验证通过');
- if (this.form.addressType =='') {
- uni.showToast({
- title: '请选择用户类型',
- icon: 'none'
- })
- return false
- }
-
- const testVal=/^1[34578]\d{9}$/
- if (!testVal.test(this.form.contactMobile)) {
- uni.showToast({
- title: '请输入正确的联系电话',
- icon: 'none'
- })
- return false
- }
- if (this.form.contactName==='') {
- uni.showToast({
- title: '请输入用户名称',
- icon: 'none'
- })
- return false
- }
- if (this.form.contactAddress ==='') {
- uni.showToast({
- title: '请选择通信地址',
- icon: 'none'
- })
- return false
- }
- if (this.form.houseAddress ==='') {
- uni.showToast({
- title: '请输入详细地址',
- icon: 'none'
- })
- return false
- }
- const params=Object.assign(this.form,{lat:this.form.lat,lng:this.form.lng})
- if(this.photograph){
- params.imageHeader=this.photograph[0]
- }
- userInfoSave(params).then(res=>{
- if(res.status==200){
- uni.$emit('pageType', {data: 'userInfo' })
- setTimeout(()=>{
- uni.navigateBack({
-
- })
- },300)
- }
- })
-
- } else {
- console.log('验证失败');
- }
- });
- },
- },
- // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
- onReady() {
- this.$refs.uForm.setRules(this.rules);
- }
- }
- </script>
- <style lang="scss">
- .content{
- width: 100%;
- height: 100vh;
- padding: 0;
- background: #F5F5F5;
- display: flex;
- flex-direction: column;
- .content-form{
- flex: 1;
- overflow-y: scroll;
- }
- .receiveAddress{
- width: 100%;
- line-height: 1.5em;
- box-sizing: border-box;
- font-style: normal;
- }
- .form-data{
- padding: 0 30upx 0 50upx;
- margin-bottom: 20upx;
- background-color: #fff;
- }
- .qyImg{
- padding: 40upx ;
- }
- .info-main {
- margin-top: 14upx;
- border-radius: 12upx;
- background-color: #fff;
- display: flex;
- .location-icon {
- padding-left: 10upx;
- vertical-align: sub;
- }
- .photograph-camera {
- border: 2upx dashed #bfbfbf;
- border-radius: 12upx;
- width: 140upx;
- height: 140upx;
- display: flex;
- align-items: center;
- justify-content: center;
- }
- .camera-btn{
- display: flex;
- flex-direction: column;
- align-items: center;
- color: #999999;
- font-size: 24upx;
- }
- .photograph-con {
- margin: 0 20upx;
- width: 140upx;
- height: 140upx;
- text-align: center;
- position: relative;
- .photograph-icon {
- display: inline-block;
- padding-top: 48upx;
- }
- .close-circle-icon {
- background-color: #fff;
- border-radius: 50%;
- position: absolute;
- right: -23upx;
- top: -23upx;
- z-index: 9;
- }
- }
- }
- .houseAddress{
- display: flex;
- flex-wrap: wrap;
- }
- .btns{
- padding: 30upx 30upx 50upx;
- background-color: #fff;
- }
- }
- </style>
|