18034727885
2026-06-21 f32d25d2a605df16abe0e53a1b43b74649bda668
app/src/main/java/com/xw/yunwei/ui/user/mine/scheduling/SchedulingVM.kt
@@ -3,11 +3,9 @@
import android.annotation.SuppressLint
import android.app.Application
import android.view.View
import androidx.core.os.bundleOf
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import com.xw.common.base.BaseViewModel
import com.xw.common.utils.ToastUtilCommon
import com.xw.yunwei.R
import com.xw.yunwei.model.ClockInStatusModel
import com.xw.yunwei.net.UserRepository
@@ -16,7 +14,6 @@
import java.time.LocalDate
import java.time.format.DateTimeFormatter
import java.util.Locale
import kotlin.getValue
@SuppressLint("SimpleDateFormat")
class SchedulingVM(application: Application) : BaseViewModel(application) {
@@ -24,25 +21,13 @@
    var today = ""
    val selectTime = MutableLiveData<String>()
    val yearMonth = selectTime.map {
        try {
            val inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
            val date = LocalDate.parse(it, inputFormatter)
            val outputFormatter = DateTimeFormatter.ofPattern("yyyy年M月", Locale.CHINESE)
            date.format(outputFormatter)
        } catch (e: Exception) {
            ""
        }
    }
    // 一周的中文以及格式化时间
    val showWeekDay: MutableLiveData<List<String>> = MutableLiveData()
    val showWeekDate: MutableLiveData<List<String>> = MutableLiveData()
    val yearMonth = MutableLiveData<String>()
    // 对应currentTime的打卡信息
    val clockModel: MutableLiveData<ClockInStatusModel?> = MutableLiveData()
    val clockTime = clockModel.map {
//        "${it?.xpShift?.startTime ?: ""} - ${it?.xpShift?.restStartTime ?: ""}  ${it?.xpShift?.restEndTime ?: ""} - ${it?.xpShift?.endTime ?: ""}"
        "${selectTime.value?:""} ${it?.xpShift?.startTime ?: ""}~${it?.xpShift?.endTime ?: ""}"
        "${selectTime.value ?: ""} ${it?.xpShift?.startTime ?: ""}~${it?.xpShift?.endTime ?: ""}"
    }
    val onClick = View.OnClickListener {
@@ -51,13 +36,6 @@
//                CheckInActivity::class.java,
//                bundleOf("clockModel" to clockModel.value)
//            )
            R.id.date1 -> selectTime.value = showWeekDate.value?.getOrNull(0) ?: ""
            R.id.date2 -> selectTime.value = showWeekDate.value?.getOrNull(1) ?: ""
            R.id.date3 -> selectTime.value = showWeekDate.value?.getOrNull(2) ?: ""
            R.id.date4 -> selectTime.value = showWeekDate.value?.getOrNull(3) ?: ""
            R.id.date5 -> selectTime.value = showWeekDate.value?.getOrNull(4) ?: ""
            R.id.date6 -> selectTime.value = showWeekDate.value?.getOrNull(5) ?: ""
            R.id.date7 -> selectTime.value = showWeekDate.value?.getOrNull(6) ?: ""
            R.id.clockIn -> startActivity(
                CheckInActivity::class.java,
                CheckInActivity.getParams(clockModel.value!!, 1)
@@ -76,36 +54,5 @@
                clockModel.postValue(it)
            }
        }
    }
    /**
     * 生成从输入日期开始后7天的星期名称
     * @param dateString 日期字符串
     */
    fun createNext7DaysWeekNames(dateString: String) {
        val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd")
        val startDate = LocalDate.parse(dateString, formatter)
        // 中文星期简写映射
        val weekDayMap = mapOf(
            java.time.DayOfWeek.MONDAY to "一",
            java.time.DayOfWeek.TUESDAY to "二",
            java.time.DayOfWeek.WEDNESDAY to "三",
            java.time.DayOfWeek.THURSDAY to "四",
            java.time.DayOfWeek.FRIDAY to "五",
            java.time.DayOfWeek.SATURDAY to "六",
            java.time.DayOfWeek.SUNDAY to "日"
        )
        val days = mutableListOf<String>()
        val weeks = mutableListOf<String>()
        (0 until 7).map { dayOffset ->
            val date = startDate.plusDays(dayOffset.toLong())
            days.add(date.format(formatter))  // 几号:24, 25, 26...
            weeks.add(weekDayMap[date.dayOfWeek] ?: "")
        }
        showWeekDate.value = days
        showWeekDay.value = weeks
    }
}