<template>
  <div class="app-container">
    <search-form
      :list-loading="listLoading"
      @change="searchHandle"
    />
    <table-list
      :list-loading="listLoading"
      :data="tableData2"
      :columns="listConfig"
      :current-page="currentPage"
      :page-size="pageSize"
      :total-records="totalRecords"
      @currentChange="pageHandle"
      @sizeChange="sizeChange"
    >
    </table-list>
  </div>
</template>
<script>
import { arrToObj } from '@/utils'
import SearchForm from './components/searchForm/Index'
import baseTable from '_m/baseTable.js'
export default {
  name: 'index',
  components: {
    SearchForm,
  },
  provide() {
    return {
      parentData: this
    }
  },
  mixins: [baseTable],
  data() {
    return {
      apiStr: 'other.planlist',
      searchForm: null,
      isDtlShow: false,
      curObj: {}
    }
  },
  computed: {
    tableData2() {
      const arr = [...this.tableData]
      arr.map(item => {
        const userInfo = item.userinfo
        if (userInfo) {
          const UI = JSON.parse(userInfo)
          item.wxName = `${UI.nickName}(${UI.phone})`
          item.wxImg = UI.avatarUrl
        }
        const atObj = arrToObj(this.$dictData.area_type)
        const area_type = item.area_type ? item.area_type.split(',') : []
        const areaTypeArr = area_type.map(v => {
          return atObj[v]
        })
        item.areaType = areaTypeArr.join(',')

        const htObj = arrToObj(this.$dictData.house_type)
        const house_type = item.house_type ? item.house_type.split(',') : []
        const houseTypeArr = house_type.map(v => {
          return htObj[v]
        })
        item.houseType = houseTypeArr.join(',')
      })
      return arr
    }
  },
  created() {},
  mounted() {
    this.listConfig = {
      rows: [
        { label: '提交时间', prop: 'create_at' },
        { label: '意向楼盘', prop: 'estate_name' },
        { label: '用户名称', prop: 'name' },
        { label: '手机号', prop: 'phone' },
        { label: '首付款(万)', prop: 'sfk' },
        { label: '月供预算(元)', prop: 'ygys' },
        { label: '总价预算(万)', prop: 'zjys' },
        { label: '微信昵称(手机)', prop: 'wxName', fullShow: true },
        { label: '微信头像', prop: 'wxImg', type: 'img' },
        { label: '意向区域', prop: 'areaType', fullShow: true, minWidth: 120  }, 
        { label: '意向房型', prop: 'houseType', fullShow: true, minWidth: 120 },
        { label: '限购', prop: 'xg', type: 'tag', tags: arrToObj([{key: '不限', val: '-1'}, ...this.$dictData.sys_yesno]) }, 
        { label: '学区', prop: 'mxzb', type: 'tag', tags: arrToObj([{key: '不限', val: '-1'}, ...this.$dictData.sys_yesno]) },
        { label: '公积金', prop: 'gjj', type: 'tag', tags: arrToObj([{key: '不限', val: '-1'}, ...this.$dictData.sys_yesno]) },
        { label: '精装', prop: 'mpjz', type: 'tag', tags: arrToObj([{key: '不限', val: '-1'}, ...this.$dictData.sys_yesno]) },
        { label: '新房', prop: 'xf', type: 'tag', tags: arrToObj([{key: '不限', val: '-1'}, ...this.$dictData.sys_yesno]) },
        { label: '交房时间', prop: 'jfsj' },
        { label: '周边配套', prop: 'zbpt' },
        { label: '备注', prop: 'remark' },
        { label: '操作', width: 60, type: 'handle2', operations:
          [
            { label: '删除', func: this.delHandle, btnType: 'danger' },
          ]
        }
      ]
    }
  },
  methods: {
    delHandle(row) {
      this.$msg(`您确定要删除该文章吗？`, 'confirm', () => {
        this.$api.other.plandel({
          id: row.id,
        }).then(data => {
          this.$msgs(`已删除！`)
          this.fetchData()
        })
      }, null, true)
    },
  }
}
</script>
<style lang="scss" scoped>
</style>

