<template>
  <a-row :gutter="10">
    <a-col :md="leftColMd" :sm="24" style="margin-bottom: 20px">
      <a-card :bordered="false">
        <!-- 查询区域 -->
<!--        <div class="table-page-search-wrapper">-->
<!--          <a-form layout="inline" @keyup.enter.native="searchQuery">-->
<!--            <a-row :gutter="24">-->
<!--            </a-row>-->
<!--          </a-form>-->
<!--        </div>-->
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
<!--          <a-button type="primary" icon="download" @click="handleExportXls('clock_in_project')">导出</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>-->
          <!-- 高级查询区域 -->
<!--          <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>-->
          <a-dropdown v-if="selectedRowKeys.length > 0">
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
            </a-menu>
            <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
          </a-dropdown>
        </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="htmlSlot" slot-scope="text">
              <div v-html="text"></div>
            </template>
            <template slot="imgSlot" slot-scope="text,record">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img v-else :src="getImgView(text)" :preview="record.id" 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="downloadFile(text)">
                下载
              </a-button>
            </template>

            <span slot="action" slot-scope="text, record">
              <a @click="handleOpen(record)">配置</a>
              <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
            <a-menu slot="overlay">
<!--              <a-menu-item>-->
<!--                <a @click="handleLocation(record)">定位</a>-->
<!--              </a-menu-item>-->
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

          </a-table>
        </div>

        <clock-in-project-modal ref="modalForm" @ok="modalFormOk"></clock-in-project-modal>
      </a-card>
    </a-col>
    <a-col :md="rightColMd" :sm="24" v-if="this.rightcolval == 1">
      <a-card :bordered="false">
        <div style="text-align: right;">
          <a-icon type="close-circle" @click="hideUserList" />
        </div>
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline">
            <a-row :gutter="24">

              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
<!--            <a-col :md="9" :sm="24">-->
                <!--             <a-button type="primary" @click="searchQuery2" icon="search" style="margin-left: 21px">查询</a-button>-->
                <!--              <a-button type="primary" @click="searchReset2" icon="reload" style="margin-left: 8px">重置</a-button>-->

                <!--            </a-col>-->
          </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" :md="24" :sm="24">
          <a-button @click="handleAdd2" type="primary" icon="plus" style="margin-top: 16px">新增</a-button>
          <!--          <a-button @click="handleAdd2" type="primary" icon="plus" style="margin-top: 16px">新增规格</a-button>-->
          <!--<a-button @click="handleEdit2" type="primary" icon="edit" style="margin-top: 16px">用户编辑</a-button>-->
          <!--          <a-button @click="handleAddUserRole" type="primary" icon="plus" style="margin-top: 16px">已有用户</a-button>-->

          <!--          <a-dropdown v-if="selectedRowKeys2.length > 0">-->
          <!--            <a-menu slot="overlay">-->
          <!--              <a-menu-item key="1" @click="batchDel2">-->
          <!--                <a-icon type="delete"/>-->
          <!--                删除-->
          <!--              </a-menu-item>-->
          <!--            </a-menu>-->
          <!--            <a-button style="margin-left: 8px"> 批量操作-->
          <!--              <a-icon type="down"/>-->
          <!--            </a-button>-->
          <!--          </a-dropdown>-->
        </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">{{-->
          <!--              selectedRowKeys2.length }}</a>项-->
          <!--            <a style="margin-left: 24px" @click="onClearSelected2">清空</a>-->
          <!--          </div>-->
          <a-table
            style="height:500px"
            ref="table2"
            bordered
            size="middle"
            rowKey="id"
            :columns="columns2"
            :dataSource="dataSource2"
            :pagination="ipagination2"
            :loading="loading2"
            :rowSelection="{selectedRowKeys: selectedRowKeys2, onChange: onSelectChange2}"
            @change="handleTableChange2">
            <template slot="imgSlot" slot-scope="text,record">
              <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
              <img v-else :src="getImgView(text)" :preview="record.id" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
            </template>
            <span slot="action" slot-scope="text, record">
           <a @click="handleEdit2(record)">编辑</a>
                        <a-divider type="vertical"/>
          <a-dropdown>
            <a class="ant-dropdown-link">
              更多 <a-icon type="down"/>
            </a>
                        <a-menu slot="overlay">
                          <a-menu-item>
                <a @click="handleDetail2(record)">详情</a>
              </a-menu-item>
                          <a-menu-item>
                            <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete2(record.id)">
                              <a>删除</a>
                            </a-popconfirm>
                          </a-menu-item>
                        </a-menu>
          </a-dropdown>
        </span>
          </a-table>
        </div>
        <!-- 表单区域 -->
        <clock-in-project-item-modal ref="modalForm2" @ok="modalFormOk2"></clock-in-project-item-modal>
        <!--        <Select-User-Modal ref="selectUserModal" @selectFinished="selectOK"></Select-User-Modal>-->
      </a-card>
    </a-col>
  </a-row>

</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ClockInProjectModal from './modules/ClockInProjectModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import {deleteAction, getAction, httpAction} from "@api/manage";
  import ClockInProjectItemModal from './modules/ClockInProjectItemModal'

  export default {
    name: 'ClockInProjectList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ClockInProjectModal,
      ClockInProjectItemModal
    },
    data () {
      return {
        description: 'clock_in_project管理页面',
        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'项目名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'经度',
            align:"center",
            dataIndex: 'lon'
          },
          {
            title:'纬度',
            align:"center",
            dataIndex: 'lat'
          },
          {
            title:'打卡距离(单位米)',
            align:"center",
            dataIndex: 'distance'
          },

          {
            title:'团队编号',
            align:"center",
            dataIndex: 'teamId_dictText'
          },
          {
            title:'是否删除',
            align:"center",
            dataIndex: 'delFlag_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
        url: {
          list: "/clockInproject/clockInProject/list",
          delete: "/clockInproject/clockInProject/delete",
          deleteBatch: "/clockInproject/clockInProject/deleteBatch",
          exportXlsUrl: "/clockInproject/clockInProject/exportXls",
          importExcelUrl: "clockInproject/clockInProject/importExcel",
          detailList: "/clockInprojectitem/clockInProjectItem/list",
          delete2: "/clockInprojectitem/clockInProjectItem/delete"
        },
        dictOptions:{},
        superFieldList:[],
        rightcolval:0,
        currentRoleId: '',
        selectionRows2: [],
        selectedRowKeys2:[],
        dataSource2:[],
        ipagination2: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        columns2:[
          {
            title:'打卡开始时间',
            align:"center",
            dataIndex: 'clockStartTime'
          },
          {
            title:'打卡结束时间',
            align:"center",
            dataIndex: 'clockEndTime'
          },
          {
            title:'类型',
            align:"center",
            dataIndex: 'type_dictText'
          },
          {
            title:'排序',
            align:"center",
            dataIndex: 'sort'
          },
          {
            title:'是否删除',
            align:"center",
            dataIndex: 'delFlag_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],
      }
    },
    created() {
    this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      leftColMd() {
        return this.selectedRowKeys.length === 0 ? 24 : 12
      },
      rightColMd() {
        return this.selectedRowKeys.length === 0 ? 0 : 12
      }
    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'name',text:'项目名',dictCode:''})
        fieldList.push({type:'string',value:'lon',text:'经度',dictCode:''})
        fieldList.push({type:'string',value:'lat',text:'纬度',dictCode:''})
        fieldList.push({type:'string',value:'teamId',text:'团队编号',dictCode:"clockin_team,name,id"})
        fieldList.push({type:'int',value:'delFlag',text:'是否删除',dictCode:'is_delete'})
        this.superFieldList = fieldList
      },
      searchQuery2() {
        this.loadData2(1)
      },
      searchReset2() {
        this.queryParam2 = {}
        this.loadData2(1)
      },
      handleTableChange2(pagination, filters, sorter) {
        //分页、排序、筛选变化时触发
        //TODO 筛选
        if (Object.keys(sorter).length > 0) {
          this.isorter2.column = sorter.field
          this.isorter2.order = 'ascend' == sorter.order ? 'asc' : 'desc'
        }
        this.ipagination2 = pagination
        this.loadData2()
      },
      hideUserList(){
        //this.rightcolval = 0
        this.selectedRowKeys = []
      },
      handlePerssion(roleId){
        this.$refs.modalUserRole.show(roleId);
      },
      onSelectChange2(selectedRowKeys, selectionRows) {
        this.selectedRowKeys2 = selectedRowKeys
        this.selectionRows2 = selectionRows
      },
      onClearSelected2() {
        this.selectedRowKeys2 = []
        this.selectionRows2 = []
      },
      handleOpen(record) {
        this.rightcolval = 1
        this.selectedRowKeys = [record.id]
        this.model = Object.assign({}, record)
        this.currentRoleId = record.id
        this.onClearSelected2()
        this.loadData2()
      },
      loadData2(arg) {
        if (!this.url.detailList) {
          this.$message.error('请设置url.list2属性!')
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination2.current = 1
        }
        if (this.currentRoleId === '') return
        // let params = this.getQueryParams2()//查询条件
        // params.orderId = this.currentRoleId
        let params = {
          projectId: this.currentRoleId
        }
        this.loading2 = true
        getAction(this.url.detailList, params).then((res) => {
          if (res.success) {
            this.dataSource2 = res.result.records
            this.ipagination2.total = res.result.total

          }
          this.loading2 = false
        })

      },
      getQueryParams2() {
        //获取查询条件
        let sqp = {}
        if (this.superQueryParams2) {
          sqp['superQueryParams'] = encodeURI(this.superQueryParams2)
          sqp['superQueryMatchType'] = this.superQueryMatchType2
        }
        var param = Object.assign(sqp, this.queryParam2, this.isorter2, this.filters2)
        param.field = this.getQueryField2()
        param.pageNo = this.ipagination2.current
        param.pageSize = this.ipagination2.pageSize
        return filterObj(param)
      },
      handleEdit2: function(record) {
        this.$refs.modalForm2.title = '编辑'
        this.$refs.modalForm2.roleDisabled = true
        this.$refs.modalForm2.edit(record)
      },
      modalFormOk2() {
        // 新增/修改 成功时，重载列表
        this.loadData2()
      },
      handleAdd2: function() {
        if (this.currentRoleId == '') {
          this.$message.error('!')
        } else {
          this.$refs.modalForm2.roleDisabled = true
          this.$refs.modalForm2.title = '新增'
          this.$refs.modalForm2.edit({activitiSync:'1',userIdentity:1,projectId:this.currentRoleId})
        }
      },
      handleDetail2:function(record){
        this.$refs.modalForm2.edit(record);
        this.$refs.modalForm2.title="详情";
        this.$refs.modalForm2.disableSubmit = true;
      },
      handleDelete2: function (id) {
        if(!this.url.delete){
          this.$message.error("请设置url.delete属性!")
          return
        }
        var that = this;
        deleteAction(that.url.delete2, {id: id}).then((res) => {
          if (res.success) {
            //重新计算分页问题
            that.reCalculatePage(1)
            that.$message.success(res.message);
            that.loadData2();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>