package com.kuanzhai.user.ui.trip
|
|
import android.app.Activity
|
import android.content.Intent
|
import android.graphics.Typeface
|
import android.net.Uri
|
import android.view.View
|
import android.widget.CheckBox
|
import androidx.core.os.bundleOf
|
import cn.sinata.xldutils.*
|
import cn.sinata.xldutils.utils.*
|
import com.kuanzhai.user.KuanzhaiApplication
|
import com.kuanzhai.user.R
|
import com.kuanzhai.user.dialog.*
|
import com.kuanzhai.user.interfaces.StringCallback
|
import com.kuanzhai.user.network.Apis
|
import com.kuanzhai.user.network.HttpManager
|
import com.kuanzhai.user.network.entity.CarPrice
|
import com.kuanzhai.user.network.entity.Order
|
import com.kuanzhai.user.network.request
|
import com.kuanzhai.user.ui.H5Activity
|
import com.kuanzhai.user.ui.TransparentStatusBarActivity
|
import com.kuanzhai.user.ui.crosscity.ShuttleBusActivity
|
import com.kuanzhai.user.utils.Const
|
import com.kuanzhai.user.utils.pay.PayListener
|
import com.kuanzhai.user.utils.pay.PayUtil
|
import com.share.utils.ShareUtils
|
import com.umeng.socialize.UMShareListener
|
import com.umeng.socialize.bean.SHARE_MEDIA
|
import kotlinx.android.synthetic.main.activity_order_detail.*
|
import kotlinx.android.synthetic.main.item_img_ads.view.*
|
import org.jetbrains.anko.backgroundColorResource
|
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,couponType: Int) {
|
pay(way,couponId,couponType)
|
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_detail_special.onClick {
|
startActivity<PriceDetailActivity>("order" to order)
|
}
|
tv_rule.clickDelay {
|
if (type == Const.OrderType.TYPE_SPECIAL){
|
order?.apply {
|
when(rideType){
|
1->startActivity<PriceRuleActivity>("title" to "独享","describe" to fareTypeNote2,"rule" to contentExclusive)
|
2->startActivity<PriceRuleActivity>("title" to "一口价","describe" to fareTypeNote3,"rule" to contentPrice)
|
3->{
|
val carPrice = CarPrice()
|
carPrice.contentPutOne = contentPutOne
|
carPrice.contentNotOne = contentNotOne
|
carPrice.contentPutTwo = contentPutTwo
|
carPrice.contentNotTwo = contentNotTwo
|
carPrice.contentPutThree = contentPutThree
|
carPrice.contentNotThree = contentNotThree
|
startActivity<PinPriceRuleActivity>("title" to "%d人%s".format(peopleNumber,if (spellSuccess == 0) "未拼成" else "拼成"),
|
"describe" to fareTypeNote1, "rule" to carPrice)
|
}
|
}
|
}
|
}else
|
getRule()
|
}
|
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)
|
PayUtil.initWeChatPay(this,Const.WX_APP_ID)
|
}
|
|
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){
|
if (driverCancle == 1){ //司机取消
|
tv_tip.text = "司机取消订单"
|
tv_money.gone()
|
}else
|
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 getRule(){
|
HttpManager.getH5(13).request(this){_,data->
|
data?.let {
|
startActivity<H5Activity>("title" to "计价规则","url" to it.optString("content"))
|
tv_rule.setOnClickListener {_->
|
startActivity<H5Activity>("title" to "计价规则","url" to it.optString("content"))
|
}
|
}
|
}
|
}
|
|
/**
|
* 评价成功以后需要查询是否可以获得分享红包
|
*/
|
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 == Const.OrderType.TYPE_SPECIAL) { //快车/专车有查看明细
|
tv_detail.visible()
|
tv_rule.visible()
|
}
|
if (type == Const.OrderType.TYPE_TAXI) //漆联刚:出租车车有查看明细
|
tv_detail.visible()
|
if (order?.rideType == 3){
|
tv_pin.visible()
|
if (order?.spellSuccess == 0){
|
tv_pin.text = "(未拼成)-${order?.peopleNumber?:1}人价"
|
}else{
|
tv_pin.text = "(拼成)-${order?.peopleNumber?:1}人价"
|
}
|
}
|
}
|
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){ //快车/专车有查看明细
|
cl_evaluate.backgroundColorResource = R.color.white
|
ll_special_pay.visible()
|
ll_pay.gone()
|
tv_money_special.text = String.format("¥%.2f",order!!.payMoney)
|
}
|
getAds() //母贝:所有的订单结束界面需要有“广告”
|
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")
|
//查询活动优惠券
|
// getCoupon()
|
}
|
}
|
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"),
|
"discount" to it.optDouble("discountAmount"), "coupon" to it.optString("objectId"),
|
"discountType" to it.optInt("type"), "money" to payMoney,"id" to id,"type" to type)
|
}
|
}
|
}
|
|
private fun getAds(){
|
HttpManager.getAds(3, KuanzhaiApplication.chooseCityCode).request(this,false){ _, data->
|
data?.let {
|
it.forEach {
|
val view = layoutInflater.inflate(R.layout.item_img_ads, null)
|
view.iv_img.setImageURI(it.imgUrl)
|
view.iv_img.setOnClickListener { _ ->
|
if (it.isJump == 1) { //要跳转
|
if (it.jumpType == "2")
|
startActivity<H5Activity>(
|
"title" to it.name,
|
"url" to it.content
|
)
|
else {
|
val intent = Intent()
|
intent.action = "android.intent.action.VIEW"
|
intent.data = Uri.parse(it.jumpUrl)
|
startActivity(intent)
|
}
|
}
|
}
|
ll_ads.addView(view)
|
}
|
}
|
}
|
}
|
|
/**
|
* @param way 1=微信,2=支付宝,3=余额
|
*/
|
private fun pay(way:Int,couponId:Int,couponType: Int){
|
// if (way == 1){ //微信支付,跳转微信小程序
|
// val api = WXAPIFactory.createWXAPI(this, Const.WX_APP_ID)
|
// val req = WXLaunchMiniProgram.Req()
|
// req.userName = "gh_a6c22560b6be" // 填小程序原始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!!.orderInfo)
|
else
|
PayUtil.weChatPay(data!!)
|
} else
|
HttpManager.payTaxiOrder(id,way,type,if (couponId == 0) null else couponId,if (couponType == 0) null else couponType).request(this){_,data->
|
if (way == 3)
|
onPaySuccess()
|
else if (way == 2)
|
PayUtil.aliPay(this,data!!.orderInfo)
|
else
|
PayUtil.weChatPay(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{
|
getCoupon()
|
showDialog()
|
getData()
|
}
|
}
|
|
/**
|
* 订单完成 获取商家优惠券
|
*/
|
private fun getCoupon() {
|
HttpManager.giveAwayMerchantCoupon(type, id).request(this,false){_,data->
|
if (data?.isNullOrEmpty() == false){
|
val businessCouponDialog = BusinessCouponDialog()
|
businessCouponDialog.arguments = bundleOf("data" to data)
|
businessCouponDialog.show(supportFragmentManager,"coupon")
|
}
|
}
|
}
|
|
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)
|
PayUtil.unregisterApp()
|
}
|
|
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?) {
|
|
}
|
|
}
|