123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205 |
- <template>
- <view>
- <view class="form-card" v-if="viewStatus">
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">规格类型</view>
- <up-radio-group v-model="formData.serviceType" class="form-input">
- <up-radio v-for="(item, index) in serviceOption" :key="index" :label="item.name" :name="item.value"
- activeColor="#07C160" inactiveColor="#C4C4C4">
- </up-radio>
- </up-radio-group>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">规格说明</view>
- <up-input v-model="formData.specDescribe" clearable border="none" placeholder="填写本服务内容说明"
- class="form-input" placeholder-class="form-placeholder"></up-input>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">服务价格</view>
- <up-input v-model="formData.price" clearable border="none" placeholder="单次服务的价格" class="form-input"
- placeholder-class="form-placeholder" @blur="blurInput('number','price')"></up-input>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">购买单位</view>
- <up-input v-model="formData.unit" clearable border="none" placeholder="购买单位如次、平方" class="form-input"
- placeholder-class="form-placeholder"></up-input>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">最少购买</view>
- <up-input v-model="formData.minPurchaseQuantity" clearable border="none" placeholder="用户下单最少购买数量"
- class="form-input" placeholder-class="form-placeholder" @blur="blurInput('number','minPurchaseQuantity')"></up-input>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">服务时长</view>
- <up-input v-model="formData.duration" clearable border="none" placeholder="预计单次服务时常" class="form-input"
- placeholder-class="form-placeholder" @blur="blurInput('number','duration')"></up-input>
- </view>
- </view>
- <view class="form-card" v-else>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">规格类型</view>
- <view class="form-input">{{ serviceType }}服务</view>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">规格说明</view>
- <view class="form-input">{{ formData.specDescribe }}</view>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">服务价格</view>
- <view class="form-input">{{ formData.price }}</view>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">购买单位</view>
- <view class="form-input">{{ formData.unit }}</view>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">最少购买</view>
- <view class="form-input">{{ formData.minPurchaseQuantity }}</view>
- </view>
- <view class="flex_c_l form-item hr-solid">
- <view class="form-lable">服务时长</view>
- <view class="form-input">{{ formData.duration }}</view>
- </view>
- </view>
- </view>
- </template>
- <script setup>
- import { computed, ref, reactive } from 'vue';
- import { provide, inject } from 'vue';
- const viewStatus = inject('viewStatus');
- const props = defineProps({
- form: {
- type: Object,
- default: () => {
- return {
- name: '',
- }
- }
- }
- })
- const serviceOption = [
- {
- name: '周期',
- value: '10'
- },
- {
- name: '单次',
- value: '20'
- },
- {
- name: '非时效',
- value: '30'
- }
- ]
- const formData = computed(() => {
- return props.form;
- })
- const serviceType = computed(() =>{
- const type = serviceOption.find(item => item.value === formData.value.serviceType)
- return type.name
- })
- function isNumber(str) {
- return /^[\+\-]?(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?$/.test(str);
- }
- //数字校验
- const numberVer = (key) => {
- return new Promise((resolve, reject) => {
- if(!formData.value[key]){
- reject('请输入内容');
- }
- const isNum = isNumber(formData.value[key]);
- if (!isNum) {
- formData.value[key] = formData.value[key].replace(/[^0-9.]/g, '');// 移除非数字字符
- formData.value[key] = Number(formData.value[key]);
- reject('请输入正确的数值');
- }
- const value = Number(formData.value[key]);
- if (value < 0) {
- reject('数值过小,请重新输入');
- }
- formData.value[key] = value;
- resolve();
- })
- }
- // 校验
- const blurInput = async (key,objectKey) => {
- try {
- const verFun = {
- number: numberVer,
- }
- const res = await verFun[key](objectKey);
- console.log("TCL: numberInput -> res", res)
- } catch (error) {
- uni.showToast({
- title: error,
- icon: 'none',
- duration: 1000
- });
- console.log("TCL: numberInput -> error", error)
- }
- }
- </script>
- <style lang="scss" scoped>
- .form-card {
- background: #fff;
- border-radius: 20rpx;
- margin-bottom: 20rpx;
- .form-item {
- padding: 32rpx 0;
- margin-left: 32rpx;
- padding-right: 32rpx;
- .form-lable {
- font-size: 32rpx;
- line-height: 44rpx;
- color: #1D2129;
- margin-right: 48rpx;
- }
- }
- .form-input {
- flex: 1;
- font-family: PingFang SC;
- font-size: 32rpx;
- line-height: 44rpx;
- color: #130F26;
- }
- }
- .code-btn {
- border-radius: 14rpx;
- background: linear-gradient(180deg, #FD8F7C -75%, #FE534B 140%);
- // margin-right: 32rpx;
- font-family: PingFang SC;
- font-size: 26rpx;
- font-weight: normal;
- line-height: 42rpx;
- letter-spacing: normal;
- color: #FFFFFF;
- padding: 13rpx 20rpx;
- }
- </style>
- <style>
- .form-placeholder {
- color: #C9CDD4;
- }
- </style>
|