<template>
  <div class="dashboard-container">
    <el-form :model="peopleform" label-width="88px" ref="peopleform">
      <el-row>
        <el-col :span="8">
          <div>
            <el-form-item label="监测点" class="fourLabel" label-width="60px">
              <el-input placeholder="请输入" v-model="peopleform.companyName" clearable>
              </el-input>
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="9">
          <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="2">
          <div>
            <el-button class="outButton mgt-3" type="primary">
              <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 style="clear:both;border-top:1px dashed #5aaafa;margin-bottom:10px;">
      </div>
      <el-row>
        <div class="addBtnBg">
          <el-button class="outButton" type="primary" @click="addBtn">
            <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="周刊报表类型" prop="reportTypeName">
        </el-table-column>
        <!-- <el-table-column align="center" :show-overflow-tooltip="true" label="排序顺序" prop="companyHierarchy">
        </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="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_edit_btn" type="primary" @click.stop="setPrice(scope.row)">
                <i class="iconfont"> &#xe699;</i>
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="light" content="删除" placement="top">
              <el-button class="button operate_delete_btn" type="primary" @click.stop="deleteFn(scope.row)">
                <i class="iconfont"> &#xec21;</i>
              </el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="light" content="查看" placement="top">
              <el-button class="button operate_show_btn" type="primary" @click.stop="see(scope.row)">
                <i class="iconfont">&#xe67e;</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>
    <el-dialog title="设置周刊报表价格" :visible.sync="priceDialog" width="50%">
      <el-row>
        <el-col :span="24">
          <el-form :model="priceForm" status-icon label-width="100px" class="demo-ruleForm">
            <el-form-item label="周刊报表类型" prop="reportTypeName" label-width="110px">
              <el-input type="text" v-model="priceForm.reportTypeName" :disabled="isShow"></el-input>
            </el-form-item>
            <el-form-item>
              <el-table border :data="tablePrice" style="width: 100%" @selection-change="handleSelectionChange">
                <el-table-column type="selection">
                </el-table-column>
                <el-table-column label="价格类型">
                  <template slot-scope="scope">{{ scope.row.priceTypeName }}</template>
                </el-table-column>
              </el-table>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="priceAdd('reportForm')">增加</el-button>
              <el-button @click="priceDialog = false">关闭</el-button>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>

    </el-dialog>
    <el-dialog :title="titleHead" :visible.sync="reportDialog" width="40%">
      <el-row>
        <el-form :model="reportForm" status-icon :rules="rules" ref="reportForm" class="demo-ruleForm">
          <el-col :span="24">
            <el-form-item label="周刊报表类型" prop="reportTypeName" label-width="110px">
              <el-input type="text" v-model.number="reportForm.reportTypeName" :disabled="isShow"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item align="center">
              <el-button type="primary" @click="submitForm('reportForm')" v-show="!isShow">
                <i class="iconfont">&#xe683;</i>
                <span> 确定</span>
              </el-button>
              <el-button type="primary" @click="reportDialog = false">
                <i class="iconfont">&#xe688;</i>
                <span> 关闭</span>
              </el-button>
            </el-form-item>

          </el-col>

          <!-- 
            <el-form-item label="描述" prop="pass">
              <el-input type="textarea" v-model="reportForm.newPassword" auto-complete="off"></el-input>
            </el-form-item> -->

        </el-form>
      </el-row>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'

import { reportSave, reportUpdate, reportPage, getReportById, reportDelete, getPriceTable, priceTypeSave, queryPriceType } from '@/api/indexManage/index'

export default {
  name: 'Daily',
  data() {
    return {
      priceForm: {},
      reportForm: {},
      titleHead: '',
      title: { add: '新增报表类型', edit: '修改报表类型', see: '查看报表类型' },
      reportDialog: false,
      rules: {
        reportTypeName: [
          { required: true, message: '周刊报表类型名称', trigger: 'blur' },
        ]
      },
      rules2: {
        reportTypeName: [
          { required: true, message: '周刊报表类型名称', trigger: 'blur' },
        ]
      },
      tableData3: [],
      priceDialog: false,
      peopleform: {},
      yearArr: [{
        index: 1,
        value: '发布',

      }],
      status: [{
        index: 1,
        dictName: '未提交',
      }, {
        index: 2,
        dictName: '已提交',
      }, {
        index: 3,
        dictName: '审核通过',
      }, {
        index: 4,
        dictName: '驳回',
      }],
      dataDictioPubArr: [{
        index: 1
      }],
      tableData: [],
      isAdd: true,
      isShow: false,
      limit: {
        page: 1,
        size: 10,
        total: 0
      }
    }
  },
  computed: {
    ...mapGetters([
      'name'
    ])
  },
  mounted() {
    this.getAll(this.limit, {})
    getPriceTable().then(res => {
      this.tablePrice = res.data.resultList
    })
  },
  methods: {

    deleteFn(row) {
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
        cancelButtonText: '取消',
        confirmButtonText: '确定',
        type: 'warning'
      }).then(() => {
        let arr = [];
        arr.push(row.id)
        reportDelete(arr).then(res => {
          this.$message({
            type: "success",
            message: '删除成功'
          })
          this.getAll(this.limit, {})
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    chakan(id) {
      getReportById(id).then(res => {
        this.reportForm = res.data
      })
    },
    edit(item) {
      this.isAdd = false
      this.isShow = false
      this.titleHead = this.title.edit;
      this.reportDialog = true
      this.chakan(item.id)
    },
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.isAdd) {
            reportSave(this.reportForm).then(res => {
              if (res.infoCode === 200) {
                this.$message({
                  type: 'success',
                  message: '保存成功'
                })
              } else {
                this.$message({
                  type: 'warning',
                  message: res.data
                })
              }
              this.getAll(this.limit, {})
              this.reportDialog = false
            })

          } else {
            reportUpdate(this.reportForm).then(res => {
              this.$message({
                type: 'success',
                message: '修改成功'
              })
              this.getAll(this.limit, {})
              this.reportDialog = false

            })

          }

        }
      })
    },
    getAll(obj, data) {
      reportPage(obj, data).then(res => {
        this.tableData = res.data.resultList
        this.limit.total = res.data.total
      })
    },
    query() {
      this.getAll(this.limit, this.peopleform)
    },
    handleSelectionChange(value) {
      this.priceForm.priceTypeVO = value
    },
    priceAdd() {
      priceTypeSave(this.priceForm).then(res => {
        this.$message({
          type: "success",
          message: '添加成功'
        })
      })
    },
    setPrice(row) {
      this.priceDialog = true
      this.priceForm.reportTypeName = row.reportTypeName
      this.priceForm.indicatorId = row.id


      queryPriceType(row.id).then(res => {
        for (let i = 0; i < res.data.priceTypeVO.length; i++) {
          for (let j = 0; j < this.tableData.length; j++) {
            if (res.data.priceTypeVO[i].priceTypeName === this.tablePrice[j].priceTypeName) {
              this.toggleSelection([this.tableData[j]])
              // this.tableData[j].momVal = res.data.priceTypeVO[i].momVal
            }
          }
        }
      })
    },
    see(row) {
      this.isAdd = false
      this.isShow = true;
      this.titleHead = this.title.see;
      this.reportDialog = true
      this.chakan(row.id)
    },
    handleChangeSize(value) {

    },
    handleCurrentChangePage(value) {
    },
    addBtn() {
      this.reportDialog = true
    }
  }
}
</script>


