<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 class="formSearch">
          <el-form :inline="true" :model="pagequery">
            <el-form-item label="商铺名称" prop="shopName">
              <el-input v-model="pagequery.shopName" placeholder="请输入" maxlength="50"></el-input>
            </el-form-item>
            <el-form-item label="所属区域" prop="belongingRegion">
              <el-select v-model="pagequery.belongingRegion" placeholder="请选择" style="width: 168px;margin-right: 15px">
                <el-option label="成华区" value="成华区"></el-option>
                <el-option label="武侯区" value="武侯区"></el-option>
                <el-option label="锦江区" value="锦江区"></el-option>
                <el-option label="青羊区" value="青羊区"></el-option>
                <el-option label="金牛区" value="金牛区"></el-option>
                <el-option label="双流区" value="双流区"></el-option>
                <el-option label="郫都区" value="郫都区"></el-option>
                <el-option label="龙泉驿区" value="龙泉驿区"></el-option>
                <el-option label="温江区" value="温江区"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="所属绿道段" prop="belongingGreenwaySection">
              <el-select v-model="pagequery.belongingGreenwaySection" placeholder="请选择">
                <el-option :label="item.name" :value="item.code" v-for="(item,index) in lvdaoList"
                  :key="index"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="归属部门" prop="belongingDepartment">
              <el-input v-model="pagequery.belongingDepartment" placeholder="请输入" maxlength="50"></el-input>
            </el-form-item>
          </el-form>

          <div>
            <el-button @click="onSubmit" style="background-color: #3F9B6A;color: #fff">查询
            </el-button>
            <el-button @click="resetting" class="buttonHover"
              style="color: #606266;border: 1px solid #dddfe5;background-color: #fff;">重置
            </el-button>
          </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>
        <!-- 表格 -->

        <el-table :data="tableData" border :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#f5f8f9'}">
          <el-table-column label="序号" min-width="50">
            <template slot-scope="scope">
              {{scope.$index +1 }}
            </template>
          </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="200" 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' || scope.row.publishStatus=='2'" @click="removeinfo(scope.row,'编辑')">编辑
              </div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0' || scope.row.publishStatus=='2' || scope.row.publishStatus=='4'" @click="closemsg(scope.row)">删除</div>
              <div class="tableBtn greens" v-if="scope.row.publishStatus=='0' || scope.row.publishStatus=='2' || scope.row.publishStatus=='4'"
              @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>
        <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>商铺基本信息</span> <span style="padding:0 5px;">></span> <span
            style="color:#000000e6">新增</span></div>
      </div>

      <div style="padding: 20px 20px 20px 0;">
        <add @removeonaction="removeonaction"></add>
      </div>
    </div>
    <div class="zhuti" v-if="onaction == '3'">
      <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>
        <resourceCommodity :editbgid="detailsinfo" @removeonaction="removeonaction"></resourceCommodity>
      </div>
    </div>
    <div class="zhuti" v-if="onaction == '4'">
      <div style="height:58px;line-height:58px;">
        <div style="color:#0006"> <span>商铺基本信息</span> <span style="padding:0 5px;">></span> <span
            style="color:#000000e6">{{contractChangeReason}}</span></div>
      </div>
      <div style="padding: 20px 20px 20px 0;">
        <add :info="detailsinfo" @removeonaction="removeonaction"></add>
      </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 {
    delList,
    editList,
    lvdaoduan,
    getAlls
  } from '@/api/information';
  import add from '@/components/add/addinformation'
  import resourceCommodity from '@/components/resourceCommodity/index'
    import cl from '@/components/change/cl.vue'
    import {
    cereResourceStrategy,
    editStatus
  } from '@/api/newly.js'
  export default {
    data() {
      return {
        lvdaoList:[],
        oncetype:'',
        addcl:false,
        oninfo:{},
        multipleSelection:[],
        contractChangeReason: '',
        detailsinfo: {},
        pagequery: {
          belongingRegion:'',
          shopName:'',
          pageNumber: 0,
          pageSize: 10,
          belongingGreenwaySection:'',
          belongingDepartment:''
        },
        tableData: [],
        total: 0,
        onaction: '2',
        formInline: {
        },
      }
    },
    components: {
      cl,
      add,
      resourceCommodity,
    },
    async created() {
      this.getAll()
      const lvdao = await lvdaoduan()
      this.lvdaoList = lvdao.data
    },
    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
      },
      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(() => {
          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'
              })
            }

          })
        })
      },
      details(row) {
        this.detailsinfo = row
        this.onaction = '3'
      },
      removeinfo(row, e) {
        this.contractChangeReason = e
        this.detailsinfo = row
        this.onaction = '4'
      },
      async getAll() {
        const res = await getAlls(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 = {
            belongingRegion:'',
            shopName:'',
            pageNumber: 0,
            pageSize: 10,
            belongingGreenwaySection:'',
            belongingDepartment:''
          },
          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') {
              delList({
                id: item.id
              }).then(res => {
                this.$message({
                  message: '删除成功',
                  type: 'success'
                })
                this.getAll()
                done();
              })
            } else {
              done();
            }
          }
        })
      },
    }

  }
</script>

<style 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;
  }


  .formSearch {
    display: flex;
    width: 100%;
    font-size: 14px;
    justify-content: space-between;
  }
  .greens {
    color: #3F9B6A;
  }
  .bg-purple-dark {
    background: #99a9bf;
  }

  .bg-purple {
    background: #d3dce6;
  }

  .bg-purple-light {
    background: #e5e9f2;
  }
  .grid-content {
    border-radius: 4px;
    min-height: 36px;
  }

</style>
<style lang="scss" scoped>
  ::v-deep .el-dialog__body {
    padding: 0 0 !important;
  }
  .el-dialog__header{
    padding: 0;
    display: none;
  }
</style>
