<template>
  <page-layout>
    <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="平台名称">
              <a-input placeholder="请输入平台名称" v-model="queryParam.platformName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="企业名称">
              <a-input placeholder="请输入企业名称" v-model="queryParam.enterpriseName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8" >
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <!--<a @click="handleToggleSearch" style="margin-left: 8px">-->
                <!--{{ toggleSearchStatus ? '收起' : '展开' }}-->
                <!--<a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>-->
              <!--</a>-->
            </span>
          </a-col>

        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus" v-has="'platform:add'">新增</a-button>
    </div>

    <!-- table区域-begin -->
    <div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <!--<a @click="handleSubcontractor(record)" v-has="'platform:subcontractor'">服务商</a>-->
          <!--<a-divider type="vertical" v-has="'platform:subcontractor'"/>-->
          <a @click="handleEdit(record)" v-has="'platform:edit'">编辑</a>
          <a-divider type="vertical" v-if="record.isLock == 0" v-has="'platform:lock'"/>
          <a-divider type="vertical" v-if="record.isLock == 1" v-has="'platform:lock'"/>
          <a @click="handleLock(record)" v-if="record.isLock == 0" v-has="'platform:lock'">锁定</a>
          <a @click="handleLock(record)" v-if="record.isLock == 1" v-has="'platform:lock'">解锁</a>
          <a-divider type="vertical" v-has="'platform:del'" />
          <a @click="handleDel(record)" v-has="'platform:del'">删除</a>
        </span>

        <span slot="action1" slot-scope="text, record">
           <a @click="handleDetail(record)">{{record.platformName}}</a>
        </span>

      </a-table>
    </div>

    <hlgPlatform-modal ref="modalForm" @ok="modalFormOk"></hlgPlatform-modal>
  </a-card>
  </page-layout>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HlgPlatformModal from './modules/HlgPlatformModal'
  import JDate from '@/components/jeecg/JDate.vue'
  import PageLayout from '@/components/page/PageLayout'
  import { getAction, deleteAction, putAction, postAction } from '@/api/manage'
  const lockPlatform = (params) => putAction('/hlgplatform/hlgPlatform/lockPlatform', params)
  const deletePlatform = (params) => deleteAction('/hlgplatform/hlgPlatform/deletePlatform', params)

  export default {
    name: "HlgPlatformList",
    mixins:[JeecgListMixin],
    components: {
      JDate,
      HlgPlatformModal,
      PageLayout
    },
    data () {
      return {
        description: '平台信息表管理页面',
        // 表头
        columns: [
          {
            title:'平台名称',
            align:"left",
            dataIndex: 'platformName',
            scopedSlots: { customRender: 'action1' },
          },
          {
            title:'企业名称',
            align:"left",
            dataIndex: 'enterpriseName'
          },
          {
            title:'状态',
            align:"left",
            dataIndex: 'isLock_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"left",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/hlgplatform/hlgPlatform/list",
          delete: "/hlgplatform/hlgPlatform/delete",
          deleteBatch: "/hlgplatform/hlgPlatform/deleteBatch",
          exportXlsUrl: "/hlgplatform/hlgPlatform/exportXls",
          importExcelUrl: "hlgplatform/hlgPlatform/importExcel",
        },
        dictOptions:{
        } 
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      //查看服务商
      handleSubcontractor(record){
        this.$refs.modalSubcontractorForm.edit(record)
        this.$refs.modalSubcontractorForm.title = '服务商'
        this.$refs.modalSubcontractorForm.disableSubmit = false
      },
      //锁定/解锁
      handleLock(record){
        let content = ''
        let title = ''
        if (record.isLock == 0) {
          content = '确定要锁定该平台吗？'
          title = '锁定企业'
        } else {
          content = '确定要解锁该平台吗？'
          title = '解锁企业'
        }
        let that = this
        const modal = that.$confirm({
          title: title,
          closable: true,
          keyboard: false,
          maskClosable: true,
          content: content,
          okText: '确定',
          cancelText: '取消',
          onOk: function() {
            lockPlatform({ id: record.id, isLock: record.isLock == 0 ? 1 : 0 }).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.loadData()
              } else {
                that.$message.warning(res.message)
              }
            })
          },
          onCancel(e) {
            modal.destroy()
          }
        })
      },
      //删除
      handleDel(record){
        let that = this
        const modal = that.$confirm({
          title: '删除平台',
          closable: true,
          keyboard: false,
          maskClosable: true,
          content: '确定要删除该平台?',
          okText: '确定',
          cancelText: '取消',
          onOk: function() {
            deletePlatform({ id: record.id}).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.loadData()
              } else {
                that.$error({
                  title: '删除失败',
                  content: res.message,
                  okText: '确定',
                  centered:true
                })
              }
            })
          },
          onCancel(e) {
            modal.destroy()
          }
        })
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>