index.vue 7.2 KB
<!-- 评价管理-->
<template>
  <div class="marketing p-t-20">
    <div class="container">
      <div>
        <glsx-combi-form ref="showSearch" :formObj="searchForm" :formData="searchFormData">
          <span slot="footer" class="footer-btns">
            <el-button :size="size" type="default" @click="handleReset">重置</el-button>
            <el-button :size="size" type="primary" @click="handleSearch">查询</el-button>
          </span>
        </glsx-combi-form>
      </div>

      <!-- 表格区域 开始 -->
      <GLTable ref="commentRef" :getListApi="getListApi" :noDataImg="url" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn" @setTableFinishFun="setTableFinishFun">
        <div class="table-btns" slot="auth-button" slot-scope="scope">
          <el-button v-if="scope.scope.commentStatus == '0'" type="text" @click="handleRevoke(scope.scope)">发布</el-button>
          <el-button v-if="scope.scope.commentStatus == '1'" type="text" @click="handleRevoke(scope.scope)">撤回</el-button>
          <!-- <el-button type="text" @click="handleDetail(scope.scope)">查看</el-button> -->
          <GLButton type="text" fn="评价详情" @click="handleDetail(scope.scope)">查看</GLButton>
          <!-- <el-button type="text" @click="handleDelete(scope.scope)">删除</el-button> -->
        </div>
      </GLTable>
      <!-- 表格区域 end -->
    </div>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import url from "@/assets/empty.png"
export default {
  name: 'orderComment',
  data() {
    return {
      size: 'small',
      url: url,
      searchForm: {
        commentStatus: '',
        createDate: []
      },
      tableSearchForm: {},
      // 搜索
      searchFormData: [
        {
          label: '评价日期',
          name: 'createDate',
          type: 'datePicker',
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          label: '评价状态',
          name: 'commentStatus',
          type: 'select',
          optionList: [],
          optionId: 'confId',
          optionLabel: 'confName',
          optionsName: 'commentStatusList'
        }
      ],
      // 表格
      getListApi: this.$apis.orderComment.getListApi,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '评价日期',
            prop: 'createdDate',
            // width: '180',
            formatter: cellValue => {
              return dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss')
            }
          },
          {
            label: '评价状态',
            prop: 'commentStatus',
            line: 1,
            formatter: cellValue => {
              return this.baseData.commentStatusList.find(item => item.confId == cellValue.commentStatus).confName
            }
          },
          {
            label: '评论人',
            prop: 'customerName',
            line: 1,
            formatter: cellValue => {
              return cellValue.customerName || '-'
            }
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'currentPage', totalCount: 'total' },
      baseData: {
        commentStatusList: [
          {
            confId: '0',
            confName: '未发布'
          },
          {
            confId: '1',
            confName: '已发布'
          }
        ]
      }
    }
  },

  mounted() {
    this.getOptionsList('searchFormData')
  },

  methods: {
    getParams() {
      var params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm.createDate.length) {
        params.createStartDateStr = new Date(this.searchForm.createDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.createEndDateStr = new Date(this.searchForm.createDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      delete params.createDate
      return params
    },
    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        delete this.tableSearchForm.createDate
        resolve()
      })
    },

    secondConfirm(title, txt, apiModule, apiName, apiParams, fn) {
      this.$confirm(txt, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
        callback: action => {
          if (action == 'confirm') {
            this.$apis[apiModule][apiName](apiParams).then(res => {
              this.$message({
                message: res.code == '0' ? '操作成功' : res.message,
                type: res.code == '0' ? 'success' : 'error'
              })
              if (res.code == '0') {
                fn && fn()
                this.handleSearch()
              }
            })
          }
        }
      })
    },
    
    // 查看
    handleDetail(row) {
      this.$router.push({
        path: '/orderComment/commentDetail',
        query: {
          id: row.id
        }
      })
    },

    // 发布/撤回
    handleRevoke(row) {
      var txt = row.commentStatus == '0' ? '发布' : '撤回'
      this.secondConfirm(txt, '是否确认'+ txt +'该评论?', 'orderComment', 'changeCommentStatusApi', { id: row.id, commentStatus: row.commentStatus == '0' ? 1 : 0 })
    },

    handleDelete(row) {
      this.secondConfirm('删除', '是否确认删除该评论?', 'orderComment', 'deleteCommentApi', { id: row.id })
    },

    getOptionsList(formName, hasAll = true, refreshSigle) {
      if (refreshSigle) {
        var item = this[formName].find(k => k.name == refreshSigle)
        var index = this[formName].findIndex(k => k.name == refreshSigle)
        this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
        if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
          const temp = {}
          temp[this[formName][index].optionId] = ''
          temp[this[formName][index].optionLabel] = '全部'
          this[formName][index].optionList.unshift(temp)
        }
      } else {
        this[formName].forEach((item, index) => {
          if (item.type === 'select' && this.baseData[item.optionsName].length) {
            this.$set(this[formName][index], 'optionList', this.$common.utils.deepClone(this.baseData[item.optionsName]))
            if (hasAll && this.baseData[item.optionsName].length && this.baseData[item.optionsName][0][this[formName][index].optionLabel] !== '全部') {
              const temp = {}
              temp[this[formName][index].optionId] = ''
              temp[this[formName][index].optionLabel] = '全部'
              this[formName][index].optionList.unshift(temp)
            }
          }
        })
      }
    },
    
    setTableFinishFun() {
      //接收到的数据为空
      this.$refs.commentRef.data.length ? (this.$refs.commentRef.tableHeightValues = '') : this.$refs.commentRef.setTableHeightFun()
    },

    handleSearch() {
      this.$refs.commentRef.refreshTable()
    },

    handleReset() {
      this.searchForm = {
        commentStatus: '',
        createDate: []
      }
      this.handleSearch()
    }
  }
}
</script>

<style scoped></style>