package com.fuban.user.ui.trip
|
|
import android.app.Activity
|
import android.graphics.Typeface
|
import android.view.View
|
import android.widget.CheckBox
|
import androidx.core.os.bundleOf
|
import cn.sinata.xldutils.*
|
import cn.sinata.xldutils.utils.*
|
import com.fuban.user.R
|
import com.fuban.user.interfaces.StringCallback
|
import com.fuban.user.network.Apis
|
import com.fuban.user.network.HttpManager
|
import com.fuban.user.network.entity.Order
|
import com.fuban.user.network.request
|
import com.fuban.user.ui.TransparentStatusBarActivity
|
import com.fuban.user.ui.crosscity.ShuttleBusActivity
|
import com.fuban.user.dialog.PayDialog
|
import com.fuban.user.dialog.ShareDialog
|
import com.fuban.user.dialog.SpecialSuggestDialog
|
import com.fuban.user.dialog.TipDialog
|
import com.fuban.user.utils.Const
|
import com.fuban.user.utils.pay.PayListener
|
import com.fuban.user.utils.pay.PayUtil
|
import com.fuban.user.wxapi.WXPayEntryActivity
|
import com.share.utils.ShareUtils
|
import com.tencent.mm.opensdk.modelbiz.WXLaunchMiniProgram
|
import com.tencent.mm.opensdk.openapi.WXAPIFactory
|
import com.umeng.socialize.UMShareListener
|
import com.umeng.socialize.bean.SHARE_MEDIA
|
import kotlinx.android.synthetic.main.activity_order_detail.*
|
import org.jetbrains.anko.sdk27.coroutines.onClick
|
import org.jetbrains.anko.startActivity
|
|
class OrderDetailActivity : TransparentStatusBarActivity(), PayListener, UMShareListener {
|
override fun setContentView() = R.layout.activity_order_detail
|
|
private val id by lazy {
|
intent.getIntExtra("id", 0)
|
}
|
private val type by lazy {
|
intent.getIntExtra("type", 0)
|
}
|
private var order: Order? = null
|
private var payMoney = 0.0//支付费用
|
private var isGotoWx = false //是否跳转到微信小程序支付 true:回来时需要查询是否支付成功
|
|
private val mPayDialog by lazy {
|
val payDialog = PayDialog()
|
payDialog.setCallback(object : PayDialog.Callback {
|
override fun onOk(way: Int, couponId: Int) {
|
pay(way, couponId)
|
payDialog.dismiss()
|
}
|
|
override fun onClose() {
|
}
|
})
|
payDialog
|
}
|
private var score = 0
|
|
override fun initClick() {
|
iv_call.setOnClickListener {
|
callPhone(order?.driverPhone)
|
}
|
tv_action.setOnClickListener {
|
if (order?.state == 7 || order?.state == 12) {
|
mPayDialog.show(supportFragmentManager, "pay")
|
} else if (order?.state == 8) {
|
HttpManager.orderEvaluate(id, score, type, checkList.joinToString(",") { it })
|
.request(this) { _, _ ->
|
setResult(Activity.RESULT_OK)
|
myToast("评价成功")
|
tv_action.gone()
|
tv_title1.text = "评价详情"
|
getData()
|
getRedMoney()
|
}
|
}
|
}
|
rating.setOnRatingChangeListener {
|
if (!rating.clickable)
|
return@setOnRatingChangeListener
|
tv_action.visible()
|
if (it == 5f && score != 5) {
|
inputLabel(true)
|
}
|
if (it != 5f && (score == 0 || score == 5)) {
|
inputLabel(false)
|
}
|
score = it.toInt()
|
}
|
iv_header_home.setOnClickListener {
|
if (order != null)
|
startActivity<DriverDetailActivity>("id" to order!!.driverId)
|
}
|
tv_detail.onClick {
|
startActivity<PriceDetailActivity>("order" to order)
|
}
|
tv_pay_offline.onClick {
|
// val tipDialog = TipDialog()
|
// tipDialog.arguments = bundleOf("msg" to "是否确认已线下支付费用?","ok" to "确认","cancle" to "取消")
|
// tipDialog.setCallback(object :TipDialog.OnClickCallback{
|
// override fun onOk() {
|
// HttpManager.completeOrder(id,type).request(this@OrderDetailActivity){_,_->
|
// onPaySuccess()
|
// }
|
// }
|
//
|
// override fun onCancel() {
|
// }
|
// })
|
// tipDialog.show(supportFragmentManager,"offline")
|
}
|
}
|
|
override fun initView() {
|
titleBar.addRightButton("投诉司机", onClickListener = View.OnClickListener {
|
order?.driverId?.let {
|
startActivity<ComplainActivity>("id" to it)
|
}
|
})
|
showDialog()
|
getData()
|
PayUtil.addPayListener(this)
|
}
|
|
private fun getData() {
|
HttpManager.queryOrderInfo(id, type).request(this) { _, data ->
|
order = data
|
data?.run {
|
tv_start.text = startAddress
|
tv_end.text = endAddress
|
tv_time.text = travelTime
|
iv_header_home.setImageURI(driverAvatar)
|
tv_name.text = "$driverName $licensePlate"
|
tv_car_info.text = "$brand·$carColor"
|
tv_score.text = String.format("%.1f", score)
|
tv_count.text = String.format("%d单", orderNum)
|
if (type == Const.OrderType.TYPE_CROSS_CITY) {
|
tv_passenger_num.visible()
|
tv_passenger_num.text =
|
String.format("%d人乘车:%s号座位", peopleNumber, seatNumber).replace(",", "号,")
|
tv_remark.visibility = if (remark.isNotEmpty()) View.VISIBLE else View.GONE
|
tv_remark.text = remark
|
}
|
setStateUI()
|
if (state == 10 || state == 12)
|
tv_tip.text = "注:司机已接单后用户取消订单费用"
|
else if (tipMoney == 0.0) {
|
tv_tip.invisible()
|
} else {
|
tv_tip.typeface = Typeface.DEFAULT_BOLD
|
val content = String.format("其中含小费:¥%.2f", tipMoney)
|
tv_tip.text = SpanBuilder(content).color(
|
this@OrderDetailActivity,
|
6,
|
content.length,
|
R.color.colorPrimary
|
).build()
|
}
|
}
|
}
|
}
|
|
/**
|
* 评价成功以后需要查询是否可以获得分享红包
|
*/
|
private fun getRedMoney() {
|
HttpManager.queryRedMoney(id, type).request(this) { _, data ->
|
data?.let {
|
val money = it.optDouble("amount")
|
if (money > 0) {
|
val tipDialog = TipDialog()
|
tipDialog.arguments = bundleOf(
|
"msg" to String.format("分享APP给好友可以获得%.2f元打车红包", money),
|
"ok" to "去分享", "cancel" to "不分享"
|
)
|
tipDialog.setCallback(object : TipDialog.OnClickCallback {
|
override fun onOk() {
|
val shareDialog = ShareDialog()
|
shareDialog.setCallback(object : ShareDialog.Callback {
|
override fun onOk(way: Int) { //0:wx 1:qq 2:msg
|
ShareUtils.share(
|
this@OrderDetailActivity,
|
if (way == 0) SHARE_MEDIA.WEIXIN else if (way == 1) SHARE_MEDIA.QQ else
|
SHARE_MEDIA.MORE,
|
Const.Share.NORMAL_CONTENT,
|
Const.Share.TITLE,
|
String.format(
|
Apis.SHARE_URL,
|
SPUtils.instance().getInt(Const.User.USER_ID)
|
),
|
this@OrderDetailActivity,
|
""
|
)
|
shareDialog.dismiss()
|
getRed(money)
|
}
|
})
|
shareDialog.show(supportFragmentManager, "share")
|
}
|
|
override fun onCancel() {}
|
})
|
tipDialog.show(supportFragmentManager, "red")
|
}
|
}
|
|
}
|
}
|
|
private fun setStateUI() {
|
tv_pay_offline.gone()
|
when (order?.state) {
|
7 -> { //待支付
|
tv_pay_offline.visible() //新增提示文字
|
payMoney = order!!.orderMoney
|
tv_money.text = String.format("¥%.2f", payMoney)
|
title = "支付费用"
|
tv_action.visible()
|
tv_title.visible()
|
// titleBar.getRightButton(0)?.gone() //刘矩:都加上投诉
|
tv_action.text = "立即支付"
|
queryBalance()
|
if (order!!.device == 2) {//车载端,显示线下付款按钮 2.0客户反馈,不要该按钮
|
// tv_pay_offline.visible()
|
}
|
if (type == 1) //专车有查看明细
|
tv_detail.visible()
|
}
|
8 -> { //待评价
|
title = if (type == Const.OrderType.TYPE_CROSS_CITY) "已完成" else "行程结束"
|
tv_money.text = String.format("¥%.2f", order!!.payMoney)
|
if (0.0 == order!!.payMoney && order!!.tipMoney == 0.0) { //其他方式收费
|
tv_money.invisible()
|
tv_tip.invisible()
|
}
|
tv_title.hide()
|
tv_action.text = "匿名评价"
|
titleBar.getRightButton(0)?.visible()
|
cl_evaluate.visible()
|
tv_detail.visible()
|
if (type == Const.OrderType.TYPE_SPECIAL) //专车有查看明细
|
tv_detail.visible()
|
if (type == Const.OrderType.TYPE_CROSS_CITY) {//跨城要提示摆渡车
|
val specialSuggestDialog = SpecialSuggestDialog()
|
specialSuggestDialog.setCallback(object : StringCallback {
|
override fun onRlt(rlt: String) {
|
if (rlt == "ok")
|
startActivity<ShuttleBusActivity>("order" to order,"isStart" to false)
|
}
|
})
|
specialSuggestDialog.show(supportFragmentManager,"suggest")
|
}
|
}
|
9 -> { //已完成
|
title = "行程结束"
|
tv_money.text = String.format("¥%.2f", order!!.payMoney)
|
if (0.0 == order!!.payMoney && order!!.tipMoney == 0.0) { //其他方式收费
|
tv_money.invisible()
|
tv_tip.invisible()
|
}
|
tv_action.gone()
|
titleBar.getRightButton(0)?.visible()
|
cl_evaluate.visible()
|
rating.isClickable = false
|
rating.setStar(order!!.orderScore.toFloat())
|
fl_label.removeAllViews()
|
val list = arrayListOf<String>()
|
list.addAll(if (order!!.orderScore == 5) highList else lowList)
|
val split = order!!.evaluate.split(",")
|
list.forEach {
|
val view = layoutInflater.inflate(R.layout.item_score_label, null) as CheckBox
|
view.text = it
|
view.isEnabled = false
|
if (it in split)
|
view.isChecked = true
|
fl_label.addView(view)
|
}
|
tv_detail.visible()
|
}
|
10 -> {
|
title = "已取消"
|
tv_money.text = String.format("¥%.2f", order!!.cancelPayMoney)
|
titleBar.getRightButton(0)?.gone() //刘矩:已取消没有投诉
|
if (type == Const.OrderType.TYPE_CROSS_CITY) { //跨城取消没有扣钱
|
tv_money.gone()
|
tv_tip.gone()
|
}
|
}
|
12 -> {//取消待支付
|
title = "支付费用"
|
titleBar.getRightButton(0)?.gone()
|
payMoney = order!!.cancelPayMoney
|
tv_money.text = String.format("¥%.2f", payMoney)
|
tv_action.visible()
|
tv_title.visible()
|
tv_action.text = "立即支付"
|
// queryBalance()
|
mPayDialog.arguments =
|
bundleOf("isCancel" to true, "money" to payMoney, "id" to id, "type" to type)
|
}
|
}
|
}
|
|
private val lowList = arrayListOf(
|
"道路不熟", "服务态度恶劣", "车辆肮脏", "车内有异味", "车牌号不符",
|
"司机吸烟", "打电话玩手机", "未坐好就开车", "未提醒系安全带", "未提醒开门注意", "过路口不减速", "索要好评"
|
)
|
private val highList = arrayListOf("车内整洁", "活地图认路准", "驾驶平稳", "态度好服务棒")
|
private val checkList = arrayListOf<String>()
|
private fun inputLabel(isHigh: Boolean) {
|
fl_label.removeAllViews()
|
checkList.clear()
|
val list = arrayListOf<String>()
|
list.addAll(if (isHigh) highList else lowList)
|
list.forEach {
|
val view = layoutInflater.inflate(R.layout.item_score_label, null) as CheckBox
|
view.text = it
|
view.setOnCheckedChangeListener { _, isChecked ->
|
if (isChecked)
|
checkList.add(view.text.toString())
|
else
|
checkList.remove(view.text.toString())
|
}
|
fl_label.addView(view)
|
}
|
}
|
|
/**
|
* 查询余额和优惠券以供支付
|
*/
|
private fun queryBalance() {
|
HttpManager.queryBalance(id, type).request(this) { _, data ->
|
data?.let {
|
mPayDialog.arguments = bundleOf(
|
"isCancel" to (order?.state == 12), "balance" to it.optDouble("balance"),
|
"coupon" to it.optInt("coupon"), "money" to payMoney, "id" to id, "type" to type
|
)
|
}
|
}
|
}
|
|
/**
|
* @param way 1=微信,2=支付宝,3=余额
|
*/
|
private fun pay(way: Int, couponId: Int) {
|
// if (way == 1){ //微信支付,跳转微信小程序
|
// val api = WXAPIFactory.createWXAPI(this, Const.WX_APP_ID)
|
// val req = WXLaunchMiniProgram.Req()
|
// req.userName = "gh_bc8f199f11ae" // 填小程序原始id
|
// val content = if (order!!.state == 12)"{\"cancleId\":${order!!.cancelId}}"
|
// else if (couponId!=0) "{\"couponId\":${couponId}}"
|
// else ""
|
// req.path = "/pages/appPay/appPay?orderId=${id}&orderType=${type}&type=${if (order!!.state == 12) 2 else 1}" +
|
// "&userType=1&uid=${SPUtils.instance().getInt(Const.User.USER_ID)}&content=${content}"
|
// req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE// 可选打开 开发版,体验版和正式版
|
// isGotoWx = true
|
// api.sendReq(req)
|
// }else{
|
if (order!!.state == 12)
|
HttpManager.cancleOrderTaxi(id, way, order!!.cancelId, type).request(this) { _, data ->
|
if (way == 3)
|
onPaySuccess()
|
else if (way == 2)
|
PayUtil.aliPay(this, data!!.orderString)
|
else if (way == 1)
|
startActivity<WXPayEntryActivity>("type" to 1, "data" to data)
|
|
} else
|
HttpManager.payTaxiOrder(id, way, type, if (couponId == 0) null else couponId)
|
.request(this) { _, data ->
|
if (way == 3)
|
onPaySuccess()
|
else if (way == 2)
|
PayUtil.aliPay(this, data!!.orderString)
|
else if (way == 1)
|
startActivity<WXPayEntryActivity>("type" to 1,"data" to data)
|
}
|
// }
|
}
|
|
/**
|
* 分享后获得红包
|
*/
|
private fun getRed(money: Double) {
|
HttpManager.shareRedEnvelope(id, type).request(this) { _, _ ->
|
val tipDialog = TipDialog()
|
tipDialog.arguments = bundleOf(
|
"msg" to String.format("您收到一个%.2f元的打车红包,已经放入钱包,下次打车可抵扣金额", money),
|
"ok" to "确定", "isAlert" to true
|
)
|
tipDialog.show(supportFragmentManager, "red")
|
}
|
}
|
|
override fun onPaySuccess() {
|
myToast("支付成功")
|
setResult(Activity.RESULT_OK)
|
tv_title.hide()
|
tv_action.gone()
|
if (order?.state == 12) {
|
title = "已取消"
|
titleBar.getRightButton(0).gone()
|
} else {
|
showDialog()
|
getData()
|
}
|
}
|
|
override fun onPayCancel() {
|
|
}
|
|
override fun onResume() {
|
super.onResume()
|
if (isGotoWx) {
|
isGotoWx = false
|
HttpManager.queryOrderInfo(id, type).request(this) { _, data ->
|
if (data?.state == order?.state) {
|
myToast("支付失败")
|
} else {
|
onPaySuccess()
|
}
|
}
|
}
|
}
|
|
|
override fun onDestroy() {
|
super.onDestroy()
|
PayUtil.removePayListener(this)
|
}
|
|
override fun onResult(p0: SHARE_MEDIA?) {
|
}
|
|
override fun onCancel(p0: SHARE_MEDIA?) {
|
}
|
|
override fun onError(p0: SHARE_MEDIA?, p1: Throwable?) {
|
}
|
|
override fun onStart(p0: SHARE_MEDIA?) {
|
|
}
|
|
}
|