<template>
  <!-- 所在路段选择弹层 -->
  <SuperTableSelectorDialog
    width="75%"
    v-on="$listeners"
    v-bind="$attrs"
    title="救援单选择"
    selectKey="propertySubjectId"
    selectLabel="roadName"
    select-title-name="路损项目明细"
    :isShowTree="false"
    :isShowSearch="false"
    :isShow.sync="isShowDialog"
    hintLanguage="提示：请在列表中选择救援单后，点击确认。"
    :table-data="tableData"
    :table-options="tableOptions"
    :table-loading="tableLoading"
    :tableParams="params"
    isSingleChoice
    :isShowSelect="false"
    @open="open"
    @closed="closed"
    @tableRefresh="getTableData"
    ref="superTableSelectorDialog"
  />
</template>

<script>
import {rescueInfoData} from '@/api/patrolAndRescue/commandDispatch/eventManagement/eventEdit'
import {refineRequestBody, setQueryValue} from '@/utils/requestWrappers'
import SuperTableSelectorDialog from '@/components/SuperTableSelectorDialog/index.vue'
import {getDictionaryByCode, dictionaryEscape} from '@/utils/dictionary'

export default {
  name: 'EventChoiceDialog',
  components: {SuperTableSelectorDialog},
  props: {
    isShow: {
      default: false,
      type: Boolean
    },
    eventId: {
      default: '',
      type: String,
      required: true
    }
  },
  data() {
    return {
      tableOptions: [
        {label: '救援单号', minWidth: '100', prop: 'rescueNo'},
        {label: '报案电话', minWidth: '80', prop: 'rescueTel'},
        {
          label: '救援类型',
          minWidth: '80',
          prop: 'rescueType',
          formatter: ({rescueType}) =>
            dictionaryEscape('jylx', rescueType + '') || '-'
        },
        {label: '开始站', minWidth: '60', prop: 'startPatrolName'},
        {label: '结束站', minWidth: '60', prop: 'endPatrolName'},
        {
          label: '方向',
          minWidth: '80',
          prop: 'direction',
          formatter: ({direction}) =>
            dictionaryEscape('xsfx', direction + '') || '-'
        },
        {label: '桩号全值', minWidth: '120', prop: 'pegVal'}
      ],
      params: {
        pageBean: {pageSize: 20, page: 1, total: 0},
        querys: [
          {operation: 'EQUAL', property: 'event_Type_', value: ''},
          {operation: 'EQUAL', property: 'event_Src_', value: ''},
          {operation: 'EQUAL', property: 'eventId'}
        ],
        sorter: [{direction: 'DESC', property: 'rescueTime'}]
      },
      tableData: [], // 所在路段数据
      tableLoading: false // 表格loading
    }
  },
  computed: {
    isShowDialog: {
      get() {
        return this.isShow
      },
      set(val) {
        this.$emit('update:isShow', val)
      }
    }
  },
  created() {},
  methods: {
    // 打开弹层时触发
    open() {
      setQueryValue(this.params, 'eventId', this.eventId)
      this.$nextTick(() => {
        this.getTableData()
      })
    },

    // 关闭弹层触发
    closed() {
      // 重置data中的数据
      Object.assign(this.$data, this.$options.data.call(this), {})
    },

    //获取所在路段列表数据
    async getTableData() {
      this.tableData = []
      this.tableLoading = true
      const {total = 0, rows = []} = await rescueInfoData(
        refineRequestBody(this.params)
      )
      this.params.pageBean.total = total
      this.tableData = rows
      this.tableLoading = false
    },
    confirm() {
      const {id, rescueNo} = this.$refs.superTableSelectorDialog.getSelectData()
      this.$emit('confirm', {id, rescueNo})
      this.isShowDialog = false
    }
  }
}
</script>

<style lang="scss" scoped></style>
