123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- <template>
- <mobile-frame>
- <view class="main">
- <view class="one">
- <uni-forms ref="form" v-model="form" :rules="rules" label-width="auto">
- <uni-forms-item label="收货人" name="name">
- <uni-easyinput type="text" v-model="form.name" placeholder="请输入收货人" />
- </uni-forms-item>
- <uni-forms-item label="联系电话" name="phone">
- <uni-easyinput type="number" v-model="form.phone" placeholder="请输入联系电话" />
- </uni-forms-item>
- <uni-forms-item label="地图选点">
- <button type="default" size="mini" class="toLoacl" @click="toLocaltion()">地图选点</button>
- </uni-forms-item>
- <uni-forms-item label="所在省份">
- <picker class="picker" mode="selector" :range="provinceList" @change="proChange" range-key="value">
- <view>{{form.province||'请选择所在省份'}}</view>
- </picker>
- </uni-forms-item>
- <uni-forms-item label="所在市">
- <picker class="picker" mode="selector" :range="cityList" @change="cityChange" range-key="value">
- <view>{{form.city||'请选择所在市'}}</view>
- </picker>
- </uni-forms-item>
- <uni-forms-item label="所在区">
- <picker class="picker" mode="selector" :range="areaList" @change="areaChange" range-key="value">
- <view>{{form.area||'请选择所在区'}}</view>
- </picker>
- </uni-forms-item>
- <uni-forms-item label="详细地址" name="address">
- <uni-easyinput type="textarea" v-model="form.address" placeholder="请输入所在小区/大厦/学校" />
- </uni-forms-item>
- </uni-forms>
- <view class="btn">
- <button type="primary" @click="onSubmit('form')" size="small">提交保存</button>
- </view>
- </view>
- </view>
- </mobile-frame>
- </template>
- <script>
- const chooseLocation = requirePlugin('chooseLocation');
- export default {
- data() {
- return {
- id: '',
- form: {},
- rules: {
- // name: {
- // rules: [{
- // required: true,
- // errorMessage: '请输入收货人',
- // }]
- // },
- // phone: {
- // rules: [{
- // required: true,
- // errorMessage: '请输入联系电话',
- // tel: true
- // }]
- // },
- // deptname: {
- // rules: [{
- // required: true,
- // errorMessage: '请输入机构名称'
- // }]
- // },
- // address: {
- // rules: [{
- // required: true,
- // errorMessage: '请输入详细地址'
- // }]
- // },
- },
- provinceList: [ //所在省份
- {
- code: '1',
- value: '吉林省',
- },
- {
- code: '2',
- value: '辽宁省',
- },
- {
- code: '3',
- value: '黑龙江省',
- },
- ],
- cityList: [ //所在市
- {
- code: '1-1',
- value: '长春市',
- },
- {
- code: '2-1',
- value: '大连市',
- },
- {
- code: '3-1',
- value: '哈尔滨市',
- },
- ],
- areaList: [ //所在区
- {
- code: '1-1-1',
- value: '朝阳区'
- },
- {
- code: '2-1-1',
- value: '开发区'
- },
- {
- code: '3-1-1',
- value: '发展区'
- },
- ]
- };
- },
- onLoad: function(e) {
- const that = this;
- that.$set(that, `id`, e && e.id || '');
- that.search()
- },
- onShow: function() {
- const that = this;
- that.searchLocal()
- },
- onUnload: function() {
- chooseLocation.setLocation(null);
- },
- methods: {
- // 查询详细信息
- async search() {
- const that = this;
- if (that.id) {
- let res = await that.$api(`/address/${that.id}`, 'GET')
- if (res.errcode == '0') {
- console.log(res.data);
- that.$set(that, `form`, res.data)
- }
- }
- },
- // 定位
- toLocaltion() {
- const that = this;
- const key = that.$config.txlocalKey;
- const referer = that.$config.txlocalReferer;
- uni.navigateTo({
- url: `plugin://chooseLocation/index?key=${key}&referer=${referer}`
- });
- },
- searchLocal() {
- const location = chooseLocation.getLocation();
- console.log(location);
- },
- // 选择省份
- proChange(e) {
- const that = this;
- let data = that.provinceList[e.detail.value];
- if (data) {
- that.$set(that.form, `province`, data.value)
- }
- },
- // 选择区
- areaChange(e) {
- const that = this;
- let data = that.areaList[e.detail.value];
- if (data) {
- that.$set(that.form, `area`, data.value)
- }
- },
- // 选择市
- cityChange(e) {
- const that = this;
- let data = that.cityList[e.detail.value];
- if (data) {
- that.$set(that.form, `city`, data.value)
- }
- },
- // 提交保存
- onSubmit() {
- const that = this;
- let data = that.form;
- data = {
- ...data,
- check: that.check
- }
- },
- }
- }
- </script>
- <style lang="scss">
- .main {
- display: flex;
- flex-direction: column;
- width: 100vw;
- height: 100vh;
- .one {
- padding: 2vw;
- .toLoacl {
- margin: 1vw 0 0 0;
- }
- .picker {
- border: 1px solid #3333;
- border-radius: 5px;
- padding: 2vw;
- }
- }
- }
- // .uni-forms-item {
- // margin-bottom: 6vw !important;
- // display: flex;
- // flex-direction: row;
- // }
- // .local {
- // .uni-data-tree {
- // width: 60vw;
- // }
- // }
- // .localicon {
- // position: absolute;
- // right: 0;
- // top: 5px;
- // }
- </style>
|