<template>
  <div style="background-color:#f7f7f7;padding:10px 10px;">
    <div class="zhuti" v-if="onaction == '1'">
      <div style="height:58px;line-height:58px;">
        <div style="color:#0006"> <span>招商资源监测</span> <span style="padding:0 5px;">></span> <span
            style="color:#000000e6">资源地图</span></div>
      </div>
      <!-- 线上 -->
      <div>
        <div style="margin-bottom: 20px;">
          <el-button @click="removeonaction('2')" style="background-color: #3F9B6A;color: #fff;padding:8px 15px;"
            icon="el-icon-circle-plus-outline">新增</el-button>
          <!-- <el-button @click="" style="background-color: #3F9B6A;color: #fff">批量导入</el-button> -->
        </div>
        <!-- 地图 -->
        <div style="display: flex;justify-content: space-between;margin-bottom: 20px;">
          <div style="width: 100%;height: 400px; border: 1px solid #3F9B6A;position: relative;">
            <MapContainer :message="tableData" @MapItem='HandMapItem' ref="mapComponent"></MapContainer>
          </div>
        </div>
        <div style="margin: 20px 0;">
          <div style="display: flex;font-size: 14px">
            <div style="margin-right: 25px;cursor: pointer;" @click="chenge('1')" :class="ontype=='1'?'chengeXia':''">商铺
            </div>
            <div style="margin-right: 25px;cursor: pointer;" @click="chenge('2')" :class="ontype=='2'?'chengeXia':''">
              广告位</div>
            <div style="margin-right: 25px;cursor: pointer;" @click="chenge('3')" :class="ontype=='3'?'chengeXia':''">场地
            </div>
          </div>
        </div>
        <!-- 表格 -->
        <el-table v-if="ontype=='1'" :data="tableData"
          :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}">
          <el-table-column label="序号" min-width="80">
            <template slot-scope="scope">
              {{scope.$index +1 }}
            </template>
          </el-table-column>
          <el-table-column label="编号" prop="venueNumber" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="门牌号" prop="houseNumber" show-overflow-tooltip>

          </el-table-column>
          <el-table-column label="商铺名称" prop="shopName" show-overflow-tooltip>

          </el-table-column>
          <el-table-column label="所属区域" prop="belongingRegion" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="建筑形式" prop="architecturalForm" show-overflow-tooltip>
          </el-table-column>
          <el-table-column prop="detailedLocation" label="详细地址" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="实际使用面积" prop="actualUsableArea" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="负责人" prop="head" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="租赁到期时间" prop="leaseExpirationDate" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="状态" prop="publishStatus" show-overflow-tooltip>
            <template slot-scope="scope">
              {{scope.row.publishStatus=='0'?'待发布':scope.row.publishStatus=='1'?'已发布':scope.row.publishStatus=='2'?'已下架':scope.row.publishStatus=='3'?'待审核':scope.row.publishStatus=='4'?'驳回':'-'}}
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="250" fixed="right">
            <template slot-scope="scope">
              <div @click="details(scope.row)" class="tableBtn greens">查看</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0'" @click="removeinfo(scope.row,'编辑')">编辑
              </div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0'" @click="closemsg(scope.row)">删除</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0'"
              @click="opencl(scope.row,'sp')">发布</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='1'"
                @click="removeinfozz(scope.row,'2','下架')">下架</div>
            </template>
          </el-table-column>
        </el-table>
        <el-table v-if="ontype=='2'" :data="tableData"
          :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}">
          <el-table-column label="序号" min-width="100">
            <template slot-scope="scope">
              {{scope.$index +1}}
            </template>
          </el-table-column>
          <el-table-column label="广告位名称" prop="advertisingName" min-width="200">
          </el-table-column>
          <el-table-column label="广告位类型" prop="advertisingType" min-width="150">
          </el-table-column>
          <!-- <el-table-column label="详细地址" prop="detailedLocation" min-width="200">
          </el-table-column>
          <el-table-column label="设备类型" prop="deviceType" min-width="150">
          </el-table-column>
          <el-table-column label="设备尺寸" prop="equipmentSize" min-width="200">
          </el-table-column>
          <el-table-column label="场地编号" prop="venueNumber" min-width="150">
          </el-table-column>
          <el-table-column label="广告尺寸" prop="dimensions" min-width="200">
          </el-table-column>
          <el-table-column label="广告材质" prop="advertisingMaterial" min-width="150">
          </el-table-column>
          <el-table-column prop="createUser" label="创建人" min-width="120">
          </el-table-column>
          <el-table-column prop="rentalStatus" label="租赁状态" min-width="120">
            <template slot-scope="scope">
              {{scope.row.rentalStatus == 0?'未租':'已租'}}
            </template>
          </el-table-column> -->
          <el-table-column prop="publishStatus" label="发布状态" min-width="120">
              <template slot-scope="scope">
              {{scope.row.publishStatus=='0'?'待发布':scope.row.publishStatus=='1'?'已发布':scope.row.publishStatus=='2'?'已下架':scope.row.publishStatus=='3'?'待审核':scope.row.publishStatus=='4'?'驳回':'-'}}
            </template>
          </el-table-column>
          <el-table-column prop="leaseExpirationDate" label="租赁到期时间" min-width="200">
          </el-table-column>
          <el-table-column label="操作" fixed="right">
            <template slot-scope="scope">
              <div @click="details(scope.row)" class="tableBtn greens">查看</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0'" @click="removeinfo(scope.row,'编辑')">编辑
              </div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0'" @click="closemsg(scope.row)">删除</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0'"
              @click="opencl(scope.row,'gg')">发布</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='1'"
                @click="removeinfozz(scope.row,'2','下架')">下架</div>
            </template>
          </el-table-column>
        </el-table>
        <el-table v-if="ontype=='3'" :data="tableData"
          :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}">
          <el-table-column label="序号">
            <template slot-scope="scope">
              {{scope.$index +1}}
            </template>
          </el-table-column>
          <!-- <el-table-column label="编号" prop="id" v-if="activeName == 'second'">
                     </el-table-column> -->
          <el-table-column label="场地名称" prop="venueName">
          </el-table-column>
          <el-table-column label="实际使用面积" prop="actualArea">
          </el-table-column>
          <el-table-column label="场地类型" prop="venueType">
          </el-table-column>
          <el-table-column label="所属区域" prop="district">
          </el-table-column>
          <el-table-column label="详细位置" prop="detailedLocation">
          </el-table-column>
          <!-- <el-table-column label="租赁状态" >
          </el-table-column> -->
          <!-- <el-table-column label="状态" >
          </el-table-column> -->
          <el-table-column prop="publishStatus" label="发布状态" min-width="120">
            <template slot-scope="scope">
              {{scope.row.publishStatus == 0?'待发布':'已提交'}}
            </template>
          </el-table-column>
          <el-table-column label="操作"  fixed="right">
            <template slot-scope="scope">
              <div @click="details(scope.row)" class="tableBtn greens">查看</div>
              <!-- <div @click="opencl(scope.row,'cd')" class="tableBtn greens">绑定策略</div> -->
              <div class="tableBtn greens" @click="removeinfo(scope.row,'编辑')">编辑
              </div>
              <!-- <div class="tableBtn greens" v-if="scope.row.publishStatus=='0'" @click="closemsg(scope.row)">删除</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0'"
                @click="removeinfozz(scope.row,'1','发布')">发布</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='1'"
                @click="removeinfozz(scope.row,'0','下架')">下架</div> -->
            </template>
          </el-table-column>
        </el-table>
        <div style="display: flex;justify-content: space-between;" class="bom">
          <div style="font-size: 14px;">共 <span style="color: #3F9B6A;">{{total}}</span> 项数据</div>
          <el-pagination :current-page="pagequery.pageNumber+1" :page-sizes="[10, 20, 50, 100]" :page-size="10"
            background small layout="prev, pager, next" :total="total" @size-change="handleSizeChange"
            @current-change="handleCurrentChange">
          </el-pagination>
        </div>

      </div>

    </div>






    <div class="zhuti" v-if="onaction == '2'">
      <div style="height:58px;line-height:58px;">
        <div style="color:#0006"> <span>{{onaction == '1'?'商铺基本信息':onaction == '2'?'广告位基本信息管理':onaction == '3'?'场地基本信息管理':'-'  }}</span> <span style="padding:0 5px;">></span> <span
            style="color:#000000e6">新增</span></div>
      </div>
      <div style="margin: 20px 0;">
        <div style="display: flex;font-size: 14px">
          <div style="margin-right: 25px;cursor: pointer;" @click="chenge('1')" :class="ontype=='1'?'chengeXia':''">商铺
          </div>
          <div style="margin-right: 25px;cursor: pointer;" @click="chenge('2')" :class="ontype=='2'?'chengeXia':''">
            广告位</div>
          <div style="margin-right: 25px;cursor: pointer;" @click="chenge('3')" :class="ontype=='3'?'chengeXia':''">场地
          </div>
        </div>
      </div>
      <div v-if="ontype == '1'" style="padding: 20px 20px 20px 0;">
        <add @removeonaction="removeonaction"></add>
      </div>
      <div v-if="ontype == '2'" style="padding: 20px 20px 20px 0;">
        <addmap @removeonaction="removeonaction" :leixing="leixing"></addmap>
      </div>
      <div v-if="ontype == '3'" style="padding: 20px 20px 20px 0;">
        <addcd @removeonaction="removeonaction"></addcd>
      </div>
    </div>
    <div class="zhuti" v-if="onaction == '3'">
      <div style="height:58px;line-height:58px;">
        <div style="color:#0006"> <span>{{onaction == '1'?'商铺基本信息':onaction == '2'?'广告位基本信息管理':onaction == '3'?'场地基本信息管理':'-'  }}</span> <span style="padding:0 5px;">></span> <span
            style="color:#000000e6">查看</span></div>
      </div>
      <div v-if="ontype == '1'">
        <resourceCommodity :editbgid="detailsinfo" @removeonaction="removeonaction"></resourceCommodity>
      </div>
      <div v-if="ontype == '2'">
        <chakanmap :editbgid="detailsinfo" @removeonaction="removeonaction" :leixing="leixing"></chakanmap>
      </div>
      <div v-if="ontype == '3'">
        <chakancd :editbgid="detailsinfo" @removeonaction="removeonaction"></chakancd>
      </div>
    </div>
    <div class="zhuti" v-if="onaction == '4'">
      <div style="height:58px;line-height:58px;">
        <div style="color:#0006"> <span>{{onaction == '1'?'商铺基本信息':onaction == '2'?'广告位基本信息管理':onaction == '3'?'场地基本信息管理':'-'  }}</span> <span style="padding:0 5px;">></span> <span
            style="color:#000000e6">{{contractChangeReason}}</span></div>
      </div>
      <div v-if="ontype == '1'" style="padding: 20px 20px 20px 0;">
        <add :info="detailsinfo" @removeonaction="removeonaction"></add>
      </div>
      <div v-if="ontype == '2'" style="padding: 20px 20px 20px 0;">
        <addmap :info="detailsinfo" @removeonaction="removeonaction" :leixing="leixing"></addmap>
      </div>
      <div v-if="ontype == '3'" style="padding: 20px 20px 20px 0;">
        <addcd :info="detailsinfo" @removeonaction="removeonaction"></addcd>
      </div>
    </div>
    <el-dialog :visible.sync="addcl" title="选择策略" width="65%" append-to-body center
      :close-on-click-modal="false" :close-on-press-escape="false" :show-close="false">
      <cl v-if="addcl" @minSev="minSev" @mingClose="mingClose"></cl>
    </el-dialog>
  </div>


</template>

<script>
  import {
    cereResourceStrategy,editStatus
  } from '../../api/newly.js'
  import {
    ceGetAll
  } from '../../api/sam.js'
  import * as information from '../../api/information';
  import * as map1 from '../../api/map1';
  import {
    likeGet,
  } from '../../api/map1'
  import {
    getAlls,
    changAlls
  } from '../../api/information';
  import add from '../../components/add/addinformation'
  import resourceCommodity from '../../components/resourceCommodity/index'
  import MapContainer from "@/components/MapContainer/MapContainer"
  import addmap from '../../components/add/addmap'
  import addcd from '../../components/add/addcd'
  import chakanmap from '../../components/chakan/map'
  import chakancd from '../../components/chakan/cd'
    import cl from '@/components/change/cl.vue'
  import {
    on
  } from 'screenfull';
  export default {
    data() {
      return {
        oninfo: {},
        celueData: [],
        clData: [],
        multipleSelection: [],
        addcl: false,
        leixing: true,
        //传地图数据
        parentMessage: [],
        ontype: '1',
        contractChangeReason: '',
        detailsinfo: {},
        pagequery: {
          dataStatus: '1',
          pageNumber: 0,
          pageSize: 10,
          contractName: ''
        },
        tableData: [],
        total: 0,
        onaction: '1',
        formInline: {},
        pageindex: {
          pageNumber: 1,
          pageSize: 10,
        },
      }
    },
    components: {
      cl,
      chakancd,
      addcd,
      addmap,
      chakanmap,
      MapContainer,
      add,
      resourceCommodity,
    },
    created() {
      this.getAll()
    },
    methods: {
      minSev(e) {
        this.multipleSelection = e
        console.error(this.multipleSelection)
        let ids = []
        for (let index = 0; index < this.multipleSelection.length; index++) {
          ids.push(this.multipleSelection[index].id)
        }
        console.error(this.oninfo)
        let c1 = {
          resourcesId: this.oncetype+this.oninfo.id,
          rentalPoliciesIds: ids,
        }
        console.error(c1)
        cereResourceStrategy(c1).then(res => {
          if (res.code == 200) {
            this.addcl = false
            this.$message({
              message: '绑定成功',
              type: 'success'
            })
            editStatus({
              resourcesId: this.oncetype+this.oninfo.id,
              publishStatus: '3'
            }).then(res => {
              this.onSubmit()
            })
          } else {
            this.$message({
              message: '绑定失败',
              type: 'error'
            })
          }
        })
      },
      mingClose() {
        this.multipleSelection = []
        this.addcl = false
      },
      async opencl(row,e) {
        this.oncetype = e
        this.oninfo = row
        this.multipleSelection = []
        this.addcl = true
      },
      chenge(e) {
        this.ontype = e
        this.pagequery.pageNumber = 0
        this.getAll()
      },
      gettime() {
        // 获取当前时间
        let currentTime = new Date();

        // 获取年份
        let year = currentTime.getFullYear();

        // 获取月份（注意月份是从0开始计数的，所以需要加1）
        let month = currentTime.getMonth() + 1;

        // 获取日期
        let day = currentTime.getDate();

        // 获取小时
        let hours = currentTime.getHours();

        // 获取分钟
        let minutes = currentTime.getMinutes();

        // 获取秒数
        let seconds = currentTime.getSeconds();

        // 获取毫秒数
        let milliseconds = currentTime.getMilliseconds();

        // 格式化时间为 YYYY-MM-DD
        let formattedDate = `${year}-${month.toString().padStart(2, '0')}-${day.toString().padStart(2, '0')}`;

        // 格式化时间为 HH:MM:SS
        let formattedTime =
          `${hours.toString().padStart(2, '0')}:${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;

        // 格式化时间为 YYYY-MM-DD HH:MM:SS
        let formattedDateTime = `${formattedDate} ${formattedTime}`;
        return formattedDateTime

      },
      removeinfozz(row, e, tit) {
        let that = this
        this.$confirm('确定要' + tit + '吗？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          if (this.ontype == '1') {
            information.editList({
              ...row,
              publishStatus: e
            }).then(res => {
              console.error(res)
              if (res.code == 200) {
                this.$message({
                  message: tit + '成功',
                  type: 'success'
                })
                this.removeonaction('1')
              } else {
                this.$message({
                  message: res.msg,
                  type: 'error'
                })
              }
            })
          } else if (this.ontype == '2') {
            map1.editList({
              ...row,
              publishStatus: e
            }).then(res => {
              console.error(res)
              if (res.code == 200) {
                this.$message({
                  message: tit + '成功',
                  type: 'success'
                })
                this.removeonaction('1')
              } else {
                this.$message({
                  message: res.msg,
                  type: 'error'
                })
              }
            })
          } else if (this.ontype == '3') {
            information.changedit({
              ...row,
              publishStatus: e
            }).then(res => {
              console.error(res)
              if (res.code == 200) {
                this.$message({
                  message: tit + '成功',
                  type: 'success'
                })
                this.removeonaction('1')
              } else {
                this.$message({
                  message: res.msg,
                  type: 'error'
                })
              }
            })
          }

        })
      },
      details(row) {
        this.detailsinfo = row
        this.onaction = '3'
      },
      removeinfo(row, e) {
        this.contractChangeReason = e
        this.detailsinfo = row
        this.onaction = '4'
      },
      async getAll() {
        if (this.ontype == '1') {
          const res = await getAlls(this.pagequery)
          this.tableData = res.data.content
          this.total = res.data.totalElements
        } else if (this.ontype == '2') {
          const res = await likeGet(this.pagequery)
          this.tableData = res.data.content
          this.total = res.data.totalElements
        } else if (this.ontype == '3') {
          const res = await changAlls(this.pagequery)
          this.tableData = res.data.content
          this.total = res.data.totalElements
        }

      },
      removeonaction(e) {
        console.error(e)
        this.onaction = e
        this.pagequery.pageNumber = 0
        this.getAll()
      },
      handleCurrentChange(val) {
        this.pagequery.pageNumber = val - 1
        this.getAll()
      },
      handleSizeChange(val) {
        this.pagequery.pageSize = val
      },
      // 查询按钮
      async onSubmit() {
        this.pagequery.pageNumber = 0
        this.getAll()
      },
      //重置按钮
      resetting() {
        this.pagequery = {
            pageNumber: 0,
            pageSize: 10,
            dataStatus: '1',
            contractName: ''
          },
          this.getAll()
      },
      //删除
      closemsg(item) {
        const h = this.$createElement;
        this.$msgbox({
          title: '消息',
          message: h('p', null, [
            h('span', null, '是否删除 '),
          ]),
          showCancelButton: true,
          showClose: false,
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          customClass: 'oe-dialog-btn',
          beforeClose: (action, instance, done) => {
            if (action === 'confirm') {
              if (this.ontype == '1') {
                information.delList({
                  id: item.id
                }).then(res => {
                  this.$message({
                    message: '删除成功',
                    type: 'success'
                  })
                  this.getAll()
                  done();
                })
              } else if (this.ontype == '2') {
                map1.delList({
                  id: item.id
                }).then(res => {
                  this.$message({
                    message: '删除成功',
                    type: 'success'
                  })
                  this.getAll()
                  done();
                })
              } else if (this.ontype == '3') {
                information.changDel({
                  id: item.id
                }).then(res => {
                  this.$message({
                    message: '删除成功',
                    type: 'success'
                  })
                  this.getAll()
                  done();
                })
              }
            } else {
              done();
            }
          }
        })
      },
      //地图详细
      HandMapItem(item) {
        console.log(item)


        // if (this.activeName == 'first') {
        //   this.editbgid = item
        //   this.restype = '商铺'

        //   this.showBian = true
        //   if (typeof this.editbgid.mapPunctuation == 'string') {
        //     this.parentMessage = JSON.parse(this.editbgid.mapPunctuation)
        //   }

        // } else if (this.activeName == 'second') {
        //   this.editbgid = item
        //   this.restype = '广告位'

        //   this.showBian = true
        //   if (item.advertisingType == '线上广告位') {
        //     this.leixing = true
        //   } else {
        //     this.leixing = false
        //   }

        //   if (typeof this.editbgid.mapMarker == 'string') {
        //     this.parentMessage = JSON.parse(this.editbgid.mapMarker)
        //   }
        // } else if (this.activeName == 'third') {
        //   this.editbgid = item
        //   this.restype = '场地'

        //   this.showBian = true
        //   if (typeof this.editbgid.mapMarker == 'string') {
        //     this.parentMessage = JSON.parse(this.editbgid.mapMarker)
        //   }
        // } else if (this.activeName == 'fourth') {

        // }


      },
    }

  }
</script>
<style lang="scss" scoped>
  .zhuti {
    padding: 0 20px 20px 20px;
    min-height: calc(100vh - 50px - 20px);
    background-color: #Fff;

  }

  .chengeXia {
    border-bottom: 6px solid #3F9B6A;
    padding-bottom: 4px;
    color: #3F9B6A;
  }
  .tableBtn {
    display: inline-block;
    margin-right: 10px;
    cursor: pointer;
  }
</style>


