接口调用

This commit is contained in:
ljx120 2024-12-25 17:27:20 +08:00
parent 7d27322db5
commit e980db2999
2 changed files with 347 additions and 29 deletions

View File

@ -11,6 +11,6 @@ export default {
//本地服务
base_url: 'http://192.168.1.222:8082',
base_url: 'http://192.168.1.2:7002',
}

View File

@ -1,11 +1,80 @@
<script setup lang="ts">
import {ref} from 'vue'
import {onMounted, ref} from 'vue'
import { formatDate } from '../../utils/date';
import { getAction, postAction } from '../../common/http';
import { showToast } from 'vant';
const form = ref({data:formatDate(new Date()),list:[{}]} as any)
const form = ref({createTime:formatDate(new Date()),dict:[{infos:[]}]} as any)
const show = ref(false)
const onSubmit = () =>{
const gysList = ref([])
const djList = ref([])
const showPicker = ref(false)
const popuList = ref([])
const showDialog = ref(false)
const pickerList = ref([])//
const pickerContainerList = ref([])
const showPickerList = ref(false)
const searchValue = ref('')//
const searchIndex = ref(0)//
const mlList = ref([])
onMounted(()=>{
getAction('/suppliers',{page:1,size:100}).then((res:any)=>{
if(res.code===200){
gysList.value=res.data.record
}
})
getAction('/rawFabricLevels',{page:1,size:100}).then((res:any)=>{
if(res.code===200){
djList.value=res.data.record
}
})
getAction('/fabric/info/all').then((res:any)=>{
if(res.code===200){
djList.value=res.data.record
}
})
})
const typeData = ref()
const indexData = ref()
//
const choosePic = (type:any,index:any) =>{
showPicker.value=true
typeData.value=type
indexData.value=index
}
//
const pickerConfirm = (val:any) =>{
if(typeData.value==='level'){
form.value.dict[indexData.value][typeData.value]=val.selectedValues[0]
}else{
form.value[typeData.value]=val.selectedValues[0]
}
showPickerCancel()
}
//
const showPickerCancel = () =>{
showPicker.value=false
}
//
const handleOpen = () =>{
if(typeData.value==='supplier'){
popuList.value=gysList.value.map(l=>({text:l.name,value:l.name}))
}else if(typeData.value==='level'){
popuList.value=djList.value.map(l=>({text:l.level,value:l.level}))
}
}
const onSubmit = () =>{
postAction('/rawFabric',form.value).then((res:any)=>{
if(res.code===200){
showToast('提交成功!')
uni.redirectTo({
url:'/pages/whiteEmbryo/w-warehousing'
})
}
})
}
const onClickLeft = () =>{
@ -17,13 +86,14 @@ const chooseDate = ()=>{
show.value=true
}
const onConfirmDate = (val:any) =>{
form.value.data = formatDate(val)
form.value.createTime = formatDate(val)
show.value = false
}
const h5ScanCode = ref(false);
function scanCode() {
function scanCode(index:any) {
// #ifdef H5
h5ScanCode.value = true;
indexData.value=index
// #endif
// #ifndef H5
uni.scanCode({
@ -32,8 +102,6 @@ function scanCode() {
icon: "none",
title: res.result,
});
// TODO
},
faile: (err) => {
console.log("err", err);
@ -41,14 +109,19 @@ function scanCode() {
});
// #endif
}
function handleSuccess(res) {
const barcode = ref()
function handleSuccess(res:any) {
h5ScanCode.value = false;
uni.showToast({
icon: "none",
title: res,
});
barcode.value=res
getAction('/rawFabric/valid',{barcode:res}).then((res:any)=>{
if(res.code===200){
showDialog.value=true
}else{
showToast('扫码失败,该编号已被使用,请重新扫码!')
}
})
}
function handleFail(err) {
function handleFail(err:any) {
uni.showModal({
title: err.errName,
content: err.errMsg,
@ -57,10 +130,91 @@ function handleFail(err) {
},
});
}
function handleClose() {
h5ScanCode.value = false;
}
//
const meter = ref('' as any)
const checked = ref(false)
const confirmSecond = () =>{
if(!meter.value) return showToast('请填写米数!')
var x = String(meter.value).indexOf('.') + 1; //
var y = String(meter.value).length - x; //
if(y===0) return showToast('请输入正确数字!')
if(x>0 && y > 1) return showToast('请保留一位小数!')
form.value.dict[indexData.value].infos.push({barcode:barcode.value,len:meter.value,freeze:checked.value})
showDialog.value=false
}
//
const selectChoose = () =>{
showPickerList.value = true
}
//
const mlmcOpen = () => {
pickerList.value = mlList.value
pickerContainerList.value = pickerList.value
searchValue.value = ''
}
//
const pickerCancel = () => {
showPickerList.value = false
}
//
const selectedValue = ref()
const getSeachList = () => {
searchIndex.value = 0
let reg = new RegExp(searchValue.value)
let arr = []
pickerList.value.forEach(l => {
if (reg.test(l.text)) {
arr.push(l)
}
})
pickerContainerList.value = arr
}
//
const upSearch = () => {
if (searchIndex.value === 0 && pickerContainerList.value.length) {
searchIndex.value = pickerContainerList.value.length - 1
selectedValue.value = [pickerContainerList.value[searchIndex.value].text]
} else if (pickerContainerList.value.length) {
searchIndex.value--
selectedValue.value = [pickerContainerList.value[searchIndex.value].text]
} else {
showToast('没有了!')
}
}
//
const downSearch = () => {
if (pickerContainerList.value.length) {
if (searchIndex.value === pickerContainerList.value.length) {
searchIndex.value = 0
selectedValue.value = [pickerContainerList.value[searchIndex.value].text]
} else {
searchIndex.value++
selectedValue.value = [pickerContainerList.value[searchIndex.value].text]
}
} else {
showToast('没有了!')
}
}
//
const timer = ref()
const searchTo = () => {
if (timer.value) {
clearTimeout(timer.value)
}
timer.value = setTimeout(() => {
getSeachList()
}, 800)
}
const onConfirm = (val:any) => {
console.log(val);
}
</script>
<template>
@ -76,51 +230,54 @@ function handleClose() {
<van-form @submit="onSubmit">
<van-cell-group inset>
<van-field
v-model="form.data"
v-model="form.createTime"
name="入库日期"
label="入库日期"
colon
class="bor"
label-width="5em"
readonly
:rules="[{ required: true, message: '请填写' }]"
@click="chooseDate()"
:rules="[{ required: true, message: '请填写' }]"
/>
<van-field
v-model="form.gys"
v-model="form.supplier"
name="供应商名"
label="供应商名"
colon
class="bor"
label-width="5em"
:rules="[{ required: true, message: '请填写' }]"
@click="choosePic('supplier',0)"
readonly
:rules="[{ required: true, message: '请填写' }]"
/>
<van-field
v-model="form.mlmc"
v-model="form.fabricName"
name="面料名称"
label="面料名称"
colon
class="bor"
:rules="[{ required: true, message: '请填写' }]"
@click="selectChoose"
label-width="5em"
readonly
:rules="[{ required: true, message: '请填写' }]"
/>
<view class="content">
<template v-for="(item,index) in form.list" :key="index">
<template v-for="(item,index) in form.dict" :key="index">
<van-field
v-model="item.bpdj"
name="白胚等级"
label="白胚等级"
colon
class="bor"
:rules="[{ required: true, message: '请填写' }]"
@click="choosePic('bpdj',index)"
label-width="5em"
readonly
:rules="[{ required: true, message: '请填写' }]"
>
<template #button>
<van-icon name="add" color="red" size="25" @click="form.list.push([])" v-if="index===0"/>
<van-icon name="clear" color="red" size="25" @click="form.list.splice(index,1)" v-else/>
<van-icon name="add" color="red" size="25" @click.stop="form.dict.push([])" v-if="index===0"/>
<van-icon name="clear" color="red" size="25" @click.stop="form.dict.splice(index,1)" v-else/>
</template>
</van-field>
<view class="grid-container">
@ -128,14 +285,14 @@ function handleClose() {
<view class="grid-item">米数</view>
<view class="grid-item">操作</view>
</view>
<view class="grid-container" v-for="(itemSecond,indexSecond) in item.list" :key="indexSecond">
<view class="grid-item">面料编号</view>
<view class="grid-item">米数</view>
<view class="grid-item">操作</view>
<view class="grid-container" v-for="(itemSecond,indexSecond) in item.infos" :key="indexSecond">
<view class="grid-item">{{itemSecond.barcode}}</view>
<view class="grid-item">{{itemSecond.len}}</view>
<view class="grid-item" style="color:red">删除</view>
</view>
<view class="grid-container">
<view class="grid-item">
<van-button type="primary" @click="scanCode">扫一扫</van-button>
<van-button type="primary" @click="scanCode(index)">扫一扫</van-button>
<cshaptx4869-scancode
v-if="h5ScanCode"
@success="handleSuccess"
@ -162,7 +319,76 @@ function handleClose() {
</view>
</view>
</view>
<van-dialog v-model:show="showDialog" title="扫码成功,请输入米数">
<div>
<van-cell-group inset>
<van-field
v-model="meter"
name="面料米数"
label="面料米数"
colon
class="line"
type="number"
label-width="5em"
/>
</van-cell-group>
<van-checkbox v-model="checked" style="margin-left:5.5em;">暂存</van-checkbox>
</div>
<template #footer>
<div class="footer-button">
<van-button plain size="small" native-type="button" style="width: 25vw;"
@click="showDialog=false">
取消
</van-button>
<van-button size="small" type="success" native-type="submit" style="width: 25vw;" @click="confirmSecond">
确认
</van-button>
</div>
</template>
</van-dialog>
<van-calendar v-model:show="show" @confirm="onConfirmDate" :min-date="new Date(2010, 0, 1)" :max-date="new Date(2050, 0, 31)"/>
<!--选择框-->
<van-popup v-model:show="showPicker" round position="bottom" @open="handleOpen">
<van-picker
show-toolbar
:columns="popuList"
@confirm="pickerConfirm"
@cancel="showPickerCancel"
ref="pickerRef"
/>
</van-popup>
<!-- 面料选择框-->
<van-popup v-model:show="showPickerList" position="bottom" @open="mlmcOpen">
<view class="select-model">
<van-picker
:columns="pickerContainerList"
@cancel="pickerCancel"
v-model="selectedValue"
@confirm="onConfirm"
/>
<view>
<view class="top-select">
<view class="confirm-select">
<p>请选择品种</p>
</view>
<view class="search-box">
<view>
<van-search placeholder="请输入品种名字" v-model="searchValue" label="面料搜索:" background="#ffffff"
@input="searchTo()" :clearable="false"/>
</view>
<view class="flex-btn">
<button class="search-btn" @click="upSearch()"></button>
<button class="search-btn" @click="downSearch()"></button>
</view>
</view>
</view>
</view>
</view>
</van-popup>
</template>
<style scoped lang="scss">
@ -182,6 +408,7 @@ function handleClose() {
.grid-item{
border: 1px solid #f2f2f2;
text-align: center;
padding: 8rpx 0;
::v-deep .van-cell {
padding: 0 5px;
}
@ -203,4 +430,95 @@ function handleClose() {
padding: 5px 8px;
height: 30px;
}
.footer-button{
margin: 20px;
display: flex;
justify-content: space-around;
}
.line{
::v-deep .van-field__control {
border-bottom: 1px solid #d7d7d7;
text-align: center;
}
}
/*面料选择搜索框*/
.select-model {
position: relative;
}
.confirm-select {
width: 100%;
}
.confirm-select > p {
text-align: center;
}
.confirm-select > button {
border: none;
background-color: #ffffff;
color: #388aed;
margin: 10px 30px 0 0;
}
.top-select {
position: absolute;
top: 30px;
left: 0;
right: 0;
margin: auto;
z-index: 999;
}
::v-deep .select-model .van-picker__toolbar {
height: 66px;
align-items: flex-start;
/*justify-content: flex-end;*/
}
::v-deep .select-model .van-picker__cancel, .select-model .van-picker__confirm {
height: 30px;
padding: 10px 16px 0;
}
.search-btn {
padding: 1px 8px;
border: none;
background-color: #388aed;
color: #ffffff;
margin-left: 5px;
height: 30px;
line-height: 25px;
}
.search-box {
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
padding-top: 15px;
padding-bottom: 5px;
position: relative;
background-color: #fff;
}
.van-search {
background-color: #f7f7f8;
}
.ml-search-jump {
padding: 3px 10px;
background-color: #388aed;
color: #ffffff;
border: none;
margin-left: 10px;
}
.flex-btn {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
}
</style>