Pu Zhibing
2025-06-25 844fc3910b72130f79480714bcba98106d8f9177
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
package com.ziang.driver.ui.mine
 
import androidx.recyclerview.widget.GridLayoutManager
import cn.sinata.xldutils.utils.getContent
import cn.sinata.xldutils.utils.gone
import cn.sinata.xldutils.utils.setTextChange
import com.google.gson.Gson
import com.ziang.driver.R
import com.ziang.driver.base.BaseEvent
import com.ziang.driver.base.local.BasePhotoActivity
import com.ziang.driver.netUtls.Api
import com.ziang.driver.netUtls.callNet
import com.ziang.driver.netUtls.getMapByAny
import com.ziang.driver.ui.adapter.PhotoAdapter
import kotlinx.android.synthetic.main.activity_feedback_order.*
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.toast
 
class ComplainOrderActivity: BasePhotoActivity() {
    override fun setContentView() {
        setContentView(R.layout.activity_feedback_order)
    }
 
    private val orderId by lazy { intent.getIntExtra("id",0) }
    private val orderType by lazy { intent.getIntExtra("type",0) }
    private val isBack by lazy { intent.getIntExtra("isBack",0) } //isBack ==1 已投诉
    private val isReturn by lazy { intent.getBooleanExtra("isReturn",false) } //是否申请退款
 
    private val photoAdapter = PhotoAdapter()
 
    override fun initView() {
        setTitleText("投诉反馈")
        if (isBack == 1){
            et_content.isEnabled = false
            photoAdapter.editAble = false
            tv_hint.text = ""
            val mapByAny = getMapByAny()
            mapByAny["id"] = orderId
            callNet(Api.backreson,mapByAny){
                val fromJson = Gson().fromJson<ComplainBean>(it, ComplainBean::class.java).data
                et_content.setText(fromJson.backReason)
                photoAdapter.data.addAll(fromJson.pic.split(",").filter { !it.isNullOrEmpty() })
                tv_hint.text = ""
                tv_Right.setOnClickListener {  }
                photoAdapter.notifyDataSetChanged()
            }
        }else{
            tv_Right.text = "提交"
            photoAdapter.data.add("")
        }
        rv_photo.layoutManager = GridLayoutManager(this,3)
        rv_photo.adapter = photoAdapter
 
        if(isReturn){
            setTitleText("申请退款")
            rv_photo.gone()
            et_content.hint = "请填写退款原因"
        }
    }
 
    override fun setOnclick() {
        tv_Right.setOnClickListener {
            if (et_content.getContent().isEmpty()){
                toast("请输入内容")
                return@setOnClickListener
            }
            var map = getMapByAny()
            if (isReturn){
                map["orderType"] = orderType
                map["orderId"] = orderId
                map["reason"] = et_content.getContent()
                callNet(Api.addDriverApplyRefund,map){
                    toast("提交成功")
                    onBackPressed()
                }
            }else{
                map["id"] = orderId
                map["backReason"] = et_content.getContent()
                map["backPic"] = photoAdapter.data.filter { !it.isNullOrEmpty() }.joinToString(",") { it }
                callNet(Api.orderFeedback,map){
                    EventBus.getDefault().post(BaseEvent(BaseEvent.COMPLAIN_SUC,orderId))
                    toast("提交成功")
                    onBackPressed()
                }
            }
        }
        et_content.setTextChange {
            tv_hint.text = "还可以输入"+(200 - it.length)+"个字"
        }
    }
 
    override fun getPhoneUrl(url: String, type: Int, path: String) {
        super.getPhoneUrl(url, type, path)
        photoAdapter.data.add(photoAdapter.data.lastIndex,url)
        if (photoAdapter.data.size > 3)
            photoAdapter.data.remove("")
        photoAdapter.notifyDataSetChanged()
    }
 
    data class ComplainBean(
        val code: Int,
        val `data`: Data,
        val msg: String
    )
 
    data class Data(
        val backReason: String,
        val pic: String
    )
}