<template>
  <el-dialog
    :modal="true"
    title="登录成功项目"
    :visible.sync="showDialog"
    width="70%"
    :show-close="false"
    :close-on-click-modal="false"
    :modal-append-to-body="false"
    :append-to-body="true"
  >
    <div v-if="showDialog" style="height: 60vh">
      <template-page
        ref="pageRefTable"
        :pofx="true"
        :get-list="getList"
        :column-parsing="columnParsing"
        :operation-column-width="200"
        :table-attributes="tableAttributes"
        :table-events="tableEvents"
        :replace-or-not-map="false"
      />
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button size="mini" @click="cancel">取 消</el-button>
      <el-button size="mini" type="primary" @click="confirm">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import TemplatePage from '@/components/template/template-page-1.vue'
import { getLoginHomeDecorationList } from '@/api/homeDecoration'
import { getLoginCrossDistrictList } from '@/api/crossDistrict'
import { getLoginFrockList } from '@/api/frock'
import { getLoginList } from '@/api/summaryTable'

export default {
  components: { TemplatePage },
  mixins: [],
  props: {
    pageType: {
      type: String,
      required: true
    },
    showDialog: {
      type: Boolean,
      required: true
    },
    formData: {
      type: Object,
      default: () => ({})
    }
  },
  data() {
    return {
      // 表格属性
      tableAttributes: {
        // 启用勾选列
        selectColumn: true,
        selectable: this.selectable
      },
      // 表格事件
      tableEvents: {
        'selection-change': this.selectionChange,
        select: (selection, row) => {
          this.$refs.pageRefTable.$refs.zjpage.$refs.tableEl.$refs.tableView.clearSelection()
          this.$refs.pageRefTable.$refs.zjpage.$refs.tableEl.$refs.tableView.toggleRowSelection(row)
        }
      },
      recordSelected: []
    }
  },
  computed: {},
  watch: {
    showDialog: {
      handler(nl, ol) {
        // console.log(this.pageType, this.formData, 9999)
      }
    }
  },
  created() {
  },
  methods: {
    selectable(row, index) {
      if (this.formData.id == row.id) {
        return false
      } else {
        return true
      }
    },
    // 表格列解析渲染数据更改
    columnParsing(item, defaultData) {
      return defaultData
    },
    // 监听勾选变化
    selectionChange(data) {
      this.recordSelected = data
    },
    getList(...p) {
      this.recordSelected = []
      p[0].params = [...p[0].params, { param: 'a.order_status', compare: '=', value: 'OK' }, {
        param: 'a.is_span',
        compare: '=',
        value: ['home', 'frock'].includes(this.pageType)? 0 : 1
      }]

      if (this.pageType === 'cross') {
        return getLoginCrossDistrictList(...p)
      }
      return getLoginList(...p)
    },
    cancel() {
      this.$emit('cancel')
    },
    confirm() {
      this.$emit('success', this.recordSelected)
      this.cancel()
    }
  }
}
</script>

<style scoped></style>
