
<style lang="scss">
.PubState {
  color: #9e4141;
}

.PubState1 {
  color: #6ab35f;
}
</style>
<template>
  <div class="dashboard-container">
    <el-form :model="peopleform" ref="peopleform">
      <div class="search-div">
        <el-row>
          <el-col :span="6">
            <div>
              <el-form-item label="权重名称" class="fourLabel" label-width="80px">
                <el-input placeholder="请输入" v-model="peopleform.weightName" clearable>
                </el-input>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="8">
            <div>
              <el-form-item label="维护日期" class="fourLabel" label-width="80px">
                <el-date-picker v-model="peopleform.value6" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
                </el-date-picker>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="6">
            <div>
              <el-form-item label="权重类别" class="fourLabel" label-width="90px">
                <el-select class="wdh" placeholder="请选择" v-model="peopleform.weightTypeName" clearable>
                  <el-option v-for="item in powerType" :key="item.value" :label="item.priceTypeName" :value="item.priceTypeName"></el-option>
                </el-select>
              </el-form-item>
            </div>
          </el-col>
          <el-col :span="2">
            <div>
              <el-button class="outButton mgt-3" type="primary" @click="query">
                <i class="iconfont">&#xe67f;</i> <span>
                  查询
                </span>
              </el-button>
              <!-- <el-button class="outButton" icon="el-icon-search"  type="primary">清空</el-button> -->
            </div>
          </el-col>
        </el-row>
      </div>

      <div style="clear:both;border-top:1px dashed #5aaafa;margin-bottom:10px;">
      </div>
      <el-row>
        <div class="addBtnBg">
          <el-button class="outButton" @click="addBtn" type="primary">
            <i class="iconfont">&#xe698;</i>
            <span> 新增 </span>
          </el-button>
        </div>
      </el-row>
    </el-form>
    <el-row>
      <el-table tooltip-effect="dark" style="width: 100%;" align="center" border stripe highlight-current-rowv-loading="tableLoading" :data="tableData">
        <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="权重代码" width="310px" prop="weightCode">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" label="权重名称" prop="weightName">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" label="权重类别" prop="weightTypeName">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" label="维护日期" prop="date">
        </el-table-column>
        <el-table-column align="center" :show-overflow-tooltip="true" label="状态" prop="isPublish">
          <template slot-scope="scope"><span class="PubState1" :class="{PubState:scope.row.isPublish === '0'}">{{scope.row.isPublish === '0'?'禁用':'应用中'}}</span></template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="light" content="修改" placement="top">
              <el-button class="button operate_edit_btn" type="primary" @click.stop="see('update',scope.row)">
                <i class="iconfont">&#xe693;</i>
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="light" :content="scope.row.isPublish === '1'?'禁用':'启用'" placement="top">
              <el-button class="button operate_forbidden_btn" type="primary" @click.stop="forbidden(scope.row)">
                <i class="iconfont">&#xe7cf;</i>

              </el-button>
            </el-tooltip>
            <!-- <el-tooltip class="item" effect="light" content="删除" placement="top">
              <el-button class="button"  type="primary" @click.stop="deleteFn(scope.row)">
                <i class="el-icon-delete"></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="handleChangeSize" @current-change="handleCurrentChangePage" layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
    </el-row>

  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { allWeightsPage, weightsDelete, priceWeghtTypes, updateWeight } from '@/api/indexManage/index'
import { constants } from 'crypto';

export default {
  name: 'Daily',
  data() {
    return {
      powerType: [],
      peopleform: {},
      yearArr: [{
        index: 1,
        value: '发布'
      }],
      status: [{
        index: 1,
        dictName: '未提交',
      }, {
        index: 2,
        dictName: '已提交',
      }, {
        index: 3,
        dictName: '审核通过',
      }, {
        index: 4,
        dictName: '驳回',
      }],
      dataDictioPubArr: [{
        index: 1
      }],
      tableData: [],
      limit: {
        page: 1,
        size: 10,
        total: 0
      }
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])





  },
  mounted() {
    this.getAll(this.limit, {})
    priceWeghtTypes().then(res => {
      this.powerType = res.data
    })
  },
  methods: {
    forbidden(item) {
      let obj = {
        weightCode: item.weightCode,
        isPublish: item.isPublish === "1" ? '0' : '1'
      }
      updateWeight(obj).then(res => {
        this.getAll(this.limit, {})
      })
    },
    getAll(obj, data) {
      allWeightsPage(obj, data).then(res => {
        this.tableData = res.data.resultList
        this.limit.total = res.data.total
      })
    },
    query() {
      this.getAll(this.limit, this.peopleform)
    },
    see(state, row) {
      this.$router.push({ path: '/monitorArea/powerDetails', query: { id: row.weightCode, state: 'update' } })
    },
    deleteFn(row) {
      let arr = [];
      arr.push(row.id)
      weightsDelete(arr).then(res => {
        this.$message({
          type: "success",
          message: '删除成功'
        })
        this.getAll(this.limit, {})
      })
    },
    handleChangeSize(value) {
      this.limit.size = value
      this.getAll(this.limit, {})

    },
    handleCurrentChangePage(value) {
      this.limit.page = value
      this.getAll(this.limit, {})
    },
    addBtn() {
      this.$router.push({ path: '/monitorArea/powerDetails' })
    }
  }
}
</script>

