<template>
  <a-card>
    <div :class="$style.wrapHeight">
      <sd-data-table-ex
        ref="kpiIndiTaskTable"
        form-id="kpiIndiTask"
        data-url="api/xcoa-mobile/v1/kpi-indi-task/all-list"
        :columns="columns"
        :actions="actions"
        show-selection
        :filter-expressions="expressions"
        :search-fields="['taskName']"
      >
        <template slot="islink" slot-scope="text, record">
          <a @click="open(record)">{{ text }}</a>
        </template>
      </sd-data-table-ex>
      <div :class="[$style.btns]">
        <a-col :span="13" :offset="0">
          <a-radio-group v-model="radioValue" @change="radioOnChange">
            <a-radio :value="'0'">
              全部
            </a-radio>
            <a-radio :value="'1'">
              待处理
            </a-radio>
          </a-radio-group>
        </a-col>
      </div>
    </div>
  </a-card>
</template>

<script>
import crossWindowWatcher from '@/common/services/cross-window-watcher'
import TableColumnTypes from '@/common/services/table-column-types'
import components from './_import-components/kpi-indi-task-list-import'

export default {
  name: 'KpiIndiTaskList',
  metaInfo: {
    title: '指标报送任务',
  },
  components,
  data() {
    return {
      columns: [
        {
          title: '序号',
          customRender: (text, record, index) => `${index + 1}`,
          width: '80px',
        },
        { dataIndex: 'id', sdHidden: true },
        { dataIndex: 'instId', sdHidden: true },
        {
          title: '任务名称',
          dataIndex: 'taskName',
          scopedSlots: { customRender: 'islink' },
        },
        {
          title: '任务来源',
          dataIndex: 'taskFrom',
        },
        {
          title: '报送人',
          dataIndex: 'submitterName',
        },
        {
          title: '创建日期',
          dataIndex: 'creationTime',
          sdRender: TableColumnTypes.date,
          defaultSortOrder: 'descend',
        },
        {
          title: '当前状态',
          dataIndex: 'flowState',
        },
        {
          title: '当前处理人',
          dataIndex: 'nowUser',
        },
        { title: '文档状态', dataIndex: 'endType', width: '120px', sdHidden: true },
      ],
      actions: [],
      radioType: false,
      radioValue: '0',
      expressions: [],
    }
  },
  created() {},
  methods: {
    open(record) {
      const url = `/sd-webflow/done-pages/` + record.instId
      crossWindowWatcher.waitForChanged(url).then((refreshFlag) => {
        if (refreshFlag) {
          // 这里写或者调刷新的方法
          this.refresh()
        }
      })
    },
    // 状态筛选单选按钮变化时
    radioOnChange(e, info) {
      this.radioValue = e.target.value
      this.radioType = true
      this.expressions.forEach((item) => {
        if (item.name === 'pending') {
          item.stringValue = this.radioValue
          this.radioType = false
        }
      })

      if (this.radioType) {
        this.expressions.push({
          dataType: 'str',
          name: 'pending',
          op: 'eq',
          stringValue: this.radioValue,
        })
      }
      this.expressions = [...this.expressions]
      this.$refs.kpiIndiTaskTable.clearSelection()
    },
  },
}
</script>

<style module lang="scss">
@use '@/common/design' as *;
.btns {
  position: absolute;
  top: 20px;
  right: 0;
  left: 20px;
  z-index: 100;
  width: calc(100% - 400px);
  span {
    // color: blue;
  }
}
</style>
