comoros.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div>
  3. <div @click="visibleFun">
  4. <slot>
  5. <div class="comoros-input">
  6. <div v-if="!Object.keys(data).length" class="comoros-input-empty">
  7. <div>选择云手机</div>
  8. <img src="@/assets/image/transferDuration/arrow-right.png" alt="" class="comoros-input-empty-img" />
  9. </div>
  10. <div v-else>
  11. <div class="comoros-list-item_left" style="margin: 0 12px;">
  12. <img :src="require(`@/assets/image/transferDuration/${data.buyVipType}_icon.png`)" alt=""
  13. class="comoros-list-item_left-img" />
  14. <div>
  15. <div class="comoros-list-item_left-title">{{ data.diskName }}</div>
  16. <div v-if="data.userCardType === 1" class="comoros-list-item_left-tips">
  17. 剩{{ timeStamp(data.validTime, item.userCardType) }}
  18. </div>
  19. <div v-else-if="data.validTime > 0"
  20. :class="['comoros-list-item_left-tips', { 'red-time': item.validTime <= 4320 }]">
  21. 剩{{ timeStamp(data.validTime, data.userCardType) }}</div>
  22. <div v-else class="comoros-list-item_left-tips red-time">已过期</div>
  23. </div>
  24. </div>
  25. </div>
  26. </div>
  27. </slot>
  28. </div>
  29. <van-popup v-model="visible" position="bottom">
  30. <div class="comoros-list">
  31. <div style="display: flex;justify-content: space-between;margin-bottom: 16px;">
  32. <div>请选择云手机</div>
  33. </div>
  34. <div class="comoros-list-container">
  35. <van-checkbox-group v-model="id" ref="checkboxGroup" v-if="filterTransferPhoneList.length">
  36. <div v-for="item in filterTransferPhoneList" :key="item.id" class="comoros-list-item">
  37. <div class="comoros-list-item_left">
  38. <img :src="require(`@/assets/image/transferDuration/${item.buyVipType}_icon.png`)" alt=""
  39. class="comoros-list-item_left-img" />
  40. <div>
  41. <div class="comoros-list-item_left-title">{{ item.diskName }}</div>
  42. <div v-if="item.userCardType === 1" class="comoros-list-item_left-tips">
  43. 剩{{ timeStamp(item.validTime, item.userCardType) }}
  44. </div>
  45. <div v-else-if="item.validTime > 0"
  46. :class="['comoros-list-item_left-tips', { 'red-time': item.validTime <= 4320 }]">
  47. 剩{{ timeStamp(item.validTime, item.userCardType) }}</div>
  48. <div v-else class="comoros-list-item_left-tips red-time">已过期</div>
  49. </div>
  50. </div>
  51. <div class="comoros-list-item_right"><van-checkbox :name="item.id" shape="square"
  52. icon-size="15px" @click="changeCheckbox(item)"></van-checkbox></div>
  53. </div>
  54. </van-checkbox-group>
  55. <div v-else style="height: 100%;display: flex;align-self: center;justify-content: center;">
  56. <van-empty description="暂时没有数据哦~"></van-empty>
  57. </div>
  58. </div>
  59. <div class="comoros-list-btn">
  60. <van-button type="info" block :disabled="!id.length" @click="confirm">确认</van-button>
  61. </div>
  62. </div>
  63. </van-popup>
  64. </div>
  65. </template>
  66. <script>
  67. export default {
  68. name: 'comoros',
  69. props: {
  70. // 云机数据
  71. transferPhoneList: {
  72. type: Array,
  73. default: () => {
  74. return []
  75. }
  76. },
  77. // 已选择的云机类型
  78. buyVipType: {
  79. type: String,
  80. default: ''
  81. },
  82. // 过滤类型
  83. filterType: {
  84. type: String,
  85. default: ''
  86. },
  87. value: {
  88. type: [String, Number],
  89. default: ''
  90. },
  91. // 不能勾选需要过滤的云机
  92. disabledId: {
  93. type: [String, Number],
  94. default: ''
  95. },
  96. // 云机名字
  97. name: {
  98. type: String,
  99. default: ''
  100. },
  101. // distinguishBool false是减少、true是增加时长云机列表
  102. distinguishBool: {
  103. type: Boolean,
  104. default: false
  105. },
  106. dayTime: {
  107. type: [String, Number],
  108. default: ''
  109. }
  110. },
  111. data() {
  112. return {
  113. // 显示弹窗
  114. visible: false,
  115. // 选中的数据
  116. id: [],
  117. // vip类型
  118. vipType: '',
  119. data: {},
  120. item: {}
  121. };
  122. },
  123. computed: {
  124. // 过滤云机
  125. filterTransferPhoneList() {
  126. return this.transferPhoneList.filter(item => {
  127. if (this.distinguishBool) {
  128. return this.filterType ? this.disabledId !== item.id : true
  129. } else {
  130. return this.dayTime ? item.validTime > +this.dayTime : true
  131. }
  132. })
  133. }
  134. },
  135. methods: {
  136. // 点击显示弹框
  137. visibleFun() {
  138. this.visible = true
  139. this.id = this.value ? [this.value] : []
  140. this.vipType = this.buyVipType
  141. setTimeout(() => {
  142. const documents = document.getElementsByClassName('comoros-list-container')
  143. const length = documents.length
  144. for (let i = 0; i < length; i++) {
  145. documents[i].scrollTop = 0
  146. }
  147. })
  148. },
  149. // 转化时长
  150. timeStamp(StatusMinute, userCardType, nextSendTime) {
  151. var day = parseInt(StatusMinute / 60 / 24);
  152. var hour = parseInt((StatusMinute / 60) % 24);
  153. var min = parseInt(StatusMinute % 60);
  154. StatusMinute = '';
  155. if (day > 0) {
  156. StatusMinute = day + '天';
  157. }
  158. if (hour > 0) {
  159. StatusMinute += hour + '小时';
  160. }
  161. if (day === 0 && min > 0) {
  162. StatusMinute += parseFloat(min) + '分钟';
  163. }
  164. return StatusMinute.length ? StatusMinute : userCardType === 1 ? '0小时' : '';
  165. },
  166. // 点击复选框触发
  167. changeCheckbox(data) {
  168. if (!this.id.length) return
  169. if (this.id.includes(data.id)) {
  170. this.id = []
  171. }
  172. this.id = [data.id]
  173. this.vipType = data.buyVipType
  174. this.item = data
  175. },
  176. // 确认选择云机
  177. confirm() {
  178. this.visible = false
  179. this.$emit('input', this.id[0])
  180. this.$emit('update:buyVipType', this.vipType)
  181. this.data = this.item
  182. this.$emit('update:name', this.item.diskName)
  183. this.$emit('confirm')
  184. }
  185. },
  186. };
  187. </script>
  188. <style lang="scss" scoped>
  189. .comoros-input {
  190. margin-top: 8px;
  191. height: 52px;
  192. background: #2C2C2D;
  193. border-radius: 8px;
  194. // line-height: 52px;
  195. display: flex;
  196. align-items: center;
  197. font-size: 12px;
  198. .comoros-input-empty {
  199. width: 100%;
  200. margin: 0 12px;
  201. display: flex;
  202. justify-content: space-between;
  203. .comoros-input-empty-img {
  204. width: 16px;
  205. height: 16px;
  206. }
  207. }
  208. }
  209. .comoros-list {
  210. background: #fff;
  211. margin: 0 10px;
  212. background: #2C2C2D;
  213. border-radius: 20px 20px 0 0;
  214. padding: 24px 16px 8px;
  215. color: #CFD1D4;
  216. height: 60vh;
  217. overflow-y: auto;
  218. display: flex;
  219. flex-direction: column;
  220. ::v-deep .van-checkbox__label {
  221. color: #CFD1D4;
  222. }
  223. .comoros-list-container {
  224. flex: 1;
  225. overflow-y: auto;
  226. .comoros-list-item {
  227. box-sizing: border-box;
  228. padding: 16px 16px 16px 10px;
  229. height: 65px;
  230. background: #363636;
  231. border-radius: 6px;
  232. margin-top: 12px;
  233. display: flex;
  234. justify-content: space-between;
  235. .comoros-list-item_right {
  236. display: flex;
  237. align-items: center;
  238. }
  239. }
  240. }
  241. .comoros-list-btn {
  242. margin: 16px 0 9px;
  243. }
  244. }
  245. .comoros-list-item_left {
  246. display: flex;
  247. vertical-align: middle;
  248. font-size: 14px;
  249. line-height: 18px;
  250. .comoros-list-item_left-img {
  251. width: 34px;
  252. height: 34px;
  253. vertical-align: middle;
  254. margin-right: 8px;
  255. }
  256. .comoros-list-item_left-tips {
  257. &>img {
  258. width: 12px;
  259. height: 12px;
  260. margin-bottom: 2px;
  261. margin-right: 5px;
  262. vertical-align: middle;
  263. }
  264. font-size: 12px;
  265. font-weight: 100;
  266. vertical-align: middle;
  267. &.red-time {
  268. color: #F04646;
  269. }
  270. }
  271. }
  272. ::v-deep .van-popup {
  273. background: transparent;
  274. }
  275. </style>