;(function () {
  function _toConsumableArray(arr) {
    return (
      _arrayWithoutHoles(arr) ||
      _iterableToArray(arr) ||
      _unsupportedIterableToArray(arr) ||
      _nonIterableSpread()
    )
  }
  function _nonIterableSpread() {
    throw new TypeError(
      'Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.'
    )
  }
  function _unsupportedIterableToArray(o, minLen) {
    if (!o) return
    if (typeof o === 'string') return _arrayLikeToArray(o, minLen)
    var n = Object.prototype.toString.call(o).slice(8, -1)
    if (n === 'Object' && o.constructor) n = o.constructor.name
    if (n === 'Map' || n === 'Set') return Array.from(o)
    if (n === 'Arguments' || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
      return _arrayLikeToArray(o, minLen)
  }
  function _iterableToArray(iter) {
    if (
      (typeof Symbol !== 'undefined' && iter[Symbol.iterator] != null) ||
      iter['@@iterator'] != null
    )
      return Array.from(iter)
  }
  function _arrayWithoutHoles(arr) {
    if (Array.isArray(arr)) return _arrayLikeToArray(arr)
  }
  function _arrayLikeToArray(arr, len) {
    if (len == null || len > arr.length) len = arr.length
    for (var i = 0, arr2 = new Array(len); i < len; i++) {
      arr2[i] = arr[i]
    }
    return arr2
  }
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
    try {
      var info = gen[key](arg)
      var value = info.value
    } catch (error) {
      reject(error)
      return
    }
    if (info.done) {
      resolve(value)
    } else {
      Promise.resolve(value).then(_next, _throw)
    }
  }
  function _asyncToGenerator(fn) {
    return function () {
      var self = this,
        args = arguments
      return new Promise(function (resolve, reject) {
        var gen = fn.apply(self, args)
        function _next(value) {
          asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'next', value)
        }
        function _throw(err) {
          asyncGeneratorStep(gen, resolve, reject, _next, _throw, 'throw', err)
        }
        _next(undefined)
      })
    }
  }
  var __vite_style__ = document.createElement('style')
  __vite_style__.innerHTML =
    '._useCoupon_dzp2v_1{padding-top:.42667rem;padding-bottom:.42667rem}._useCoupon_dzp2v_1 ._couponCount_dzp2v_5{color:#ff3535;font-size:.42667rem;font-weight:600}._useCoupon_dzp2v_1 ._couponCount_dzp2v_5 i{font-style:normal;font-size:.37333rem}._choiceCoupon_dzp2v_14{display:flex;flex-direction:column;overflow:hidden;height:100%}._couponTitle_dzp2v_20{display:flex;align-items:center;justify-content:space-between;flex-shrink:0;padding:0 .45333rem;height:1.6rem;line-height:1.6rem;font-size:.48rem;font-weight:600;color:#1a1a1a}._couponTitle_dzp2v_20 ._iconClose_dzp2v_32{display:inline-block;width:.64rem;height:.64rem;background:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAMAAABg3Am1AAAAAXNSR0IArs4c6QAAAG9QTFRFAAAAzMzM8fHx8/Pz6+vr8fHx6urq7Ozs6urq6+vr7Ozs6+vr6+vr6+vr6+vr7Ozs6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr6+vr7OzsZmZma2trbGxsgYGBj4+PysrKy8vLzMzMz8/P39/f6+vrszxq/gAAABp0Uk5TAAUSFhkkJVBXZmt1jY+2yM7b6/Hz9Pj8/v60zef/AAABRUlEQVRIx61W2baCMAyMIIvsm6ChgGD+/xvvA4gta+O580TITE+bpEkBljDdMEqzsszSKHRNOIHhxQ+S8Ig944B+De60wj247tAvfkGbKPzLFt9KaBeJteY7OR0gd5b8W0WHqG4L/pNO8FQUTkWnqKRd2TlpILfneCakheQTXZ804U/5LXQFxZjzgLQRAAAYcv28W9EMX3NoRPuW68oAAE9eokXEuvtYXY2Irez3ACCWfwhERPEajddoyf4YwFTqv8GvYuRjo9wPE1zlVEM9KyZ+PSgEF0I1Dt1IE30/fXSqP4RoEblpYSFQPs6MCFLaVmzzKYWM9hVrPmVQrvM5bR9Fv/aVfAF7S+xDs8PKThy7NNjFxy5v/gViX1F2E+C3GXYj47dK3WZs/d7u+QOFP7L4QxHAPhq79n8Mdv7T4YfHic7z5w+yIe8epvSUygAAAABJRU5ErkJggg==) no-repeat center;background-size:contain}._couponContent_dzp2v_39{flex:1 auto;overflow-y:auto;-webkit-overflow-scrolling:touch;padding:.32rem .37333rem;--coupon-point: #fff}._couponFooter_dzp2v_46{display:flex;align-items:center;justify-content:space-between;line-height:1.49333rem;padding:0 .42667rem}._couponFooter_dzp2v_46 ._couponSelectText_dzp2v_53{font-size:.42667rem;color:#1a1a1a}._couponFooter_dzp2v_46 ._couponSelectText_dzp2v_53 span{padding:0 .24rem;font-weight:600;color:#fc1a19}\n'
  document.head.appendChild(__vite_style__)
  System.register(
    [
      './index-legacy.595c24c3.js',
      './vendor-legacy.09f20d09.js',
      './index-legacy.f25f109a.js',
      './item-legacy.bddec109.js'
    ],
    function (exports) {
      'use strict'
      var ColResult,
        request,
        state,
        defineComponent,
        createVNode,
        createTextVNode,
        Fragment,
        Loading,
        Button,
        Cell,
        Popup,
        Item
      return {
        setters: [
          function (module) {
            ColResult = module.C
            request = module.r
            state = module.s
          },
          function (module) {
            defineComponent = module.d
            createVNode = module.a
            createTextVNode = module.j
            Fragment = module.F
            Loading = module.L
            Button = module.B
            Cell = module.C
            Popup = module.P
          },
          function () {},
          function (module) {
            Item = module.I
          }
        ],
        execute: function execute() {
          var useCoupon = '_useCoupon_dzp2v_1'
          var couponCount = '_couponCount_dzp2v_5'
          var choiceCoupon = '_choiceCoupon_dzp2v_14'
          var couponTitle = '_couponTitle_dzp2v_20'
          var iconClose = '_iconClose_dzp2v_32'
          var couponContent = '_couponContent_dzp2v_39'
          var couponFooter = '_couponFooter_dzp2v_46'
          var couponSelectText = '_couponSelectText_dzp2v_53'
          var styles = {
            useCoupon: useCoupon,
            couponCount: couponCount,
            choiceCoupon: choiceCoupon,
            couponTitle: couponTitle,
            iconClose: iconClose,
            couponContent: couponContent,
            couponFooter: couponFooter,
            couponSelectText: couponSelectText
          }
          var ChoiceCoupon = defineComponent({
            name: 'choice-coupon',
            props: {
              orderAmount: { type: Number, default: 0 },
              useCoupon: {
                type: Array,
                default: function _default() {
                  return []
                }
              },
              couponCategory: { type: String, default: 'UNIVERSAL' },
              couponList: {
                type: Array,
                default: function _default() {
                  return []
                }
              }
            },
            emits: ['close', 'submit'],
            data: function data() {
              return {
                list: [], // consumeAmount: 0 // 消耗金额
                dataLoading: false
              }
            },
            computed: {
              // 使用优惠券的数量
              useLength: function useLength() {
                return (
                  this.list.filter(function (list) {
                    return list.checked
                  }).length || 0
                )
              }
            },
            mounted: function mounted() {
              var _this = this
              return _asyncToGenerator(
                /*#__PURE__*/ regeneratorRuntime.mark(function _callee() {
                  var canUsable, canUsed
                  return regeneratorRuntime.wrap(function _callee$(_context) {
                    while (1) {
                      switch ((_context.prev = _context.next)) {
                        case 0: // this.getList()
                          // 处理显示已选择的优惠券
                          // 处理可用优惠券是否支付使用
                          _this.couponList.forEach(function (item) {
                            _this.useCoupon.forEach(function (coupon) {
                              if (item.couponIssueId === coupon.couponIssueId) {
                                item.checked = true
                              }
                            })
                          })
                          canUsable = _this.couponList.filter(function (list) {
                            return !list.disabled
                          })
                          canUsed = _this.couponList.filter(function (list) {
                            return list.disabled
                          })
                          _this.list = [].concat(
                            _toConsumableArray(canUsable),
                            _toConsumableArray(canUsed)
                          )
                          _this.calcCoupon()
                        case 5:
                        case 'end':
                          return _context.stop()
                      }
                    }
                  }, _callee)
                })
              )()
            },
            methods: {
              // async getList() {
              //   if (this.dataLoading) return
              //   this.dataLoading = true
              //   try {
              //     const res = await request.post(`${state.platformApi}/couponInfo/page`, {
              //       data: {
              //         couponCategory: this.couponCategory,
              //         couponType: 'FULL_DISCOUNT',
              //         useState: 'USABLE',
              //         page: 1,
              //         rows: 100
              //       }
              //     })
              //     this.dataLoading = false
              //     const result = res.data || {}
              //     // 处理重复请求数据
              //     if (this.list.length > 0 && result.pageNo === 1) return
              //     this.list = result.rows || []
              //     // 处理可用优惠券是否支付使用
              //     this.list.forEach((item: any) => {
              //       item.checked = false
              //       // 如果使用金额大于订单金额则优惠券不可用
              //       if (item.useLimit > this.orderAmount) {
              //         item.disabled = true
              //       } else {
              //         item.disabled = false
              //       }
              //       // 处理显示已选择的优惠券
              //       this.useCoupon.forEach((coupon: any) => {
              //         if (item.couponIssueId === coupon.couponIssueId) {
              //           item.checked = true
              //         }
              //       })
              //     })
              //     // 初始化排序
              //     const canUsable = this.list.filter((list: any) => !list.disabled)
              //     const canUsed = this.list.filter((list: any) => list.disabled)
              //     this.list = [...canUsable, ...canUsed]
              //     this.calcCoupon()
              //   } catch {
              //     //
              //   }
              // },
              onSubmit: function onSubmit() {
                // 返回选中的优惠券
                this.$emit(
                  'submit',
                  this.list.filter(function (list) {
                    return list.checked
                  })
                )
                this.list.forEach(function (item) {
                  item.checked = false
                })
              },
              onSelect: function onSelect(item) {
                item.checked = !item.checked
                this.calcCoupon()
              },
              calcCoupon: function calcCoupon() {
                // 计算优惠券
                // 已使用的优惠券
                var useList = this.list.filter(function (list) {
                  return list.checked
                })
                var limitCount = useList.map(function (list) {
                  return Number(list.useLimit || 0)
                })
                var usePrice =
                  limitCount.length > 0
                    ? limitCount.reduce(function (sum, list) {
                        return sum + list
                      })
                    : 0 // 使用优惠券后，可判断的金额
                var useLastAmount = this.orderAmount - usePrice // 判断使用优惠券之后还有没有其它优惠券可用
                this.list.forEach(function (item) {
                  if (Number(item.useLimit) > useLastAmount && !item.checked) {
                    item.disabled = true
                  } else {
                    item.disabled = false
                  }
                })
              }
            },
            render: function render() {
              var _this2 = this
              return createVNode('div', { class: styles.choiceCoupon }, [
                createVNode('div', { class: styles.couponTitle }, [
                  createVNode('span', null, [
                    createTextVNode('\u4F18\u60E0\u5238')
                  ]),
                  createVNode(
                    'i',
                    {
                      class: styles.iconClose,
                      onClick: function onClick() {
                        return _this2.$emit('close')
                      }
                    },
                    null
                  )
                ]),
                createVNode('div', { class: styles.couponContent }, [
                  !this.dataLoading
                    ? createVNode(Fragment, null, [
                        this.list.length > 0
                          ? createVNode(Fragment, null, [
                              this.list.map(function (item) {
                                return createVNode(
                                  Item,
                                  {
                                    item: item,
                                    isSelect: true,
                                    onClick: _this2.onSelect
                                  },
                                  null
                                )
                              })
                            ])
                          : createVNode(
                              ColResult,
                              {
                                btnStatus: false,
                                tips: '暂无优惠券',
                                classImgSize: 'SMALL'
                              },
                              null
                            )
                      ])
                    : createVNode(
                        Loading,
                        {
                          size: 48,
                          color: '#01C1B5',
                          vertical: true,
                          style: { height: '100%', justifyContent: 'center' }
                        },
                        {
                          default: function _default() {
                            return [createTextVNode('\u52A0\u8F7D\u4E2D...')]
                          }
                        }
                      )
                ]),
                createVNode(
                  'div',
                  { class: [styles.couponFooter, 'van-hairline--top'] },
                  [
                    createVNode('div', { class: styles.couponSelectText }, [
                      createTextVNode('\u5DF2\u9009'),
                      createVNode('span', null, [this.useLength]),
                      createTextVNode('\u5F20')
                    ]),
                    createVNode(
                      Button,
                      {
                        type: 'primary',
                        round: true,
                        style: { minWidth: '105px', fontSize: '16px' },
                        onClick: this.onSubmit
                      },
                      {
                        default: function _default() {
                          return [createTextVNode('\u786E\u5B9A')]
                        }
                      }
                    )
                  ]
                )
              ])
            }
          })
          /*
           * 订单类型对应优惠券类型
           */ var couponEnum = {
            UNIVERSAL: 'UNIVERSAL',
            VIP: 'VIP',
            PINAO_ROOM: 'PIANO',
            GOODS: 'MALL',
            MUSIC: 'MUSIC',
            PRACTICE: 'SPARRING',
            LIVE: 'LIVE',
            VIDEO: 'VIDEO'
          }
          var UseCoupons = exports(
            'U',
            defineComponent({
              name: 'use-conpon',
              props: {
                disabled: { type: Boolean, default: false },
                orderAmount: { type: Number, default: 0 },
                orderType: { type: String, default: '' },
                discountPrice: {
                  // 优惠券使用金额
                  type: Number,
                  default: 0
                }
              },
              emits: ['couponSelect'],
              data: function data() {
                return {
                  popupStatus: false,
                  popupLoading: false,
                  useCouponList: [],
                  useCouponLoading: false,
                  useCouponCount: 0,
                  dataLoading: false,
                  list: []
                }
              },
              computed: {
                couponCount: function couponCount() {
                  var limitCount = this.useCouponList.map(function (list) {
                    return Number(list.discountPrice || 0)
                  })
                  var count = 0
                  if (this.disabled) {
                    count = this.discountPrice
                  } else {
                    count =
                      limitCount.length > 0
                        ? limitCount.reduce(function (sum, list) {
                            return sum + list
                          })
                        : 0
                  }
                  return count
                },
                couponCategory: function couponCategory() {
                  // 如果订单类型不在优惠券类型里面，则默认查询通用券
                  return couponEnum[this.orderType] || 'UNIVERSAL'
                }
              },
              mounted: function mounted() {
                // this.getUseableCoupon()
                this.getList()
              },
              methods: {
                getList: function getList() {
                  var _this3 = this
                  return _asyncToGenerator(
                    /*#__PURE__*/ regeneratorRuntime.mark(function _callee2() {
                      var res, result, count
                      return regeneratorRuntime.wrap(
                        function _callee2$(_context2) {
                          while (1) {
                            switch ((_context2.prev = _context2.next)) {
                              case 0:
                                if (!_this3.dataLoading) {
                                  _context2.next = 2
                                  break
                                }
                                return _context2.abrupt('return')
                              case 2:
                                _this3.dataLoading = true
                                _context2.prev = 3
                                _context2.next = 6
                                return request.post(
                                  ''.concat(
                                    state.platformApi,
                                    '/couponInfo/page'
                                  ),
                                  {
                                    data: {
                                      couponCategory: _this3.couponCategory,
                                      couponType: 'FULL_DISCOUNT',
                                      useState: 'USABLE',
                                      orderUse: 1,
                                      page: 1,
                                      rows: 100
                                    }
                                  }
                                )
                              case 6:
                                res = _context2.sent
                                _this3.dataLoading = false
                                result = res.data || {} // 处理重复请求数据
                                if (
                                  !(
                                    _this3.list.length > 0 &&
                                    result.pageNo === 1
                                  )
                                ) {
                                  _context2.next = 11
                                  break
                                }
                                return _context2.abrupt('return')
                              case 11:
                                _this3.list = result.rows || [] // 处理可用优惠券是否支付使用
                                _this3.list.forEach(function (item) {
                                  item.checked = false // 如果使用金额大于订单金额则优惠券不可用
                                  if (item.useLimit > _this3.orderAmount) {
                                    item.disabled = true
                                  } else {
                                    item.disabled = false
                                  }
                                })
                                count = 0
                                _this3.list.forEach(function (item) {
                                  if (!item.disabled) {
                                    count++
                                  }
                                })
                                console.log(_this3.list, 'list')
                                _this3.useCouponCount = count
                                _context2.next = 21
                                break
                              case 19:
                                _context2.prev = 19
                                _context2.t0 = _context2['catch'](3)
                              case 21:
                              case 'end':
                                return _context2.stop()
                            }
                          }
                        },
                        _callee2,
                        null,
                        [[3, 19]]
                      )
                    })
                  )()
                }, // async getUseableCoupon() {
                //   try {
                //     this.useCouponLoading = true
                //     // 判断是哪个端
                //     const url =
                //       state.platformType === 'STUDENT' ? '/api-student' : '/api-teacher'
                //     const res = await request.get(`${url}/couponInfo/statInfo`)
                //     this.useCouponLoading = false
                //     const result = (res.data || []).find(
                //       result => result.useState === 'USABLE'
                //     )
                //     this.useCouponCount = result.total || 0
                //   } catch {
                //     // TODO: handle
                //   }
                // },
                onSubmit: function onSubmit(item) {
                  // useCouponList
                  this.useCouponList = item
                  this.$emit('couponSelect', item)
                  this.popupStatus = false
                  this.popupLoading = false
                }
              },
              render: function render() {
                var _this4 = this
                return createVNode(Fragment, null, [
                  createVNode(
                    Cell,
                    {
                      title: '优惠券',
                      class: styles.useCoupon,
                      style: { borderRadius: '8px' },
                      isLink: !this.disabled,
                      clickable: false,
                      onClick: function onClick() {
                        if (_this4.disabled) return
                        _this4.popupStatus = true
                        _this4.popupLoading = true
                      }
                    },
                    {
                      value: function value() {
                        return (
                          !_this4.useCouponLoading &&
                          createVNode(Fragment, null, [
                            _this4.couponCount > 0
                              ? createVNode(
                                  'span',
                                  { class: styles.couponCount },
                                  [
                                    createVNode('i', null, [
                                      createTextVNode('-\uFFE5')
                                    ]),
                                    _this4.couponCount
                                  ]
                                )
                              : createVNode(Fragment, null, [
                                  _this4.useCouponCount > 0
                                    ? ''.concat(
                                        _this4.useCouponCount,
                                        '\u5F20\u53EF\u4F7F\u7528'
                                      )
                                    : '暂无可使用优惠券'
                                ])
                          ])
                        )
                      }
                    }
                  ),
                  createVNode(
                    Popup,
                    {
                      show: this.popupStatus,
                      'onUpdate:show': function onUpdateShow($event) {
                        return (_this4.popupStatus = $event)
                      },
                      position: 'bottom',
                      round: true,
                      safeAreaInsetBottom: true,
                      style: { height: '75%' },
                      onClosed: function onClosed() {
                        _this4.popupLoading = false
                      }
                    },
                    {
                      default: function _default() {
                        return [
                          _this4.popupLoading &&
                            createVNode(
                              ChoiceCoupon,
                              {
                                couponCategory: _this4.couponCategory,
                                useCoupon: _this4.useCouponList,
                                orderAmount: _this4.orderAmount,
                                couponList: _this4.list,
                                onClose: function onClose() {
                                  return (_this4.popupStatus = false)
                                },
                                onSubmit: function onSubmit(item) {
                                  return _this4.onSubmit(item)
                                }
                              },
                              null
                            )
                        ]
                      }
                    }
                  )
                ])
              }
            })
          )
        }
      }
    }
  )
})()
