18034727885
2026-07-09 f35664f0ad753df3dc4ca3b47c2f91263973af34
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
package com.igo.user.ui.logistics
 
import android.annotation.SuppressLint
import android.util.Log
import android.util.TypedValue
import android.webkit.WebSettings
import android.webkit.WebView
import android.widget.CheckBox
import android.widget.TextView
import androidx.core.os.bundleOf
import cn.sinata.xldutils.toBrowser
import cn.sinata.xldutils.utils.LanguageUtil
import cn.sinata.xldutils.utils.myToast
import cn.sinata.xldutils.utils.optDouble
import cn.sinata.xldutils.utils.optInt
import cn.sinata.xldutils.utils.optString
import cn.sinata.xldutils.utils.toTime
import com.igo.user.IGoApplication
import com.igo.user.R
import com.igo.user.dialog.ChooseCardDialog
import com.igo.user.dialog.PayDialog
import com.igo.user.extension.safeLoadDataWithBaseURL
import com.igo.user.extension.setSafeSetting
import com.igo.user.interfaces.StringCallback
import com.igo.user.network.HttpManager
import com.igo.user.network.entity.Order
import com.igo.user.network.request
import com.igo.user.ui.H5Activity
import com.igo.user.ui.TransparentStatusBarActivity
import com.igo.user.ui.crosscity.PayCrossActivity
import com.igo.user.ui.trip.TripActivity
import com.igo.user.utils.Const
import com.igo.user.utils.pay.PayListener
import com.igo.user.utils.pay.PayUtil
import org.jetbrains.anko.find
import org.jetbrains.anko.startActivity
 
class LogisticsGuideActivity : TransparentStatusBarActivity(), PayListener {
    override fun setContentView() = R.layout.activity_logistics_guide
 
    private val webView by lazy { find<WebView>(R.id.webView) }
    private val tv_rule by lazy { find<TextView>(R.id.tv_rule) }
    private val tv_action by lazy { find<TextView>(R.id.tv_action) }
    private val cb_rule by lazy { find<CheckBox>(R.id.cb_rule) }
 
    private val carTypeId by lazy { intent.getIntExtra("carTypeId", 0) } //车型id
    private val goodsNum by lazy { intent.getIntExtra("goodsNum", 1) } //货物数量
    private val goodsType by lazy { intent.getIntExtra("goodsType", 1) } //货物类型(1=普通货物,2=贵重货物)
    private val startLat by lazy { intent.getDoubleExtra("startLat", 0.0) }
    private val startLon by lazy { intent.getDoubleExtra("startLon", 0.0) }
    private val endLat by lazy { intent.getDoubleExtra("endLat", 0.0) }
    private val endLon by lazy { intent.getDoubleExtra("endLon", 0.0) }
    private val receiveAddress by lazy { intent.getStringExtra("receiveAddress") }
    private val receiveName by lazy { intent.getStringExtra("receiveName") }
    private val receivePhone by lazy { intent.getStringExtra("receivePhone") }
    private val remark by lazy { intent.getStringExtra("remark") }
    private val startName by lazy { intent.getStringExtra("startName") }
    private val fastMoney by lazy { intent.getIntExtra("fastMoney", 0) } // 加急费用
    private val urgent by lazy { intent.getIntExtra("urgent", 1) }
    private val type by lazy {
        intent.getIntExtra("type", Const.OrderType.TYPE_SAME_CITY)
    } // 默认为同城物流
 
    private var isGotoWx = false //是否跳转到微信小程序支付 true:回来时需要查询是否支付成功
 
    private var isCancel = false
    private var balance = -1.0
    private var coupon = 0
    private var redTotal = 0.0
    private var deductionAmount = 0.0
    private var payMoney = 0.0//支付费用
    private var order: Order? = null
    private var id: Int = 0 // 订单id
 
    override fun initClick() {
        tv_rule.setOnClickListener {
            HttpManager.getH5(15).request(this, showDialog = true) { _, data ->
                val url = data?.optString("content") ?: ""
                startActivity<H5Activity>("url" to url, "title" to getString(R.string.邮寄快件指南))
            }
        }
        tv_action.setOnClickListener {
            if (cb_rule.isChecked) {
//                setResult(Activity.RESULT_OK)
//                finish()
                // 犟种测试非要在这支付
                createOrder()
            } else {
                myToast(getString(R.string.阅读并同意邮寄指南))
            }
        }
    }
 
    override fun initView() {
        title = getString(R.string.邮寄快件指南)
        if (LanguageUtil.getLanguage() == Const.Language.FRENCH) { //解决法文标题过长问题
            titleBar.titleView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f)
        }
        PayUtil.addPayListener(this)
        initWeb(webView)
        initRule()
    }
 
    //初始化规格
    private fun initRule() {
        HttpManager.getH5(15, Const.Language.CHINESE).request(this, showDialog = true) { _, data ->
            data?.optString("content")?.also {
                setContent(webView, it)
            }
        }
    }
 
    @SuppressLint("SetJavaScriptEnabled")
    private fun initWeb(webView: WebView) {
        webView.isHorizontalScrollBarEnabled = false
        //声明WebSettings子类
        val webSettings = webView.settings
        webSettings.domStorageEnabled = true //设置适应Html5
 
        //如果访问的页面中要与Javascript交互,则webview必须设置支持Javascript
        webSettings.javaScriptEnabled = true //允许js调用
        webSettings.allowContentAccess = true //是否允许在WebView中访问内容URL(Content Url),默认允许
 
        //缩放操作
        webSettings.setSupportZoom(false) //支持缩放,默认为true。是下面那个的前提。
        webSettings.builtInZoomControls = false //设置内置的缩放控件。若为false,则该WebView不可缩放
        webSettings.displayZoomControls = false //不显示缩放按钮
 
        //其他细节操作
        webSettings.cacheMode = WebSettings.LOAD_CACHE_ELSE_NETWORK //关闭webview中缓存
        webSettings.javaScriptCanOpenWindowsAutomatically = true //支持通过JS打开新窗口
        webSettings.loadsImagesAutomatically = true //支持自动加载图片
        webSettings.defaultTextEncodingName = "utf-8" //设置编码格式
 
        webView.setSafeSetting()//安全设置
    }
 
    @SuppressLint("SetJavaScriptEnabled")
    private fun setContent(webView: WebView, content: String?) {
        content?.let {
            // 加载并显示HTML代码
            webView.safeLoadDataWithBaseURL(
                null,
                content,
                "text/html",
                "utf-8",
                null
            )
        }
    }
 
    private fun createOrder() {
        HttpManager.smallLogistics(
            carTypeId,
            "$endLon,$endLat",
            goodsNum,
            goodsType,
            receiveAddress ?: "",
            IGoApplication.lat,
            IGoApplication.lon,
            receiveName ?: "",
            receivePhone ?: "",
            remark ?: "",
            startName ?: "",
            startLat,
            startLon,
            fastMoney,
            System.currentTimeMillis().toTime(),
            type,
            urgent
        ).request(this, showDialog = true) { _, data ->
            data?.run {
                id = optInt("id")
                getOrderInfo()
            }
        }
    }
 
    private fun getOrderInfo() {
        HttpManager.queryOrderInfo(id, type).request(this, showDialog = true) { _, data ->
            order = data
            queryBalance()
        }
    }
 
    /**
     * 查询余额和优惠券以供支付
     */
    private fun queryBalance() {
        HttpManager.queryBalance(id, type).request(this, showDialog = true) { _, data ->
            data?.let {
                isCancel = false
                balance = it.optDouble("balance")
                coupon = it.optInt("coupon")
                redTotal = it.optDouble("redTotal")
                deductionAmount = it.optDouble("deductionAmount")
 
                startPay()
            }
        }
    }
 
    private fun startPay() {
        val payDialog = PayDialog()
        payDialog.arguments = bundleOf(
            "isCancel" to false,
            "balance" to balance,
            "coupon" to coupon,
            "money" to order!!.orderMoney,
            "id" to id,
            "type" to type,
            "isFrozen" to (order?.isDispute == 1),
            "discount" to order?.discountMoney,
            "redTotal" to redTotal,
            "deductionAmount" to deductionAmount
        )
        payDialog.setCallback(object : PayDialog.Callback {
            override fun onOk(way: Int, couponId: Int, useRed: Boolean) {
                if (way == 2) {
                    val dialog = ChooseCardDialog()
                    dialog.setCallback(object : StringCallback {
                        override fun onRlt(rlt: String) {
                            pay(way, couponId, rlt, useRed)
                        }
                    })
                    dialog.show(supportFragmentManager, "card")
                } else {
                    pay(way, couponId, null, useRed)
                }
                payDialog.dismiss()
            }
 
            override fun onClose() {
            }
        })
        payDialog.show(supportFragmentManager, "pay")
    }
 
    /**
     * @param way 1=微信,2=支付宝,3=余额,4=现金
     */
    private fun pay(way: Int, couponId: Int, cardId: String?, useRed: Boolean) {
        tv_action.isEnabled = false
        HttpManager.payTaxiOrder(
            id, way, type, if (couponId == 0) null else couponId, cardId, if (useRed) 1 else 0
        ).request(this, showDialog = true, success = { _, data ->
 
            tv_action.isEnabled = true
            if (way in 3..4) {
                if (type == 4) {
                    Log.e("当前订单详情: ", "小件物流支付成功进入下个流程 ")
                    queryTripping()
                }
                onPaySuccess()
            } else {
                isGotoWx = true
                toBrowser(data.toString())
            }
        }) { _, _ ->
            tv_action.isEnabled = true
        }
    }
 
    /**
     * 查询是否有进行中的订单
     */
    fun queryTripping() {
        showDialog()
        HttpManager.queryServingOrder().request(this, false, showDialog = true) { _, data ->
            data?.let {
                if (it.isNotEmpty()) {
                    if (order?.state == 7 && order?.orderType == Const.OrderType.TYPE_CROSS_CITY) {
                        startActivity<PayCrossActivity>("id" to order?.orderId)
                    }
                    finish()
                }
            }
        }
    }
 
    override fun onPaySuccess() {
        myToast(getString(R.string.支付成功))
//        startActivity<OrderDetailActivity>("id" to id, "type" to type)
        startActivity<TripActivity>(
            "id" to order?.orderId,
            "type" to order?.orderType
        )
        finish()
    }
 
    override fun onPayCancel() {
    }
 
    override fun onResume() {
        super.onResume()
        if (isGotoWx) {
            isGotoWx = false
            HttpManager.queryOrderInfo(id, type).request(this, showDialog = true) { _, data ->
                if (data?.state == order?.state) {
                    myToast(getString(R.string.支付失败))
                } else {
                    onPaySuccess()
                }
            }
        }
    }
 
    override fun onDestroy() {
        super.onDestroy()
        PayUtil.removePayListener(this)
    }
}