import { createStore } from "vuex"; import api from "apis/fetch.js"; import _ from "lodash"; const store = createStore({ state: { isLogin: false, currentTabText: "运输安全管理中心", cargoOwnerInfo: { cargoOwnerName: "", contractId: 1, data: [ { title: "货种", text: "", icon: "cargo", }, { title: "吨位", text: "", unit: "吨", icon: "ship", }, { title: "航线", text: "", icon: "hangxian", }, ], }, shipInfo: { shipOwnerName: "", shipOwnerId: "", shipName: "", icon: "china", mmsi: "", length: 0, width: 0, imgs: [], data: [ { title: "MMSI", text: "", icon: "ship-fill", }, { title: "船长", text: "", unit: "米", icon: "ship-length", }, { title: "船宽", text: "", unit: "米", icon: "ship-width", }, ], }, damInfo: { data: [ { title: "上游前往三峡数量", text: "0", unit: "艘", icon: "ship-fill", }, { title: "三峡等闸船舶数量", text: "0", unit: "艘", icon: "dam", }, { title: "预计等待时间", text: "0", unit: "分", icon: "clock", }, ], }, capacity: { id: 1, shipownerName: "", shipownerCompany: "", cargoowner: "", shipStatus: 0, }, numbers: [], }, mutations: { changeLogin(state, b) { state.isLogin = b; }, changeTab(state, text) { state.currentTabText = text; }, setNumbers(state, numbers) { state.numbers = numbers; }, setDamInfo(state, nums) { state.damInfo.data[0].text = nums.upstreamShipNum; state.damInfo.data[1].text = nums.waitingShipNum; state.damInfo.data[2].text = nums.estimatedWaitingTime; }, setManageShipDetail(state, data) { let { cargoownerDetail, capacityDetail, shipDetail } = data; state.cargoOwnerInfo.cargoOwnerName = cargoownerDetail.cargoowner; state.cargoOwnerInfo.data[0].text = cargoownerDetail.cargo; state.cargoOwnerInfo.data[1].text = cargoownerDetail.tons; state.cargoOwnerInfo.data[2].text = cargoownerDetail.loadPort + " - " + cargoownerDetail.dischargePort; state.shipInfo.shipName = shipDetail.shipName; state.shipInfo.imgs = shipDetail.exhibitImgs; state.shipInfo.shipOwnerName = shipDetail.shipownerName; state.shipInfo.shipOwnerId = shipDetail.shipownerIdcard; state.shipInfo.data[0].text = shipDetail.shipMmsi; state.shipInfo.data[1].text = shipDetail.shipLength; state.shipInfo.data[2].text = shipDetail.shipBreadth; state.capacity = capacityDetail; }, setTradeShipDetail(state, data) { state.shipInfo.shipName = data.shipName; state.shipInfo.shipOwnerName = data.shipownerName; state.shipInfo.shipOwnerId = data.shipownerIdcard; state.shipInfo.data[0].text = data.shipMmsi; state.shipInfo.data[1].text = data.shipLength; state.shipInfo.data[2].text = data.shipBreadth; }, }, actions: { Login({ commit }, userInfo) { return new Promise((resolve, reject) => { localStorage.setItem("id", 1); commit("changeLogin", true); resolve(1); }); }, LogOut({ commit }) { return new Promise((resolve, reject) => { commit("changeLogin", false); localStorage.removeItem("id"); resolve(0); }); }, GetSanxiaInfo({ commit }) { api.getSanxiaInfo().then((e) => { commit("setDamInfo", e.data.result); }); }, GetNumbers({ commit, state }) { let t = state.currentTabText == "运输安全管理中心"; if (t) { api.getShipStatusCount().then((e) => { let { result } = e.data; state.numbers = [ { icon: "loading", title: "装货中船舶数量", num: result.loadingShipCount, }, { icon: "transit", title: "运输中船舶数量", num: result.transitShipCount, }, { icon: "unloading", title: "卸货中船舶数量", num: result.unloadingShipCount, }, ]; }); } else { api.getShipTracksCount().then((e) => { let { result } = e.data; state.numbers = [ { icon: "ship-fill-2", title: "船舶数量", num: result.shipNum }, { icon: "ship-line", title: "轨迹数量", num: result.trackNum }, ]; }); } }, GetManageShipDetail({ commit }, shipId) { api.getManageShipDetail({ shipId }).then((e) => { commit("setManageShipDetail", e.data.result); }); }, GetTradeShipDetail({ commit }, shipId) { api.getTradeShipDetail({ shipId }).then((e) => { commit("setTradeShipDetail", e.data.result); }); }, }, }); export default store;