代码更新
This commit is contained in:
@@ -29,10 +29,7 @@
|
||||
<picker @change="categoryChange" :value="categoryCurrent" range-key="name" :range="category">
|
||||
<view class=" u-flex u-row-between border-bottom u-relative ">
|
||||
<view class="zhezhao u-absolute position-all" style="z-index: 1;"></view>
|
||||
<!-- <view>
|
||||
<text class="" v-if="form.category!==''">{{category[form.category].name}}</text>
|
||||
<text class="color-999 " v-else>选择分类</text>
|
||||
</view> -->
|
||||
|
||||
<view class="u-flex-1">
|
||||
<uni-easyinput :inputBorder="false" paddingNone v-model="form.category"
|
||||
placeholder="选择分类"></uni-easyinput>
|
||||
@@ -111,26 +108,12 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import {
|
||||
returnAllCategory
|
||||
} from '@/pageProduct/util.js'
|
||||
import {
|
||||
$tbShopCategory,
|
||||
$tbShopUnit
|
||||
} from '@/http/yskApi/goods.js'
|
||||
import {
|
||||
$temporaryDishes
|
||||
} from '@/http/yskApi/Instead.js'
|
||||
import {
|
||||
reactive,
|
||||
onMounted,
|
||||
ref,
|
||||
onBeforeMount,
|
||||
} from 'vue';
|
||||
import {
|
||||
onLoad,
|
||||
onShow
|
||||
} from '@dcloudio/uni-app'
|
||||
import { reactive, onMounted, ref, onBeforeMount } from 'vue';
|
||||
import { onLoad, onShow } from '@dcloudio/uni-app'
|
||||
import { getCategoryList, getProdUnitList } from '@/api/product.js'
|
||||
import { inject } from 'vue';
|
||||
|
||||
const websocketUtil = inject('websocketUtil'); // 注入 WebSocket 工具类实例
|
||||
const units = reactive({
|
||||
list: [],
|
||||
current: ''
|
||||
@@ -138,17 +121,6 @@
|
||||
let category = reactive([])
|
||||
let categoryCurrent = ref('')
|
||||
|
||||
function categoryChange(e) {
|
||||
console.log(e);
|
||||
categoryCurrent.value = e.detail.value
|
||||
form.category = category[e.detail.value].name
|
||||
}
|
||||
|
||||
function unitChange(e) {
|
||||
units.current = e.detail.value
|
||||
form.unit = units.list[e.detail.value].name
|
||||
}
|
||||
|
||||
const refform = ref(null)
|
||||
const form = reactive({
|
||||
name: '',
|
||||
@@ -191,97 +163,107 @@
|
||||
},
|
||||
}
|
||||
let timer = null
|
||||
|
||||
const option = reactive({
|
||||
|
||||
})
|
||||
onLoad((opt) => {
|
||||
Object.assign(option, opt)
|
||||
setTimeout(() => {
|
||||
getTbShopUnit()
|
||||
getCategory()
|
||||
}, 600)
|
||||
})
|
||||
|
||||
onBeforeMount(() => {
|
||||
clearInterval(timer)
|
||||
})
|
||||
|
||||
/**
|
||||
* 获取单位数据
|
||||
*/
|
||||
async function getTbShopUnit() {
|
||||
const res = await getProdUnitList({
|
||||
page: 1,
|
||||
size: 200,
|
||||
sort: "id"
|
||||
})
|
||||
units.list = res.map(v => {
|
||||
return {
|
||||
...v,
|
||||
value: v.id
|
||||
}
|
||||
})
|
||||
}
|
||||
/**
|
||||
* 获取分类数据
|
||||
*/
|
||||
async function getCategory() {
|
||||
const res = await getCategoryList({
|
||||
page: 1,
|
||||
size: 600
|
||||
})
|
||||
category = res.map(v => {
|
||||
return {
|
||||
...v,
|
||||
value: v.id
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function categoryChange(e) {
|
||||
categoryCurrent.value = e.detail.value
|
||||
form.category = category[e.detail.value].name
|
||||
}
|
||||
|
||||
function unitChange(e) {
|
||||
units.current = e.detail.value
|
||||
form.unit = units.list[e.detail.value].name
|
||||
}
|
||||
|
||||
|
||||
function submit() {
|
||||
refform.value.validate(res => {
|
||||
console.log(res)
|
||||
if (!res) {
|
||||
$temporaryDishes({
|
||||
"useType": option.useType,
|
||||
"masterId": option.masterId,
|
||||
"tableId": option.tableId,
|
||||
"name": form.name,
|
||||
"categoryId": category[categoryCurrent.value].id,
|
||||
"price": form.price,
|
||||
"num": form.num,
|
||||
unit: units.list[units.current].id,
|
||||
"note": form.note,
|
||||
"vipUserId": option.vipUserId
|
||||
}).then(r => {
|
||||
uni.$emit('add:cashCai')
|
||||
clearInterval(timer)
|
||||
timer = setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 500)
|
||||
let params = {
|
||||
type:'onboc',
|
||||
account: uni.getStorageSync("iToken").loginId,
|
||||
shop_id: uni.getStorageSync("shopInfo").id,
|
||||
operate_type: 'add',
|
||||
table_code: option.tableCode,
|
||||
product_name: form.name,
|
||||
sku_name: form.category, //
|
||||
number: form.num, //数量
|
||||
discount_sale_amount: form.price, //数量
|
||||
pack_number: 0, //数量
|
||||
is_gift: 0,
|
||||
is_temporary: 1, //是否是临时菜
|
||||
}
|
||||
websocketUtil.send(JSON.stringify(params))
|
||||
|
||||
uni.$emit('add:cashCai',{
|
||||
name: form.name,
|
||||
lowPrice: form.price,
|
||||
number: form.num,
|
||||
is_temporary: 1, //是否是临时菜
|
||||
})
|
||||
clearInterval(timer)
|
||||
timer = setTimeout(() => {
|
||||
uni.navigateBack()
|
||||
}, 500)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}).catch(err => {
|
||||
console.log(err);
|
||||
})
|
||||
}
|
||||
//获取单位数据
|
||||
async function getTbShopUnit() {
|
||||
const res = await $tbShopUnit({
|
||||
page: 0,
|
||||
size: 200,
|
||||
sort: "id"
|
||||
})
|
||||
units.list = res.content.map(v => {
|
||||
return {
|
||||
...v,
|
||||
value: v.id
|
||||
}
|
||||
})
|
||||
}
|
||||
async function getCategory() {
|
||||
const res = await $tbShopCategory({
|
||||
page: 0,
|
||||
size: 600
|
||||
})
|
||||
const arr = forList(res.content).map(v => {
|
||||
return {
|
||||
...v,
|
||||
value: v.id
|
||||
}
|
||||
})
|
||||
category.length = arr.length
|
||||
for (let i in arr) {
|
||||
category[i] = arr[i]
|
||||
}
|
||||
}
|
||||
|
||||
function forList(arr) {
|
||||
let arrs = []
|
||||
arr.forEach(ele => {
|
||||
arrs.push(ele)
|
||||
if (ele.childrenList.length) {
|
||||
ele.childrenList.forEach(res => {
|
||||
arrs.push(res)
|
||||
})
|
||||
}
|
||||
})
|
||||
return arrs
|
||||
}
|
||||
async function init() {
|
||||
getTbShopUnit()
|
||||
getCategory()
|
||||
}
|
||||
// onMounted(() => {
|
||||
// init()
|
||||
// })
|
||||
onLoad((opt) => {
|
||||
Object.assign(option, opt)
|
||||
setTimeout(() => {
|
||||
init()
|
||||
}, 600)
|
||||
})
|
||||
|
||||
|
||||
onBeforeMount(() => {
|
||||
clearInterval(timer)
|
||||
})
|
||||
const option = reactive({
|
||||
|
||||
})
|
||||
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
|
||||
Reference in New Issue
Block a user