<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.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="身份证号">
              <a-input placeholder="请输入身份证号" v-model="queryParam.idcardNumber"></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 :triggerChange="false" v-model="queryParam.idcardPictureType" placeholder="请选择身份证照片查询"
                                   dictCode="idcardPictureType" v-decorator="['idcardPictureType', {}]"/>
              </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.contractUpload" placeholder="请选择"
                                     dictCode="contractUpload"></j-dict-select-tag>
                </a-form-item>
              </a-col>
            </template>



            <a-col :md="6" :sm="8">
              <a-form-item label="最后付款企业">
                <a-input placeholder="请输入最后付款企业" v-model="queryParam.lastPaymentCompany"></a-input>
              </a-form-item>
            </a-col>
            <!--<a-col :md="6" :sm="8">-->
            <!--<a-spin :spinning="confirmLoading">-->
              <!--<a-form :form="form">-->

                <!--<a-form-item label="服务商" :labelCol="labelCol" :wrapperCol="wrapperCol">-->
                  <!--<template v-if="!model.id">-->
                    <!--<a-input-search-->
                      <!--placeholder="选择服务商"-->
                      <!--disabled-->
                      <!--v-decorator="[ 'subcontractorName', {}]"-->
                      <!--@search="onSearch">-->
                      <!--<a-button slot="enterButton" icon="search" v-if="!model.id">选择</a-button>-->
                    <!--</a-input-search>-->
                  <!--</template>-->
                <!--</a-form-item>-->

              <!--</a-form>-->
            <!--</a-spin>-->
            <!--</a-col>-->

            <!--<a-col :md="6" :sm="8">-->
              <!--<a-form-item label="用户合同">-->
                <!--<j-dict-select-tag :triggerChange="false" v-model="queryParam.subcontractType" placeholder="请选择用户合同查询"-->
                                   <!--dictCode="idcardPictureType" v-decorator="['subcontractType', {}]"/>-->
              <!--</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="this.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="'hlguser:add'">新增</a-button>
      <!--<a-button type="primary" icon="download" @click="handleExportXls('hlg_user')">导出</a-button>-->
      <a class="ant-btn ant-btn-primary" @click="handleImportExcel1()" icon="import" type="primary" v-has="'hlguser:inport'">导入</a>

      <!--<a-button @click="deleteUser()" type="primary"  style="margin-left: 8px" v-has="'hlguser:delete'">删除</a-button>-->
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        @change="handleTableChange">
        
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="图片不存在" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无此文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="uploadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleUserSubcontractor(record)" v-has="'hlguser:subcontractor'">服务商</a>

          <a-divider type="vertical" v-has="'hlguser:edit'"/>
          <a @click="handleEdit(record)" v-has="'hlguser:edit'">编辑</a>
        </span>


        <span slot="action1" slot-scope="text, record">
          <template v-if="record.idcardPicture">
            <a style="color:#000c17">已上传
              <a-icon type="upload" :style="{color:'#8e8e8e'}" title="点击上传" @click="uploadIdcardPicture(record)" style="margin-left: 8px" />
            </a>
            </template>
            <template v-if="!record.idcardPicture">
            <a style="color:#000c17">未上传
              <a-icon type="upload" :style="{color:'#8e8e8e'}" title="点击上传" @click="uploadIdcardPicture(record)" style="margin-left: 8px" />
            </a>
            </template>
        </span>

      </a-table>
    </div>

    <hlgUser-modal ref="modalForm" @ok="modalFormOk"></hlgUser-modal>
    <hlg-user-subcontractor  ref="userSubcontractorForm" @ok="modalFormOk"></hlg-user-subcontractor>
    <hlg-user-export-modal ref="modalSelectRequireForm" @ok="modalFormOk"></hlg-user-export-modal>
    <user-subcontractor-window ref="subcontractorWindow" @ok="modalFormOk1"></user-subcontractor-window>
    <hlg-upload-photo-modal  ref="uploadPhotoForm" @ok="modalFormOk"></hlg-upload-photo-modal>
  </a-card>
  </page-layout>
</template>

<script>

  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import HlgUserModal from './modules/HlgUserModal'
  import HlgUserSubcontractor from './modules/HlgUserSubcontractor'
  import HlgUserExportModal from './modules/HlgUserExportModal'
  import UserSubcontractorWindow from './modules/UserSubcontractorWindow'
  import HlgUploadPhotoModal from './modules/HlgUploadPhotoModal'
  import PageLayout from '@/components/page/PageLayout'
  import { getAction, deleteAction, putAction, postAction } from '@/api/manage'
  const deleteMany = (params) => deleteAction('/hlguser/hlgUser/deleteBatch', params)
  export default {
    name: "HlgUserList",
    mixins:[JeecgListMixin],
    components: {
      HlgUploadPhotoModal,
      UserSubcontractorWindow,
      HlgUserExportModal,
      HlgUserSubcontractor,
      HlgUserModal,
      PageLayout
    },
    data () {
      return {
        model: {},
        form: this.$form.createForm(this),
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        queryParam:{},
        selectedDepartKeys:[], //保存用户选择服务商id
        checkedDepartKeys:[],
        confirmLoading: false,
        platformId: 0,
        description: 'hlg_user管理页面',
        selectedRowKeys: [],
        selectedRows: [],
        // 表头
        columns: [
          {
            title:'姓名',
            align:"left",
            dataIndex: 'name'
          },
          {
            title:'身份证号',
            align:"left",
            dataIndex: 'idcardNumber'
          },
          {
            title:'身份证照片',
            align:"left",
            dataIndex: 'idcardPicture',
            scopedSlots: { customRender: 'action1' }
          },
          {
            title:'最后付款企业',
            align:"left",
            dataIndex: 'lastPaymentCompany'
          },
          {
            title:'合同情况',
            align:"left",
            dataIndex: 'contractUpload',
            customRender:function (text) {
              if(text==0){
                return "待上传"
              }else if(text==1){
                return "已上传"
              }else{
                return "--"
              }
            }

          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"left",
            scopedSlots: { customRender: 'action' },
          }
        ],
        url: {
          list: "/hlguser/hlgUser/list",
          delete: "/hlguser/hlgUser/delete",
          deleteBatch: "/hlguser/hlgUser/deleteBatch",
          exportXlsUrl: "/hlguser/hlgUser/exportXls",
          importExcelUrl: "hlguser/hlgUser/importExcel",
        },
        dictOptions:{
        } 
      }
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      }
    },
    methods: {
      initDictConfig(){
      },
      handleUserSubcontractor(record){
        this.$refs.userSubcontractorForm.edit(record)
        this.$refs.userSubcontractorForm.title = '服务商'
        this.$refs.userSubcontractorForm.disableSubmit = false
      },
      handleImportExcel1(){
        this.$refs.modalSelectRequireForm.edit()
        this.$refs.modalSelectRequireForm.title = '导入用户'
        this.$refs.modalSelectRequireForm.disableSubmit = false
      },

      //搜索服务商
      onSearch(){
        this.$refs.subcontractorWindow.add(this.checkedDepartKeys);
      },
      handleCancel () {
        this.close()
        this.selectedDepartKeys = [];
        this.checkedDepartKeys = [];
      },
      // 获取用户选择服务商弹提交的返回数据
      modalFormOk1 (formData) {
        console.log(1111,formData)
        this.selectedDepartKeys = [];
        for (let i = 0; i < formData.departIdList.length; i++) {
          this.selectedDepartKeys.push(formData.departIdList[i].key);
          this.form.setFieldsValue({ subcontractorName: formData.departIdList[i].title })
        }
        this.checkedDepartKeys = this.selectedDepartKeys  //更新当前的选择keys
         this.queryParam.subcontractorId= this.checkedDepartKeys[0];
      },

      uploadIdcardPicture(record){
        this.$refs.uploadPhotoForm.edit(record)
        this.$refs.uploadPhotoForm.title = '身份证照片'
        this.$refs.uploadPhotoForm.disableSubmit = false
      },
      onSelectChange (selectedRowKeys,selectedRows) {
        this.selectedRowKeys = selectedRowKeys;
        this.selectedRows = selectedRows;
      },
      deleteUser(){
        if(this.selectedRowKeys.length==0){
          this.$message.warning('请先选择')
          return
        }
        var list=""
        for(var i=0;i<this.selectedRowKeys.length;i++){
          if(i==0){
            list=this.selectedRowKeys[i]
          }else{
            list=list+","+this.selectedRowKeys[i]
          }
        }
        let that = this
        const modal = that.$confirm({
          title: '删除用户',
          closable: true,
          keyboard: false,
          maskClosable: true,
          content: '删除用户将失去用户的身份证和合同信息，确认要删除该用户吗',
          okText: '确定',
          cancelText: '取消',
          onOk: function() {
            that.loading = true;
            var param={ids:list}
            deleteMany(
              {ids:list}
            ).then((res) => {
              if (res.success) {
                that.$message.success(res.message)
                that.selectedRowKeys = [];
                that.selectedRows = [];
                // 刷新参数放到这里去触发，就可以刷新相同界面了
                that.loadData()
              } else {
                that.$message.warning(res.message)
              }
              that.loading = false
            })
          },
          onCancel() {
            modal.destroy()
          }
        })
      },
      // 重置
      searchReset(){
        var that = this;
        var logType = that.queryParam.logType;
        that.queryParam = {}; //清空查询区域参数
        that.queryParam.logType = logType;
        this.form.setFieldsValue({ subcontractorName: null})
        that.loadData(this.ipagination.current);
      },




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