<template>
  <div>
    <el-drawer
      :show-close="false"
      :title="curObj.id ? '编辑楼盘摇号信息' : '新增楼盘摇号信息'"
      :wrapper-closable="false"
      :close-on-press-escape="false"
      :visible.sync="isShow"
      size="960px"
      custom-class="xl-drawer"
      direction="rtl"
    >
      <table-list
        :list-loading="listLoading"
        :data="tableData2"
        :columns="listConfig"
        :current-page="currentPage"
        :page-size="pageSize"
        :total-records="totalRecords"
        :operationsDefaultLength="3"
        @currentChange="pageHandle"
        :isAdd="true"
        @add="openLEPopup"
      />
      <div class="xl-form">
        <div class="xl-form-footer fixed" style="width:960px;padding-top: 20px;border-top: 1px solid #dcdcdc;right:0;">
          <el-button class="xl-form-btn t2" @click="close">关 闭</el-button>
        </div>
      </div>
    </el-drawer>
    <lottery-edit
      :isShow="isLEShow"
      :curObj="cObj"
      @close="closeLEPopup"
    />
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import baseTable from '_m/baseTable.js'
import LotteryEdit from './LotteryEdit'
export default {
  components: {
    LotteryEdit
  },
  mixins: [baseTable],
  props: {
    isShow: Boolean,
    curObj: Object
  },
  inject: ['parentData'],
  data() {
    return {
      apiStr: 'house.admestatelottery2list',
      searchForm: {},
      noCreated: true,
      isLEShow: false,
      cObj: {},
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        if (Number(item.push_state) !== 1) item.noYFYJ = true
        if (Number(item.push_state) !== 2) item.noResult = true
      })
      return arr
    }
  },
  mounted() {
    this.listConfig = {
      rows: [
        { label: '期数', prop: 'batch'},
        { label: '排序', prop: 'sort' },
        { label: '摇号中标题', prop: 'under_way'},
        { label: '摇号时间', prop: 'lottery_time'},
        { label: '摇号结果标题', prop: 'lottery_res'},
        { label: '推送状态', prop: 'push_state', type: 'flag', flags: arrToObj(this.$dictData.push_state) },
        { label: '操作', width: 180, type: 'handle2', operations:
          [
            { label: '编辑', func: this.openLEPopup, btnType: 'primary' },
            { label: '推一房一价', func: this.pushYFYJ, btnType: 'warning', hide: 'noYFYJ' },
            { label: '推结果', func: this.pushResult, btnType: 'warning', hide: 'noResult' },
            // { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  watch: {
    isShow: function(val) {
      if (val) {
        // this.$api.house.admestatelottery2list({estate_id: this.curObj.estate_id}).then(res => {
        //   console.log(res)
        // })
        this.searchForm = {
          estate_id: this.curObj.estate_id
        }
        this.fetchData()
      }
    },
  },
  methods: {
    pushYFYJ (row) {
      this.$msg(`您确定要推送一房一价给关注的用户吗？`, 'confirm', () => {
        this.$api.user.admestatelottery2pushprice({
          id: row.id
        }).then(() => {
          this.$msgs('推送成功~')
          this.fetchData()
        })
      }, null, true)
    },
    pushResult (row) {
      this.$msg(`您确定要推送摇号结果给关注的用户吗？`, 'confirm', () => {
        this.$api.user.admestatelottery2pushres({
          id: row.id
        }).then(() => {
          this.$msgs('推送成功~')
          this.fetchData()
        })
      }, null, true)
    },
    delHandle(row) {
      this.$msg(`您确定要删除该楼盘吗？`, 'confirm', () => {
        this.$api.house.admestatelottery2del({
          id: row.id,
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
    openLEPopup(row) {
      let cObj = {
        estate_id: this.curObj.estate_id
      }
      if (row && row.id) {
        this.cObj = {...cObj, ...row}
      } else {
        this.cObj = {...cObj}
      }
      this.isLEShow = true
    },
    closeLEPopup(obj) {
      this.isLEShow = false
      if (obj) {
        this.fetchData()
      }
    },
    close(str) {
      this.$emit('close')
    }
  }
}
</script>
<style lang="scss" scoped>
</style>
