1.上传组件

<!--
- hasBorder {Boolean} cell底部边框,oneline 为 true 有效
- inlineBorder {Boolean} cell底部短边框
- height
- titleColor {String} 标题颜色
- readOnly {Boolean} date/radio/address 类型只读
- inputData @updateValue传递value 获取 输出String或Number,address类型输出 [provinceId, cityId]
以下参数只用于 radio 类型
- radioValues {Array} 单选选项数组,["苹果","橘子"] 或 [{name: "苹果",value: "apple"}](updateValue传递value)
- labelKey {String} 数组项为对象类型时要显示值的 key
- emitObject {Boolean} 数组项为对象时决定是否将选中的整个对象上报
- radio 示例
<form-cell title="单选"
:readOnly="false"
:value="radioValue"
titleColor="#575fb6"
inputType="radio"
:oneLine="true"
:arrow="true"
:radio-values="[{name:'苹果', value:'apple'},{name:'桔子', value:'orange'}]"
@updateValue="val => {radioValue = val}"
></form-cell>
- address 示例
<form-cell title="省市选择"
:readOnly="false" // true 不可点击,可返回绑定 value 对应的 name
:value="addressIdArr" // {Array || ''} 数组前两项必须为[provinceId,cityId],输出第三项为'广东省广州市'
titleColor="#575fb6"
inputType="address"
:oneLine="true"
:arrow="true"
@updateValue="val => {addressIdArr = val}"
></form-cell>
-->
<template>
<div>
<div class="cell-wrapper new-line" v-if="!oneLine">
<span class="title"
@click="activeInput"
:style="{ color: titleColor, lineHeight: height }">{{ title }}</span>
<span class="value value-single-line"
v-if="inputType === 'number'">
<span class="icon-edit" v-if="!disabled"></span>
<input v-if="!disabled"
v-model="inputData"
ref="numberInput"
:style="{'text-align': textAlign}"
@change="updateValue"
type="number"
:placeholder="placeholder">
<span v-else>{{ inputData }}</span>
<span v-show="inputData && !disabled"
@click="emptyInput"
class="btn__empty"></span>
<!-- <span v-show="inputData"
class="icon-empty__inline-text"
@click="emptyInput"
></span> -->
<span class="input-unit">{{unit}}</span>
</span>
<span class="value value-single-line"
v-if="inputType === 'text'">
<span class="icon-edit" v-if="!disabled"></span>
<input v-if="!disabled"
v-model="inputData"
ref="textInput"
:style="{'text-align': textAlign}"
@change="updateValue"
@blur="handleInputBlur"
type="text"
:placeholder="placeholder">
<span v-else>{{ inputData }}</span>
<span v-show="inputData && !disabled"
@click="emptyInput"
class="btn__empty"></span>
<!-- <span v-show="inputData"
class="icon-empty__inline-text"
@click="emptyInput"
></span> -->
</span>
<span v-if="inputType === 'textarea'"
v-show="inputData && !disabled"
@click="emptyInput"
class="btn__empty-textarea">清除</span>
<span class="value"
v-if="inputType === 'textarea'">
<span class="icon-edit"
v-if="showIcon && !disabled"></span>
<!-- <div class="auto-height">
<pre><br>{{ inputData }}</pre> -->
<span class="icon-history" v-if="showHistory" @click="selectHistory"></span>
<textarea v-if="!disabled" ref="remark" v-autosize="inputData" v-model="inputData" @change="updateValue" :rows="rows" :placeholder="placeholder"
:style="fixHistory"></textarea>
<span v-else>{{ inputData }}</span>
<!-- </div> -->
</span>
<div v-if="inlineBorder"
class="inline-border"></div>
<slot></slot>
</div>
<div class="cell-wrapper one-line" v-else
:class="{ 'has-border': hasBorder}"
:style="{ minHeight: height }">
<span class="title"
v-if="!multiLine"
@click="activeInput"
:style="{ color: titleColor, width: titleWidth, lineHeight: height }">{{ title }}</span>
<span class="title-multiLine"
v-else
:style="{ color: titleColor}">{{ title }}</span>
<span class="value"
:style="{ lineHeight: height, color: valueColor }"
v-if="readOnly && !multiLine && !isLabelShowing">{{ value }}</span>
<span class="value value-multiLine"
:style="{ color: valueColor }"
v-if="readOnly && multiLine && !isLabelShowing">{{ value }}</span>
<span class="value switch-wrapper"
v-if="inputType === 'switch' && !readOnly">
<mt-switch v-model="inputData" @change="updateValue"></mt-switch>
</span>
<span v-if="inputType === 'date' && !readOnly"
class="value date">
<input v-model="inputData"
@click="selectDate"
:style="{ lineHeight: height }">
<mt-datetime-picker
:value="startDate"
ref="picker"
type="date"
@confirm="updateDate"
@touchmove.prevent.stop.native>
</mt-datetime-picker>
</span>
<span v-if="inputType === 'time' && !readOnly"
class="value date">
<input v-model="inputData"
@click="selectDate"
:style="{ lineHeight: height }">
<mt-datetime-picker
:value="startDate"
ref="picker"
type="dateTime"
@confirm="updateDate"
@touchmove.prevent.stop.native>
</mt-datetime-picker>
</span>
<span v-if="inputType === 'radio'"
class="value date">
<input v-model="popupLabel"
@click="showPopup"
:style="{ lineHeight: height }">
<popup-picker ref="radio"
:picker-type="inputType"
:radio-values="radioValues"
:label-key="labelKey"
:value="value"
:emitObject="emitObject"
@updateLabel="setLabelandArrow"
@confirm="confirmPopup">
</popup-picker>
</span>
<span v-if="inputType === 'address'"
class="value date">
<input v-model="popupLabel"
@click="showPopup"
:style="{ lineHeight: height }">
<popup-picker ref="address"
:picker-type="inputType"
:value="value"
:provinceList="provinceList"
:cityList="cityList"
:label-key="labelKey"
:addressSlotsObject="addressSlotsObject"
@updateLabel="setLabelandArrow"
@confirm="confirmPopup">
</popup-picker>
</span>
<span v-if="inputType === 'counties'"
class="value date">
<input v-model="popupLabel"
@click="showPopup"
:style="{ lineHeight: height }">
<popup-picker ref="counties"
:picker-type="inputType"
:value="value"
:saveCityMap="saveCityMap"
:needCounties="needCounties"
@updateLabel="setLabelandArrow"
@confirm="confirmPopup">
</popup-picker>
</span>
<span v-if="inputType === 'dateTime'"
class="value date">
<input v-model="value"
@click="showPopup"
:style="{ lineHeight: height }">
<popup-picker ref="dateTime"
:picker-type="inputType"
:value="value"
@updateLabel="setLabelandArrow"
@confirm="confirmPopup">
</popup-picker>
</span>
<span class="arrow" v-show="arrow"></span>
<div v-if="inlineBorder"
class="inline-border"></div>
</div>
</div>
</template> <script>
import PopupPicker from './formCellPicker'
export default {
name: 'formCell',
props: {
disabled: {
type: Boolean,
default: false
},
hasBorder: {
type: Boolean,
default: false
},
inlineBorder: {
type: Boolean,
default: false
},
height: {
type: String,
default: '1.333rem'
},
titleColor: {
type: String,
default: '#999999'
},
readOnly: {
type: Boolean,
default: true
},
unit: {
type: String,
default: ''
},
title: {
type: String,
required: true
},
titleWidth: {
type: String
},
value: {
require: true
},
valueColor: {
type: String,
default: '#4a4a4a'
},
multiLine: {
type: Boolean,
default: false
},
placeholder: {
type: String,
default: '请输入'
},
arrow: {
type: Boolean,
default: false
},
inputType: {
type: String,
default: 'text'
},
oneLine: {
type: Boolean,
defalut: false
},
showIcon: {
type: Boolean,
default: true
},
textAlign: {
type: String,
default: 'left'
},
radioValues: {
type: Array
},
labelKey: {
type: String
},
rows: {
type: Number,
default: 1
},
reportFocusAndBlur: {
type: Boolean,
defalut: false
},
showHistory: {
type: Boolean,
default: false
},
saveCityMap: {
type: Boolean,
default: false
},
needCounties: {
type: Boolean,
default: false
},
provinceList: {
type: Array,
defalut: () => { return [] }
},
cityList: {
type: Object,
defalut: () => { return {} }
},
emitObject: {
type: Boolean,
defalut: false
},
addressSlotsObject: {
type: String,
default: 'NONE'
}
},
components: {
PopupPicker
},
data () {
return {
inputData: '',
showArrow: false,
startDate: new Date(),
popupLabel: '',
isIos: /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent),
isAndroid: /(Android)/i.test(navigator.userAgent),
fixHistory: {
paddingRight: this.showHistory ? '1rem' : 0
}
}
},
computed: {
isLabelShowing () {
return this.inputType === 'radio' || this.inputType === 'address' || this.inputType === 'counties' || this.inputType === 'dateTime'
}
},
created () {
this.inputData = this.value
this.showArrow = this.arrow
},
mounted () {
this.inputData = this.value
this.showArrow = this.arrow
if (this.inputData && (this.inputType === 'time' || this.inputType === 'date')) {
this.startDate = new Date(this.inputData.replace('-', '/'))
}
if (this.reportFocusAndBlur) {
let inputEl = 'textInput'
if (this.inputType === 'number') {
inputEl = 'numberInput'
}
if (this.inputType === 'textarea') {
inputEl = 'remark'
}
let that = this
this.$refs[inputEl].addEventListener('focus', () => {
setTimeout(() => {
that.$emit('inputFocus')
}, 100)
})
this.$refs[inputEl].addEventListener('blur', () => {
setTimeout(() => {
that.$emit('inputBlur')
}, 100)
})
}
if (this.inputType === 'number') {
this.$refs['numberInput'].addEventListener('paste', (e) => {
if (!(e.clipboardData && e.clipboardData.items)) {
return
}
let that = this
for (let i = 0, len = e.clipboardData.items.length; i < len; i++) {
let item = e.clipboardData.items[i]
if (item.kind === 'string') {
item.getAsString((string) => {
that.inputData = string ? string.replace(/[^\d]/g, '') : ''
})
}
}
})
}
},
watch: {
value: function () {
this.inputData = this.value
},
inputData: function () {
this.$emit('updateValue', this.inputData)
}
},
methods: {
updateValue () {
this.$emit('updateValue', this.inputData)
},
handleInputBlur () {
this.$emit('handleBlur')
},
selectHistory () {
this.$emit('history')
},
activeInput () {
if (this.inputType === 'date') {
this.selectDate()
}
if (this.inputType === 'radio' || this.inputType === 'address' || this.inputType === 'counties' || this.inputType === 'dateTime') {
this.showPopup()
}
if (this.inputType === 'textarea') {
this.$refs.remark.focus()
}
if (this.inputType === 'number') {
this.$refs.numberInput.focus()
}
if (this.inputType === 'text') {
this.$refs.textInput.focus()
}
},
emptyInput () {
this.inputData = ''
this.activeInput()
},
selectDate () {
document.activeElement.blur()
this.$mint.delayWhileInputFocus(() => {
this.$refs.picker.open()
})
},
updateDate (value) {
let year = value.getFullYear()
let month = value.getMonth() + 1
let day = value.getDate()
if (this.inputType === 'date') {
this.inputData = year + '-' + month + '-' + day
}
if (this.inputType === 'time') {
let hour = value.getHours() < 10 ? '0' + value.getHours() : value.getHours()
let minute = value.getMinutes() < 10 ? '0' + value.getMinutes() : value.getMinutes()
this.inputData = year + '-' + month + '-' + day + ' ' + hour + ':' + minute
}
this.$emit('updateValue', this.inputData)
},
showPopup () {
document.activeElement.blur()
if (this.readOnly) {
return
}
this.$mint.delayWhileInputFocus(() => {
if (this.inputType === 'radio') {
this.$refs.radio.open()
} else if (this.inputType === 'address') {
this.$refs.address.open()
} else if (this.inputType === 'counties') {
this.$refs.counties.open()
} else if (this.inputType === 'dateTime') {
this.$refs.dateTime.open()
}
})
},
confirmPopup (obj) {
this.inputData = obj.val
// this.showArrow = obj.showArrow
this.$emit('updateValue', this.inputData)
},
setLabelandArrow (val) {
this.popupLabel = val
this.$emit('updateLabel', val)
// this.$nextTick(()=>{this.showArrow = !val})
}
}
}
</script> <style lang="stylus" scoped>
@import "~@/assets/mixin.stylus"
.cell-wrapper{
position relative
font-dpr(16px)
padding 0 .5rem
background-color white
vertical-align middle
box-sizing border-box
.title{
width 3.5rem
}
.title-multiLine{
display inline-block
width 3.5rem
height 1.2rem
line-height 1.2rem
}
.value{
position relative
display inline-block
width 5.5rem
// color #4A4A4A
.auto-height{
position relative
padding .1rem 0
pre{
display block
visibility hidden
line-height normal
}
}
}
.switch-wrapper{
display flex
justify-content flex-end
}
.btn__empty-textarea {
position absolute
top .4rem
right .5rem
display inline-block
width 1.2rem
height .5rem
line-height .5rem
text-align center
border-radius .3rem
background-color #D8D8D8
font-dpr(12px)
color #4a4a4a
}
.value-multiLine{
padding .32rem 0
word-wrap break-word
// line-height .7rem
}
.arrow{
position relative
top .45rem
display inline-block
width .2rem
height .4rem
bg-image('~@/assets/img/arrow')
background-size contain
margin-left .3rem
}
.inline-border{
position absolute
bottom 0
left .4rem
width 9.6rem
height 1px
background-color #ECECEC
}
}
.new-line{
.value{
display flex
width 100%
padding-bottom .3rem
.icon-edit{
position relative
top .05rem
display inline-block
width .45rem
height .45rem
padding-right .3rem
bg-image('img/pen')
background-size contain
}
.icon-history{
position absolute
right 0
bottom .3rem
display inline-block
width .56rem
height .56rem
bg-image('img/record')
background-size contain
z-index 11
}
input{
height .6rem
width 100%
margin-right .2rem
text-align left
color #4a4a4a
&:placeholder {
font-dpr(16px)
color #979797
}
&::-webkit-input-placeholder {
font-dpr(16px)
color #979797
}
&:-moz-placeholder {
font-dpr(16px)
color #979797
}
&::-moz-placeholder {
font-dpr(16px)
color #979797
}
&:-ms-input-placeholder {
font-dpr(16px)
color #979797
}
}
.btn__empty {
display inline-block
width .5rem
height .5rem
bg-image('./img/close')
background-size contain
position relative
top .08rem
}
.icon-empty__inline-text {
float right
position relative
display inline-block
height .6rem
width .6rem
margin-right .2rem
bg-image('~@detailComponents/img/delete')
background-size contain
}
textarea{
font-dpr(16px)
position relative
width 100%
color #4a4a4a
&:placeholder {
font-dpr(16px)
color #979797
}
&::-webkit-input-placeholder {
font-dpr(16px)
color #979797
}
&:-moz-placeholder {
font-dpr(16px)
color #979797
}
&::-moz-placeholder {
font-dpr(16px)
color #979797
}
&:-ms-input-placeholder {
font-dpr(16px)
color #979797
}
}
}
}
.one-line{
display flex
.value{
text-align right
}
.switch-wrapper{
display flex
justify-content flex-end
}
.date{
input{
width 100%
text-align right
}
}
}
.has-border{
border-bottom 1px solid #ECECEC
}
</style>
<template>
<div>
<mt-popup v-if="pickerType === 'radio'"
v-model="popupVisible"
class="lx-popup"
position="bottom">
<mt-picker @touchmove.prevent.stop.native
ref="radio"
:slots="radioSlots"
:value-key="labelKey"
show-toolbar>
<span class="mint-datetime-action mint-datetime-cancel" @click="popupVisible=false">取消</span>
<span class="mint-datetime-action mint-datetime-confirm" @click="confirmRadio">确认</span>
</mt-picker>
</mt-popup>
<mt-popup v-else-if="pickerType === 'address'"
v-model="popupVisible"
class="lx-popup"
position="bottom">
<mt-picker @touchmove.prevent.stop.native
ref="address"
@change="onAddressChange"
:slots="addressSlots"
:value-key="labelKey"
show-toolbar>
<span class="mint-datetime-action mint-datetime-cancel" @click="popupVisible=false">取消</span>
<span class="mint-datetime-action mint-datetime-confirm" @click="confirmAddress">确认</span>
</mt-picker>
</mt-popup>
<mt-popup v-else-if="pickerType === 'counties'"
v-model="popupVisible"
class="lx-popup"
position="bottom">
<mt-picker @touchmove.prevent.stop.native
ref="counties"
@change="onCountiesChange"
:slots="countiesSlots"
value-key="name"
show-toolbar>
<span class="mint-datetime-action mint-datetime-cancel"
:class="{'lx-action__with-title': title}" @click="popupVisible=false">取消</span>
<span class="lx-picker-title" v-if="title">{{title}}</span>
<span class="mint-datetime-action mint-datetime-confirm"
:class="{'lx-action__with-title': title}" @click="confirmCounties">确认</span>
</mt-picker>
</mt-popup>
<mt-popup v-else-if="pickerType === 'dateTime'"
v-model="popupVisible"
class="lx-popup"
position="bottom">
<mt-picker @touchmove.prevent.stop.native
ref="dateTime"
@change="onTimeChange"
:slots="dateTimeSlots"
show-toolbar>
<span class="mint-datetime-action mint-datetime-cancel"
:class="{'lx-action__with-title': title}" @click="popupVisible=false">取消</span>
<span class="lx-picker-title" v-if="title">{{title}}</span>
<span class="mint-datetime-action mint-datetime-confirm"
:class="{'lx-action__with-title': title}" @click="confirmTime">确认</span>
</mt-picker>
</mt-popup>
</div>
</template> <script>
import store from '@/utils/store'
import mapCity from '@/api/mapAsk'
let loadingAddress = false export default {
name: 'PopupPicker',
props: {
pickerType: {
type: String
},
radioValues: {
type: Array
},
labelKey: {
type: String,
default: 'name'
},
value: {
default: ''
},
title: {
default: ''
},
saveCityMap: {
type: Boolean,
default: false
},
needCounties: {
type: Boolean,
default: false
},
provinceList: {
type: Array,
default: () => { return [] }
},
cityList: {
type: Object,
default: () => { return {} }
},
emitObject: {
type: Boolean,
default: false
},
/**
* address picker 组件判断各slot内部选项是否为对象 NONE--都不是 FIRST--第一个slot为对象 LAST--最后一个slot为对象
* BOTH--都是对象
*/
addressSlotsObject: {
type: String,
default: 'NONE'
}
},
data () {
return {
popupVisible: false,
selectedRadioIndex: 0,
selectAddressIndex: [0, 0],
selectCountiesIndex: [0, 0, 0],
selectTimeIndex: [0, 0, 0],
dateForOddMonth: ['1日', '2日', '3日', '4日', '5日', '6日', '7日', '8日', '9日', '10日', '11日', '12日', '13日', '14日', '15日', '16日', '17日', '18日', '19日', '20日', '21日', '22日', '23日', '24日', '25日', '26日', '27日', '28日', '29日', '30日', '31日'],
dateForEvenMonth: ['1日', '2日', '3日', '4日', '5日', '6日', '7日', '8日', '9日', '10日', '11日', '12日', '13日', '14日', '15日', '16日', '17日', '18日', '19日', '20日', '21日', '22日', '23日', '24日', '25日', '26日', '27日', '28日', '29日', '30日'],
addressData: [],
addressSlots: [
{
flex: 1,
values: [],
textAlign: 'center'
}, {
divider: true,
content: '-'
}, {
flex: 1,
values: [],
textAlign: 'center'
}
],
countiesSlots: [
{
flex: 1,
values: [],
textAlign: 'center'
}, {
flex: 1,
values: [],
textAlign: 'center'
}, {
flex: 1,
values: [],
textAlign: 'center'
}
],
dateTimeSlots: [
{
flex: 0.5,
values: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
textAlign: 'right'
},
{
flex: 0.5,
values: ['1日', '2日', '3日', '4日', '5日', '6日', '7日', '8日', '9日', '10日', '11日', '12日', '13日', '14日', '15日', '16日', '17日', '18日', '19日', '20日', '21日', '22日', '23日', '24日', '25日', '26日', '27日', '28日', '29日', '30日', '31日'],
textAlign: 'left'
},
{
flex: 1,
values: ['0:00 - 0:30', '0:30 - 1:00', '1:00 - 1:30', '1:30 - 2:00', '2:00 - 2:30', '2:30 - 3:00', '3:00 - 3:30', '3:30 - 4:00', '4:00 - 4:30', '4:30 - 5:00', '5:00 - 5:30', '5:30 - 6:00', '6:00 - 6:30', '6:30 - 7:00', '7:00 - 7:30', '7:30 - 8:00', '8:00 - 8:30', '8:30 - 9:00', '9:00 - 9:30', '9:30 - 10:00', '10:00 - 10:30', '10:30 - 11:00', '11:00 - 11:30', '11:30 - 12:00', '12:00 - 12:30', '12:30 - 13:00', '13:00 - 13:30', '13:30 - 14:00', '14:00 - 14:30', '14:30 - 15:00', '15:00 - 15:30', '15:30 - 16:00', '16:00 - 16:30', '16:30 - 17:00', '17:00 - 17:30', '17:30 - 18:00', '18:00 - 18:30', '18:30 - 19:00', '19:00 - 19:30', '19:30 - 20:00', '20:00 - 20:30', '20:30 - 21:00', '21:00 - 21:30', '21:30 - 22:00', '22:00 - 22:30', '22:30 - 23:00', '23:00 - 23:30', '23:30 - 24:00'],
textAlign: 'center'
}
]
}
},
computed: {
dateForFeb () {
let year = new Date().getFullYear()
if (year % (year % 100 ? 4 : 400)) {
return ['1日', '2日', '3日', '4日', '5日', '6日', '7日', '8日', '9日', '10日', '11日', '12日', '13日', '14日', '15日', '16日', '17日', '18日', '19日', '20日', '21日', '22日', '23日', '24日', '25日', '26日', '27日', '28日']
} else {
return ['1日', '2日', '3日', '4日', '5日', '6日', '7日', '8日', '9日', '10日', '11日', '12日', '13日', '14日', '15日', '16日', '17日', '18日', '19日', '20日', '21日', '22日', '23日', '24日', '25日', '26日', '27日', '28日', '29日']
}
},
radioSlots () {
if (this.pickerType !== 'radio') {
return []
}
const arr = this.radioValues.slice()
if (arr.length === 0) {
return []
}
if (typeof arr[0] !== 'object') {
// if (arr[0] !== '请选择') {arr.splice(0,0,'请选择')}
return [{
flex: 1,
values: arr
}]
} else {
// if (arr[0][this.labelKey] !== '请选择') {
// const obj ={}
// obj[this.labelKey] = '请选择'
// obj.value = ''
// arr.splice(0,0,obj)
// }
return [{
flex: 1,
values: arr
}]
}
},
label () {
if (this.pickerType === 'radio') {
if (this.radioValues.length === 0) {
return ''
}
// radioValues 数组元素不是对象直接返回
if (Object.prototype.toString.call(this.radioValues[0]) !== '[object Object]') {
this.selectedRadioIndex = this.radioValues.indexOf(this.value)
return this.value
}
// 是对象进行对比
const values = this.radioValues
for (let i = 0; i < values.length; i++) {
const obj = values[i]
if (obj.value && this.value === obj.value) {
this.selectedRadioIndex = i
return obj[this.labelKey]
} else if (this.value === obj[this.labelKey]) {
this.selectedRadioIndex = i
return obj[this.labelKey]
}
}
} else if (this.pickerType === 'counties') {
if (this.addressData.length === 0 || !this.isArray(this.value)) {
return ''
}
const selectedProvinceId = this.value[0]
const selectedCityId = this.value[1]
const selectedCountyId = this.value[2]
for (var i = 0; i < this.addressData.length; i++) {
const province = this.addressData[i]
if (selectedProvinceId === province.id) {
for (var j = 0; j < province.cities.length; j++) {
const city = province.cities[j]
if (selectedCityId === city.id) {
if (this.pickerType === 'address') {
this.selectAddressIndex = [i, j]
return `${province.name} ${city.name}`
} else {
for (var k = 0; k < city.counties.length; k++) {
const county = city.counties[k]
if (selectedCountyId === county.id) {
this.selectCountiesIndex = [i, j, k]
return `${province.name} ${city.name} ${county.name !== '暂不选择' ? county.name : ''}`
}
}
}
}
}
}
}
} else if (this.pickerType === 'address') {
if (this.provinceList.length === 0 || !this.isArray(this.value)) {
return ''
}
const values = this.value
let label = ''
switch (this.addressSlotsObject) {
case 'NONE':
label = `${values[0]}${values[1]}`
break
case 'FIRST':
label = `${values[0][this.labelKey]}${values[1]}`
break
case 'LAST':
label = `${values[0]}${values[1][this.labelKey]}`
break
case 'BOTH':
label = `${values[0][this.labelKey]}${values[1][this.labelKey]}`
break
default:
label = `${values[0]}${values[1]}`
break
}
return label
}
return ''
}
},
watch: {
label (val) {
this.$emit('updateLabel', val)
}
},
methods: {
open () {
if (this.pickerType === 'radio') {
this.$nextTick(() => {
this.$refs.radio.setValues([this.radioValues[this.selectedRadioIndex]])
})
this.popupVisible = true
// if (this.selectedRadioIndex < 0) return
} else if (this.pickerType === 'address') {
if (this.provinceList && this.provinceList.length > 0) {
this.addressSlots[0].values = this.provinceList
this.addressSlots[2].values = this.cityList[this.provinceList[0]]
if (this.value[0]) {
this.addressSlots[2].values = this.cityList[this.value[0]]
}
this.popupVisible = true
}
const values = this.value.length === 0 ? [this.provinceList[0], this.cityList[this.provinceList[0]][0]] : this.value
this.$refs.address.setValues(values)
} else if (this.pickerType === 'counties') {
if (this.addressData.length === 0) {
loadingAddress = true
this.$indicator.open()
this.getAddressData()
} else {
this.popupVisible = true
}
if (!this.isArray(this.selectCountiesIndex)) {
return
}
// if (this.selectCountiesIndex[0] < 0&&this.selectCountiesIndex[1] < 0) {return}
const selectedProvince = this.addressData[this.selectCountiesIndex[0]]
const selectedCity = selectedProvince.cities[this.selectCountiesIndex[1]]
const selectCounty = selectedCity.counties[this.selectCountiesIndex[2]]
this.$refs.counties.setValues([selectedProvince, selectedCity, selectCounty])
} else if (this.pickerType === 'dateTime') {
this.popupVisible = true
if (this.value) {
const month = this.value.split('月')[0] === this.value ? '1月' : this.value.split('月')[0] + '月'
let day = '1日'
if (this.value.split('月')[1]) {
day = this.value.split('月')[1].split('日')[0] + '日'
}
let time = '0:00 - 0:30'
let values = this.value.split('')
if (values.length === 4) {
time = `${values[1]} - ${values[3]}`
}
this.$refs.dateTime.setValues([month, day, time])
} else {
let month = new Date().getMonth() + 1 + '月'
let date = new Date().getDate() + '日'
this.$refs.dateTime.setValues([month, date, '0:00 - 0:30'])
}
}
},
confirmRadio () {
let val
const valArr = this.$refs.radio.getValues()
const temVal = valArr[0]
if (typeof temVal === 'undefined') {
this.popupVisible = false
return
}
if (this.emitObject) {
val = typeof temVal === 'object' ? temVal : {}
} else {
val = typeof temVal === 'object' ? temVal.value : temVal
val = val === '请选择' ? '' : val
}
this.popupVisible = false
this.$emit('confirm', {
val
})
},
confirmAddress () {
const values = this.$refs.address.getValues()
// const pickerSlots = this.$refs.address.$children
// this.selectAddressIndex = [pickerSlots[0].valueIndex, pickerSlots[2].valueIndex]
this.popupVisible = false
this.$emit('confirm', {
val: [values[0], values[1]]
// label: `${values[0].name} ${values[1].name}`,
// showArrow: false
})
},
onAddressChange (picker, values) {
for (let i = 0; i < this.provinceList.length; i++) {
if (values[0] === this.provinceList[i]) {
picker.setSlotValues(1, this.cityList[values[0]])
break
}
}
},
confirmCounties () {
const values = this.$refs.counties.getValues()
const label = `${values[0].name}${values[1].name}${values[2].name !== '暂不选择' ? values[2].name : ''}`
this.popupVisible = false
this.$emit('confirm', {
val: [values[0].id, values[1].id, values[2].id, label]
})
},
onCountiesChange (picker, values) {
for (let i = 0; i < this.addressData.length; i++) {
if (values[0].id === this.addressData[i].id) {
const cities = this.addressData[i].cities
picker.setSlotValues(1, cities)
for (let j = 0; j < cities.length; j++) {
if (!values[1]) return
if (values[1].id === cities[j].id) {
// 增加区暂不选择选项
if (cities[j].counties[0].name !== '暂不选择' && !this.needCounties) {
cities[j].counties.unshift({id: '', name: '暂不选择'})
}
picker.setSlotValues(2, cities[j].counties)
break
}
}
}
}
},
onTimeChange (picker, values) {
if (values[0] === '2月') {
picker.setSlotValues(1, this.dateForFeb)
return
}
if (values[0] === '4月' || values[0] === '6月' || values[0] === '9月' || values[0] === '11月') {
picker.setSlotValues(1, this.dateForEvenMonth)
return
}
picker.setSlotValues(1, this.dateForOddMonth)
},
confirmTime () {
const values = this.$refs.dateTime.getValues()
const value = `${values[0]}${values[1]} ${values[2]}`
this.popupVisible = false
this.$emit('confirm', {
val: value
})
},
getAddressData () {
if (!this.pickerType || this.pickerType === 'radio' || this.pickerType === 'dateTime') {
return
}
mapCity().then(res => {
this.$indicator.close()
if (res.status === 200) {
if (loadingAddress) {
this.popupVisible = true
loadingAddress = false
}
this.addressData = res.data.data
if (this.saveCityMap) {
store.set('vehicle-map-city', this.addressData)
}
if (this.pickerType === 'address') {
const slots = this.addressSlots
slots[0].values = this.addressData
} else if (this.pickerType === 'counties') {
const slots = this.countiesSlots
slots[0].values = this.addressData
}
} else {
if (loadingAddress) {
this.$toast({
message: '获取地址列表失败,请稍后重试',
iconClass: 'icon icon-warning'
})
loadingAddress = false
}
console.log(res.data.message)
}
})
},
isArray (item) {
return Object.prototype.toString.call(item) === '[object Array]'
}
},
created () {
if (this.pickerType === 'counties') {
this.getAddressData()
}
},
mounted () {
this.$emit('updateLabel', this.label)
}
}
</script> <style lang="stylus" scoped>
@import "~@/assets/mixin.stylus"
.lx-popup {
width: 100%
// 取消确定键栏
>>> .picker-toolbar {
border-bottom 1px solid #eaeaea
}
}
.lx-picker-title
display inline-block
width 60%
line-height 40px
text-align center
font-dpr(16px)
.lx-action__with-title
width 20%
</style>
<image-cell @click.native="uploadImage('idCardPics', '身份证正反面')"
:imageTitle="'身份证正反面'"
:titleColor="titleColor"
:image="searchCar.idCardPics"
:hasBorder="true">
</image-cell>
   uploadImage (tag, title) {
const that = this
let images = that.searchCar[tag] || []
let data = {
functionName: 'sendImage',
data: {
tag: tag,
imageUrl: images,
countLimit: 9,
title: title,
compression: 0.8,
editable: true
}
}
try {
window.JSBridge.navigationTo('imagePick', JSON.stringify(data))
} catch (error) {
console.error(error)
}
}

app内嵌H5的上传图片的功能的更多相关文章

  1. 移动端开发利器vConsole.js,app内嵌H5开发时调试用

    vConsole:一个轻量.可拓展.针对手机网页的前端开发者调试面板,主要还是用于内嵌app页面时在手机上进行调试,打印完全和在PC端一样,方便大家找出问题所在. 不说废话直接进入主题,vConsol ...

  2. app内嵌h5分享到小程序分享功能

    if (this.GLOBAL.env !== 'production') { try { window.JSBridge.shareMiniProgramToWx('https://www.lexi ...

  3. app内嵌H5调用分享

    最近产品提出了一个需求:我们在合作方的app中提供的部分页面中增加分享页面,具体要求是在3个二维码推广页面调用app的分享接口,分享方式有3种,分别是点击”分享链接“按钮调起分享,点击”分享图片“按钮 ...

  4. ios下app内嵌h5页面是video适配问题

    ios下做新闻详情用h5页面实现然后打包到app中,其中新闻详情页会有视频,安卓下video的poster可以做到适应video大小,但是ios下会按照poster图片大小将video等比撑大,但是视 ...

  5. app内嵌H5网页(webviewJavaScriptBridge)

    摘要:使用的插件为webviewJavaScriptBridge,app端需要引入一下这个包,html页面只需一段JS代码 与IOS交互 <! 申明交互(此处代码固定) > functio ...

  6. app内嵌h5页面在ios手机端滑动卡顿的解决方法

    1.带滚动条的dom需加样式 -webkit-overflow-scrolling: touch;2.去掉 width:100%; height:100%

  7. app内嵌 h5页面 再滑动的时候 触发击穿底下的一些touchstart事件

    我们的目的是再滑动的时候 不要触发到touchstart事件. // 再滑动的时候无法点开视频 var is_scroll_start,is_scroll_end; $(window).on({ 't ...

  8. APP内的H5页面测试方法, 移动端的浏览器(例如UC浏览器)测试方法

    前言: 用appium做UI自动化,测试APP里面的H5和测试手机浏览器打开的H5的操作流程上是有所区别的.比如要测试APP内嵌的H5需要先操作appium启动APP,然后通过context切到web ...

  9. APP中内嵌H5页面为什么不能下载?

    在APP中内嵌H5页面,若页面上存在下载链接,没有任何反应,为什么呢? 原因是app中内嵌的H5页面是WebView解析的,什么是WebView呢? 在Android手机中内置了一款高性能webkit ...

随机推荐

  1. pandas-07 DataFrame修改index、columns名的方法

    pandas-07 DataFrame修改index.columns名的方法 一般常用的有两个方法: 1.使用DataFrame.index = [newName],DataFrame.columns ...

  2. vue-router中的router-view的困扰

    刚开始接触vue的时候有很长一段时间被router-view的渲染困扰着,不知道为什么明明有很多router-link和不同的router-view,但是为什么渲染的时候不会出现错乱呢 这是我自己写的 ...

  3. Celery:Next Steps

    参考文档:http://docs.celeryproject.org/en/latest/getting-started/next-steps.html#next-steps

  4. http请求的几种content-type

    1. 2.二进制文件 3.form-data 数据:a=1 总结: 1.对于我自己的写的服务来说,只要是raw,接收到的都是二进制字符: 2.如果是urlencode,接收到的是拼接的字符串(和使用p ...

  5. Tomcat启动堆栈异常

    近日部署项目到Tomcat,访问一直404. 于是查看 catalina.out 日志信息,发现如下信息 30-Jun-2019 16:38:03.642 SEVERE [main] org.apac ...

  6. Java字符串操作工具类

    import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; import java.lang. ...

  7. 【转载】Linux磁盘管理:LVM逻辑卷管理

    Linux学习之CentOS(二十五)--Linux磁盘管理:LVM逻辑卷基本概念及LVM的工作原理 这篇随笔将详细讲解Linux磁盘管理机制中的LVM逻辑卷的基本概念以及LVM的工作原理!!! 一. ...

  8. union的使用

    将多条select语句的结果,合并到一起,称为联合查询 使用union关键字 场景: 获取数据的条件,出现逻辑冲突,或者很难在一个逻辑内表示,就可以拆成多个逻辑,分别实现,最后将结果合并到一起 sel ...

  9. Centos7搭建DockerRegistry

    1. 说明 以下使用系统centos7,64位,镜像为CentOS-7-x86_64-Minimal-1804,均已root用户进行操作 2. 安装Registry Docker Registry 是 ...

  10. Yii2模型介绍

    通过来说,我们可以把yii2中的Mdoel分为两种: 1)数据模型: 2)表单模型: 数据模型 数据模型关联数据表,用来实现对数据的操作; 一般数据模型放在common/models下: 表单模型 表 ...