<template>
  <div class="dashboard-container">
    <el-form :model="queryform"  label-width="88px" ref="queryform">
      <el-row>
        <el-col :span="10">
          <div>
            <el-form-item label="上报日期" class="fourLabel" label-width="80px">
              <el-date-picker v-model="queryform.data" type="daterange" range-separator="至" start-placeholder="开始日期"
                end-placeholder="结束日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd">
              </el-date-picker>
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="7">
          <div>
            <el-form-item label="价格类型" class="fourLabel">
              <el-select class="wdh" placeholder="请选择" v-model="queryform.priceType" clearable>
                <el-option v-for="item in listTi" :key="item.id" :label="item.bblxmc" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </el-col>
        <el-col :span="7">
          <div>
            <el-form-item label="监测点" class="fourLabel">
              <el-select class="wdh" placeholder="请选择" v-model="queryform.priceType" clearable>
                <el-option v-for="item in listTi" :key="item.id" :label="item.bblxmc" :value="item.id">
                </el-option>
              </el-select>
            </el-form-item>
          </div>
        </el-col>
        <!-- <el-col :span="7"> -->

        <!-- </el-col> -->
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="addBtnBg">
            <el-button class="outButton" icon="el-icon-search" size="medium" type="primary" @click="getList">查询
            </el-button>
            <el-button class="outButton" icon="el-icon-refresh" size="medium" type="primary">清空</el-button>
            <el-button class="outButton" icon="el-icon-upload2"  @click="see" type="primary">导出
            </el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <el-row>
      <el-table tooltip-effect="dark" style="width: 100%;margin-top:10px;" align="center" border
        v-loading:body="isloading" :data="tableData">
        <el-table-column type="selection" width="50"></el-table-column>
        <el-table-column type="index" :index="typeIndex" label="序号" width="50"></el-table-column>
        <el-table-column align="center" label="监测点" :show-overflow-tooltip="true" prop="sbdq"></el-table-column>
        <el-table-column align="center" label="价格类型" :show-overflow-tooltip="true" prop="bblxmc"></el-table-column>
        <el-table-column align="center" label="上报日期" :show-overflow-tooltip="true" prop="sbjssj"></el-table-column>
        <el-table-column align="center" label="填报方式" :show-overflow-tooltip="true" prop="reportWay"></el-table-column>
        <!-- <el-table-column align="center" label="状态" :show-overflow-tooltip="true" prop="findingsAudit"></el-table-column> -->
        <el-table-column width="150" label="操作">
          <template slot-scope="scope">
            <el-tooltip class="item" effect="light" content="查看" placement="top">

              <el-button class="button operate_show_btn"  type="primary" @click.stop="see('see',scope.row)"
                v-if="scope.row.bblxmc==='集贸零售价格'">
                <i class="iconfont ">&#xe67e;</i>
              </el-button>

              <el-button class="button operate_show_btn"  type="primary"
                @click.stop="seePifa('see',scope.row)" v-if="scope.row.bblxmc==='集贸批发价格'">
                <i class="iconfont ">&#xe67e;</i>
              </el-button>
              <el-button class="button operate_show_btn"  type="primary"
                @click.stop="seeChaoshi('see',scope.row)" v-if="scope.row.bblxmc==='超市价格'">
                <i class="iconfont ">&#xe67e;</i>
              </el-button>
              <!-- <el-button class="button"  type="primary" @click.stop="see(scope.row)">
                  <i class="iconfont">
                      &#xe67f;
                    </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="see('edit',scope.row)"
                v-if="scope.row.bblxmc==='集贸零售价格'">
                <i class="iconfont ">&#xe693;</i>
              </el-button>

              <el-button class="button operate_edit_btn"  type="primary"
                @click.stop="seePifa('edit',scope.row)" v-if="scope.row.bblxmc==='集贸批发价格'">
                <i class="iconfont">&#xe693;</i>
              </el-button>
              <el-button class="button operate_edit_btn"  type="primary"
                @click.stop="seeChaoshi('edit',scope.row)" v-if="scope.row.bblxmc==='超市价格'">
                <i class="iconfont">&#xe693;</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 { getLists, priceType } from '@/api/priceReport/list'
  export default {
    name: 'Daily',
    data() {
      return {
        queryform: {
          priceType: '',
          data: ''
        },
        yearArr: [{
          index: 1,
          value: '发布'
        }],
        dataDictioPubArr: [{
          index: 1
        }],
        tableData: [{
          index: 1
        }],
        limit: {
          page: 1,
          size: 10,
          total: 0
        },
        isloading: false,
        startDate: '',
        endDate: '',
        listTi: []
      }
    },
    computed: {
      ...mapGetters([
        'name'
      ])
    },
    beforeCreate() {
      priceType().then((response) => {
        this.listTi = response.data;
      });


    },
    created() {
      this.getList();
    },
    methods: {
      // List init
      getList() {
        if (this.queryform.data.length > 1) {
          this.startDate = this.queryform.data[0]
          this.endDate = this.queryform.data[1]
        }
        const data = {
          startDate: this.startDate,
          endDate: this.endDate,
          priceType: this.queryform.priceType,
          page: this.limit.page,
          size: this.limit.size
        }
        getLists(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/priceReceiveAdd', query: { id: row.id, state: 'see' } })
        } else if (state === 'edit') {
          if (row.bblxmc == '集贸零售价格') {
            this.$router.push({ path: '/priceMonitoring/priceReceiveAdd', query: { id: row.id, state: 'edit' } })
          }
        }
        else if (state === 'add') {
          this.$router.push({ path: '/priceMonitoring/priceReceiveAdd', query: { state: 'add' } })


        }
      },
      seeChaoshi(state, row) {
        if (state === 'see') {
          this.$router.push({ path: '/priceMonitoring/priceReceiveAddChaoshi', query: { id: row.id, state: 'see' } })
        } else if (state === 'edit') {
          this.$router.push({ path: '/priceMonitoring/priceReceiveAddChaoshi', query: { id: row.id, state: 'edit' } })
        }
        else if (state === 'add') {
          this.$router.push({ path: '/priceMonitoring/priceReceiveAddChaoshi', query: { state: 'add' } })
        }
      },
      seePifa(state, row) {
        if (state === 'see') {
          this.$router.push({ path: '/priceMonitoring/priceReceiveAddPifa', query: { id: row.id, state: 'see' } })
        } else if (state === 'edit') {
          this.$router.push({ path: '/priceMonitoring/priceReceiveAddPifa', query: { id: row.id, state: 'edit' } })
        }
        else if (state === 'add') {
          this.$router.push({ path: '/priceMonitoring/priceReceiveAddPifa', query: { state: 'add' } })


        }
      },
      handleChangeSize(value) {

      },
      handleCurrentChangePage(value) {
      },
      // addBtn() {
      //   this.$router.push({ path: '/priceMonitoring/priceReportAdd' })
      // },
      typeIndex(index) {
        return index + (this.limit.page - 1) * this.limit.size + 1;
      },
    }
  }
</script>

<style lang="scss" scoped>
  .dashboard {
    &-container {
      margin: 30px;
    }

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