diff --git a/pages/bill/add-bill/add-bill.vue b/pages/bill/add-bill/add-bill.vue index 488f388..76f8454 100644 --- a/pages/bill/add-bill/add-bill.vue +++ b/pages/bill/add-bill/add-bill.vue @@ -277,6 +277,7 @@ import { import { onLoad, onShow, + onUnload } from '@dcloudio/uni-app' @@ -477,13 +478,20 @@ onShow(() => { plus.navigator.setStatusBarStyle("dark"); }, 500); // #endif + // #endif +}) + +onUnload(() => { + uni.$off('addBillDetail') }) onLoad((option) => { - uni.$on('addBill', (res) => { - console.log("addBill", res); + uni.$on('addBillDetail', (res) => { + console.log("billData", billData.value); billData.value.imgUrl = res.url billData.value.name = res.name + const billDataList = JSON.parse(JSON.stringify(getBillList())) + console.log("billDataList", billDataList) console.log(billData.value) }); console.log(option) @@ -491,9 +499,10 @@ onLoad((option) => { data.type = option.type data.navBar.title = '新增余额明细' } - if (option.id) { + if (option.id && isEdit) { + console.log('编辑页面') // 获取当前id账单 - const existingBill = getBillList().find(b => b.id === option.id) + const existingBill = JSON.parse(JSON.stringify(getBillList())).find(b => b.id === option.id) if (existingBill) { //表单赋值 billData.value.id = existingBill.id @@ -662,7 +671,7 @@ const setItemInfoValue = (id) => { * 切换头像 */ const changeAvatar = () => { - util.goPage("/pages/common/hot-icon/hot-icon" + "?page=addBill") + util.goPage("/pages/common/hot-icon/hot-icon" + "?page=addBillDetail") } @@ -771,6 +780,7 @@ const validateBillData = () => { */ const onRightClick = async () => { if (!validateBillData()) return + console.log("1111111111"); if (billData.value.merchantOption.serviceDetail && billData.value.merchantOption.serviceDetailInfo && billData.value.merchantOption.serviceDetailInfo.imgUrl) { const url = await saveAndDisplayImage(billData.value.merchantOption.serviceDetailInfo.imgUrl) billData.value.merchantOption.serviceDetailInfo.imgUrl = url @@ -794,9 +804,6 @@ const onRightClick = async () => { billData.value.payMethod = "余额" } addBill(billData.value) - const allBillList = getBillList() - - console.log("getBillDataList------", allBillList) } uni.showToast({ diff --git a/store/index.js b/store/index.js index 6f47cb7..9e606b5 100644 --- a/store/index.js +++ b/store/index.js @@ -35,7 +35,7 @@ export const store = reactive({ }, // 账单列表 - billList: storage.get('bill_list') || [], + billList: JSON.parse(JSON.stringify(storage.get('bill_list') || [])), }); @@ -83,7 +83,7 @@ export const useStore = () => { }; const getBillList = () => { - return store.billList + return JSON.parse(JSON.stringify(store.billList)) } @@ -107,7 +107,10 @@ export const useStore = () => { // 监听billList改变自动保存 watch( () => store.billList, - (newValue) => storage.set('bill_list', newValue), + (newValue) => { + console.log("store.billList") + storage.set('bill_list', newValue) + }, { deep: true } );