<!--
  @description:评价汇总
  @Modifier：qink / dijia
  @routerPath:/personalCenter/supplierSummary
  @date：  2020/4/13 15:46
-->
<template>
  <div>
    <div class="shopmall-page-title">
      评价汇总
    </div>
    <div class="search-content clearfix">
      <section class="fl">
        <el-form ref="orderFrom" :inline="true" :model="orderFrom">
          <el-form-item v-if="currentRole !=='shopSupplier'" label="供应商名称" prop="supplierName">
            <el-select v-model="orderFrom.supplierName" placeholder="--请选择--">
              <el-option
                v-for="item in ground"
                :key="item.value"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item label="年度时间" prop="date">
            <el-date-picker
              v-model="date"
              value-format="yyyy-MM"
              type="monthrange"
              start-placeholder="开始月份"
              end-placeholder="结束月份"
            />
          </el-form-item>
        </el-form>
      </section>
      <div class="fr">
        <el-button type="purple" @click.native="searchOrderBtn">
          搜索
        </el-button>
        <el-button type="gray" @click.native="resetOrderBtn">
          重置
        </el-button>
      </div>
    </div>
    <div class="shopmall-view">
      <el-table
        :header-cell-style="{color:'#666666'}"
        :data="orderList"
        :row-class-name="tableRowClassName"
        class="el-table--striped-border"
        style="font-size: 12px;font-family:'MicrosoftYaHei';text-align: left;color: #333333"
      >
        <el-table-column label="序号" width="60" type="index" />
        <el-table-column prop="supplierName" label="供应商名称" />
        <el-table-column prop="expressPackaging" label="快递包装好评率" />
        <el-table-column prop="deliverySpeed" label="送货速度好评率" />
        <el-table-column prop="distributorSpeed" label="配送员服务好评率" />
        <el-table-column prop="productMark" label="商品好评率" />
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-link type="primary" @click="addClick(scope.row)">
              [评价详情]
            </el-link>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
import { assessReckon } from '@/api/shoppingmall/order.js'
import { getToken } from '@/assets/js/utils/auth'
export default {
  components: {
  },
  data() {
    return {
      currentRole: '',
      date: '',
      childenData: {
        dialog: false,
        id: ''
      },
      orderFrom: {
        pageNo: 1, // 当前页
        pageSize: 10, // 每页数目条数
        supplierName: '', // 供应商名称
        startYear: '', // 年度事件
        endYear: '' // 结束
      },
      total: 0,
      initParams: {
        pageNo: 1, // 当前页
        pageSize: 10 // 每页数目条数
      },
      orderList: [],
      ground: [{
        value: '京东商城',
        label: '京东商城'
      },
      // {
      //   value: '晨光办公',
      //   label: '晨光办公'
      // },
      // {
      //   value: '固安捷',
      //   label: '固安捷'
      // },
      // {
      //   value: '震坤行',
      //   label: '震坤行'
      // },
      // {
      //   value: '史泰博',
      //   label: '史泰博'
      // },
      {
        value: '国信创新',
        label: '国信创新'
      }]
    }
  },
  created() {
    if (getToken()) {
      this.currentRole = this.$store.getters.info.currentRol.roleCode
    }
    this.initData(this.initParams)
  },
  methods: {
    initData(params) {
      assessReckon(params).then((res) => {
        if (res.header.ret === '0') {
          this.orderList = res.data
        }
      }).catch((err) => {
        throw new Error('获取订单列表数据失败' + err)
      })
    },
    addClick(row) {
      this.$router.push({ path: '/personalCenter/supplierSummaryDetail', query: { name: row.supplierName }})
    },
    /**
       * 分页
       */
    handleCurrentChange(val) {
      this.initParams.pageNo = val
      this.initData(this.initParams)
    },
    handleSizeChange(val) {
      this.initParams.pageSize = val
      this.initData(this.initParams)
    },
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex === 1) {
        return 'warning-row'
      } else if (rowIndex === 3) {
        return 'success-row'
      }
      return ''
    },
    /**
       * 搜索
       */
    searchOrderBtn() {
      this.orderFrom.startYear = this.date[0]
      this.orderFrom.endYear = this.date[1]
      const array = JSON.parse(JSON.stringify(this.orderFrom))
      this.initData(array)
    },
    /**
       * 重置
       */
    resetOrderBtn() {
      this.date = ''
      this.orderFrom.startYear = ''
      this.orderFrom.endYear = ''
      this.$refs.orderFrom.resetFields()
      this.initData(this.initParams)
    }
  }
}
</script>

<style scoped lang="less">
</style>
