pageMixin.js 1.99 KB
import { marketingApi } from '@/api'
export default {
	data () {
		return {
			list: [],
			total: 0,
			flag: false,
			businessText: '全部',
			materialName: '',
			sort: 0,
			businessType: '',
			groupId: '',
		}
	},
	mounted () {
		let { groupId } = this.getQuery()
		if (groupId) {
			this.groupId = groupId
			return
		}
		if (this.$route.name != 'psd') {
			this.init()
		}
	},
	methods: {
		init () {
			this.showLoading()
			this.getList()
		},
		search (e) {
			this.materialName = e
			this.clearData()
		},
		change (index) {
			let { psdGroupList } = this
			if (psdGroupList.length > 1) this.groupId = psdGroupList[index + 1].value
			this.clearData()
		},
		menuSelect (e) {
			this.groupId = e && e.length && e[0].value || ''
			this.clearData()
		},
		clearData () {
			this.flag = false
			this.list = []
			this.init()
		},
		changeSort (e) {
			this.sort = e
			this.clearData()
		},
		businessConfirm (chooseList) {
			console.log(chooseList)
			if (chooseList.length) {
				let text = []
				let businessType = []
				chooseList.map(e => {
					text.push(e.text)
					businessType.push(e.value)
				})
				this.businessText = `${text.join(',').substring(0, 5)}...`
				this.businessType = businessType.join(',')
			} else {
				this.businessType = ''
				this.businessText = '全部'
			}
			this.clearData()
		},
		onReachBottom () {
			this.$refs.scrollView.finished = true
		},
		sortList (data, attr) {
			return data.sort((a, b) => b[attr] - a[attr])
		},
		getList () {
			let { materialName, businessType, groupId, sort } = this
			setTimeout(()=>{
				marketingApi.getPsdList({ materialName, businessType, groupId }).then(data => {
					console.log('素材列表', data)
					if (sort != 0 && data && data.materialToCRpcResponses && data.materialToCRpcResponses.length) data.materialToCRpcResponses = this.sortList(data.materialToCRpcResponses, sort == 1 ? 'sendNum' : 'readNum')
					this.list = data.materialToCRpcResponses || []
					this.flag = true
					this.hideLoading()
				})
			},500)
		}
	}
}