<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="小区名称">
              <j-input placeholder="请输入小区名称" v-model="queryParam.communityName"></j-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="商铺名称">
              <j-input placeholder="请输入商铺名称" v-model="queryParam.shopName"></j-input>
            </a-form-item>
          </a-col>
          <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
            <a-col :md="6" :sm="24">
              <a-button type="primary" @click="searchQuery">查询</a-button>
              <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
            </a-col>
          </span>
        </a-row>
      </a-form>
    </div>
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="propertyDetails(1)" type="primary" icon="plus">绑定商铺</a-button>
    </div>
    <!-- table区域-begin -->
    <div>
      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns"
        :dataSource="dataSource" :pagination="pagination" :loading="loading" class="j-table-force-nowrap"
        @change="handleTableChange">
        <span slot="auditStatus" slot-scope="text, record">
          <a-tag color="orange" v-if="record.auditStatus === 'waitAudit'">待审核</a-tag>
          <a-tag color="green" v-if="record.auditStatus === 'auditPass'">审核通过</a-tag>
          <a-tag color="red" v-else-if="record.auditStatus === 'refuse'">审核拒绝</a-tag>
        </span>
        <span slot="freezingStatus" slot-scope="text, record">
          <a-tag color="green" v-if="record.freezingStatus === 'normal'">正常</a-tag>
          <a-tag color="red" v-else-if="record.freezingStatus === 'freeze'">冻结</a-tag>
        </span>
        <span slot="action" slot-scope="text, record">
          <a href="javascript:;" @click="propertyDetails(4, record.id)">详情</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item v-if="record.auditStatus === 'auditPass'">
                <a href="javascript:;"
                  @click="onStatus(record)">{{record.freezingStatus === 'normal' ? '冻结' : '解冻'}}</a>
              </a-menu-item>
              <!-- <a-menu-item>
                <a href="javascript:;" @click="propertyDetails(2, record.id)">修改</a>
              </a-menu-item> -->
              <a-menu-item v-if="record.auditStatus != 'auditPass'">
                <a href="javascript:;" @click="propertyDetails(3, record.id)">审核</a>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
  </a-card>
</template>

<script>
import { partnersShopOperateApi } from '@/api/api'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

const columns = [
  {
    title: '所属小区',
    dataIndex: 'communityName',
    key: 'communityName',
    align: 'center',
  },
  {
    title: '商铺名称',
    dataIndex: 'shopName',
    key: 'shopName',
    align: 'center',
  },
  {
    title: '统一社会信用代码',
    dataIndex: 'creditCode',
    key: 'creditCode',
    align: 'center',
  },
  {
    title: '联系人',
    dataIndex: 'contactName',
    key: 'contactName',
    align: 'center',
  },
  {
    title: '电话',
    dataIndex: 'contactPhone',
    key: 'contactPhone',
    align: 'center',
  },
  {
    title: '分利',
    dataIndex: 'totalDivideProfits',
    key: 'totalDivideProfits',
    align: 'center',
  },
  {
    title: '交易金额',
    dataIndex: 'totalAmount',
    key: 'totalAmount',
    align: 'center',
  },
  {
    title: '审核状态',
    dataIndex: 'auditStatus',
    scopedSlots: { customRender: 'auditStatus' },
    key: 'auditStatus',
    align: 'center',
  },
  {
    title: '冻结/解冻',
    dataIndex: 'freezingStatus',
    scopedSlots: { customRender: 'freezingStatus' },
    key: 'freezingStatus',
    align: 'center',
  },
  {
    title: '操作',
    dataIndex: 'action',
    scopedSlots: { customRender: 'action' },
    align: 'center',
    fixed: 'right',
    width: 150,
  },
]

export default {
  name: 'ShopsList',
  mixins: [JeecgListMixin],
  components: {},
  data() {
    return {
      columns: columns,
      loading: false,
      pagination: {
        total: 0,
        current: 1,
        pageSize: 10,
        showSizeChanger: true,
      },
      url: {
        list: '/property-central/partners/partnersShop/list',
      },
    }
  },
  methods: {
    propertyDetails(type, id) {
      if (type == 1) {
        this.$router.push({
          path: '/shops/shopsDetails?type=add',
        })
      } else if (type == 2) {
        this.$router.push({
          path: '/shops/shopsDetails?type=edit&id=' + id,
        })
      } else if (type == 3) {
        this.$router.push({
          path: '/shops/shopsDetails?type=audit&id=' + id,
        })
      } else if (type == 4) {
        this.$router.push({
          path: '/shops/shopsDetails?type=detail&id=' + id,
        })
      }
    },
    onStatus(record) {
      let that = this
      this.$confirm({
        title: `确认${record.freezingStatus === 'normal' ? '冻结' : '解冻'}此商铺?`,
        closable: true,
        okText: `${record.freezingStatus === 'normal' ? '冻结' : '解冻'}`,
        onOk() {
          return partnersShopOperateApi({
            id: record.id,
            status: `${record.freezingStatus === 'normal' ? 'freeze' : 'normal'}`,
          }).then((res) => {
            that.searchQuery()
          })
        },
        onCancel() {},
      })
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>