481 lines
20 KiB
JavaScript
481 lines
20 KiB
JavaScript
// 1 => LOADING
|
|
// 2 => DONE
|
|
// 3 => ERROR
|
|
import * as api from "../api/mapping.js"
|
|
|
|
export default {
|
|
namespaced: true,
|
|
state: {
|
|
lookup_status: 0,
|
|
loading: false,
|
|
page: 1,
|
|
totalPageHeader: 0,
|
|
pageDetail: 1,
|
|
totalPageDetail: 0,
|
|
searchHeader: "",
|
|
searchDetail: "",
|
|
selectedSetup: {
|
|
Mgm_McuID: '0',
|
|
},
|
|
setupList: [],
|
|
kelainanList: [],
|
|
errorMsg: '',
|
|
snackbarSuccess: false,
|
|
snackbarError: false,
|
|
successMsg: '',
|
|
},
|
|
mutations: {
|
|
update_lookup_status(state, val) {
|
|
state.lookup_status = val
|
|
},
|
|
update_searchHeader(state, val) {
|
|
state.searchHeader = val
|
|
},
|
|
update_searchDetail(state, val) {
|
|
state.searchDetail = val
|
|
},
|
|
update_loading(state, val) {
|
|
state.loading = val
|
|
},
|
|
update_page(state, val) {
|
|
state.page = val
|
|
},
|
|
update_totalPageHeader(state, val) {
|
|
state.totalPageHeader = val
|
|
},
|
|
update_pageDetail(state, val) {
|
|
state.pageDetail = val
|
|
},
|
|
update_totalPageDetail(state, val) {
|
|
state.totalPageDetail = val
|
|
},
|
|
update_errorMsg(state, val) {
|
|
state.errorMsg = val
|
|
},
|
|
update_snackbarSuccess(state, val) {
|
|
state.snackbarSuccess = val
|
|
},
|
|
update_snackbarError(state, val) {
|
|
state.snackbarError = val
|
|
},
|
|
update_successMsg(state, val) {
|
|
state.successMsg = val
|
|
},
|
|
update_selectedSetup(state, val) {
|
|
state.selectedSetup = val
|
|
},
|
|
update_setupList(state, val) {
|
|
state.setupList = val
|
|
},
|
|
update_kelainanList(state, val) {
|
|
state.kelainanList = val
|
|
},
|
|
},
|
|
actions: {
|
|
async searchSetup(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
page: context.state.page,
|
|
search: context.state.searchHeader
|
|
}
|
|
let resp = await api.search(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_setupList", resp.data.records)
|
|
if (resp.data.records.length > 0 && context.state.selectedSetup.Mgm_McuID === "0") {
|
|
context.commit("update_selectedSetup", resp.data.records[0])
|
|
context.dispatch("searchDetail")
|
|
// this.$store.dispatch("price/searchpricetest");
|
|
|
|
} else if (resp.data.records.length > 0 && context.state.selectedSetup.Mgm_McuID !== "0") {
|
|
for (let i = 0; i < resp.data.records.length; i++) {
|
|
const e = resp.data.records[i];
|
|
if (e.headerID === context.state.selectedSetup.Mgm_McuID) {
|
|
context.commit("update_selectedSetup", e)
|
|
}
|
|
|
|
}
|
|
}
|
|
context.commit("update_totalPageHeader", resp.data.total)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
}
|
|
},
|
|
async searchDetail(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
setupid: context.state.selectedSetup.Mgm_McuID,
|
|
page: context.state.pageDetail,
|
|
search: context.state.searchDetail
|
|
}
|
|
let resp = await api.getdetail(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
let data = {
|
|
records: resp.data.records,
|
|
total: resp.data.total
|
|
}
|
|
context.commit("update_kelainanList", resp.data.records)
|
|
|
|
context.commit("update_totalPageDetail", resp.data.total)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", false)
|
|
|
|
}
|
|
},
|
|
async addKelainanGroup(context, data) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
setup: context.state.selectedSetup,
|
|
data: data,
|
|
}
|
|
let resp = await api.save(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", true)
|
|
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_successMsg", 'Berhasil ubah data')
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_loading", false)
|
|
context.dispatch("searchDetail")
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
context.commit("update_snackbarError", true)
|
|
}
|
|
},
|
|
async insertPriceHeader(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
name: context.state.nameHeader,
|
|
sd: context.state.startDateHeader,
|
|
ed: context.state.endDateHeader
|
|
}
|
|
let resp = await api.insertheader(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarError", true)
|
|
context.commit("update_errorMsg", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_successMsg", 'Berhasil Membuat Harga ' + context.state.nameHeader)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_dialogPriceHeader", false)
|
|
context.commit("update_nameHeader", '')
|
|
context.dispatch("searchPriceHeader")
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarError", true)
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
async editPriceHeader(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
id: context.state.selectedPriceHeader.headerID,
|
|
token: one_token(),
|
|
name: context.state.nameHeader,
|
|
sd: context.state.startDateHeader,
|
|
ed: context.state.endDateHeader
|
|
}
|
|
let resp = await api.editheader(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarError", true)
|
|
context.commit("update_errorMsg", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_successMsg", 'Berhasil Edit Harga ' + context.state.nameHeader)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_dialogPriceHeader", false)
|
|
context.commit("update_nameHeader", '')
|
|
context.dispatch("searchPriceHeader")
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarError", true)
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
async deletePriceHeader(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
id: context.state.selectedPriceHeader.headerID,
|
|
token: one_token(),
|
|
}
|
|
let resp = await api.deleteheader(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarError", true)
|
|
context.commit("update_errorMsg", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_successMsg", 'Berhasil Hapus Harga ' + context.state.nameHeader)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarSuccess", true)
|
|
context.commit("update_dialogDeleteHeader", false)
|
|
context.commit("update_nameHeader", '')
|
|
context.dispatch("searchPriceHeader")
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarError", true)
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
async getpricefilter(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
}
|
|
let resp = await api.getfilterprice(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
|
|
|
|
context.commit("update_filterStatus", resp.data.status)
|
|
context.commit("update_filterSubGroup", resp.data.subgroup)
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
async searchpricetest(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
search: context.state.filterName,
|
|
subgroup: context.state.selectedFilterSubGroup.id,
|
|
status: context.state.selectedFilterStatus.id,
|
|
headerid: context.state.selectedPriceHeader.headerID,
|
|
page: context.state.priceTestPage,
|
|
}
|
|
let resp = await api.searchpricetest(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
context.commit("update_priceTestList", resp.data.records)
|
|
context.commit("update_priceTestPageTotal", resp.data.total)
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
async savetest(context, prm) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
prm.token = one_token();
|
|
prm.headerid = context.state.selectedPriceHeader.headerID
|
|
|
|
let resp = await api.savetest(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_snackbarError", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_successMsg", 'Berhasil simpan harga')
|
|
context.commit("update_snackbarSuccess", false)
|
|
context.commit("update_loading", false)
|
|
context.dispatch("searchpricetest");
|
|
context.dispatch("searchPriceHeader");
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
async copyharga(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
headerid: context.state.selectedPriceHeaderCopy.headerID,
|
|
name: context.state.nameHeader,
|
|
copypacket: context.state.copyPacket
|
|
}
|
|
|
|
let resp = await api.copyharga(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
context.commit("update_snackbarError", false)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_loading", false)
|
|
context.commit("update_successMsg", 'Berhasil copy harga')
|
|
context.commit("update_snackbarSuccess", false)
|
|
context.dispatch("searchPriceHeader");
|
|
context.commit("update_dialogCopyHarga", false)
|
|
context.commit("update_nameHeader", '')
|
|
context.commit("update_selectedPriceHeaderCopy", {})
|
|
context.commit("update_copyPacket", false)
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
async validateheader(context) {
|
|
context.commit("update_lookup_status", 1)
|
|
context.commit("update_loading", true)
|
|
try {
|
|
let prm = {
|
|
token: one_token(),
|
|
id: context.state.selectedPriceHeader.headerID,
|
|
}
|
|
|
|
let resp = await api.validateheader(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_successMsg", 'Berhasil validasi price header')
|
|
context.commit("update_snackbarSuccess", false)
|
|
|
|
context.commit("update_loading", false)
|
|
context.commit("update_dialogValidasi", false)
|
|
context.dispatch("searchPriceHeader");
|
|
context.dispatch("searchpricetest");
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
context.commit("update_loading", false)
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
async searchPriceHeaderAutocomplete(context, prm) {
|
|
context.commit("update_lookup_status", 1)
|
|
try {
|
|
prm.token = one_token();
|
|
prm.headerid = context.state.selectedPriceHeader.headerID
|
|
|
|
let resp = await api.searchpricetestautocomplete(prm)
|
|
if (resp.status != "OK") {
|
|
context.commit("update_lookup_status", 3)
|
|
|
|
context.commit("update_errorMsg", resp.message)
|
|
} else {
|
|
context.commit("update_lookup_status", 2)
|
|
context.commit("update_errorMsg", '')
|
|
context.commit("update_priceHeaderCopyList", resp.data.records)
|
|
|
|
}
|
|
} catch (e) {
|
|
console.log(e)
|
|
context.commit("update_lookup_status", 3)
|
|
|
|
context.commit("update_errorMsg", e)
|
|
}
|
|
},
|
|
}
|
|
}
|