import { ACTION_GO_SCAN } from '../../const/actioncmd'



Page({
  data: {
    storeName:"--",
  },
  onLoad() {
    my.ix.onBuddyMessage({
      success: (res) => {
        console.info(`onBuddyMessage success: ${JSON.stringify(res)}`);
        
        
        // if (res.action == ACTION_PRINT_RESULT) {
        //   //获取到打印结果
        //   var printResult = res.data;
        // } else if (res.action == ACTION_GOODS) {
        //   //商品信息同步
        //   my.hideLoading();
        //   let viewGoodsInfo = res.data
        //   if (viewGoodsInfo.goods != null && viewGoodsInfo.goods.length > 0) {
        //     context.setData({
        //       goods: viewGoodsInfo.goods,
        //       totalPrice: viewGoodsInfo.totalPrice,
        //       totalQuantity: viewGoodsInfo.totalQuantity,
        //       totalDisc: viewGoodsInfo.totalDisc,
        //     })
        //   }
        // } else {
        //   //未知指令
        // }
      }
    });

  },

  onHide(){
    my.ix.offBuddyMessage();
  },

  collections(){
    //发送跳转到收银页面的命令
    var commonRequest = {
        action:ACTION_GO_SCAN,
        data:this.data
    };
    my.ix.sendBuddyMessage({
      target: getApp().globalData.frontScreenAppId,
      data: commonRequest,
      success: (res) => {
        console.log("发送商品数据到前屏小程序成功 ===》" + JSON.stringify(res));
      },
      fail: (res) => {
        // console.log("发送商品数据到前屏小程序 失败 ===》 " + JSON.stringify(res));
        // //发送失败重试
        // context.sendGoodInfoToFront();
      }
    });
  },


});
