import pullUpRefresh from "@/utils/pullUpRefresh";
import dayjs from  "dayjs";
export default {
	mixins: [pullUpRefresh],
	
	computed: {
		currentIndex() {
			return this.queryParams.type == 1 ? 0 : 1;
		}
	},
	onPullDownRefresh() {
		uni.stopPullDownRefresh();
		// 刷新
		
	},
	data() {
		return {

			clueStateList: [],

			mapHeight: "0px",

			key: new Date().getTime(),

			clueTagGroupVoList: [],

			dicts: {
					caseStatusDicts: [],
					crmFollowStatus: [],
					crmCallStatus: [],
					clueEntranceType: [],
					crmClueBiz: [],
					crmClueObj: [],
					crmClueType: []
				},

			options: [{
					value: "3",
					label: "电话/微信"
				},
				{
					value: "1",
					label: "姓名"
				},
				{
					value: "8",
					label: "广告主ID"
				},
				{
					value: "7",
					label: "广告主名称"
				},
				{
					value: "10",
					label: "广告ID"
				},
				{
					value: "9",
					label: "广告名称"
				},
				{
					value: "11",
					label: "标题ID"
				},
				{
					value: "12",
					label: "视频ID"
				},
				{
					value: "5",
					label: "qq号"
				},
				{
					value: "6",
					label: "邮箱"
				},
				{
					value: "2",
					label: "线索ID"
				},
			],

			queryParams: {
				name: undefined,
				telephone: undefined,
				weixin: undefined,
				createTimeStart: dayjs().format("YYYY-MM-DD"),
				createTimeEnd: dayjs().format("YYYY-MM-DD"),
				conditionContent: undefined,
				condition: "3",
				batchCodes: [],
				clueIds: [],
				deptName: undefined,
				deptId: undefined,
				type: "1",
				pageNum: 1,
				pageSize: 20,
				allTagList: [],
				clueStateList: [],
				followStatusList: [],
				handleStateList: [],
				convertStatusList: [],
				followCountStart: undefined,
				followCountEnd: undefined,
				autoProvince: undefined,
				autoCity: undefined,
				autoArea: undefined,
				manualProvince: undefined,
				manualCity: undefined,
				manualArea: undefined,
				clueEntranceType: [],
				clueBizType: undefined,
				clueObjType: undefined,
				clueAdType: undefined,
				clueOperationId: undefined,
				clueOwnerId: undefined,
				sort: undefined,
				clueState: undefined,
				sortField: undefined,
				appNames: [],
				appNameLabel: undefined,
				isRepetitionOperWeixinName : '',
				isRepetitionOperationName : '',
				isVideoIdIsNull : '',
				advName: "",
				promotionName: "",
				advId: "",
				promotionId: "",
				titleId: "",
				videoId: ""
			},
		}
	},
	onPullDownRefresh() {
		uni.stopPullDownRefresh();
		this.resetData();
	},
	mounted() {
		uni.getSystemInfo({
			success: (e) => {
				const {
					windowTop,
					windowBottom,
					windowHeight
				} = e;
				this.mapHeight = (windowHeight - 70) + 'px';
			}
		});
		this.getDicts();
		// this.handleLoadData();
		this.resetData();
	},
	// onShow() {
	// 	this.resetData();
	// },
	methods: {
		handleAddClue() {
			uni.navigateTo({
				url: "/pages/addClue/index"
			})
		},
		handleClueStateClick(item) {
			this.queryParams.clueState = item.clueState;
			this.resetData();
		},
		handleKeyword() {
			this.resetData();
		},
		handleKeywordClear() {
			// 组件有bug 清空后的值还是存在
			this.queryParams.conditionContent = "";
			this.resetData();
		},
		handleShowTag() {
			this.$refs.clueTag.showModal();
		},
		async handleClueTagConfirm() {
			this.resetData();
		},
		async getDicts() {
				this.$getDicts('crm_clue_phase').then(res => {
					this.dicts.caseStatusDicts = res;
				});
				this.$getDicts('crm_follow_status').then(res => {
					this.dicts.crmFollowStatus = res;
				})
				this.$getDicts('crm_call_status').then(res => {
					this.dicts.crmCallStatus = res;
				})
				this.$getDicts('clue_entrance_type').then(res => {
					this.dicts.clueEntranceType = res;
				});
				this.$getDicts('crm_clue_biz').then(res => {
					this.dicts.crmClueBiz = res;
				});
				this.$getDicts('crm_clue_obj').then(res => {
					this.dicts.crmClueObj = res;
				});
				this.$getDicts('crm_clue_type').then(res => {
					this.dicts.crmClueType = res;
				});
				uni.$u.api.getClueTagGroupVoList({ tagGroupApplication : '1' }).then(({
					data
				}) => {
					this.clueTagGroupVoList = data;
				});
		},
		getOtherData() {
			this.statisticsCaseState();
		},
		async statisticsCaseState() {
			const {
				data
			} = await uni.$u.api.statisticsCaseState(this.queryParams);
			this.clueStateList = data;
		},
		handleshowFilter() {
			this.$refs.filter.show();
		},
		handleShowSort() {
			this.$refs.sort.show();
		},
		sectionChange(val) {
			this.queryParams.type = val == 0 ? 1 : 2;
			this.resetData();
		},
		handleConfirm() {
			this.resetData();
		},
		handleConditionChange() {
			if (this.queryParams.conditionContent) {
				this.resetData();
			}
		},
		handleToDetail(item) {
			const {
				id,
				name
			} = item;
			uni.navigateTo({
				url: `/pages/clueDetail/index?clueId=${id}&name=${name}&type=${this.queryParams.type}`,
			});
		},
		async getList() {
			const {
				pageNum,
				pageSize,
				...params
			} = this.queryParams;
			const {
				rows,
				total
			} = await uni.$u.api.getClueMainInfoList({
				pageSize,
				pageNum
			}, params);
			rows.forEach(v=>{
				if(v.repetitionOperationName){
					// 按逗号分割成数组
					const parts = v.repetitionOperationName.split(',');
					// 对每个部分提取 '-' 前面的内容
					const result = parts.map(part => part.split('-')[0]).join(',');
					v.repetitionOperationName = result;
				}
				if(v.repetitionOperWeixinName){
					// 按逗号分割成数组
					const parts = v.repetitionOperWeixinName.split(',');
					// 对每个部分提取 '-' 前面的内容
					const result = parts.map(part => part.split('-')[0]).join(',');
					v.repetitionOperWeixinName = result;
				}
			})
			return rows;
		}
	}
}