package com.kuanzhai.user.ui.logistics
|
|
import android.animation.ObjectAnimator
|
import android.app.Activity
|
import android.content.Intent
|
import android.os.Bundle
|
import android.os.Environment
|
import android.text.TextUtils
|
import android.util.Log
|
import android.view.View
|
import androidx.core.os.bundleOf
|
import androidx.recyclerview.widget.GridLayoutManager
|
import cn.sinata.xldutils.activity.SelectPhotoDialog
|
import cn.sinata.xldutils.fragment.BaseFragment
|
import cn.sinata.xldutils.gone
|
import cn.sinata.xldutils.ioScheduler
|
import cn.sinata.xldutils.rxutils.ResultException
|
import cn.sinata.xldutils.utils.*
|
import cn.sinata.xldutils.visible
|
import com.amap.api.maps.AMap
|
import com.amap.api.maps.CameraUpdateFactory
|
import com.amap.api.maps.TextureMapView
|
import com.amap.api.maps.model.BitmapDescriptorFactory
|
import com.amap.api.maps.model.CameraPosition
|
import com.amap.api.maps.model.LatLng
|
import com.amap.api.maps.model.MyLocationStyle
|
import com.amap.api.services.core.LatLonPoint
|
import com.amap.api.services.poisearch.PoiResult
|
import com.amap.api.services.poisearch.PoiSearch
|
import com.autonavi.amap.mapcore.Inner_3dMap_location
|
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.HttpManager
|
import com.kuanzhai.user.network.requestByF
|
import com.kuanzhai.user.ui.H5Activity
|
import com.kuanzhai.user.ui.MainActivity
|
import com.kuanzhai.user.ui.logistics.adpter.GoodsImgAdapter
|
import com.kuanzhai.user.ui.mine.OrderActivity
|
import com.kuanzhai.user.ui.trip.BuyCardActivity
|
import com.kuanzhai.user.ui.trip.ChoosePositionActivity
|
import com.kuanzhai.user.utils.Const
|
import com.kuanzhai.user.utils.OSSUtil
|
import com.kuanzhai.user.utils.event.BaseEvent
|
import com.kuanzhai.user.utils.pay.PayListener
|
import com.kuanzhai.user.utils.pay.PayUtil
|
import io.reactivex.Flowable
|
import io.reactivex.subscribers.DisposableSubscriber
|
import kotlinx.android.synthetic.main.fragment_logistics.*
|
import org.greenrobot.eventbus.EventBus
|
import org.greenrobot.eventbus.Subscribe
|
import org.jetbrains.anko.sdk27.coroutines.onClick
|
import org.jetbrains.anko.support.v4.find
|
import org.jetbrains.anko.support.v4.runOnUiThread
|
import org.jetbrains.anko.support.v4.startActivity
|
import org.jetbrains.anko.support.v4.startActivityForResult
|
import top.zibin.luban.Luban
|
import top.zibin.luban.OnCompressListener
|
import java.io.File
|
|
class LogisticsFragment : BaseFragment(), PayListener {
|
override fun contentViewId() = R.layout.fragment_logistics
|
|
var type = Const.OrderType.TYPE_SAME_CITY //默认为同城物流
|
|
private val imgs = arrayListOf("") //实物图
|
private val imgAdapter = GoodsImgAdapter(imgs)
|
|
private val DEFAULT_SCALE_LEVEL = 20f
|
private var startByChoose = false //true 通过选择出发地移动地图,false 通过手势拖动地图
|
private var startByLocal = false //true 通过复位按钮移动地图,false 通过手势拖动地图
|
|
//取件经纬度
|
private var startLon = 0.0
|
private var startLat = 0.0
|
private var startName = ""
|
|
//收件信息
|
private var receiveName = ""
|
private var receivePhone = ""
|
private var receiveRegion = ""
|
private var provinceIndex = 0
|
private var cityIndex = 0
|
private var regionIndex = 0
|
private var receiveAddress = ""
|
private var timeFormat = "" //取件时间:例 2020-09-17 21:00:00
|
private var timeArriveFormat = "" //送达时间:例 2020-09-17 21:00:00
|
|
private var isFirstOrder = false
|
|
//货物信息
|
private var goodsType = 0 //货物类型(1=普通货物,2=贵重货物)
|
private var goodsNum = 0 //货物数量
|
private var remark = ""
|
|
private var orderMoney = 0.0 //物流费用
|
private var fastMoney = 0 //加急费用
|
|
private val mMapView by lazy {
|
find<TextureMapView>(R.id.mMapView)
|
}
|
|
private val aMap by lazy {
|
mMapView.map
|
}
|
private val mainActivity by lazy {
|
activity as MainActivity
|
}
|
private val tipsDialog by lazy {
|
val dialog = SingleWheelDialog()
|
dialog.arguments = bundleOf(
|
"title" to "修改加急金额",
|
"subTitle" to "加急费用归司机所有,添加将提高应答率",
|
"data" to (1..20).map { "${it}元" })
|
dialog.setCallback(object : StringCallback {
|
override fun onRlt(rlt: String) {
|
tv_tips.text = rlt
|
fastMoney = rlt.substring(0, rlt.length - 1).toInt()
|
val format = "物流费用¥%.2f".format(orderMoney+fastMoney)
|
tv_price.text = SpanBuilder(format).color(activity!!, 0, 4, R.color.textColor)
|
.size(0, 4, 14).build()
|
}
|
})
|
dialog
|
}
|
private val successDialog by lazy {
|
val dialog = TipDialog()
|
dialog.arguments = bundleOf("msg" to "您已下单成功,我们将根据预约时间安排人员领取物品,请保持电话通畅!", "isAlert" to true)
|
dialog.setDismissCallback(object : TipDialog.OnDismiss {
|
override fun onDismiss() {
|
startActivity<OrderActivity>("type" to type)
|
}
|
})
|
dialog
|
}
|
|
|
override fun onFirstVisibleToUser() {
|
EventBus.getDefault().register(this)
|
if ((activity as MainActivity).isShowCard){
|
tv_buy_card_2.visible()
|
}else{
|
tv_buy_card_2.gone()
|
}
|
rv_photo.layoutManager = GridLayoutManager(requireContext(), 3)
|
rv_photo.adapter = imgAdapter
|
|
initMap()
|
initClick()
|
PayUtil.addPayListener(this)
|
}
|
|
private fun initClick() {
|
tv_order_count.onClick {
|
if (mainActivity.checkLogin())
|
startActivity<OrderActivity>("type" to type)
|
}
|
//点击归位
|
iv_location.setOnClickListener {
|
startByLocal = true
|
aMap.animateCamera(
|
CameraUpdateFactory.newLatLngZoom(
|
LatLng(
|
KuanzhaiApplication.lat,
|
KuanzhaiApplication.lon
|
), DEFAULT_SCALE_LEVEL
|
)
|
)
|
}
|
tv_start.onClick {
|
startActivityForResult<ChoosePositionActivity>(
|
Const.RequestCode.LOGISTICS_START,
|
"isLogistics" to true
|
)
|
}
|
tv_receiver.onClick {
|
startActivityForResult<ReceiverActivity>(
|
Const.RequestCode.LOGISTICS_RECEIVER,
|
"name" to receiveName,
|
"phone" to receivePhone,
|
"region" to receiveRegion,
|
"address" to receiveAddress,
|
"provinceIndex" to provinceIndex,
|
"cityIndex" to cityIndex,
|
"regionIndex" to regionIndex
|
)
|
}
|
tv_type.onClick {
|
if (startName.isEmpty()) {
|
myToast("请选择取件地点")
|
return@onClick
|
}
|
if (receiveAddress.isEmpty()) {
|
myToast("请完善收货人信息")
|
return@onClick
|
}
|
if (mainActivity.checkLogin())
|
startActivityForResult<GoodsTypeActivity>(
|
Const.RequestCode.LOGISTICS_TYPE, "address" to receiveRegion + receiveAddress,
|
"lat" to startLat, "lon" to startLon, "type" to type
|
)
|
}
|
tv_time.onClick {
|
val chooseReserveTimeDialog = ChooseReserveTimeDialog()
|
chooseReserveTimeDialog.arguments = bundleOf("title" to "设置取货时间")
|
chooseReserveTimeDialog.setCallback(object : ChooseReserveTimeDialog.Callback {
|
override fun onOk(s: String, formatS: String) {
|
tv_time.text = s
|
timeFormat = formatS
|
}
|
})
|
chooseReserveTimeDialog.show(fragmentManager!!, "timeLogistics")
|
}
|
tv_arrive_time.onClick {
|
val chooseReserveTimeDialog = ChooseReserveTimeDialog()
|
chooseReserveTimeDialog.arguments = bundleOf("title" to "设置送达时间","isArrive" to true)
|
chooseReserveTimeDialog.setCallback(object : ChooseReserveTimeDialog.Callback {
|
override fun onOk(s: String, formatS: String) {
|
tv_arrive_time.text = s
|
timeArriveFormat = "$formatS:00"
|
}
|
})
|
chooseReserveTimeDialog.show(fragmentManager!!, "timeLogistics")
|
}
|
tv_tips.onClick {
|
if (cb_fast.isChecked && !tipsDialog.isAdded) {
|
tipsDialog.show(fragmentManager!!, "tips")
|
}
|
}
|
tv_action.onClick {
|
if (timeFormat.isEmpty()) {
|
myToast("请选择司机取货时间")
|
return@onClick
|
}
|
// if (timeArriveFormat.isEmpty()) { //杨冬梅:送达时间选填
|
// myToast("请指定送达时间")
|
// return@onClick
|
// }
|
if (type == Const.OrderType.TYPE_SAME_CITY && cb_fast.isChecked && fastMoney == 0) {
|
myToast("请选择加急费用")
|
return@onClick
|
}
|
if (isFirstOrder) {
|
HttpManager.getH5(15).requestByF(this@LogisticsFragment) { _, data ->
|
val url = data?.optString("content") ?: ""
|
startActivityForResult<H5Activity>(
|
Const.RequestCode.LOGISTICS_RULE,
|
"url" to url,
|
"title" to "小件物流服务协议",
|
"actionEnable" to true
|
)
|
}
|
} else
|
createOrder()
|
}
|
cb_fast.setOnCheckedChangeListener { _, isChecked ->
|
if (!isChecked) {
|
fastMoney = 0
|
tv_tips.text = ""
|
}
|
}
|
tv_buy_card_2.setOnClickListener {
|
if ((activity as MainActivity).checkLogin()) {
|
startActivity<BuyCardActivity>("type" to type)
|
}
|
}
|
imgAdapter.setOnItemClickListener { view, position ->
|
if (imgs[position].isEmpty()) {
|
startActivityForResult<SelectPhotoDialog>(Const.RequestCode.LOGISTICS_IMG)
|
}
|
}
|
}
|
|
var savedInstanceState: Bundle? = null
|
override fun onCreate(savedInstanceState: Bundle?) {
|
super.onCreate(savedInstanceState)
|
this.savedInstanceState = savedInstanceState
|
}
|
|
private var locCount = 0L //定位次数
|
|
private fun initMap() {
|
mMapView.onCreate(savedInstanceState)
|
val myLocationStyle = MyLocationStyle()
|
myLocationStyle.strokeColor(resources.getColor(R.color.colorBrown))
|
myLocationStyle.radiusFillColor(resources.getColor(R.color.colorTransBrown))
|
myLocationStyle.interval(5000)
|
myLocationStyle.anchor(0.5f, 0.5f)
|
myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER)//
|
myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.icon_coordinate))
|
aMap.myLocationStyle = myLocationStyle//设置定位蓝点的Style
|
aMap.uiSettings.isMyLocationButtonEnabled = false//设置默认定位按钮是否显示,非必需设置。
|
aMap.uiSettings.setZoomInByScreenCenter(true)
|
aMap.uiSettings.isZoomControlsEnabled = false
|
aMap.uiSettings.isRotateGesturesEnabled = false
|
aMap.uiSettings.isTiltGesturesEnabled = false
|
aMap.isMyLocationEnabled = true
|
aMap.setOnMyLocationChangeListener {
|
it as Inner_3dMap_location
|
Log.e(Const.Tag, "物流:lat:" + it.latitude + ",lon:" + it.longitude)
|
KuanzhaiApplication.lat = it.latitude
|
KuanzhaiApplication.lon = it.longitude
|
KuanzhaiApplication.address = it.address
|
KuanzhaiApplication.cityCode = it.extras.getString("adcode") ?: ""
|
if (locCount < 1) {
|
if (mainActivity.lat != 0.0)
|
aMap.animateCamera(
|
CameraUpdateFactory.newLatLngZoom(
|
LatLng(
|
mainActivity.lat,
|
mainActivity.lon
|
), DEFAULT_SCALE_LEVEL
|
)
|
)
|
else
|
aMap.animateCamera(
|
CameraUpdateFactory.newLatLngZoom(
|
LatLng(
|
it.latitude,
|
it.longitude
|
), DEFAULT_SCALE_LEVEL
|
)
|
)
|
}
|
locCount++
|
}
|
aMap.setOnCameraChangeListener(object : AMap.OnCameraChangeListener {
|
override fun onCameraChangeFinish(p0: CameraPosition?) {
|
if (!startByChoose && iv_center_logistics.visibility == View.VISIBLE) {
|
startLat = p0?.target?.latitude ?: 0.0
|
startLon = p0?.target?.longitude ?: 0.0
|
getPoi(startLat, startLon)
|
}
|
startByChoose = false
|
startByLocal = false
|
val objectAnimator =
|
ObjectAnimator.ofFloat(iv_center_logistics, "translationY", 0f, -30f, 0f)
|
.setDuration(600)
|
val objectAnimator1 =
|
ObjectAnimator.ofFloat(tv_center, "translationY", 0f, -30f, 0f).setDuration(600)
|
objectAnimator.start()
|
objectAnimator1.start()
|
tv_center.text = "在这里领取"
|
}
|
|
override fun onCameraChange(p0: CameraPosition?) {
|
if (startByLocal)
|
tv_center.text = "正在获取定位"
|
}
|
})
|
}
|
|
private fun getOrderCount() {
|
if (mainActivity.checkLogin(false)) {
|
HttpManager.queryLogisticsNumber().requestByF(this) { _, data ->
|
data?.apply {
|
tv_order_count.text = "我的订单(%d)".format(optInt("number"))
|
}
|
}
|
} else {
|
tv_order_count.text = "我的订单(%d)".format(0)
|
}
|
}
|
|
private fun createOrder() {
|
showDialog()
|
val img = imgs.filter { it.isNotEmpty() }.joinToString(",") { it }
|
HttpManager.smallLogistics(
|
goodsNum,
|
goodsType,
|
"$receiveRegion${receiveAddress}",
|
KuanzhaiApplication.lat,
|
KuanzhaiApplication.lon,
|
receiveName,
|
receivePhone,
|
remark,
|
startName,
|
startLat,
|
startLon,
|
fastMoney,
|
timeFormat,
|
timeArriveFormat,
|
type,
|
if (cb_fast.isChecked) 2 else 1,img
|
).requestByF(this) { _, data ->
|
showDialog()
|
val orderId = data?.optInt("id") ?: 0
|
HttpManager.queryBalance(orderId,type).requestByF(this, true, { _, userInfo ->
|
userInfo?.let {
|
val payDialog = PayDialog()
|
val payMoney =
|
if (type == Const.OrderType.TYPE_SAME_CITY && cb_fast.isChecked) orderMoney + fastMoney else orderMoney
|
payDialog.arguments = bundleOf(
|
"money" to payMoney,
|
"balance" to it.optDouble("balance"),"discount" to it.optDouble("discountAmount"), "coupon" to it.optString("objectId"),
|
"discountType" to it.optInt("type"),"id" to orderId,"type" to type)
|
payDialog.setCallback(object : PayDialog.Callback {
|
override fun onOk(way: Int, couponId: Int, couponType: Int) {
|
pay(way, orderId,couponId, couponType)
|
payDialog.dismiss()
|
}
|
|
override fun onClose() {
|
onPayCancel()
|
}
|
})
|
payDialog.show(fragmentManager!!, "pay")
|
getOrderCount()
|
back()
|
}
|
}) { _, _ ->
|
getOrderCount()
|
back()
|
}
|
}
|
}
|
|
/**
|
* @param way 1=微信,2=支付宝,3=余额
|
*/
|
private fun pay(way: Int, id: Int,couponId:Int,couponType:Int) {
|
// if (way == 1){//微信支付,跳转微信小程序
|
// val api = WXAPIFactory.createWXAPI(activity, Const.WX_APP_ID)
|
// val req = WXLaunchMiniProgram.Req()
|
// req.userName = "gh_a6c22560b6be" // 填小程序原始id
|
// req.path = "/pages/appPay/appPay?orderId=${id}&orderType=${type}&type=1" +
|
// "&userType=1&uid=${SPUtils.instance().getInt(Const.User.USER_ID)}&content="
|
// req.miniprogramType = WXLaunchMiniProgram.Req.MINIPTOGRAM_TYPE_RELEASE// 可选打开 开发版,体验版和正式版
|
// api.sendReq(req)
|
// }else{
|
HttpManager.payTaxiOrder(id, way, 4,if(couponId == 0) null else couponId,
|
if(couponType == 0) null else couponType).requestByF(this) { _, data ->
|
if (way == 3)
|
onPaySuccess()
|
else if (way == 2)
|
PayUtil.aliPay(activity!!, data!!.orderInfo)
|
else
|
PayUtil.weChatPay(data!!)
|
}
|
// }
|
}
|
|
/**
|
* 返回
|
* @param isBackHome true:直接返回到首页
|
*/
|
fun back(isBackHome: Boolean = true) {
|
group_order.gone()
|
group_fast.gone()
|
iv_center_logistics.visible()
|
tv_center.visible()
|
tv_order_count.visible()
|
iv_count.visible()
|
iv_location.visible()
|
mainActivity.updateTitleVisibility(false, false)
|
mainActivity.updateLogisticsTitle(false)
|
mainActivity.updateTabVisibility(true)
|
aMap.uiSettings.isScrollGesturesEnabled = true
|
if (isBackHome) {
|
tv_receiver.text = ""
|
receiveAddress = ""
|
receiveRegion = ""
|
receiveName = ""
|
receivePhone = ""
|
provinceIndex = 0
|
cityIndex = 0
|
regionIndex = 0
|
}
|
tv_type.text = ""
|
tv_start.isEnabled = true
|
tv_receiver.isEnabled = true
|
tv_type.isEnabled = true
|
tv_time.text = ""
|
tv_arrive_time.text = ""
|
timeFormat = ""
|
timeArriveFormat = ""
|
cb_fast.isChecked = false
|
tv_tips.text = ""
|
fastMoney = 0
|
imgs.clear()
|
imgs.add("")
|
imgAdapter.notifyDataSetChanged()
|
}
|
|
/**
|
* 获取支付金额
|
*/
|
private fun getPrice() {
|
showDialog()
|
HttpManager.queryPayMoney(
|
receiveRegion + receiveAddress, "$startLon,$startLat",
|
goodsNum, type
|
).requestByF(this, false, { _, data ->
|
data?.apply {
|
group_order.visible()
|
iv_center_logistics.gone()
|
tv_center.gone()
|
tv_order_count.gone()
|
iv_count.gone()
|
iv_location.gone()
|
tv_start.isEnabled = false
|
tv_receiver.isEnabled = false
|
tv_type.isEnabled = false
|
if (type == Const.OrderType.TYPE_SAME_CITY)
|
group_fast.visible()
|
mainActivity.updateTitleVisibility(false, true)
|
mainActivity.updateLogisticsTitle(true)
|
mainActivity.updateTabVisibility(false)
|
aMap.uiSettings.isScrollGesturesEnabled = false
|
orderMoney = optDouble(if (goodsType == 1) "ordinary" else "precious")
|
val format = "物流费用¥%.2f".format(orderMoney)
|
tv_price.text = SpanBuilder(format).color(activity!!, 0, 4, R.color.textColor)
|
.size(0, 4, 14).build()
|
}
|
}) { _, _ ->
|
myToast("获取支付金额失败")
|
}
|
}
|
|
fun changeType(newType: Int) {
|
if (newType != type) {
|
type = newType
|
judgingTheCity()
|
}
|
}
|
|
/**
|
* 获取poi信息
|
*/
|
private var poiSearchDisposable: DisposableSubscriber<PoiResult>? = null
|
|
fun getPoi(lat: Double?, lng: Double?) {
|
if (lat == null || lng == null) {
|
return
|
}
|
//如果上一次还没处理完,取消订阅
|
if (poiSearchDisposable != null && !poiSearchDisposable!!.isDisposed) {
|
poiSearchDisposable?.dispose()
|
}
|
poiSearchDisposable = object : DisposableSubscriber<PoiResult>() {
|
override fun onComplete() {
|
|
}
|
|
override fun onNext(t: PoiResult?) {
|
val address = if (t != null) {
|
t.pois.sortBy { it.distance }
|
if (t.pois.isNotEmpty()) {
|
t.pois[0].title
|
} else {
|
null
|
}
|
} else {
|
null
|
}
|
runOnUiThread {
|
startName = address ?: ""
|
tv_start?.text = address
|
}
|
}
|
|
override fun onError(t: Throwable?) {
|
runOnUiThread {
|
startName = ""
|
tv_start.text = "点击选择起点"
|
}
|
}
|
}
|
val query = PoiSearch.Query("", "190000", "")
|
val poiSearch = PoiSearch(context, query)
|
poiSearch.bound = PoiSearch.SearchBound(LatLonPoint(lat, lng), 1000)
|
Flowable.just(poiSearch).ioScheduler().flatMap {
|
try {
|
val result = poiSearch.searchPOI()
|
if (result == null) {
|
Flowable.error(ResultException(""))
|
} else
|
Flowable.just(result)
|
} catch (e: Exception) {
|
e.printStackTrace()
|
Flowable.error<PoiResult>(e)
|
}
|
}.subscribe(poiSearchDisposable)
|
}
|
|
/**
|
* 判断同城小件物流是否是同城
|
*/
|
private fun judgingTheCity() {
|
if (type == Const.OrderType.TYPE_SAME_CITY && startLat != 0.0 && receiveRegion.isNotEmpty()) {
|
HttpManager.judgingTheCity(receiveRegion + receiveAddress, "$startLon,$startLat")
|
.requestByF(this, false, { _, _ ->
|
}) { _, msg ->
|
back()
|
val tipDialog = TipDialog()
|
tipDialog.arguments = bundleOf("msg" to msg, "isAlert" to true)
|
tipDialog.show(fragmentManager!!, "disable")
|
}
|
}
|
}
|
|
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
super.onActivityResult(requestCode, resultCode, data)
|
if (resultCode == Activity.RESULT_OK) {
|
if (requestCode == Const.RequestCode.LOGISTICS_RULE) {
|
createOrder()
|
}
|
if (data != null)
|
when (requestCode) {
|
Const.RequestCode.LOGISTICS_START -> {
|
startLat = data.getDoubleExtra("lat", 0.0)
|
startLon = data.getDoubleExtra("lon", 0.0)
|
startByChoose = true
|
aMap.animateCamera(
|
CameraUpdateFactory.newLatLng(
|
LatLng(
|
startLat,
|
startLon
|
)
|
)
|
)
|
startName = data.getStringExtra("name") ?: ""
|
tv_start.text = startName
|
judgingTheCity()
|
}
|
Const.RequestCode.LOGISTICS_RECEIVER -> {
|
receiveName = data.getStringExtra("name") ?: ""
|
receivePhone = data.getStringExtra("phone") ?: ""
|
receiveRegion = data.getStringExtra("region") ?: ""
|
receiveAddress = data.getStringExtra("address") ?: ""
|
provinceIndex = data.getIntExtra("provinceIndex", 0)
|
cityIndex = data.getIntExtra("cityIndex", 0)
|
regionIndex = data.getIntExtra("regionIndex", 0)
|
val receiver = "%s %s\n%s%s".format(
|
receiveName,
|
receivePhone,
|
receiveRegion,
|
receiveAddress
|
)
|
tv_receiver.text = SpanBuilder(receiver).color(
|
activity!!,
|
receiver.length - receiveAddress.length - receiveRegion.length,
|
receiver.length,
|
R.color.textColor99
|
).size(
|
receiver.length - receiveAddress.length - receiveRegion.length,
|
receiver.length, 12
|
).build()
|
judgingTheCity()
|
}
|
Const.RequestCode.LOGISTICS_TYPE -> {
|
isFirstOrder = data.getBooleanExtra("isFirstOrder", false)
|
goodsType = data.getIntExtra("goodsType", 0)
|
goodsNum = data.getIntExtra("goodsNum", 0)
|
remark = data.getStringExtra("remark") ?: ""
|
tv_type.text =
|
"%sX%d".format(if (goodsType == 1) "普通小件" else "贵重物品", goodsNum)
|
getPrice()
|
}
|
Const.RequestCode.LOGISTICS_IMG -> {
|
Luban.with(requireContext())
|
.load(File(data.getStringExtra("path")))
|
.ignoreBy(100)
|
.setTargetDir(getPath())
|
.filter { path -> !(TextUtils.isEmpty(path) || path.toLowerCase().endsWith(".gif")) }
|
.setCompressListener(object : OnCompressListener {
|
override fun onStart() {
|
showDialog(canCancel = false)
|
}
|
|
override fun onSuccess(file: File) {
|
Log.e("mmp", "压缩完成" + file.name)
|
OSSUtil(requireActivity()).uploadSingle(file.path,object :
|
OSSUtil.OSSUploadCallBack(){
|
override fun onFial(message: String?) {
|
super.onFial(message)
|
dismissDialog()
|
myToast(message ?: "上传失败")
|
}
|
|
override fun onFinish(url: String) {
|
super.onFinish(url)
|
imgs.add(imgs.size-1,url)
|
if (imgs.size>3)
|
imgs.removeAt(imgs.lastIndex)
|
imgAdapter.notifyDataSetChanged()
|
}
|
})
|
}
|
|
override fun onError(e: Throwable) {
|
e.printStackTrace()
|
}
|
}).launch()
|
}
|
}
|
}
|
}
|
|
/**
|
* 订单完成 获取商家优惠券
|
*/
|
private fun getCoupon() {
|
HttpManager.giveAwayMerchantCoupon(type, id).requestByF(this,false){_,data->
|
if (data?.isNullOrEmpty() == false){
|
val businessCouponDialog = BusinessCouponDialog()
|
businessCouponDialog.arguments = bundleOf("data" to data)
|
businessCouponDialog.show(childFragmentManager,"coupon")
|
}
|
}
|
}
|
|
protected fun getPath(): String {
|
val path = Environment.getExternalStorageDirectory().toString() + "/Luban/image/"
|
val file = File(path)
|
return if (file.mkdirs()) {
|
path
|
} else path
|
}
|
|
@Subscribe
|
fun onEvent(e: BaseEvent){
|
if (e.type == Const.Event.EVENT_CARD_SHOW){
|
if (e.obj as Boolean){
|
tv_buy_card_2.visible()
|
}else{
|
tv_buy_card_2.gone()
|
}
|
}
|
}
|
|
override fun onResume() {
|
super.onResume()
|
mMapView.onResume()
|
getOrderCount()
|
}
|
|
override fun onPause() {
|
super.onPause()
|
mMapView.onPause()
|
}
|
|
override fun onDestroy() {
|
super.onDestroy()
|
mMapView.onDestroy()
|
PayUtil.removePayListener(this)
|
PayUtil.unregisterApp()
|
EventBus.getDefault().unregister(this)
|
}
|
|
override fun onSaveInstanceState(outState: Bundle) {
|
super.onSaveInstanceState(outState)
|
mMapView.onSaveInstanceState(outState)
|
}
|
|
override fun onLowMemory() {
|
super.onLowMemory()
|
mMapView.onLowMemory()
|
}
|
|
override fun onPaySuccess() {
|
if (!successDialog.isAdded)
|
successDialog.show(fragmentManager!!, "suc")
|
}
|
|
override fun onPayCancel() {
|
startActivity<OrderActivity>("type" to type)
|
}
|
}
|