<template>
  <div class="dashboard-container">
    <el-form  class="demo-form-inline mar-l-0 listStyle" style="width:100%;" :model="form" ref="form">
      <div class="all-row-b5" style="margin-bottom:10px;">
        <el-row>
          <el-col :span="8">
            <el-form-item label="监测点：" placeholder="请输入" label-position="left" prop="takNameId">
              <el-input v-model="form.jcd" class="search-width" clearable></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="上报地区：" placeholder="请输入" prop="takTask" class="pubWid">
              <el-select v-model="form.sbdq" clearable placeholder="全部" class="search-width">
                <el-option v-for="item in dataDictioPubArr" :key="item.cogKey" :label="item.cogValue"
                  :value="item.cogKey">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="状态：" prop="runState">
              <el-select v-model="form.reportStatus" clearable placeholder="全部" class="search-width">
                <el-option v-for="item in dataStatus" :key="item.key" :label="item.value" :value="item.key">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="上报日期" class="fourLabel" label-width="80px">
              <el-date-picker v-model="form.data" type="daterange" range-separator="至" start-placeholder="开始日期"
                end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="10">
            <el-button class="outButton" icon="el-icon-search" size="primary" type="primary" @click='getList'>查询
            </el-button>
            <el-button class="outButton" icon="el-icon-search" size="primary" type="primary">清空</el-button>
            </el-button>
          </el-col>
        </el-row>
        <el-row>
          <div style="clear: both;border-top: 1px dashed rgb(90, 170, 250);margin-bottom: 10px;"></div>
          <div class="addBtnBg">
            <el-button class="outButton" icon="el-icon-plus" size="small" @click="publishBtn(sels)" type="primary">发布
            </el-button>
            <el-button class="outButton" icon="el-icon-plus" size="small" @click="addBtn" type="primary">生成本级数据
            </el-button>
          </div>
        </el-row>
      </div>
    </el-form>
    <el-row>
      <el-table tooltip-effect="dark" style="width: 100%;margin-top:10px;" align="center" border stripe
        highlight-current-rowv-loading="tableLoading" :data="tableData" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column align="center" label="序号" width="60">
          <template slot-scope="scope"><span>{{scope.$index+1}}</span></template>
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" label="所属地区" prop="sbdq">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" label="所属监测点" prop="jcd">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" prop="createBy" label="上报人">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" prop="createTime" label="上报时间">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" prop="sbkssj" label="上报开始时间">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" prop="sbjssj" label="上报结束时间">
        </el-table-column>
        <el-table-column prop="lcid" label="状态" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.lcid==='2'" class="PubState1">已发布</span>
            <span v-if="scope.row.lcid==='1'">已提交</span>
            <span v-if="scope.row.lcid==='3'" class="PubState">已驳回</span>
            <!-- <div class="tab-ellipsis" :title="scope.row.takTaskId">{{scope.row.takTaskId}}</div> -->
          </template>
        </el-table-column>
        <!-- <el-table-column align="center" :show-overflow-tooltip="true" prop="lcid" label="状态">
        </el-table-column> -->
        <el-table-column width="200" label="操作">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="light" content="修改" placement="top">
              <el-button class="button operate_edit_btn" size="mini" type="primary" @click.stop="see('edit',scope.row)">
                <i class="iconfont">&#xe693;</i>
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="light" content="查看" placement="top">
              <el-button class="button operate_show_btn" size="mini" type="primary" @click.stop="see('see',scope.row)">
                <i class="iconfont">&#xe67e;</i>
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="light" content="驳回" placement="top">
              <el-button class="button operate_delete_btn" size="mini" type="primary"
                @click.stop="refuseBtn('ref',scope.row)">
                <i class="iconfont">&#xe69a;</i>
              </el-button>
            </el-tooltip>

          </template>
        </el-table-column>
      </el-table>
      <!-- 分页开始 -->
      <div class="pagination-container">
        <el-pagination class="right" :current-page.sync="limit.page" :page-size="limit.size" :page-sizes="[10,20,30,40]"
          :total="limit.total" @size-change="getList" @current-change="getList"
          layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
    </el-row>

  </div>
</template>

<script>
  import { mapGetters } from 'vuex'
  import { getDataLists, reportMod } from '@/api/datauphold/index'
  import { Message } from 'element-ui';

  export default {
    name: 'Daily',
    data() {
      return {
        sels: [],
        ids: [],
        idS: '',
        form: {
          data: ''
        },
        yearArr: [{
          index: 1,
          value: '发布'
        }],
        status: [{
          index: 1,
          dictName: '未提交',
        }, {
          index: 2,
          dictName: '已提交',
        }, {
          index: 3,
          dictName: '审核通过',
        }, {
          index: 4,
          dictName: '驳回',
        }],
        dataDictioPubArr: [{
          index: 1
        }],
        tableData: [{
          index: 1
        }],
        limit: {
          page: 1,
          size: 10,
          total: 0
        },
        dataStatus: [{
          key: 1,
          value: '提交'
        },
        {
          key: 2,
          value: '发布'
        },
        {
          key: 3,
          value: '驳回'
        }
        ]
      }
    },
    computed: {
      ...mapGetters([
        'name'
      ])
    },
    created() {
      this.getList();
    },
    methods: {
      handleSelectionChange(sels) {
        /* 被选中的行数组 */
        this.sels = sels;
      },
      refuseBtn(ref,rows) { 
        // this.showLogs = true
        // if (rows.length > 0) {
          // rows.forEach((element) => {
          //   this.ids.push(element.id);
          //   this.idS = this.ids.join(',')
          // });}
        const data = {
          "ids": rows.id,
          "lcid": 3
        }
        reportMod(data).then((response) => {
          if (response.status == 'SUCCESS') {
              Message({
                message: '驳回成功！',
                type: 'success',
              });
              this.getList(1);
            } else {
              Message.error(response.msg);
            }
        })
      },
      publishBtn(rows) {
        if (rows.length > 0) {
          rows.forEach((element) => {
            this.ids.push(element.id);
            this.idS = this.ids.join(',')
          });
          const hhh = {
            "ids": this.idS,
            "lcid": 2
          }
          reportMod(hhh).then((response) => {
            if (response.status == 'SUCCESS') {
              Message({
                message: '发布成功！',
                type: 'success',
              });
              this.getList(1);
            } else {
              Message.error(response.msg);
            }
          });
          this.ids = [];

        } else {
          Message({
            message: '请选择发布的对象！',
            type: 'warning',
          });
        }
      },
      // List init
      getList() {
        if (this.form.data.length > 1) {
          this.startDate = this.form.data[0]
          this.endDate = this.form.data[1]
        }
        const data = {
          startDate: this.startDate,
          endDate: this.endDate,
          jcd: this.form.jcd,
          sbdq: this.form.sbdq,
          reportStatus: this.form.reportStatus,
          priceType:'LtdXKgAUOJ3D7tpkHxP',
          page: this.limit.page,
          size: this.limit.size
        }
        getDataLists(data).then(response => {
          this.tableData = response.data.resultList
          this.limit.total = response.data.total
          this.tableData.forEach((o) => {
            // if (o.status === '1') {
            //     o.status = false
            // } else {
            //     o.status = true
            // }
            if (o.status === '0') {
              o.status = '暂存'
            }
            if (o.status === '1') {
              o.status = '已上报'
            }
          })
          this.isloading = false
          // this.formPage.total = response.data.total
          console.log('request数据成功')
        }).catch(function (error) {
          console.log(error)
        })
      },
      see(state, row) {
        if (state === 'see') {
          this.$router.push({ path: '/priceMonitoring/dataUpholdEdit', query: { id: row.id, state: 'see' } })
        } else if (state === 'edit') { 
            this.$router.push({ path: '/priceMonitoring/dataUpholdEdit', query: { id: row.id, state: 'edit' } })  
        } 
      }, 
      handleChangeSize(value) {

      },
      handleCurrentChangePage(value) {
      },
      addBtn() {
        this.$router.push({ path: '/dailyManage/main-detail' })
      }
    }
  }
</script>

<style lang="scss" scoped>
   .PubState{
      color: #9e4141;
    }
    .PubState1{
      color: #6ab35f;
    }
  .dashboard {
    &-container {
      margin: 30px;
    }

    &-text {
      font-size: 30px;
      line-height: 46px;
    }
    
  }
</style>