package com.example.smart.ui.projectevent.widget
|
|
|
import android.annotation.SuppressLint
|
import android.app.Activity
|
import android.content.Context
|
|
import android.text.TextUtils
|
import android.util.AttributeSet
|
import android.view.LayoutInflater
|
import android.widget.LinearLayout
|
import androidx.fragment.app.FragmentActivity
|
import androidx.recyclerview.widget.LinearLayoutManager
|
import com.example.basecore.util.showCenterToast
|
import com.example.basecore.util.toast
|
import com.example.smart.R
|
import com.example.smart.bean.CommonOptionsBean
|
import com.example.smart.bean.EntityRef
|
import com.example.smart.bean.IdRef
|
import com.example.smart.bean.ImageRef
|
import com.example.smart.databinding.IssueAddUpdateWidgetBinding
|
import com.example.smart.enumlist.ErrorLevel
|
import com.example.smart.image.ImageProvider
|
import com.example.smart.ui.icondraw.DrawLiveData
|
import com.example.smart.ui.item.adapter.ImageShowAdapter
|
import com.example.smart.ui.item.bean.ImageBean
|
import com.example.smart.ui.project.ProjectDetailsActivity
|
import com.example.smart.ui.project.issue.bean.IssueBean
|
import com.example.smart.ui.project.issue.bean.IssueDetailBean
|
import com.example.smart.ui.projectevent.bean.ProblemRecordBean
|
import com.example.smart.ui.projectevent.bean.ReviewBean
|
import com.example.smart.ui.projectevent.event.IIssueEvent
|
import com.example.smart.ui.projectevent.pop.IssueReviewPopupWindow
|
import com.example.smart.widget.common.ICommonDataEvent
|
import com.example.smart.widget.dialog.CommonDialog
|
import com.example.smart.widget.dialog.list.CommListDialog
|
import com.example.smart.widget.dialog.list.CommonListBean
|
|
|
/**
|
* @description: 添加问题&修改问题view
|
*/
|
class IssueWidget @JvmOverloads constructor(
|
val mContext: Context,
|
attrs: AttributeSet? = null,
|
defStyleAttr: Int = 0,
|
) : LinearLayout(mContext, attrs, defStyleAttr), IIssueEvent {
|
|
private var onClickEvent: OnClickEvent? = null
|
|
private var canReview = false
|
|
private var issueDetailBean: IssueDetailBean? = null
|
private var issueBean: IssueBean? = null
|
|
private var dValue: Double = 0.0
|
private var cValue: Double = 0.0
|
private var rnValue: Double = 0.0
|
private var taskId = -1
|
|
private val specificTerms = ArrayList<CommonListBean>()
|
|
fun bindEvent(onClickEvent: OnClickEvent) {
|
this.onClickEvent = onClickEvent
|
}
|
|
private val mImageProvider by lazy {
|
ImageProvider(mContext as Activity, ImageCallBack())
|
}
|
|
private inner class ImageCallBack : ImageProvider.IImageCallback {
|
|
override fun onUploadSuccess(entityRef: List<ImageRef>) {
|
adapter.notifyData(entityRef)
|
// mImagePaths.addAll(entityRef)
|
}
|
|
override fun onUploadFailed() {
|
mContext.showCenterToast("图片上传失败,请稍后再试...")
|
}
|
}
|
|
private lateinit var adapter: ImageShowAdapter
|
|
private val mImageList = ArrayList<ImageBean>()
|
|
// private val mImagePaths = ArrayList<ImageRef>()
|
|
private val binding by lazy(LazyThreadSafetyMode.NONE) {
|
IssueAddUpdateWidgetBinding.bind(this)
|
}
|
|
init {
|
LayoutInflater.from(mContext).inflate(R.layout.issue_add_update_widget, this)
|
initView()
|
addListener()
|
DrawLiveData.observeForever { drawData ->
|
adapter.updateDrawData(drawData)
|
}
|
}
|
|
override fun onDetachedFromWindow() {
|
super.onDetachedFromWindow()
|
DrawLiveData.removeObserver { }
|
}
|
|
|
private fun initView() {
|
orientation = VERTICAL
|
with(binding) {
|
recyclerView.layoutManager =
|
LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)
|
adapter = ImageShowAdapter(mContext, mImageList)
|
recyclerView.adapter = adapter
|
|
recyclerView.isNestedScrollingEnabled = false
|
recyclerView.setHasFixedSize(false)
|
|
val listener = ItemClick()
|
clauseWidget.getContentView().setOnClickListener {
|
if (mContext is FragmentActivity) {
|
if (issueDetailBean == null) {
|
return@setOnClickListener
|
}
|
if (specificTerms.isEmpty()) {
|
mContext.showCenterToast("规范条款内容为空")
|
return@setOnClickListener
|
}
|
|
val listDialog = CommListDialog(specificTerms, listener)
|
listDialog.show(mContext.supportFragmentManager, "123")
|
|
// val dialog = Co
|
// mmonDialog()
|
// .setContent(specificItem.toString())
|
// dialog.show(mContext.supportFragmentManager, "123")
|
}
|
}
|
|
reviewLayout.visibility = GONE
|
}
|
}
|
|
|
private fun addListener() {
|
binding.apply {
|
takePhotoLayout.setOnClickListener {
|
if (issueDetailBean == null) {
|
mContext.showCenterToast("数据错误,请稍后再试")
|
return@setOnClickListener
|
}
|
mImageProvider.showImageSelect()
|
}
|
deleteTv.setOnClickListener {
|
if (mContext is ProjectDetailsActivity) {
|
//获取任务id
|
if (!(mContext).canUpdateTask()) {
|
return@setOnClickListener
|
}
|
}
|
val dialog = CommonDialog().setContent("确定要删除问题?").setCertainListener {
|
onClickEvent?.onDelete(issueBean?.id ?: "")
|
}
|
if (mContext is FragmentActivity) {
|
dialog.show(mContext.supportFragmentManager, "1")
|
}
|
}
|
|
editTv.setOnClickListener {
|
|
checkParams()?.let {
|
onClickEvent?.onEdit(it)
|
}
|
// if (binding.editTv.text == "编辑") {//防误触
|
// editTv.text = "保存"
|
// maskView.visibility = GONE
|
// } else {
|
// checkParams()?.let {
|
// onClickEvent?.onEdit(it)
|
// }
|
// }
|
}
|
|
submitTv.setOnClickListener {
|
if (canReview) {
|
if (issueBean == null) {
|
mContext.toast("数据错误")
|
return@setOnClickListener
|
}
|
val pop = IssueReviewPopupWindow(mContext, issueBean!!.id)
|
pop.showPopupWindow()
|
} else {
|
checkParams()?.let {
|
onClickEvent?.onAdd(it)
|
}
|
}
|
}
|
//拦截底部点击事件
|
maskView.setOnClickListener {
|
|
}
|
|
//人为不可以选择
|
// levelWidget.setDataEvent(object : ICommonDataEvent {
|
// override fun onClickView(containerId: String) {
|
//
|
// }
|
//
|
// })
|
//
|
countWidget.setDataEvent(object : ICommonDataEvent {
|
override fun onClickView(containerId: String) {
|
// cValue = containerId.toDouble()
|
cValue = issueDetailBean?.numberFactors?.get(containerId.toInt())?.value ?: 0.0
|
updateErrorLevel()
|
}
|
|
})
|
scaleWidget.setDataEvent(object : ICommonDataEvent {
|
override fun onClickView(containerId: String) {
|
// rnValue = containerId.toDouble()
|
rnValue = issueDetailBean?.scaleFactors?.get(containerId.toInt())?.factor ?: 0.0
|
updateErrorLevel()
|
}
|
})
|
// clauseWidget.setDataEvent(object :ICommonDataEvent {
|
// override fun onClickView(containerId: String) {
|
//
|
// }
|
// })
|
}
|
}
|
|
private class ItemClick : CommListDialog.ItemClickListener {
|
override fun onItemClick(bean: CommonListBean) {
|
|
}
|
|
}
|
|
private fun checkParams(): ProblemRecordBean? {
|
with(binding) {
|
if (TextUtils.isEmpty(positionWidget.getContent())) {
|
mContext.showCenterToast("请输入问题部位")
|
return null
|
}
|
}
|
if (issueDetailBean == null) {
|
mContext.showCenterToast("数据错误,请稍后再试")
|
return null
|
}
|
val issueParam = generateIssueParam(issueDetailBean!!.id)
|
return issueParam
|
}
|
|
|
private fun generateIssueParam(id: Int): ProblemRecordBean {
|
val array = mutableListOf<Int>()
|
specificTerms.forEach {
|
if (it.checked) {
|
array.add(it.id.toInt())
|
}
|
}
|
val numIndex = binding.countWidget.getContainerId().toInt()
|
val scaleIndex = binding.scaleWidget.getContainerId().toInt()
|
val errorRecordId = issueBean?.id ?: ""
|
|
val list = ArrayList<IdRef>()
|
if (mImageList.isNotEmpty()) {
|
for (data in mImageList) {
|
list.add(IdRef(data.uri))
|
}
|
}
|
var device:EntityRef? = null
|
if (issueBean != null && issueBean!!.device != null) {
|
device = EntityRef(issueBean!!.device!!.id)
|
}
|
return ProblemRecordBean(
|
errorRecordId,
|
EntityRef(taskId),
|
EntityRef(id),
|
device = device,
|
images = list,
|
numberFactorIndex = numIndex,
|
scaleFactorIndex = scaleIndex,
|
specificTermIndexes = array,
|
problemPart = binding.positionWidget.getContent(),
|
suggestion = binding.suggestEdt.text.toString(),
|
remark = binding.remarkWidget.getContent(),
|
responsiblePerson = binding.personWidget.getContent()
|
)
|
}
|
|
/**
|
* 更新数据
|
*/
|
@SuppressLint("SetTextI18n")
|
fun updateData(taskId: Int, infoBean: IssueDetailBean, bean: IssueBean?) {
|
issueDetailBean = infoBean
|
this.taskId = taskId
|
this.issueBean = bean
|
with(binding) {
|
describeWidget.setContentTxt(infoBean.description)
|
remarkWidget.setEditTxt(infoBean.remark)
|
|
var suggest = ""
|
infoBean.suggestActions?.forEach {
|
suggest += it + "\n"
|
}
|
suggestEdt.setText(suggest)
|
|
departmentWidget.setContentTxt(infoBean.responsibleDepartment)
|
|
//数量
|
val countOptions = mutableListOf<CommonOptionsBean>()
|
for ((index, item) in infoBean.numberFactors.withIndex()) {
|
countOptions.add(CommonOptionsBean(index.toString(), item.name))
|
}
|
|
countWidget.bindData(countOptions)
|
|
//规模
|
val scaleOptions = mutableListOf<CommonOptionsBean>()
|
for ((index, item) in infoBean.scaleFactors.withIndex()) {
|
scaleOptions.add(CommonOptionsBean(index.toString(), item.name))
|
}
|
scaleWidget.bindData(scaleOptions)
|
|
//条款
|
// val clauseOptions = mutableListOf<CommonOptionsBean>()
|
// infoBean.specificTerms.forEach {
|
// clauseOptions.add(CommonOptionsBean(it, it))
|
// }
|
// clauseWidget.bindData(clauseOptions)
|
|
|
infoBean.specificTerms?.let { terms ->
|
if (terms.isNotEmpty()) {
|
clauseWidget.setContentTxt(terms[0])
|
for (i in terms.indices) {
|
specificTerms.add(CommonListBean(i.toString(), terms[i]))
|
}
|
}
|
}
|
|
if (infoBean.numberFactors.isNotEmpty() && infoBean.scaleFactors.isNotEmpty()) {
|
dValue = issueDetailBean!!.numValue;
|
cValue = infoBean.numberFactors[0].value
|
rnValue = infoBean.scaleFactors[0].factor
|
updateErrorLevel()
|
}
|
|
|
//以下是编辑问题
|
|
if (bean == null) {
|
submitTv.visibility = VISIBLE
|
deleteTv.visibility = GONE
|
editTv.visibility = GONE
|
return
|
} else {
|
submitTv.visibility = GONE
|
deleteTv.visibility = VISIBLE
|
editTv.visibility = VISIBLE
|
}
|
|
val issueBean = bean
|
|
countWidget.setDataById(issueBean.numberFactorIndex.toString())
|
scaleWidget.setDataById(issueBean.scaleFactorIndex.toString())
|
cValue = infoBean.numberFactors[issueBean.numberFactorIndex].value
|
rnValue = infoBean.scaleFactors[issueBean.scaleFactorIndex].factor
|
|
infoBean.specificTerms?.let { terms ->
|
specificTerms.forEach {
|
for (item in terms) {
|
it.checked = item == it.name
|
}
|
}
|
}
|
|
|
if (issueBean.device != null) {
|
if (issueBean.device.id > 0 ){
|
deviceWidget.setContentTxt(issueBean.device.name)
|
deviceWidget.visibility = VISIBLE
|
}
|
}
|
personWidget.setEditTxt(issueBean.responsiblePerson)
|
positionWidget.setEditTxt(issueBean.problemPart)
|
suggestEdt.setText(issueBean.suggestion)
|
remarkWidget.setEditTxt(issueBean.remark)
|
|
|
commitLayout.visibility = VISIBLE
|
submitterTv.text = "提交人: " + issueBean.creator?.name
|
timeTv.text = "提交时间: ${issueBean.createTime}"
|
levelWidget.setContentTxt(issueBean.level.desc)
|
|
|
if (!issueBean.images.isNullOrEmpty()) {
|
for (data in issueBean.images) {
|
mImageList.add(ImageBean(data.id.toString(), data.name))
|
}
|
adapter.notifyData()
|
}
|
|
if (mContext is ProjectDetailsActivity) {
|
if (mContext.canReviewTask()) {
|
submitTv.visibility = VISIBLE
|
deleteTv.visibility = GONE
|
editTv.visibility = GONE
|
submitTv.text = "复核"
|
canReview = true
|
}
|
}
|
}
|
}
|
|
@SuppressLint("SetTextI18n")
|
fun bindReviewData(reviewBean: ReviewBean) {
|
binding.reviewLayout.visibility = VISIBLE
|
val list = ArrayList<ImageBean>()
|
reviewBean.images.forEach {
|
list.add(ImageBean(it.id.toString(), it.name))
|
}
|
binding.recyclerViewReview.layoutManager =
|
LinearLayoutManager(mContext, LinearLayoutManager.HORIZONTAL, false)
|
val adapter = ImageShowAdapter(mContext, list, false)
|
binding.recyclerViewReview.adapter = adapter
|
|
// binding.reviewInfoTv.text = "复核情况:${reviewBean.content}"
|
val state = reviewBean.state.desc
|
binding.reviewStateTv.text = "复核状态:${state}"
|
val time = if (reviewBean.createTime.isEmpty()) {
|
reviewBean.updateTime
|
} else{
|
reviewBean.createTime
|
}
|
binding.reviewTimeTv.text = "复核时间:${time}"
|
|
binding.reviewOpinionTv.text = "复核建议:${reviewBean.content}"
|
|
}
|
|
|
fun updateErrorLevel() {
|
val level = calcErrorLevel(dValue, cValue, rnValue)
|
binding.levelWidget.setContentTxt(level.desc)
|
}
|
|
/**
|
* 隐患等级计算
|
*/
|
private fun calcErrorLevel(d: Double, c: Double, rn: Double): ErrorLevel {
|
val l: Double = d * c * rn
|
return if (l > 24) {
|
ErrorLevel.P1
|
} else if (l > 12) {
|
ErrorLevel.P2
|
} else if (l > 4) {
|
ErrorLevel.P3
|
} else {
|
ErrorLevel.P4
|
}
|
}
|
|
|
interface OnClickEvent {
|
fun onEdit(infoBean: ProblemRecordBean)
|
|
fun onDelete(errorRecordId: String)
|
|
fun onAdd(infoBean: ProblemRecordBean)
|
|
}
|
|
}
|