<template>
  <div class="page-header-index-wide">
  <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>
          <template v-if="toggleSearchStatus">

          <a-col :md="6" :sm="8">
            <a-form-item  label="状态">
              <j-dict-select-tag v-model="queryParam.status" placeholder="请选择状态" dictCode="plat_status"/>
            </a-form-item>
          </a-col>
          </template>

          <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="'require:platformAdd'">新增</a-button>
      <!--<a-button type="primary" icon="download" @click="handleExportXls('平台信息')">导出</a-button>-->
      <!--<a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">-->
        <!--<a-button type="primary" icon="import">导入</a-button>-->
      <!--</a-upload>-->
    </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="action1" slot-scope="text, record">
           <a @click="handleDetail(record)">{{record.platformName}}</a>
        </span>

        <span slot="action2" slot-scope="text, record">
           <a-switch default-checked :defaultChecked="record.isShare==1?true:false" @change="changeIsShare(record)" />{{record.isShare==1?"已开启":"已关闭"}}
        </span>


        <span slot="action" slot-scope="text, record">

          <a @click="handleEdit(record)" v-has="'require:edit'">编辑</a>

          <template v-if="record.status==0">
            <a-divider type="vertical" v-has="'require:locking'"/>
            <a @click="locking(record,'是否确定锁定',1)" v-has="'require:locking'">锁定</a>
          </template>
          <template v-if="record.status==1">
            <a-divider type="vertical" v-has="'require:outlocking'"/>
            <a @click="locking(record,'是否确定解锁',0)" v-has="'require:outlocking'">解锁</a>
          </template>
        </span>

      </a-table>
    </div>

    <hwPlatform-modal ref="modalForm" @ok="modalFormOk"></hwPlatform-modal>
  </a-card>
  </div>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HwPlatformModal from './modules/HwPlatformModal'
  import { getAction, deleteAction, putAction, postAction } from '@/api/manage'
  const locking = (params) => putAction('/platmanager/hwPlatform/locking', params)
  export default {
    name: "HwPlatformList",
    mixins:[JeecgListMixin],
    components: {
      HwPlatformModal
    },
    data () {
      return {
        description: '平台信息管理页面',
        // 表头
        columns: [
          {
            title:'平台名称',
            align: 'left',
            dataIndex: 'platformName',
            scopedSlots: { customRender: 'action1' },
          },
          {
            title:'企业名称',
            align: 'left',
            dataIndex: 'enterpriseName'
          },
          {
            title:'业务归属',
            align: 'left',
            dataIndex: 'businessBelong'
          },
          {
            title: '数据共享开关',
            dataIndex: 'isShare',
            align: 'left',
            scopedSlots: { customRender: 'action2' },
          },
          {
            title:'状态',
            align: 'left',
            dataIndex: 'status_dictText',
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'left',
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/platmanager/hwPlatform/list",
          delete: "/platmanager/hwPlatform/delete",
          deleteBatch: "/platmanager/hwPlatform/deleteBatch",
          exportXlsUrl: "/platmanager/hwPlatform/exportXls",
          importExcelUrl: "platmanager/hwPlatform/importExcel",
          edit: '/platmanager/hwPlatform/edit',
        },
        dictOptions:{
        }
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      //锁定解锁
      locking(record,title,status) {
        let that = this
        that.$confirm({
          title: title,
          // content: record.platformName,
          okText: '确定',
          cancelText: '取消',
          onOk: function() {
            locking({ id: record.id,status:status }).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.loadData(1)
              } else {
                that.$message.warning(res.message)
              }
            })
          },
          onCancel() {

          }
        })
      },

      handleDetail(record){
        this.$refs.modalForm.view(record);
        this.$refs.modalForm.title="详情";
      },

      changeIsShare(record) {
        this.loading = true
        var isShare=record.isShare==1?0:1
        record.isShare=isShare
        let url = this.url.edit
        putAction(url, record).then(data => {
          if (data.success) {
            this.loadData

          }
          if (data.code === 510) {
            this.$message.warning(res.message)
          }
          this.loading = false
        })
      },


    },





  }
</script>
<style scoped>
  @import '~@assets/less/common.less'
</style>