import { cancelOrder } from '../../utils/service';
import { toast } from "../../../../../core/utils";
Component({
  props: {
    showStatus: true,
    detail: {},
    onRefresh: () => {}
  },
  methods: {
    // 取消预约
    cancelOrder() {
      const {
        detail
      } = this.props;
      let statusStr = '';

      if (detail.status === 0) {
        statusStr = '待支付';
      } else if (detail.status === 1) {
        statusStr = '已支付';
      } else if (detail.status === 2) {
        statusStr = '已取消';
      }

      my.prompt({
        title: '取消预约',
        message: `当前状态为: ${statusStr}`,
        placeholder: '请输入取消原因',
        okButtonText: '确定',
        cancelButtonText: '取消',
        success: result => {
          if (result.ok) {
            this.cancleConfirm(result);
          }
        }
      });
    },

    async cancleConfirm(msg) {
      const params = {
        orderId: this.props.detail.orderId,
        reason: msg.inputValue
      };
      const [err] = await cancelOrder(params);

      if (!err) {
        toast('预约取消成功');
        getApp().globalData.cancelReservation = true;
        this.props.onRefresh(params.orderId);
      }
    }

  }
});