|
@@ -1,7 +1,15 @@
|
|
|
-import { computed, reactive, ref, getCurrentInstance } from 'vue'
|
|
|
-import { checkBiddingFilterPass } from '@/api/modules'
|
|
|
+import { computed, ref, getCurrentInstance } from 'vue'
|
|
|
+import { checkBiddingFilterPass, addBiddingFilter, getBiddingFilterList, deleteBiddingFilter } from '@/api/modules'
|
|
|
import { FilterHistoryViewModel2AjaxModel, FilterHistoryAjaxModel2ViewModel} from '@/utils'
|
|
|
import { showToast } from '@/components/toast'
|
|
|
+import { MessageBox } from 'element-ui'
|
|
|
+import { useStore } from '@/store'
|
|
|
+
|
|
|
+const getters = useStore().getters
|
|
|
+
|
|
|
+const isFree = computed(() => {
|
|
|
+ return useStore().getters['user/isFree']
|
|
|
+})
|
|
|
|
|
|
const saveConfig = {
|
|
|
savedFilterListMaxCount: 10 //筛选条件保存条数最大值
|
|
@@ -9,9 +17,22 @@ const saveConfig = {
|
|
|
|
|
|
export function saveFilterActionsModel () {
|
|
|
const { savedFilterListMaxCount: maxCount } = saveConfig
|
|
|
+ // 已存筛选列表
|
|
|
+ let filterHistoryList = ref([])
|
|
|
+ // 保存筛选条件框展示与否
|
|
|
const saveFilterDialogVisible = ref(false)
|
|
|
+ // 查看已保存的历史筛选条件
|
|
|
+ const historyFilterDialogVisible = ref(false)
|
|
|
+ // 当前保存的筛选条件多返回的ID
|
|
|
+ const currentFilterParamsKey = ref('')
|
|
|
+ // 当前保存的筛选条件
|
|
|
let filterSaveParams = ref({})
|
|
|
+ // 视图可视筛选条件
|
|
|
let viewFilterParams = ref({})
|
|
|
+ // 已存搜索条件个数
|
|
|
+ const historyFilterCount = computed(() => {
|
|
|
+ return filterHistoryList.value.length
|
|
|
+ })
|
|
|
|
|
|
// 检测筛选条件是否可保存
|
|
|
async function checkFilterPass (config) {
|
|
@@ -23,15 +44,14 @@ export function saveFilterActionsModel () {
|
|
|
if (!searchvalue && !additionalWords && !industry && !hasOneKey) {
|
|
|
return showToast('请先输入关键词')
|
|
|
}
|
|
|
-
|
|
|
- // if(maxCount) {
|
|
|
- // return showToast(`对不起,最多可保存${maxCount}个筛选条件。`)
|
|
|
- // }
|
|
|
+ if(historyFilterCount.value > maxCount) {
|
|
|
+ return showToast(`对不起,最多可保存${maxCount}个筛选条件。`)
|
|
|
+ }
|
|
|
const { data: id, error_code: code = 0, error_msg: msg } = await checkBiddingFilterPass(filterSaveParams.value)
|
|
|
if(code === 0) {
|
|
|
+ currentFilterParamsKey.value = id
|
|
|
viewFilterParams.value = FilterHistoryAjaxModel2ViewModel.formatAll(filterSaveParams.value)
|
|
|
saveFilterDialogVisible.value = true
|
|
|
-
|
|
|
} else {
|
|
|
if (msg) {
|
|
|
if (msg.includes('无用户身份')) {
|
|
@@ -49,16 +69,131 @@ export function saveFilterActionsModel () {
|
|
|
}
|
|
|
|
|
|
// 确定保存筛选条件操作
|
|
|
- function saveFilterConfirm () {
|
|
|
- console.log(33333)
|
|
|
+ async function saveFilterConfirm () {
|
|
|
+ try {
|
|
|
+ const params = {
|
|
|
+ ...filterSaveParams.value,
|
|
|
+ inkey: currentFilterParamsKey.value
|
|
|
+ }
|
|
|
+ const { error_code: code = 0, error_msg: msg } = await addBiddingFilter(params)
|
|
|
+ if (code === 0) {
|
|
|
+ saveFilterDialogVisible.value = false
|
|
|
+ showToast('保存成功')
|
|
|
+ getFilterHistoryList()
|
|
|
+ } else {
|
|
|
+ if (msg) {
|
|
|
+ showToast(msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 获取已存筛选条件
|
|
|
+ async function getFilterHistoryList() {
|
|
|
+ try {
|
|
|
+ const { data, error_code: code, error_msg: msg } = await getBiddingFilterList()
|
|
|
+ if (code === 0) {
|
|
|
+ const resData = data || []
|
|
|
+ const arr = resData.map((item, index) => {
|
|
|
+ return {
|
|
|
+ ...FilterHistoryAjaxModel2ViewModel.formatAll(item),
|
|
|
+ id: item.id,
|
|
|
+ inKey: item.inKey,
|
|
|
+ isPay: item.isPay,
|
|
|
+ open: index === 0
|
|
|
+ }
|
|
|
+ })
|
|
|
+ filterHistoryList.value = arr
|
|
|
+ } else {
|
|
|
+ if (msg) {
|
|
|
+ showToast(msg)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (error) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ getFilterHistoryList()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取已保存的筛选条件
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+ async function onHasFilter () {
|
|
|
+ historyFilterDialogVisible.value = true
|
|
|
+ }
|
|
|
+ // 已存筛选条件弹窗,单条展开收起
|
|
|
+ function onHasToggle (item) {
|
|
|
+ filterHistoryList.value.forEach(function(v) {
|
|
|
+ v.open = false
|
|
|
+ })
|
|
|
+ item.open = !item.open
|
|
|
+ }
|
|
|
+
|
|
|
+ function onDeleteFilter (item) {
|
|
|
+ console.log(item)
|
|
|
+ MessageBox.confirm('确定删除该筛选条件吗?', '删除', {
|
|
|
+ confirmButtonText: '确定',
|
|
|
+ cancelButtonText: '取消',
|
|
|
+ center: true,
|
|
|
+ showClose: false,
|
|
|
+ customClass: 'filter-delete-messagebox',
|
|
|
+ confirmButtonClass: 'btn-group confirm-btn',
|
|
|
+ cancelButtonClass: 'btn-group cancel-btn'
|
|
|
+ }).then(function() {
|
|
|
+ const params = {
|
|
|
+ id: item.id
|
|
|
+ }
|
|
|
+ deleteBiddingFilter(params).then(res => {
|
|
|
+ const { error_code: code} = res
|
|
|
+ if(code === 0) {
|
|
|
+ showToast('删除成功')
|
|
|
+ getFilterHistoryList()
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }).catch(function() {})
|
|
|
+ }
|
|
|
+ // 恢复筛选条件
|
|
|
+ function onSelectedFilter (item) {
|
|
|
+ const { isPay } = item
|
|
|
+ // 恢复选中状态
|
|
|
+ if (isFree && isPay) {
|
|
|
+ MessageBox.confirm('已存筛选条件包含仅限会员用户可用的筛选条件,如需使用请开通超级订阅', '',{
|
|
|
+ confirmButtonText: '开通超级订阅',
|
|
|
+ cancelButtonText: '使用免费条件',
|
|
|
+ center: true,
|
|
|
+ showClose: false,
|
|
|
+ customClass: 'filter-delete-messagebox',
|
|
|
+ confirmButtonClass: 'btn-group confirm-btn',
|
|
|
+ cancelButtonClass: 'btn-group cancel-btn',
|
|
|
+ })
|
|
|
+ .then(() => {
|
|
|
+ // this.$router.push({
|
|
|
+ // path: '/common/order/create/svip'
|
|
|
+ // })
|
|
|
+ })
|
|
|
+ .catch((action) => {
|
|
|
+ // if (action === 'cancel') {
|
|
|
+ // this.restoreFilter(card)
|
|
|
+ // }
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return {
|
|
|
saveFilterDialogVisible,
|
|
|
+ historyFilterDialogVisible,
|
|
|
filterSaveParams,
|
|
|
viewFilterParams,
|
|
|
+ historyFilterCount,
|
|
|
checkFilterPass,
|
|
|
saveFilterCancel,
|
|
|
- saveFilterConfirm
|
|
|
+ saveFilterConfirm,
|
|
|
+ filterHistoryList,
|
|
|
+ onHasFilter,
|
|
|
+ onHasToggle,
|
|
|
+ onDeleteFilter,
|
|
|
+ onSelectedFilter
|
|
|
}
|
|
|
}
|