MedicalAddNewArchivesActivity.kt 5.54 KB
Newer Older
刘鹏 committed
1 2 3 4 5
package com.yidianling.medical.archives

import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
6
import android.view.*
刘鹏 committed
7
import com.ydl.ydlcommon.base.BaseActivity
刘鹏 committed
8
import com.ydl.ydlcommon.utils.StatusBarUtils
霍志良 committed
9
import com.ydl.ydlcommon.view.dialog.NormalDialog
刘鹏 committed
10 11
import com.yidianling.common.tools.ToastUtil
import com.yidianling.im.R
12
import com.yidianling.medical.utils.EditTextUtils
刘鹏 committed
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
import com.yidianling.uikit.custom.http.ServiceImpl
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.medical_add_new_archives_activity.*


/**
 * 新增问诊人
 * */
class MedicalAddNewArchivesActivity : BaseActivity() {


    companion object {
        var mMarried = -1
        var mRelation = -1

        @JvmStatic
        fun start(context: Context) {
            val starter = Intent(context, MedicalAddNewArchivesActivity::class.java)
            context.startActivity(starter)
        }
    }

    override fun layoutResId(): Int {
        return R.layout.medical_add_new_archives_activity
    }

    override fun initDataAndEvent() {
41 42
        mMarried = -1
        mRelation = -1
刘鹏 committed
43
        initStatus()
刘鹏 committed
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
        group_merried.setOnCheckedChangeListener { group, checkedId ->
            //婚姻状态
            when (checkedId) {
                R.id.married -> {
                    //已婚  1
                    mMarried = 1

                }
                R.id.unmarried -> {
                    //未婚  0
                    mMarried = 0
                }

                R.id.widowed -> {
                    //丧偶  2
                    mMarried = 2
                }
                R.id.divorce -> {
                    //离异  3
                    mMarried = 3
                }
                else -> {

                    mMarried = -1
                }
            }
        }
        group_relation.setOnCheckedChangeListener { group, checkedId ->
            //与本人关系
            when (checkedId) {
                R.id.me -> {
                    //本人  0
                    mRelation = 1

                }
                R.id.parent -> {
                    //父母  0
                    mRelation = 1
                }

                R.id.spouse -> {
                    //配偶  2
                    mRelation = 2
                }
                R.id.children -> {
                    //子女  3
                    mRelation = 3
                }
                R.id.other -> {
                    //其他  4
                    mRelation = 4
                }
                else -> {

                    mRelation = -1
                }
            }
        }


        add_archives_save.setOnClickListener {
            //保存新增问诊人
            checkInfo()
        }

109 110
        EditTextUtils.disableCopyAndPaste(et_name)

刘鹏 committed
111 112
        iv_back.setOnClickListener { finish() }

霍志良 committed
113
        showDialogTip()
刘鹏 committed
114
    }
刘鹏 committed
115

霍志良 committed
116 117 118
    private fun showDialogTip() {
        val builder = NormalDialog.Builder(this@MedicalAddNewArchivesActivity, "center", false)
        builder.setTitle("")
119 120 121 122
        var strs = arrayOf("就诊人的身份证号码", "就诊人的授权同意", "您需要在提供前征得该儿童监护人的同意")
        builder.setMessageAndBolds(
            "\n为向您添加的就诊人提供问诊服务,您需要向我们提供该就诊人的身份证号码,并确保在提供前已取得该就诊人的授权同意;若该就诊人为儿童的,您需要在提供前征得该儿童监护人的同意。\n",
            strs
刘鹏 committed
123
        )
霍志良 committed
124
        builder.setPositiveButton(
刘鹏 committed
125
            "同意"
霍志良 committed
126 127 128
        ) { dialog, which ->
            dialog.dismiss()
        }.setNegativeButton(
刘鹏 committed
129
            "不同意"
霍志良 committed
130
        ) { dialog, which ->
刘鹏 committed
131 132
            //关闭页面
            finish()
霍志良 committed
133 134 135
            dialog.dismiss()
        }
        builder.setRight_color("#3464EC")
刘鹏 committed
136
        builder.setLeft_color("#8595A9")
霍志良 committed
137
        builder.setContent_color("#10233A")
刘鹏 committed
138

霍志良 committed
139
        builder.create().show()
刘鹏 committed
140

霍志良 committed
141
    }
刘鹏 committed
142

刘鹏 committed
143 144 145
    @SuppressLint("CheckResult")
    private fun checkInfo() {
        if (et_name.text.isNullOrEmpty()) {
刘鹏 committed
146
            ToastUtil.toastShort("请填写姓名")
刘鹏 committed
147 148 149
            return
        }
        if (et_idcard.text.isNullOrEmpty()) {
刘鹏 committed
150
            ToastUtil.toastShort("请填写身份证号")
刘鹏 committed
151 152 153 154
            return
        }

        if (et_idcard.text.length < 15 || et_idcard.text.length > 18) {
刘鹏 committed
155
            ToastUtil.toastShort("请填写有效身份证号")
刘鹏 committed
156 157 158
            return
        }
        if (mMarried == -1) {
刘鹏 committed
159
            ToastUtil.toastShort("请选择婚姻状况")
刘鹏 committed
160 161 162
            return
        }
        if (mRelation == -1) {
刘鹏 committed
163
            ToastUtil.toastShort("请选择与就诊人的关系")
刘鹏 committed
164 165 166 167 168 169 170 171 172 173 174 175 176
            return
        }

        ServiceImpl.instance.createArchives(
            et_name.text.toString(),
            et_idcard.text.toString(),
            mMarried,
            mRelation
        )
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({
                if ("200" == it.code) {
刘鹏 committed
177
                    finish()
刘鹏 committed
178 179 180 181 182 183 184 185 186 187 188 189
                    ToastUtil.toastShort("保存成功")
                } else {
                    ToastUtil.toastShort(it.msg)
                }
            }, {
                it.printStackTrace()
                ToastUtil.toastShort("网络错误")
            })


    }

刘鹏 committed
190 191 192 193
    private fun initStatus() {
        StatusBarUtils.setTransparentForImageView(this@MedicalAddNewArchivesActivity, null)
        StatusBarUtils.statusBarLightMode(this@MedicalAddNewArchivesActivity)
    }
194

刘鹏 committed
195
}