<template>
	<view class="page">
		<view class="item">
			<text>隐藏零库存商品</text>
			<switch :checked="settings.hideZeroStock" @change="(e)=>update('hideZeroStock', e.detail.value)" />
		</view>
		<view class="item">
			<text>隐藏进货价</text>
			<switch :checked="settings.hidePurchasePrice" @change="(e)=>update('hidePurchasePrice', e.detail.value)" />
		</view>
	</view>
</template>

<script>
import { get, put } from '../../common/http.js'

export default {
	data() {
		return { settings: { hideZeroStock: false, hidePurchasePrice: false } }
	},
	onLoad() { this.load() },
	methods: {
		async load() {
			try {
				const res = await get('/api/product-settings')
				this.settings = { hideZeroStock: !!res?.hideZeroStock, hidePurchasePrice: !!res?.hidePurchasePrice }
			} catch (_) {}
		},
		async update(key, val) {
			const next = { ...this.settings, [key]: val }
			this.settings = next
			try { await put('/api/product-settings', next) } catch (_) {}
		}
	}
}
</script>

<style>
.page { background:#fff; }
.item { display:flex; justify-content: space-between; align-items:center; padding: 20rpx; border-bottom: 1rpx solid #f1f1f1; }
</style>







