<template>
  <div>
    <a-card :bordered="false">
      <div>
      </div>


      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="二级部门名称">
                <j-input placeholder="请输入二级部门名称" v-model="queryParam.aname"></j-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="三级部门名称">
                <j-input placeholder="请输入三级部门名称" v-model="queryParam.three_company_id"></j-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="营业厅名称">
                <j-input placeholder="请输入营业厅名称" v-model="queryParam.bname"></j-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <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>

            </span>
            </a-col>
          </a-row>

        </a-form>
      </div>

      <!-- 操作按钮区域 -->
      <div class="table-operator">
<!--        <a-button type="primary" icon="download" @click="handleExportXls('入网统计')">导出</a-button>-->
        <a-button type="primary" icon="add" @click="addAddress()">新增</a-button>
        <!-- 高级查询区域 -->
        <a-dropdown v-if="selectedRowKeys.length > 0">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="delList" v-has="'access:check:lists:up'">
              <a-icon type="up"/>
              删除
            </a-menu-item>
          </a-menu>
          <a-button style="margin-left: 8px"> 批量操作
            <a-icon type="down"/>
          </a-button>
        </a-dropdown>
      </div>
      <div>
        <a-modal v-model:open="open" title="请填写信息"     >
          <template slot="footer" >
            <a-button type="primary" @click="onSubmit">提交</a-button>
            <a-button style="margin-left: 10px" @click="cancellation" >取消</a-button>
          </template>

          <a-form :model="formState"  :labelCol="{ span:9}"   :wrapperCol="{ span: 14 }">
            <a-form-item label="二级部门名称"  >
              <a-input v-model:value="formState.aname"  />
            </a-form-item>
            <a-form-item label="三级部门名称"  >
              <a-input v-model:value="formState.three_company_id"  />
            </a-form-item>
            <a-form-item label="营业厅名称"  >
              <a-input v-model:value="formState.bname"  />
            </a-form-item>
            <a-form-item label="营业厅地址"  >
              <a-input v-model:value="formState.address"  />
            </a-form-item>
            <a-form-item label="坐标"  >
              <a-input v-model:value="formState.coordinate"  />
            </a-form-item>

          </a-form>

        </a-modal>

      </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"
          :scroll="{x:true}"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
          class="j-table-force-nowrap"
          @change="handleTableChange">


          <template slot="action" slot-scope="text, record">
            <div>
            <span v-has="'userStatistics:list:update'"  >
              <a @click="showImproveAndUpload(record)">修改</a>
              <a-divider type="vertical"/>
            </span>

              <span v-has="'userStatistics:list:update'"  >
              <a @click="del(record)">删除</a>
              <a-divider type="vertical"/>
            </span>

            </div>

          </template>

          <template v-slot:rowIndex="text,records,index">
            {{ (ipagination.current - 1) * ipagination.pageSize + Number(index) + 1 }}
          </template>

        </a-table>

      </div>

    </a-card>


  </div>
</template>

<script>
import {getAction, postAction,deleteAction} from "@api/manage";
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import '@/assets/less/TableExpand.less'

export default {
  name: "userStatistics",
  mixins: [JeecgListMixin],
  inject: ['closeCurrent'],
  data() {
    return {
      formState:{
        aid:'',
        aname: '',
        three_company_id: '',
        bname:'',
        address:"",
        coordinate:''
      },
      open:false,
      labelCol:{
        style: { width: '300px' }
      },
      wrapperCol:20,
      company:'',
      sysCompany: [],
      ipagination:{
        current: 1,
        pageSize: 10,
        pageSizeOptions: ['10', '20', '30','300'],
        showTotal: (total, range) => {
          return range[0] + "-" + range[1] + " 共" + total + "条"
        },
        showQuickJumper: true,
        showSizeChanger: true,
        total: 0
      },
      numberResults: null,

      delCount: 0,
      /* table选中keys*/
      selectedRowKeys: [],
      /* table选中records*/
      selectionRows: [],
      /* 查询条件-请不要在queryParam中声明非字符串值的属性 */
      queryParam: {},
      url: {
        list: "/sysCompany/listPage",
        typeCount: "/businessReminderCard/type/count",
        delete: "/businessReminderCard/delete/flagById",
        removeById: "/businessReminderCard/deleteById",
        restoreById: "/businessReminderCard/restoreById",
        notice: "/smsCheck/customerInfo/notice",
        exportXlsUrl: "/businessReminderCard/exportXls",
      },
      /**表单
       * 入网用户统计：身份证号/姓名/办理电话/创建人/创建人所属营业厅/更新人/更新人营业厅/研判结果/
       * */
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          scopedSlots: {customRender: 'rowIndex'}
        },
        {
          title: '二级部门',
          align: "center",
          sorter: true,
          dataIndex: 'aname'

        }, {
          title: '三级部门',
          align: "center",
          sorter: true,
          dataIndex: 'three_company_id'
         // scopedSlots: {customRender: 'cardName'}
        }, {
          title: '营业厅名称',
          align: "center",
          sorter: true,
          dataIndex: 'bname'
          // scopedSlots: {customRender: 'createBy'}
        },{
          title: '营业厅地址',
          align: "center",
          sorter: true,
          dataIndex: 'address'
         // scopedSlots: {customRender: 'createBy'}
        }, {
          title: '坐标',
          align: "center",
          sorter: true,
          dataIndex: 'coordinate'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'}
        }
      ],
    }
  },

  created() {


    this.getSysCompanyData();


  },
  methods: {
    cancellation(){
       this.formState = {}
      this.open=false;
    },
    onSubmit(){
      postAction("/sysCompany/add", {data:this.formState}).then((res) => {
        if (res.success) {
          this.$message.success(res.message, 3);
          this.open=false;
          this.loadData(1);
        }else {
          this.$message.error(res.message, 3);
          this.open=false;
          this.loadData(1);
        }
      })
    },
    getSysCompanyData(){
      let data = {

      };
      getAction("/sysCompany/list", data).then((res) => {
        if (res.success) {
          let result = res.result;
          console.log(result + "result");
          if (result != null) {
            this.sysCompany = result;
          }
        }
      })
    },
    getSysCompany(id) {

      for (var item of this.sysCompany) {

        for (var it of item.sysBusinessHallList) {
          if (it.id === id) {
            return it.name
          }
        }

      }
    },





    searchQuery() {
      this.loadData(1);
      this.selectedRowKeys = [];
      this.selectionRows = [];
      //this.loadTabNumber(this.task.id);
    },

    getDate(){
      var today = new Date();
      var dd = String(today.getDate()).padStart(2, '0');
      var mm = String(today.getMonth() + 1).padStart(2, '0');
      var yyyy = today.getFullYear();

      today =  yyyy+'-'+ mm+'-' +dd;
      return today;
    },
    /**修改*/
    showImproveAndUpload(record) {
      this.formState={
          bid:record.bid,
          aid:record.aid,
           aname: record.aname,
          three_company_id: record.three_company_id,
          bname:record.bname,
          address:record.address,
          coordinate:record.coordinate
      }
      this.open =true

    },
    del(record) {

      let data = {
        ids: [record.bid],
      }
      postAction("/sysCompany/delAddressList",{ids: data.ids} ).then((res) => {
        if (res.success) {
          this.$message.success(res.message, 3);
          this.loadData(1);
        } else {
          this.$message.error(res.message);
        }
      })
    },
    addAddress(){
      this.open=true;
    },
    delList(record) {
      var l =[];
      for (let i = 0; i <  this.selectionRows.length; i++) {
         l.push( this.selectionRows[i].bid)
      }
      let data = {
        ids: l,
      }

      postAction("/sysCompany/delAddressList",{ids: data.ids} ).then((res) => {
        if (res.success) {
          this.$message.success(res.message, 3);
          this.loadData(1);
        } else {
          this.$message.error(res.message);
        }
      })
    },

    selectRefresh(){
      let queryParam = {
        "cardNo":this.queryParam.cardNo,
        "cardName":record.cardName,
        "newPhone":this.queryParam.newPhone,
        "createDateStart":this.queryParam.createDateStart,
        "createDateEnd":this.queryParam.createDateEnd,
        "sysBusinessHall":this.queryParam.sysBusinessHall,
        "status":this.queryParam.status
      }
      this.loadData(null,queryParam);
    },


  },
}
</script>

<style scoped>

</style>