<template>
  <view class="uni-app">
    <view class="status-bar" />
    <view class="main-container">
      <wk-nav-bar title="跟进记录" />

      <view class="filter-group">
<!-- <wk-dropdown :auto-close="true" @change="handleDropdownChange">
					<template v-for="(item, index) in taskOptions">
						<wk-dropdown-item
							:key="index"
							:name="item.label"
							:default-index="item.defaultIndex"
							:options="item.options"
							@choose="handleFilter" />
					</template>
				</wk-dropdown> -->
        <wk-base-filter :tabs="taskOptions" @filter="handleFilter" />
      </view>

      <wk-scroll-view
        :status="listStatus"
        class="list-scroll"
        @refresh="getList({}, true)"
        @loadmore="getList()">
        <record-item
          v-for="(item, index) in listData"
          :key="index"
          :record-data="item" />
      </wk-scroll-view>
    </view>
  </view>
</template>

<script>
  import { QueryRecordList } from 'API/crm/work'
  import RecordItem from './components/recordItem.vue'
  import mainListMixins from '@/mixins/mainList.js'

  export default {
    name: 'RecordIndex',
    components: {
      RecordItem
    },
    mixins: [mainListMixins],
    data() {
      return {
        GetListFn: QueryRecordList,

        filterData: {
          dataType: 1,
          dateFilter: 'month',
          isOa: true,
          subUser: '0',
          queryType: 1 // 0 全部  1 跟进记录  2 外勤签到
        },
        taskOptions: [
          {
            label: '类型',
            field: 'subUser',
            value: 0,
            valueData: 1,
            options: [
              {label: '全部', value: '__delete__'},
              {label: '我创建的', value: '0'},
              {label: '我下属创建的', value: '1'}
            ]
          },
          {
            label: '全部时间',
            field: 'dateFilter',
            value: 'month',
            valueData: 4,
            options: [
              {label: '今天', value: 'today'},
              {label: '昨天', value: 'yesterday'},
              {label: '本周', value: 'week'},
              {label: '上周', value: 'lastWeek'},
              {label: '本月', value: 'month'},
              {label: '上月', value: 'lastMonth'},
            ]
          },
        ]
      }
    },
    onLoad(options) {
      if (options.subUser) {
        const val = Number(options.subUser)
        if (!isNaN(val)) {
          const findIndex = this.taskOptions[0].options.findIndex(o => o.value == val)
          if (findIndex != -1) {
            this.taskOptions[0].valueData = findIndex
            this.taskOptions[0].value = val
            this.filterData.subUser = val
          }
        }
      }
      this.getList()
    },
    methods: {
      getParams() {
        if (this.filterData.subUser && this.filterData.subUser === '__delete__') {
          this.filterData.subUser = ''
          this.filterData.dataType = ''
        } else if (this.filterData.subUser && this.filterData.subUser === '0') {
          this.filterData.dataType = 1
        } else if (this.filterData.subUser && this.filterData.subUser === '1') {
          this.filterData.dataType = 2
        }
        return this.filterData
      },

      handleFilter(item) {
        this.filterData[item.field] = item.value
        this.getList({}, true)
      },
    }
  }
</script>

<style scoped lang="scss">
	.main-container {
		width: 100%;
		height: 100%;
		display: flex;
		flex-direction: column;

		.list-scroll {
			flex: 1;
			overflow: hidden;
		}
	}
</style>
