<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="方案名称">
              <el-input v-model="pagequery.planName" placeholder="请输入" style="width:168px;">
              </el-input>
            </el-form-item>
            <el-form-item label="状态" prop="auditStatus">
              <el-select v-model="pagequery.auditStatus" clearable placeholder="请选择" style="margin-right: 15px">
                <el-option label="待审核" value="1"></el-option>
                <el-option label="审核通过" value="2"></el-option>
                <el-option label="已驳回" value="3"></el-option>
              </el-select>
            </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" :header-cell-style="{fontSize: '14px',color:'#0009',fontWeight: 'normal',backgroundColor:'#F2F3F5'}">

          <el-table-column label="招商方案名称" prop="planName"  show-overflow-tooltip max-width="200"/>
          <el-table-column label="涵盖资源数" prop="createTime">
            <template slot-scope="scope">
              {{scope.row.resourceManagement?(scope.row.resourceManagement.split(',').length):0}}
            </template>
          </el-table-column>
          <el-table-column label="创建时间" prop="createTime">
            <template slot-scope="scope">
              {{scope.row.createTime || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="创建人" prop="createUser">
            <template slot-scope="scope">
              {{scope.row.createUser || '-' }}
            </template>
          </el-table-column>
          <el-table-column label="状态">
            <template slot-scope="scope">
              {{scope.row.auditStatus =='1'?'待审核':scope.row.auditStatus =='2'?'审核通过':scope.row.auditStatus =='3'?'已驳回':scope.row.auditStatus =='4'?'已撤回':''}}
            </template>
          </el-table-column>
          <el-table-column label="操作"  fixed="right">
            <template slot-scope="scope">
              <div @click="details(scope.row)" class="tableBtn greens">查看</div>
              <!-- v-if="scope.row.auditStatus == '4'" -->
              <div class="tableBtn greens" v-if="scope.row.auditStatus == '4'"   @click="removeinfo(scope.row,'编辑')">编辑</div>
              <div class="tableBtn greens" v-if="scope.row.auditStatus == '4'" @click="closemsg(scope.row)">删除</div>
              <div class="tableBtn greens" v-if="scope.row.auditStatus == '4'" @click="removeinfozz(scope.row,'1','提交审核')">提交审核</div>
              <div class="tableBtn greens" v-if="scope.row.auditStatus == '1'"   @click="removeinfozz(scope.row,'4',' 撤回')">撤回</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="pagequery.pageSize"
            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>
        <fa :editbgid="detailsinfo" @removeonaction="removeonaction"></fa>
      </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 :resourcesId="oncetype+oninfo.id" v-if="addcl" @minSev="minSev" @mingClose="mingClose"></cl>
    </el-dialog>
  </div>


</template>

<script>
  import {
    delList,
    editList,
    getAlls
  } from '@/api/information';
  import add from '@/components/add/addfa'
  import fa from '@/components/chakan/fa'
  import {
    fangGetAll,
    fangDel,
    fangEdit
  } from '@/api/fangli'
    import cl from '@/components/change/cl.vue'
    import {
    cereResourceStrategy,
    editStatus,
    cereBusinessOperationadd,
    queryAllByLimit
  } 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: '1',
        formInline: {
        },
      }
    },
    computed: {
      regionOptions() {
        return this.$store.state.app.regionOptions;
      }
    },
    components: {
      cl,
      add,
      fa,
    },
    async 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(ids)
        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: '1'
            }).then(res => {
              this.onSubmit()
            })
            cereBusinessOperationadd({
              type:'发布',
              resourceId: this.oncetype+this.oninfo.id,
              operator: localStorage.getItem('roleName'),
              operationTime: this.gettime()
            }).then(res => {
              console.error(res)
            })
          } 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(() => {
          fangEdit({
            id: row.id,
            auditStatus: e
          }).then(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 queryAllByLimit(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
        this.pagequery.pageNumber = 0
        this.getAll()
      },
      // 查询按钮
      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') {
              fangDel({
                id: item.id
              }).then(res => {
                this.$message({
                  message: '删除成功',
                  type: 'success'
                })
                this.getAll()
                done();
              })
            } else {
              done();
            }
          }
        })
      },
    }

  }
</script>

<style lang="scss" scoped>
  .formSearch {
    display: flex;
    width: 100%;
    font-size: 14px;
    justify-content: space-between;
  }

  .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>
