<template>
  <div class="page">
    <topBar
      v-if="topList.length > 0"
      :top-list="topList"
      :moren="moren"
    />
    <div class="thetopbox">
      <el-form ref="form" :model="queryParams" label-width="100px">
        <el-row>
          <el-col :span="4">
            <el-form-item :label="'结算期数'" prop="memberSettlePeriodId">
              <el-select
                v-model="queryParams.memberSettlePeriodId"
                :placeholder="'请选择'"
              >
                <el-option
                  v-for="item in memberSettlePeriodList"
                  :key="item.pkId"
                  :label="item.settleDate"
                  :value="item.pkId"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item :label="'会员编号'" prop="memberCode">
              <el-input
                v-model="queryParams.memberCode"
                clearable
              />
            </el-form-item>
          </el-col>

          <el-col :span="4">
            <el-form-item label="阶段" prop="stage">
              <el-select
                v-model="queryParams.stage"
                placeholder="请选择"
              >
                <el-option
                  v-for="(item, index) in levelList"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4">
            <el-form-item label="状态" prop="stageStatus">
              <el-select
                v-model="queryParams.stageStatus"
                :placeholder="'请选择'"
                clearable
              >
                <el-option
                  v-for="(item, index) in statusEnum"
                  :key="index"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="4" style="margin-left: 30px">
            <div class="searchbox">
              <el-button
                :loading="loading"
                class="searchbtn"
                @click="getSearch"
              > {{ '搜索' }}</el-button>
              <el-button @click="resetHandle"> {{ '重置' }}</el-button>
            </div>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <div class="main">
      <div class="maintable">
        <el-table
          ref="table"
          v-loading="loading"
          :data="tableData"
          :height="'630px'"
          :header-cell-style="{ background: '#EEEEEE' }"
          lass="content"
          style="width: 100%;"
          :row-class-name="tableRowClassName"
        >
          <el-table-column type="selection" />

          <el-table-column
            align="center"
            prop="orderSourceVal"
            label="子点位"
            width="180"
          >
            <template slot-scope="scope">
              {{ tempMemberCode + '-' + scope.row.childNode }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="pointTypeLabel"
            label="点位类型"
            width="100"
          >
            <template slot-scope="scope">
              <el-tag size="small" :type="scope.row.pointTypeLabel === '普通点位' ? 'info' : 'warning'">
                {{ scope.row.pointTypeLabel }}
              </el-tag>

            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="stage"
            label="阶段"
            width="100"
          >
            <template slot-scope="scope">
              {{ scope.row.stage === 1 ? '一阶段' : scope.row.stage === 2 ? '二阶段' : '三阶段' }}
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="stageStatus"
            label="状态"
            width="100"
          >
            <template slot-scope="scope">
              <el-tag v-if="scope.row.stageStatus !== 1" size="small" type="success">已完成</el-tag>
              <span v-else>未完成</span>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="customer"
            label="点位"
          >
            <template slot-scope="scope">
              <div style="display: flex; justify-content: center;  column; gap: 20px;">
                <div style="display: flex;  column; gap: 6px;">
                  <div
                    v-for="(item, idx) in level1"
                    :key="idx"
                    class="node-wrapper"
                    :class="{ 'empty-node': !scope.row[item.memberName] }"
                    @click="handleNodeClick(item, scope.row)"
                  />
                </div>
                <div style="display: flex;  column; gap: 6px;">
                  <div
                    v-for="(item, idx) in level2"
                    :key="idx"
                    class="node-wrapper"
                    :class="{ 'empty-node': !scope.row[item.memberName] }"
                    @click="handleNodeClick(item, scope.row)"
                  />
                </div>
                <div style="display: flex;  column; gap: 6px;">
                  <div
                    v-for="(item, idx) in level3"
                    :key="idx"
                    class="node-wrapper"
                    :class="{ 'empty-node': !scope.row[item.memberName] }"
                    @click="handleNodeClick(item, scope.row)"
                  />
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column
            align="center"
            prop="creationTime"
            :label="'激活日期'"
            width="210"
          />

        </el-table>
      </div>
    </div>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <el-dialog
      :visible.sync="nodeInfoDialogVisible"
      title="子节点信息"
      width="50%"
    >
      <el-row :gutter="20">
        <el-col :span="24">
          <div class="box">
            <div class="title">
              {{ queryParams.memberCode }}
              <el-tag size="small">{{ nodeInfo.position }}</el-tab>
              </el-tag></div>
          </div>
        </el-col>
        <el-col style="margin-bottom: 10px;" :span="12">
          <span
            style="margin-right: 10px; font-weight: 500;"
            @click="copyContent(nodeInfo.memberCode)"
          >会员编号：</span>
          <span>{{ nodeInfo.memberCode }}</span>
        </el-col>
        <el-col style="margin-bottom: 10px; " :span="12">
          <span style="margin-right: 10px; font-weight: 500;">点位信息：</span>
          <span>{{ nodeInfo.memberName }}</span>
        </el-col>
        <el-col style="margin-bottom: 10px;" :span="12">
          <span style="margin-right: 10px; font-weight: 500;">荣誉奖衔：</span>
          <span>{{ nodeInfo.awardsName }}</span>
        </el-col>
        <el-col style="margin-bottom: 10px;" :span="12">
          <span style="margin-right: 10px; font-weight: 500;">隶属体系：</span>
          <span>{{ nodeInfo.vertexName }}</span>
        </el-col>
        <el-col style="margin-bottom: 10px;" :span="12">
          <span style="margin-right: 10px; font-weight: 500;">创建时间：</span>
          <span>{{ nodeInfo.creationTime }}</span>
        </el-col>
        <!-- <el-col :span="12">
          <span>隶属体系</span>
          <span>{{ nodeInfo.vertexName }}</span>
        </el-col> -->
      </el-row>
      <template #footer>
        <el-button type="primary" @click="nodeInfoDialogVisible = false">关闭</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import topBar from '@/components/topBar'
import {
  getAzFrameworkList,
  getAzFramewrokNodeInfo,
  getMemberSettlePeriod
} from '@/api/archityecture'
import { isLocals } from '../../../utils/numberToCurrency'
import tabBarMixin from './mixins/tab-bar'

const initParmas = {
  pageNum: 1,
  pageSize: 50,
  memberSettlePeriodId: '',
  memberCode: '',
  stage: 1,
  stageStatus: ''
}
export default {
  name: 'Azjg',
  components: {
    topBar
  },
  mixins: [tabBarMixin],
  data() {
    return {
      moren: 'azjg2',
      queryParams: {
        ...initParmas
      },
      levelList: [
        { value: 1, label: '一阶段' },
        { value: 2, label: '二阶段' },
        { value: 3, label: '三阶段' }
      ],
      statusEnum: [
        { value: 0, label: '已完成' },
        { value: 1, label: '未完成' }
      ],
      level1: [
        {
          memberName: 'pointMember11',
          pointKey: 'point11'
        },
        {
          memberName: 'pointMember12',
          pointKey: 'point12'
        }
      ],
      level2: [
        {
          memberName: 'pointMember21',
          pointKey: 'point21'
        },
        {
          memberName: 'pointMember22',
          pointKey: 'point22'
        },
        {
          memberName: 'pointMember23',
          pointKey: 'point23'
        },
        {
          memberName: 'pointMember24',
          pointKey: 'point24'
        }
      ],
      level3: [
        {
          memberName: 'pointMember31',
          pointKey: 'point31'
        },
        {
          memberName: 'pointMember33',
          pointKey: 'point33'
        },
        {
          memberName: 'pointMember34',
          pointKey: 'point34'
        },
        {
          memberName: 'pointMember35',
          pointKey: 'point35'
        },
        {
          memberName: 'pointMember36',
          pointKey: 'point36'
        },
        {
          memberName: 'pointMember37',
          pointKey: 'point37'
        },
        {
          memberName: 'pointMember38',
          pointKey: 'point38'
        }
      ],
      tableData: [],
      memberSettlePeriodList: [], // 期数
      loading: false,
      total: 0,
      nodeInfo: {},
      nodeInfoDialogVisible: false,
      tempMemberCode: ''
    }
  },
  created() {
    getMemberSettlePeriod().then((res) => {
      if (res.code === 200) {
        this.memberSettlePeriodList = (res.data || []).filter(item => item.isThisDay !== 0)
        this.queryParams.memberSettlePeriodId = this.memberSettlePeriodList[0].pkId
      }
    })
  },
  methods: {
    isLocals,
    getSearch() {
      if (!this.queryParams.memberCode) {
        this.$message.warning('会员编号不能为空')
        return
      }
      this.tempMemberCode = this.queryParams.memberCode
      this.queryParams.pageNum = 1
      this.getList()
    },
    getList() {
      this.loading = true
      getAzFrameworkList(this.queryParams).then((res) => {
        if (res.code === 200) {
          this.tableData = res.data.rows
          this.total = res.data.total
        }
      }).finally(() => {
        this.loading = false
      })
    },
    handleNodeClick(node, row) {
      const memberId = row[node.memberName]
      console.log(memberId, node, '...memberId')
      this.nodeInfo = {}
      if (memberId) {
        this.nodeInfoDialogVisible = true
        this.getMemberInfoById({
          pkMember: row.pkMember,
          point: row[node.pointKey],
          stage: row.stage,
          position: node.pointKey.replace('point', '').split('').join('-'),
          pointMember: memberId
        })
      }
    },
    getMemberInfoById({ pkMember, point, stage, position, pointMember }) {
      this.nodeInfo = {}
      getAzFramewrokNodeInfo({
        point,
        pkMember,
        memberSettlePeriodId: this.queryParams.memberSettlePeriodId,
        stage,
        pointMember
      }).then((res) => {
        if (res.code === 200) {
          this.nodeInfo = {
            ...res.data,
            position
          }
        }
      })
    },
    resetHandle() {
      this.queryParams = {
        ...initParmas
      }
      this.queryParams.memberSettlePeriodId = this.memberSettlePeriodList[0].pkId
      this.tableData = []
      this.childNodeList = []
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'warning-row'
      } else if (rowIndex % 2 === 0) {
        return 'success-row'
      }
      return ''
    },
    copyContent(content) {
      // this.$message.success('复制成功')
    }

  }
}
</script>
<style scoped lang="scss">

::v-deep .el-range-editor.el-input__inner{
  width: 100%!important;
}
::v-deep .el-button{
  padding: 8px 20px;
}
::v-deep .el-date-editor .el-range__close-icon{
  margin-top: -10px;
}
::v-deep .el-date-editor .el-range-separator{
  margin-top: -10px;
}
::v-deep .el-date-editor .el-range__icon{
  margin-top: -10px;
}
::v-deep .el-input__inner{
  //height:28px;
  //line-height: 28px;
}
::v-deep .el-form-item__label{
  color: #333;
  font-weight: inherit;
}
::v-deep .el-table .warning-row {
  background: #f9f9f9;
}

::v-deep .el-table .success-row {
  background: #ffffff;
}
::v-deep .el-table thead {
  color: #000000;
}
::v-deep .el-select {
  width: 100%;
}
.uploadIcon ::v-deep .el-upload--picture-card {
  display: none !important; /* 上传按钮隐藏 */
}
.page {
  padding: 20px;
  background: #f9f9f9;
  font-size: 14px;
  .main {
    background: #f9f9f9;
    .maintop {
      display: flex;
      padding: 0 0;
      justify-content: space-between;
      align-items: center;

    }
  }
}

.searchbtn {
  width: 68px;
  background: #c8161d;
  color: #ffffff;
}
.node-wrapper {
  width: 20px;
  height: 20px;
  // 激活颜色
  background-color: #007bff;
  border-radius: 50%;
  cursor: pointer;
}
.empty-node {
  background-color: #fff;
  border: 2px dashed #95a5a6;
}
.title {
  font-size: 16px;
  font-weight: bold;
  color: #333333;
  margin-bottom: 18px;
}
</style>
