index.vue 6.25 KB
<template>
  <div class="container">
    <div class="sticky">
      <GLCombiForm
        ref="showSearch"
        :rowNumber="1"
        :formObj="searchForm"
        :formData="searchFormData"
        @handleOk="handleSearch"
        @handleRest="handleReset"
      ></GLCombiForm>
      <div class="sticky-btns">
        <div class="btns">
          <el-button
            type="default"
            plain
            @click="$router.push({
              path: '/questionnaire/add'
            })"
          >新建问卷</el-button>
          <el-button
            type="default"
            @click="handleExport"
          >导出</el-button>
        </div>
      </div>
    </div>
    <div class="tabelList">
      <div class="table-title">问卷列表</div>
      <GLTable
        ref="listRef"
        :getListApi="getListApi"
        :searchForm="searchForm"
        :noDataImg="url"
        :tableParams="tableParams"
        :pageConf="pageConf"
      >
        <template
          slot="qrcode"
          slot-scope="scope"
        >
          <el-popover
            placement="top"
            trigger="hover"
          >
            <img
              class="img-plus"
              :src="scope.scope.qrcode"
            />
            <div
              slot="reference"
              class="qr"
            >
              <img :src="scope.scope.qrcode" />
            </div>
          </el-popover>
        </template>
        <span
          slot="auth-button"
          slot-scope="scope"
        >
          <GLTableButton
            :buttonList="tableButtonList"
            :buttonItem="scope.scope"
            :buttonNum="3"
          ></GLTableButton>
        </span>
      </GLTable>
    </div>
    <data-table :dataObj.sync="dataObj" />
    <GLDialog
      title="结束"
      @onOk="overQiestion"
      @onCancel="dialogVisible = false"
      :visible.sync="dialogVisible"
      mode="small"
    >
      <template #default>
        <div class="over-box">
          <div class="el-icon-warning"></div>
          请确认是否结束该调查问卷?
          <div class="tips">结束后,客户点击将提示:问卷活动已结束</div>
        </div>
      </template>
    </GLDialog>

  </div>
</template>

<script type='text/ecmascript-6'>
import url from '@/assets/empty.png'
import DataTable from './components/DataTable/index.vue'
import { exportFn } from '@/common/constant'
export default {
  name: 'Questionnaire',
  components: { DataTable },
  data () {
    return {
      url,
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'count' },
      searchForm: {
        merchantName: '',
        name: '',
      },
      searchFormData: [
        {
          label: '问卷名称',
          name: 'name',
          type: 'input',
          maxlength: 100
        },
        {
          label: '所属渠道',
          name: 'merchantName',
          type: 'input',
          maxlength: 100
        },
      ],
      getListApi: this.$apis.questionnaire.getQuestionnaireList,
      tableParams: {
        listName: 'data',
        tableOption: {
          width: '110px'
        },
        tableColumns: [
          {
            label: '问卷名称',
            prop: 'name',
            minWidth: 100
          },
          {
            label: '所属渠道',
            minWidth: 100,
            formatter: cell => `${cell.merchantId}/${cell.merchantName}`
          },
          {
            label: '卡片标题',
            prop: 'cardTitle',
            minWidth: 100
          },
          {
            label: '二维码',
            minWidth: 100,
            addHtml: 'qrcode'
          },
        ]
      },
      // 表格按钮
      tableButtonList: [
        {
          type: 'el-button',
          name: '数据',
          attrs: {
            type: 'text',
          },
          listeners: {
            click: row => this.jumpDetail(row)
          }
        },
        {
          type: 'el-button',
          name: '结束',
          attrs: {
            type: 'text',
          },
          listeners: {
            click: row => {
              this.dialogVisible = true
              this.closeParams = row
            }
          },
          condition: row => row.status != -1
        },
      ],
      dataObj: {},
      dialogVisible: false,
      closeParams: {}
    }
  },
  mounted () {
  },
  methods: {
    handleSearch () {
      this.$refs.listRef.refreshTable()
    },
    handleReset () {
      this.searchForm = this.$options.data.call(this).searchForm
      this.handleSearch()
    },
    jumpDetail (row) {
      this.dataObj = {
        show: true,
        ...row
      }
    },
    async overQiestion () {
      const { id } = this.closeParams,
        res = await this.$apis.questionnaire.closeQuestionnaire({ id })
      if (res) {
        this.dialogVisible = false
        this.$message({
          message: '操作成功',
          type: 'success'
        })
        this.handleSearch()
      } else this.$message.error('操作失败,请重试。')
    },
    handleExport () {
      this.$apis.questionnaire.exportQuestionnaireList({ ...this.searchForm, ...this.$refs.listRef.page }).then(res => {
        exportFn(res)
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.container {
  height: 100%;
  background-color: #fff;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  padding: 20px;
  .table-title {
    font-weight: 700;
    font-size: 16px;
    color: #333333;
    padding-bottom: 18px;
  }
  .sticky {
    position: relative;
    z-index: 2;
    &-btns {
      position: absolute;
      right: 0;
      bottom: -23px;
      overflow: hidden;
      .el-button + .el-button {
        margin-left: 8px;
      }
      .btns {
        transition: all 0.25s;
        .el-button {
          padding: 8px 15px;
          min-width: 60px;
        }
      }
    }
  }
  .qr {
    width: 36px;
    height: 36px;
    img {
      width: 100%;
      height: 100%;
      vertical-align: top;
    }
  }
}
.img-plus {
  width: 200px;
  height: 200px;
}
/deep/.over-box {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  font-size: 16px;
  color: #333333;
  gap: 8px;
  .el-icon-warning {
    font-size: 48px;
    color: #e6a23c;
  }
  .tips {
    font-size: 14px;
    color: #666666;
  }
}
</style>