123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294 |
- <template>
- <!-- 表单 -->
- <view style="margin: 0rpx 20rpx 0rpx 30rpx;">
- <u-form :model="model" :rules="rules" labelPosition="left" ref="uForm" labelWidth="70">
- <view v-for="(item,index) in list" :key="index">
- <u-form-item :required="item.required ? true : false" :label="item.label" :prop="item.field"
- v-if="item.type == 'input' && customerName(item)">
- <view class="card_form_item">
- <u-input v-model="model[`${item.field}`]" :disabled="item.disabled ? true : false"
- :placeholder="item.placeholder"></u-input>
- </view>
- </u-form-item>
- <u-form-item :required="item.required ? true : false" :label="item.label" :prop="item.field"
- v-else-if="item.type == 'select'">
- <view class="card_form_item">
- <u-input :placeholder="item.placeholder" suffixIcon="arrow-down"
- v-model="model[`${item.field}`]" @focus="change(item)"></u-input>
- </view>
- </u-form-item>
- <u-form-item :required="item.required ? true : false" :label="item.label" :prop="item.field"
- v-else-if="item.type == 'selectil'">
- <view class="card_form_item_selectil frameil" @click="change(item)">
- <view class="title_input_selectil" :class="model[`${item.field}`] ? '' : 'hsColor'">
- {{model[`${item.field}`] || item.placeholder}}
- </view>
- <u-icon name="arrow-down" size="18px"></u-icon>
- </view>
- </u-form-item>
- <!-- 保温箱选择 -->
- <u-form-item :required="item.required ? true : false" :label="item.label" :prop="item.field"
- v-else-if="item.type == 'selectkey' && getCooler()">
- <view class="card_form_item_selectil frameil" @click="incubatorChange(item)">
- <view class="title_input_selectil" :class="model[`${item.field}`] ? '' : 'hsColor'">
- {{model[`${item.field + 'name'}`] || item.placeholder}}
- <!-- {{model[`${item.field}`] == 0? '' : model[`${item.field}`]}} -->
- </view>
- <u-icon name="arrow-down" size="18px"></u-icon>
- </view>
- </u-form-item>
- <u-form-item :required="item.required ? true : false" :label="item.label" :prop="item.field"
- v-else-if="item.type == 'textarea'">
- <view class="card_form_item">
- <u-textarea v-model="model[`${item.field}`]" autoHeight
- :placeholder="item.placeholder"></u-textarea>
- </view>
- </u-form-item>
- </view>
- </u-form>
- <u-popup :show="incubatorShow" closeable @close="close">
- <view class="card_incubator">
- <view class="head_place">选择保温箱</view>
- <view class="card_search">
- <u-search placeholder="请输入保温箱名称" v-model="keyword" :showAction="false"
- @change="searchChange"></u-search>
- </view>
- <view class="incubator_roll" v-if="incubatorData.length > 0">
- <view class="card_title_item" :class="item.name == model.coolerBoxIdname ? 'color_blue' : ''"
- v-for="(item,index) in incubatorData" :key="index" @click="incubatorClick(item)">
- {{item.name}}
- </view>
- <view class="center_in" style="margin-top: 30rpx;">
- <u-divider style="width: 350rpx;" text="没有更多了"></u-divider>
- </view>
- </view>
- <view style="margin-bottom: 20px;" v-else>
- <u-empty mode="list" text="暂无保温箱" marginTop="50"></u-empty>
- </view>
- </view>
- </u-popup>
- <u-picker :defaultIndex="findIndex(model[fieldType], columns[0])" :show="show" :columns="columns"
- keyName="label" @confirm="confirm($event, fieldType)" @cancel="cancel"></u-picker>
- </view>
- </template>
- <script>
- export default {
- name: 'x-form',
- props: {
- list: {
- type: Array,
- default () {
- return []
- }
- },
- model: {
- type: Object,
- default () {
- return {}
- }
- },
- rules: {
- type: Object,
- default () {
- return {}
- }
- },
- },
- data() {
- return {
- show: false,
- columns: [],
- fieldType: '',
- incubatorShow: false,
- incubatorData: [],
- keyword: '',
- incuType: '',
- }
- },
- // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
- onReady() {
- this.$refs.uForm.setRules(this.rules);
- },
- methods: {
- customerName(value) {
- var userInfo = this.$cache.getCache('userInfo')
- if (userInfo.userType == 'customer') {
- if (value.field != 'customerName') {
- if (value.type == 'input') {
- return true
- }
- }
- } else {
- if (value.type == 'input') {
- return true
- }
- }
- },
- change(e) {
- this.columns = []
- this.fieldType = e.field
- this.show = true
- this.$nextTick(() => {
- this.columns.push(e.options)
- })
- },
- // 保温箱选择
- incubatorChange(event) {
- this.incuType = event.field
- // console.log(event, 3254)
- this.incubatorShow = true
- this.$api.get('/api/cooler-box', {
- page: 1,
- pageSize: 999,
- isBind: true,
- name: this.keyword,
- }).then(res => {
- if (res.code == 200) {
- this.incubatorData = res.data.list
- }
- })
- },
- // 选择保温箱
- incubatorClick(event) {
- this.$refs.uForm.validateField(this.incuType);
- this.model[this.incuType] = event.id
- this.$emit('incubatorClick', event)
- this.incubatorShow = false
- },
- // 搜索
- searchChange() {
- this.incubatorData = []
- this.incubatorChange()
- },
- // 选择确定
- confirm(value, type) {
- this.$refs.uForm.validateField(type);
- this.show = false
- this.model[type] = value.value[0].label
- },
- getCooler() {
- if (this.model.deliveryCondition == "保温箱") {
- return true
- }
- },
- // 点击确定
- cancel() {
- this.show = false
- },
- findIndex(code, list) {
- if (!code || !list) {
- return [0]
- }
- return [list.findIndex((item) => (item.label === code || item.label === code))]
- },
- close() {
- this.incubatorShow = false
- },
- //子组件校验,传递到父组件
- async validateForm() {
- let flag = null
- await this.$refs.uForm.validate(valid => {}).then(res => {
- flag = true
- }).catch(err => {
- flag = false
- })
- return flag
- }
- },
- }
- </script>
- <style lang="scss">
- .card_form_item {
- width: 100%;
- }
- .card_form_item_selectil {
- width: 100%;
- display: flex;
- flex-direction: row;
- align-items: center;
- justify-content: space-between;
- padding: 6px 9px;
- height: 52rpx;
- }
- .title_input_selectil {
- font-size: 30rpx;
- // width: 100%;
- }
- .hsColor {
- color: rgb(192, 196, 204);
- }
- // 伪元素1rpx边框
- .frameil {
- position: relative; //重要
- }
- .frameil::after {
- position: absolute;
- content: '';
- border: 2rpx solid #dadbde;
- width: 200%;
- height: 200%;
- top: 0;
- left: 0;
- transform: scale(0.5);
- transform-origin: 0 0;
- pointer-events: none;
- border-radius: 20rpx;
- /* 使伪元素不会阻止鼠标事件 */
- }
- .card_incubator {
- min-height: 600rpx;
- // max-height: 900rpx;
- // overflow-y: auto;
- touch-action: none;
- }
- .head_place {
- display: flex;
- justify-content: center;
- align-items: center;
- padding: 20rpx;
- }
- .card_search {
- margin: 20rpx;
- }
- .card_title_item {
- position: relative;
- padding: 30rpx;
- // border-bottom: 1rpx solid #dadbde;
- }
- .color_blue {
- color: #2979ff;
- }
- .card_title_item:before {
- content: " ";
- position: absolute;
- left: 0;
- bottom: 0;
- width: 100%;
- height: 1px;
- border-top: 1px solid #e7e6e4;
- -webkit-transform-origin: 0 0;
- transform-origin: 0 0;
- -webkit-transform: scaleY(0.5);
- transform: scaleY(0.5);
- }
- .incubator_roll {
- max-height: 700rpx;
- display: flex;
- flex-direction: column;
- overflow-y: auto;
- }
- </style>
|