index.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <template>
  2. <van-popup
  3. v-model="visible"
  4. v-bind="$attrs"
  5. v-on="$listeners"
  6. :position="position"
  7. :style="{ background: 'transparent' }"
  8. >
  9. <div class="cloud-mobile-phone_popup" :style="{ background }">
  10. <div class="cloud-mobile-phone_popup-title">
  11. <div class="cloud-mobile-phone_popup-title_left">
  12. <slot name="left">
  13. <div>
  14. {{ titleText }}
  15. </div>
  16. </slot>
  17. </div>
  18. <slot>
  19. <van-checkbox
  20. shape="square"
  21. v-model="checkboxAll"
  22. @change="changeCheckboxAll"
  23. icon-size="16px"
  24. >全选</van-checkbox
  25. >
  26. </slot>
  27. </div>
  28. <div class="cloud-mobile-phone_popup-content">
  29. <div v-if="data.length">
  30. <van-checkbox-group icon-size="16px" v-model="selectIds">
  31. <van-list
  32. v-model="asyncListLoading"
  33. @load="onLoad"
  34. :finished="finished"
  35. offset="10"
  36. :immediate-check="false"
  37. >
  38. <div
  39. :style="{
  40. background: backgroundItem,
  41. marginTop: index !== 0 ? '12px' : '',
  42. }"
  43. v-for="(item, index) in data"
  44. :key="item.id"
  45. class="cloud-mobile-phone_popup-content_item"
  46. >
  47. <div class="cloud-mobile-phone_popup-content_item-left">
  48. <img :src="require(`@/assets/image/${item.buyVipType}_icon.png`)" alt="" />
  49. <div>
  50. <div>{{ item.diskName }}</div>
  51. <div>
  52. <img src="@/assets/image/phone_time.png" alt="" />
  53. 剩{{ timeStamp(item.validTime, item.userCardType) }}
  54. </div>
  55. </div>
  56. </div>
  57. <div class="cloud-mobile-phone_popup-content_item-right">
  58. <van-checkbox
  59. :name="item"
  60. :shape="isMultipleChoice ? 'square' : 'round'"
  61. @click="changeSelectIds(item)"
  62. ></van-checkbox>
  63. </div>
  64. </div>
  65. </van-list>
  66. </van-checkbox-group>
  67. </div>
  68. <div v-else style="height: 100%">
  69. <van-empty description="暂无续费云手机" v-if="!loading" />
  70. <div
  71. v-else
  72. style="
  73. display: flex;
  74. height: 100%;
  75. justify-content: center;
  76. align-items: center;
  77. "
  78. >
  79. <van-loading />
  80. </div>
  81. </div>
  82. </div>
  83. <van-button
  84. type="info"
  85. color="linear-gradient(to right,#38AEFC, #3B7FFF)"
  86. :disabled="!selectIds.length"
  87. @click="confirm"
  88. >
  89. 确认
  90. </van-button>
  91. </div>
  92. </van-popup>
  93. </template>
  94. <script>
  95. import {timeStamp} from '@/plugins/plugins.js';
  96. export default {
  97. name: 'cloudMobilePhonePopup',
  98. props: {
  99. // 显示更隐藏
  100. value: {
  101. type: Boolean,
  102. default: false,
  103. },
  104. // 弹窗从哪里弹出来
  105. position: {
  106. type: String,
  107. default: 'bottom',
  108. },
  109. // 最外层弹框盒子颜色
  110. background: {
  111. type: String,
  112. default: '#fff',
  113. },
  114. // 左上角标题
  115. titleText: {
  116. type: String,
  117. default: '选择云手机',
  118. },
  119. // 云机每项的背景颜色
  120. backgroundItem: {
  121. type: String,
  122. default: '#F2F4F7',
  123. },
  124. // 最终确认的ids
  125. ids: {
  126. type: Array,
  127. default: () => {
  128. return [];
  129. },
  130. },
  131. // 是否是多选
  132. isMultipleChoice: {
  133. type: Boolean,
  134. default: false,
  135. },
  136. total: {
  137. type: [String, Number],
  138. default: 0,
  139. },
  140. data: {
  141. type: Array,
  142. default: () => {
  143. return [];
  144. },
  145. },
  146. loading: {
  147. type: Boolean,
  148. default: false,
  149. },
  150. listLoading: {
  151. type: Boolean,
  152. default: false,
  153. },
  154. },
  155. data() {
  156. return {
  157. checkboxAll: false,
  158. timeStamp,
  159. selectIds: [],
  160. finished: false,
  161. };
  162. },
  163. computed: {
  164. visible: {
  165. get() {
  166. return this.value;
  167. },
  168. set(val) {
  169. if (!val) this.selectIds = [];
  170. this.$emit('input', val);
  171. },
  172. },
  173. asyncListLoading: {
  174. get() {
  175. return this.listLoading;
  176. },
  177. set(val) {
  178. this.$emit('update:listLoading', val);
  179. },
  180. },
  181. },
  182. methods: {
  183. // 全选相关逻辑,后续再拓展
  184. changeCheckboxAll(bool) {
  185. console.log(bool);
  186. },
  187. // 用来处理单选相关的逻辑
  188. changeSelectIds(data) {
  189. if (!this.isMultipleChoice && this.selectIds.length) {
  190. this.selectIds = [data];
  191. }
  192. },
  193. // 最终确认的
  194. confirm() {
  195. this.$emit('update:ids', this.selectIds);
  196. this.$emit('confirm');
  197. },
  198. onLoad() {
  199. if (this.total === this.data.length) {
  200. this.finished = true;
  201. return
  202. }
  203. this.$emit('load');
  204. },
  205. },
  206. };
  207. </script>
  208. <style style lang="scss" scoped>
  209. .cloud-mobile-phone_popup {
  210. border-radius: 10px 10px 0 0;
  211. padding: 16px 0px;
  212. margin: 0 16px;
  213. height: 60vh;
  214. display: flex;
  215. flex-direction: column;
  216. .van-empty {
  217. padding: 0 !important;
  218. }
  219. .cloud-mobile-phone_popup-title,
  220. .cloud-mobile-phone_popup-content > div,
  221. .van-button {
  222. margin: 0 12px;
  223. }
  224. .van-button {
  225. border-radius: 8px;
  226. }
  227. .cloud-mobile-phone_popup-title {
  228. display: flex;
  229. justify-content: space-between;
  230. margin-bottom: 12px;
  231. .cloud-mobile-phone_popup-title_left {
  232. font-family: PingFangSC, PingFang SC;
  233. font-weight: bold;
  234. font-size: 16px;
  235. color: #0a132b;
  236. line-height: 22px;
  237. text-align: left;
  238. font-style: normal;
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. }
  243. }
  244. .cloud-mobile-phone_popup-content {
  245. flex: 1;
  246. overflow-y: auto;
  247. margin-bottom: 12px;
  248. .cloud-mobile-phone_popup-content_item {
  249. height: 65px;
  250. padding: 16px 12px;
  251. box-sizing: border-box;
  252. border-radius: 8px;
  253. display: flex;
  254. justify-content: space-between;
  255. & > div {
  256. display: flex;
  257. justify-content: center;
  258. align-items: center;
  259. }
  260. .cloud-mobile-phone_popup-content_item-left {
  261. & > img {
  262. margin-right: 8px;
  263. width: 34px;
  264. height: 34px;
  265. }
  266. & > div {
  267. font-family: PingFangSC, PingFang SC;
  268. & > div:first-of-type {
  269. font-weight: bold;
  270. font-size: 16px;
  271. color: #0a132b;
  272. line-height: 22px;
  273. font-style: normal;
  274. }
  275. & > div:last-of-type {
  276. font-weight: 400;
  277. font-size: 12px;
  278. color: #666666;
  279. line-height: 17px;
  280. font-style: normal;
  281. vertical-align: middle;
  282. img {
  283. width: 13px;
  284. height: 13px;
  285. vertical-align: middle;
  286. margin-bottom: 3px;
  287. }
  288. &.red-time {
  289. color: #f04646;
  290. }
  291. }
  292. }
  293. }
  294. }
  295. }
  296. }
  297. </style>