TibetanDetailsVModel.kt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package com.hdl.xl.vmodel
  2. import android.app.Activity
  3. import android.app.Application
  4. import android.content.ClipData
  5. import android.content.ClipboardManager
  6. import android.content.Context
  7. import android.text.TextUtils
  8. import android.view.View
  9. import android.widget.LinearLayout
  10. import androidx.lifecycle.MutableLiveData
  11. import androidx.lifecycle.viewModelScope
  12. import com.hdl.xl.model.MyOrderListDetail
  13. import com.hdl.xl.model.PayOrder
  14. import com.ysnows.base.base.BRepository
  15. import com.ysnows.base.base.BViewModel
  16. import com.hdl.xl.model.TibetaDetails
  17. import com.hdl.xl.utils.PopuBuyUtils
  18. import com.hdl.xl.utils.PopuDownWxUtils
  19. import com.hdl.xl.utils.net.NetEngine
  20. import kotlinx.coroutines.launch
  21. class TibetanDetailsVModel(application: Application) : BViewModel<BRepository>(application) {
  22. var ll: LinearLayout? = null
  23. var id:String?=null
  24. var link= MutableLiveData<String>()
  25. var linkName= MutableLiveData<String>()
  26. var data= MutableLiveData<TibetaDetails>()
  27. //倒计时
  28. var isUp = true
  29. var time = MutableLiveData<String>()
  30. var bean=MutableLiveData<PayOrder>()
  31. var is_remind=MutableLiveData<Boolean>()
  32. //支付成功后是否显示弹框
  33. var myBean=MutableLiveData<MyOrderListDetail>()
  34. fun toCopy(){
  35. if(TextUtils.isEmpty(link.value)){
  36. toast("合约地址为空")
  37. return
  38. }
  39. val cm: ClipboardManager? = repository().context?.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager?
  40. val mClipData = ClipData.newPlainText("Label",link.value )
  41. cm?.setPrimaryClip(mClipData)
  42. toast("文字已复制到粘贴板")
  43. }
  44. fun toClose(){
  45. (repository().context as Activity).finish()
  46. }
  47. fun getInfoTo(){
  48. viewModelScope.launch {
  49. var it=repository().preq { NetEngine.service.CollectionDetail(id) }
  50. if(it.ok()){
  51. data.value=it.data
  52. is_remind.value=it.data?.is_remind
  53. }
  54. }
  55. }
  56. //
  57. // fun getInfo(){
  58. // viewModelScope.launch {
  59. // var it=repository().lreq { NetEngine.service.CollectionDetail(id) }
  60. // if(it.ok()){
  61. //
  62. // data.value=it.data
  63. // is_remind.value=it.data?.is_remind
  64. //
  65. // }
  66. //
  67. // }
  68. // }
  69. var popuBuyUtils:PopuBuyUtils?=null
  70. fun toBuy(view :View){//支付弹框
  71. popuBuyUtils= PopuBuyUtils
  72. popuBuyUtils?.show(repository().context!!, data.value?.cover,data.value?.name,data.value?.price,data.value?.buy_count, view)
  73. // PopuBuyUtils.show(repository().context!!, data.value?.cover,data.value?.name,data.value?.price, view)
  74. }
  75. fun getUrl() {
  76. toShareCode(data.value?.cover)
  77. }
  78. fun toShareCode(shareUrl: String?) {
  79. if (TextUtils.isEmpty(shareUrl)) {
  80. return
  81. }
  82. PopuDownWxUtils.show(repository().context!!,
  83. shareUrl!!,data.value?.name,data.value?.id,
  84. "https://xlapi.xiangliannft.com/h5/pages/index/goodsinfo",
  85. ll!!,repository().context!!.contentResolver)
  86. // PopuShareWxUtils.show(repository().context!!, shareUrl!!, ll!!,repository().context!!.contentResolver)
  87. }
  88. fun getCertificate(){
  89. viewModelScope.launch {
  90. var it=repository().lreq { NetEngine.service.certificate() }
  91. if(it.ok()){
  92. link.value=it.data?.link
  93. linkName.value=it.data?.name
  94. }
  95. }
  96. }
  97. //设置购买提醒
  98. fun toBuyTime(){
  99. viewModelScope.launch {
  100. var it=repository().lreq { NetEngine.service.setRemind(data.value?.id) }
  101. if(it.ok(true)){
  102. //刷新
  103. is_remind.value=true
  104. }
  105. }
  106. }
  107. fun toPayOrder(order_no:String?,from:String?){
  108. viewModelScope.launch {
  109. var it=repository().lreq { NetEngine.service.payOrder(order_no,from) }
  110. if(it.code==0){
  111. toast(it.msg)
  112. return@launch
  113. }
  114. if(it.ok(true)){
  115. popuBuyUtils?.setDisMiss()
  116. if("sd" == from) {//杉德支付
  117. bean.value = it.data
  118. }else{
  119. //刷新数据
  120. getMyOrder(order_no)
  121. }
  122. }
  123. }
  124. }
  125. fun getMyOrder(order_no:String?){
  126. viewModelScope.launch {
  127. var it = repository().lreq { NetEngine.service.setMyOrderListDetail(order_no, "2") }
  128. if (it.ok()) {
  129. myBean.value = it.data
  130. }
  131. }
  132. }
  133. }