Files
zsw-jx-store/src/subPages/merchantChild/setInvoiceEB/setInvoiceEB.ts
2025-12-29 11:47:34 +08:00

168 lines
7.2 KiB
TypeScript

import { computed, ref, watch } from 'vue'
import { onLoad, onPullDownRefresh, onReady } from "@dcloudio/uni-app";
import { getStorage } from '@/utils/storage';
import { store } from '@/store'
import toast from "@/utils/toast";
import order from '@/api/https/order';
export default {
setup() {
const invoiceInfo = ref<AnyObject>({
invoice_contact:{
person:"",
phone:""
},
invoice_mode:"", // 开具方式
invoice_material:"", // 发票材质
invoice_class:"", // 发票种类
})
const invoice_mode_array = ref([{value:'empty',label:'无'},{value:'SYS_MANUAL',label:'人工开具'},{value:'OPEN_API',label:'开放平台'},{value:'FLASH_INVOICE',label:'闪电开票'},{value:'CODE_INVOICE',label:'扫码开票'},{value:'H5_REDIRECT',label:'H5植入'},{value:'OTHER',label:'其他形式'}])
const invoice_mode_index = ref<number>(0)
const invoice_material_array = ref([{value:'empty',label:'无'},{value:'PAPER',label:'纸质'},{value:'ELECTRONIC',label:'电子'}])
const invoice_material_index = ref<number>(0)
const invoice_class_array = ref([{value:'empty',label:'无'},{value:'VAT_COMMON',label:'普通发票'},{value:'VAT_SPECIAL',label:'专用发票'},{value:'QUOTA',label:'定额发票'}])
const invoice_class_index = ref<number>(0)
const invoice_contact_name = ref('')
const invoice_contact_phone = ref('')
const storeName = ref('') // 门店名称
const ebaiStore = ref<any>({})
const logoUrl = ref('https://image.jxc4.com/image/987f5c2f23452cdcbddde16f055437f5.png')
onLoad(async () => {
store.commit('storeInfo/jxLoadingFn', true)
if (getStorage('terrace') === 'jxgy') logoUrl.value = 'https://image.jxc4.com/image/5b24d0fae35b45d99a911bb09ecfa927.png'
else if (getStorage('terrace') === 'gblm') logoUrl.value = 'https://image.jxc4.com/image/a2164dbb2289734a7d96e778040c5776.png'
await getStores()
store.commit('storeInfo/jxLoadingFn', false)
})
const appTheme = computed(() => { return store.getters['serveInfo/appTheme'] === 'light'})
onReady(() => {
uni.setNavigationBarColor({
frontColor: !appTheme.value ? '#ffffff' : '#000000', // 前景文字颜色,必选
backgroundColor: appTheme.value ? '#ffffff' : '#000000', // 背景颜色,必选
});
})
watch(() => store.getters['storeInfo/platformInfo'],
(val) => {
if(val && val.length>0){
let findItem = val.filter((item:AnyObject) => item.vendorID === 3)
if(findItem && findItem.length>0) {
ebaiStore.value = findItem[0]
queryEbStoreInvoice()
}
}
})
/**
* 下拉刷新
*/
onPullDownRefresh(async () => {
store.commit('storeInfo/jxLoadingFn', true)
await getStores()
await queryEbStoreInvoice()
store.commit('storeInfo/jxLoadingFn', false)
})
/**
* 获取门店数据
*/
async function getStores() {
await store.dispatch('storeInfo/getOneStore',getStorage("storeID"))
const stateData = store.state.storeInfo.allStoreInfo
storeName.value = stateData.name // 门店名
}
/**
* 查询门店发票设置
*/
async function queryEbStoreInvoice() {
let res = await order.query_invoice_setting({
vendorId:'3',
vendorStoreID:ebaiStore.value.vendorStoreID
})
if(res.code === '0'){
invoiceInfo.value = res.data[0].settings
if(invoiceInfo.value.invoice_mode){
let findIndex = invoice_mode_array.value.findIndex(item => item.value === invoiceInfo.value.invoice_mode)
if(findIndex !== -1 ) invoice_mode_index.value = findIndex
}
if(invoiceInfo.value.invoice_material){
let findIndex = invoice_material_array.value.findIndex(item => item.value === invoiceInfo.value.invoice_material)
if(findIndex !== -1 ) invoice_material_index.value = findIndex
}
if(invoiceInfo.value.invoice_class){
let findIndex = invoice_class_array.value.findIndex(item => item.value === invoiceInfo.value.invoice_class)
if(findIndex !== -1 ) invoice_class_index.value = findIndex
}
}
}
/**
* 选择确认框
*/
function bindPickerChange(e:any,type:string) {
if(type === 'invoice_mode') invoice_mode_index.value = e.detail.value
if(type === 'invoice_material') invoice_material_index.value = e.detail.value
if(type === 'invoice_class') invoice_class_index.value = e.detail.value
}
/**
* 保存发票信息
*/
async function saveInvoiceInfo() {
try {
let findItem = store.getters['storeInfo/platformInfo'].filter((item:AnyObject) => item.vendorID === 3)
if(findItem.length === 0) return toast('未绑定淘宝闪购门店',2)
// if(!ebStoreInfo || JSON.stringify(ebStoreInfo) === '{}') return toast('未绑定淘宝闪购门店')
if(+invoice_mode_index.value) invoiceInfo.value.invoice_mode = invoice_mode_array.value[invoice_mode_index.value].value
if(+invoice_material_index.value) invoiceInfo.value.invoice_material = invoice_material_array.value[invoice_material_index.value].value
if(+invoice_class_index.value) invoiceInfo.value.invoice_class = invoice_class_array.value[invoice_class_index.value].value
let res = await order.bath_update_invoice_setting({
vendorId:'3',
vendorStoreID:findItem[0].vendorStoreID,
payload:JSON.stringify(invoiceInfo.value)
})
if(res.success.length>0 && !res.success[0].msg) toast('修改成功',1)
else toast('修改失败',2)
uni.hideLoading()
} catch (error) {
uni.hideLoading()
throw error
}
}
return {
invoiceInfo, // 发票信息
invoice_contact_name,
invoice_contact_phone,
invoice_mode_array, // 开具方式
invoice_mode_index, // 开具方式索引
invoice_material_array, // 发票材质
invoice_material_index, // 发票材质索引
invoice_class_array, // 发票种类
invoice_class_index, // 发票种类索引
bindPickerChange, // 选择确认框
saveInvoiceInfo, // 保存发票信息
storeName, // 门店名
logoUrl, // logoUrl
appTheme
}
}
}