| | |
| | | package com.sinata.xqmuse.ui.course |
| | | |
| | | import android.view.View |
| | | import androidx.core.os.bundleOf |
| | | import cn.sinata.xldutils.gone |
| | | import cn.sinata.xldutils.utils.SpanBuilder |
| | | import cn.sinata.xldutils.utils.isValidPhone |
| | | import cn.sinata.xldutils.utils.showAllowingStateLoss |
| | | import cn.sinata.xldutils.visible |
| | | import com.share.utils.ShareUtils |
| | | import com.sinata.xqmuse.R |
| | | import com.sinata.xqmuse.dialog.BuyRuleDialog |
| | | import com.sinata.xqmuse.dialog.ShareDialog |
| | | import com.sinata.xqmuse.dialog.TipDialog |
| | | import com.sinata.xqmuse.network.Apis |
| | | import com.sinata.xqmuse.network.HttpManager |
| | | import com.sinata.xqmuse.network.entity.ConfirmOrder |
| | | import com.sinata.xqmuse.network.request |
| | |
| | | import com.sinata.xqmuse.utils.extention.clickDelay |
| | | import com.sinata.xqmuse.utils.interfaces.StringCallback |
| | | import com.sinata.xqmuse.utils.pay.PayListener |
| | | import com.umeng.socialize.bean.SHARE_MEDIA |
| | | import kotlinx.android.synthetic.main.activity_buy_course.* |
| | | import org.jetbrains.anko.startActivity |
| | | import org.jetbrains.anko.toast |
| | |
| | | if (!phone.isValidPhone()){ |
| | | toast("手机号输入有误") |
| | | }else{ |
| | | HttpManager.getUserByPhone(phone).request(this){_,data-> |
| | | HttpManager.getUserByPhone(phone).request(this,false,{_,data-> |
| | | cl_empty.gone() |
| | | receiveId = data?.id |
| | | iv_avatar.setImageURI(data?.avatar) |
| | | tv_name.text = data?.nickname |
| | | tv_phone.text = data?.cellPhone |
| | | }){_,msg-> |
| | | if (msg == "未查询到账户信息"){ |
| | | receiveId = null |
| | | iv_avatar.setImageURI("") |
| | | tv_name.text = "" |
| | | tv_phone.text = "" |
| | | cl_empty.visible() |
| | | }else |
| | | toast(msg) |
| | | } |
| | | } |
| | | } |
| | | |
| | | tv_invite.setOnClickListener { |
| | | val shareDialog = ShareDialog() |
| | | shareDialog.callback = object :StringCallback{ |
| | | override fun onResult(rst: String) { |
| | | if (rst == "wx"){ |
| | | ShareUtils.share(this@BuyCourseActivity, |
| | | SHARE_MEDIA.WEIXIN,tv_title.text.toString(),"赠送你一个课程,快来注册领取吧", |
| | | Apis.SHARE_REGISTER,null,"") |
| | | }else{ |
| | | ShareUtils.share(this@BuyCourseActivity, |
| | | SHARE_MEDIA.WEIXIN_CIRCLE,tv_title.text.toString(),"赠送你一个课程,快来注册领取吧", |
| | | Apis.SHARE_REGISTER,null,"") |
| | | } |
| | | } |
| | | } |
| | | shareDialog.showAllowingStateLoss(supportFragmentManager,"share") |
| | | } |
| | | |
| | | tv_buy_rule.clickDelay { |
| | |
| | | |
| | | tv_action.setOnClickListener { |
| | | if (cb_rule.isChecked){ |
| | | if (rb_ali.isChecked){ |
| | | if (isSend&&receiveId.isNullOrEmpty()){ |
| | | toast("赠送好友不能为空") |
| | | return@setOnClickListener |
| | | } |
| | | if (rb_balance.isChecked&&((data?.balance?:"0.0").toDouble()>=(data?.generalPrice?:"0.0").toDouble())){//余额勾选,并且可用余额大于课程价格,直接扣余额 |
| | | payBalance() |
| | | }else if (rb_ali.isChecked){ |
| | | pay(2) |
| | | }else if (rb_wx.isChecked){ |
| | | pay(1) |
| | | } else if (rb_balance.isChecked&&((data?.balance?:"0.0").toDouble()>(data?.generalPrice?:"0.0").toDouble())){ |
| | | payBalance() |
| | | }else{ |
| | | |
| | | toast("请选择支付方式") |
| | | } |
| | | }else |
| | | toast("请阅读并同意《购买协议》") |
| | |
| | | private fun pay(way:Int) { |
| | | tv_action.isEnabled = false |
| | | showDialog() |
| | | HttpManager.placeOrder(2,way,2,null,receiveId,data?.id?:"",null).request(this,success = {_,data-> |
| | | HttpManager.placeOrder(2,way,if (rb_balance.isChecked) 1 else 2,null,receiveId,data?.id?:"",null).request(this,success = {_,data-> |
| | | onPaySuccess() |
| | | |
| | | }){_,_-> |
| | | tv_action.isEnabled = true |
| | | } |
| | |
| | | cl_send.visible() |
| | | } |
| | | data?.apply { |
| | | if (!orderId.isNullOrEmpty()){ |
| | | titleBar.addRightButton("取消订单",onClickListener = View.OnClickListener { |
| | | TipDialog.show(supportFragmentManager,"是否确认取消该订单?",object :TipDialog.OnClickCallback{ |
| | | override fun onOk() { |
| | | HttpManager.cancel(orderId).request(this@BuyCourseActivity){_,_-> |
| | | toast("取消成功") |
| | | setResult(RESULT_OK) |
| | | finish() |
| | | } |
| | | } |
| | | |
| | | override fun onCancel() { |
| | | } |
| | | }) |
| | | }) |
| | | } |
| | | if (generalPrice.isNullOrEmpty()){ |
| | | generalPrice = if (amount.isNullOrEmpty()) "0.0" else amount |
| | | } |
| | | iv_cover.setImageURI(coverUrl) |
| | | tv_title.text = courseTitle |
| | | tv_title.text = courseTitle?:title |
| | | tv_teacher.text = "导师 $tutor" |
| | | tv_price.text = SpanBuilder("¥$generalPrice").size(0,1,11).build() |
| | | tv_money.text = SpanBuilder("¥$generalPrice").size(0,1,11).build() |
| | | tv_price.text = SpanBuilder("¥${generalPrice}").size(0,1,11).build() |
| | | tv_money.text = SpanBuilder("¥${generalPrice}").size(0,1,11).build() |
| | | tv_total.text = generalPrice |
| | | val s = "余额抵扣 当前可用 ¥$balance" |
| | | rb_balance.text = SpanBuilder(s).size(4,s.length,11).color(this@BuyCourseActivity,4,s.length,R.color.textColor99).build() |