lxf
2025-07-04 5ef5f50d09b49795c4cc9ca017294cbb74083cae
1
2
3
4
5
6
7
8
9
10
11
12
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
41
42
43
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<template>
  <van-popup v-model:show="showLeft" closeable position="left"
    :style="{ width: '75%', height: '100%', background: 'rgb(31, 35, 61)' }">
    <div class="main">
      <div class="title">{{ t('selectombination') }}</div>
      <div class="list">
        <div class="item" v-for="(item, index) in optionalList" :key="index">
          <van-checkbox v-model="item.check">{{ item.listName }}</van-checkbox>
        </div>
      </div>
      <div class="submit-div">
        <van-button class="but" type="default" @click="openGroupEditOrAdd">{{ t('createDustom') }}</van-button>
        <van-button class="but" type="primary" @click="finish">{{ t('Finish') }}</van-button>
      </div>
    </div>
  </van-popup>
</template>
 
<script setup>
import { ref, onMounted, defineExpose } from 'vue'
import { _itemUserOptionalList, _itemUserOptionaSaveItem, _isItemHasAdd, _removeItem } from '@/service/quotes.api'
import { useRouter } from "vue-router";
import { showToast } from 'vant';
import { _collect, _deleteCollect } from '@/service/cryptos.api'
import { useI18n } from 'vue-i18n'
const emits = defineEmits(['updateItem'])
const router = useRouter()
const optionalList = ref([])
const { t } = useI18n()
const props = defineProps({
  isCollect: {
    type: Boolean,
    default: false
  },
})
let showLeft = ref(false)
let symbolValue = ref('')
onMounted(async () => {
  getMyCoinsList()
})
 
const itemClick = (a) => {
  emits('click-item', props.item)
  // console.log(1111)
}
//获取我的自选列表
const getMyCoinsList = () => {
  let params = {}
  _itemUserOptionalList(params).then(data => {
    data.list.map((item) => {
      item.check = false
      optionalList.value.push(item)
    })
  })
}
//打开弹窗
const openCurrency = (symbol) => {
  showLeft.value = true
  symbolValue.value = symbol
  if (props.isCollect) {
    detectionItem()
  }
}
//跳转添加分组
const openGroupEditOrAdd = () => {
  router.push('/optional/groupAdd')
}
//完成
const finish = () => {
  let checkList = optionalList.value.filter((item) => {
    return item.check
  })
  if (!props.isCollect) {
    if (checkList.length === 0) {
      showToast(t('PleaseAdd'))
      return
    }
    checkList.map((item) => {
      let obj = {
        listId: item.listId,
        symbol: symbolValue.value
      }
      if (item.listId == 0) {
        _collect(symbolValue.value).then((res) => {
          showToast(t('添加成功'))
          emits('updateItem')
          detectionItem()
          showLeft.value = false
        })
      } else {
        _itemUserOptionaSaveItem(obj).then((res) => {
          showToast(t('添加成功'))
          emits('updateItem')
          detectionItem()
          showLeft.value = false
        })
      }
    })
  } else {
    if (checkList.length === 0) {
      showToast(t('PleaseDelete'))
      return
    }
    checkList.map((item) => {
      let obj = {
        listId: item.listId,
        symbol: symbolValue.value
      }
      if (item.listId == 0) {
        _deleteCollect(symbolValue.value).then((res) => {
          showToast(t('successfullyDeleted'))
          emits('updateItem')
          detectionItem()
          showLeft.value = false
        })
      }
      _removeItem(obj).then((res) => {
        showToast(t('successfullyDeleted'))
        emits('updateItem')
        detectionItem()
        showLeft.value = false
      })
    })
  }
}
//检查币种是否存在自选
const detectionItem = () => {
  optionalList.value.map((item) => {
    let obj = {
      listId: item.listId,
      symbol: symbolValue.value
    }
    _isItemHasAdd(obj).then((data) => {
      item.check = data
    })
  })
}
defineExpose({
  openCurrency
});
 
</script>
<style lang="scss" scoped>
.main {
  .title {
    padding: 14px 20px;
    font-size: 16px;
  }
 
  .submit-div {
    position: fixed;
    bottom: 0;
    width: 100%;
    left: 0;
    padding: 10px 20px;
    display: flex;
    justify-content: space-between;
 
    .but {
      width: 120px;
    }
  }
 
  .list {
    padding: 0 20px;
    color: $text_color;
 
    .item {
      padding: 10px 0;
    }
 
    :deep(.van-checkbox__label) {
      font-size: 16px !important;
      color: $text_color;
    }
  }
}
</style>