import { compareData } from "../components-control/util/dataChange.js";
export default {
  execute(bill, param) {
    // 首张、上张、下张、末张
    let flag =
    GMS.queryObject && GMS.queryObject.isReadOnly
      ? true
      : compareData(GMS.oldBillData, bill.getBuillData());
      if (flag) {
        if (Object.keys(param.param).length > 0) {
          this.getOtherPage(Object.keys(param.param)[0]);
        }
      } else {
        GMS.$hideContainer.$Modal.confirm({
          title: "信息提示",
          content: "信息发生变化，确认切换？",
          onOk: () => {
            if (Object.keys(param.param).length > 0) {
              this.getOtherPage(Object.keys(param.param)[0]);
            }
          },
          onCancel: () => {
            GMS.$hideContainer.$Message["info"]({
              content: "已取消",
            });
          },
        });
      }
  },
  async getOtherPage(action) {
    let page = GMS.queryObject.currentDataQueryConditionSet.page;
    let index =
      GMS.queryObject.index == -1
        ? GMS.queryObject.index
        : (page.pageNum - 1) * page.size + GMS.queryObject.index;
    const url = `/rbc/bill/move/${action.toUpperCase()}/${index}`;
    const { data } = await window.GMS.$http.post(
      url,
      GMS.queryObject.currentDataQueryConditionSet
    );
    if (data) {
      console.log(data.data.id);
      if (data.data && data.data.id) {
        if (action == "down") {
          GMS.queryObject.index++;
        } else if (action == "upward") {
          GMS.queryObject.index--;
        } else if (action == "first") {
          GMS.queryObject.index = 0;
        } else if (action == "last") {
          GMS.queryObject.index = data.data.count - 1;
        }
        if (
          window.osConfig.appOpenMode &&
          window.osConfig.appOpenMode == "apploader"
        ) {
          GMS.$hideContainer.$portalAPI.emit("resetBillData", data.data.id);
        } else {
          GMS.vbus.$emit("resetBillData", data.data.id);
        }
      }
      if (data.data && data.data.message) {
        GMS.vbus.$Message.info(data.data.message);
      }
    }
  },
};
