import { ACTION_PRINT_RESULT } from '../../const/actioncmd'
import { ACTION_REPRINT } from '../../const/actioncmd'

Page({
  data: {
    payFailedReason: "xxxxxxxxxxx",
    isPaySuccess: true,
    payPriceYuan: "--.--",
    printResult: "正在打印小票...",
    isPrinting: false,
    isPrintSuccess: false,
  },
  onLoad() { },

  onShow() {
    //开启后屏监听
    my.ix.onBuddyMessage({
      success: (res) => {
        console.info(`onBuddyMessage success: ${JSON.stringify(res)}`);
        if (res.action == ACTION_PRINT_RESULT) {
          //获取到打印结果
          var printResult = res.data;
        } else {
          //未知指令
        }
      }
    });
  },

  onReprint() {
    //通知前屏重新打印
    my.ix.sendBuddyMessage({
      // 填入目标小程序的 AppID
      target: "****************",
      data: {
        action: ACTION_REPRINT,
        data: null
      },
      success: (res) => {
        console.info(`sendBuddyMessage success: ${JSON.stringify(res)}`);
      },
      fail: (res) => {
        console.info(`sendBuddyMessage failed: ${JSON.stringify(res)}`);
      }
    });
  },

  onHide() {
    //关闭后屏监听
    my.ix.offBuddyMessage();
  }
});
