index.vue 7.34 KB
<template>
  <div class="container">
    <GLCombiForm ref="showSearch" :formObj="searchForm" :formData="searchFormData" @handleOk="handleSearch" @handleRest="handleReset"></GLCombiForm>
    <div class="table-wrapper">
      <div class="operate_wrap">
        <span class="table_title">配置列表</span>
        <div class="operate_btn">
          <el-button :size="size" type="primary" @click="addClause(1)">新增</el-button>
          <el-button :size="size" @click="handleExport">导出</el-button>
        </div>
      </div>
      <GLTable ref="equityRef" :getListApi="getListApi" :searchForm="tableSearchForm" :tableParams="tableParams" :pageConf="pageConf" :beforeSearchFn="beforeSearchFn">
        <div slot="statusSlot" slot-scope="scope">
          <span class="statsu-circle" :style="{ 'background-color': scope.scope.serviceStatus == 0 ? '#FDB757' : '#2CCA74' }"></span>
          <span>{{ scope.scope.serviceStatus == 0 ? '待配置' : '已配置' }}</span>
        </div>
        <span slot="auth-button" slot-scope="scope" :data="scope.scope">
          <GLTableButton :buttonList="buttonList" :buttonItem="scope" :buttonNum="3"></GLTableButton>
        </span>
      </GLTable>
    </div>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import utils from '../../util/util'
export default {
  name: 'equityList',
  components: {},
  data() {
    return {
      size: 'small',
      buttonList: [
        {
          type: 'el-button',
          name: row => {
            return '查看'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.addClause(2, row.scope)
          }
        },
        {
          type: 'el-button',
          name: row => {
            return '编辑'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.addClause(3, row.scope)
          }
        }
      ],
      searchForm: {
        serviceName: '',
        serviceStatus: '',
        createdDate: '',
        updatedDate: ''
      },
      tableSearchForm: {},
      searchFormData: [
        {
          label: '服务名称',
          name: 'serviceName',
          type: 'input',
          isClear: true
        },
        {
          label: '状态',
          name: 'serviceStatus',
          type: 'select',
          optionList: [
            {
              id: '',
              label: '全部'
            },
            {
              id: '0',
              label: '待配置'
            },
            {
              id: '1',
              label: '已配置'
            }
          ],
          optionId: 'id',
          optionLabel: 'label',
          isClear: true
        },
        {
          label: '创建时间',
          name: 'createdDate',
          type: 'datePicker',
          labelWidth: 95,
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        },
        {
          label: '更新时间',
          name: 'updatedDate',
          type: 'datePicker',
          labelWidth: 95,
          isClear: true,
          pickerOptions: 'beforeRangePickerOptions'
        }
      ],
      // 表格
      getListApi: this.$apis.serviceConfig.getServicesItemsList,
      tableParams: {
        listName: 'list',
        tableOption: true,
        tableColumns: [
          {
            label: '服务编号',
            prop: 'serviceCode',
            width: 200
          },
          {
            label: '服务名称',
            prop: 'serviceName',
            width: 200
          },
          {
            label: '可销售服务年限',
            minWidth: 280,
            prop: 'salePeriod',
            formatter: cellValue => {
              return cellValue.salePeriod?.length
                ? cellValue.salePeriod
                    .split(',')
                    .map(item => (item = item + '年'))
                    .join('、')
                : '--'
            }
          },
          {
            label: '规格数量',
            minWidth: 150,
            prop: 'gradeCount'
          },
          {
            label: '创建时间',
            prop: 'createdDate',
            width: 200,
            formatter: cellValue => {
              return cellValue.createdDate ? dayjs(cellValue.createdDate).format('YYYY-MM-DD HH:mm:ss') : '--'
            }
          },
          {
            label: '更新时间',
            prop: 'updatedDate',
            width: 200,
            formatter: cellValue => {
              return cellValue.updatedDate ? dayjs(cellValue.updatedDate).format('YYYY-MM-DD HH:mm:ss') : '--'
            }
          },
          {
            label: '状态',
            minWidth: 150,
            prop: 'status',
            addHtml: 'statusSlot'
          },
          {
            label: '操作人',
            prop: 'updatedBy',
            width: 140
          }
        ]
      },
      pageConf: { pageSize: 'pageSize', pageNum: 'pageNum', totalCount: 'total' }
    }
  },

  mounted() {},

  methods: {
    getParams() {
      let params = JSON.parse(JSON.stringify(this.searchForm))
      if (this.searchForm?.createdDate?.length) {
        params.beginCreateTime = new Date(this.searchForm.createdDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.endCreateTime = new Date(this.searchForm.createdDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      if (this.searchForm?.updatedDate?.length) {
        params.beginUpdateTime = new Date(this.searchForm.updatedDate[0]).toLocaleDateString().replace(/\//g, '-') + ' 00:00:00'
        params.endUpdateTime = new Date(this.searchForm.updatedDate[1]).toLocaleDateString().replace(/\//g, '-') + ' 23:59:59'
      }
      delete params.createdDate
      delete params.updatedDate
      return { ...params }
    },

    beforeSearchFn() {
      return new Promise(resolve => {
        this.tableSearchForm = this.getParams()
        resolve()
      })
    },

    // 导出
    handleExport() {
      var params = this.getParams()
      this.$apis.serviceConfig.exportServicesItemsApi(params).then(res => {
        // window.open(res)
        let tempaa = utils.getExplorer()
        if (tempaa == 'QQ') {
          window.open(res)
        } else {
          let iframe = document.createElement('iframe')
          iframe.style.display = 'none'
          iframe.src = res
          document.body.appendChild(iframe)
        }
      })
    },

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

    handleReset() {
      this.searchForm = {
        serviceName: '',
        serviceStatus: '',
        createdDate: '',
        updatedDate: ''
      }
      this.handleSearch()
    },

    addClause(type, row) {
      // 1新增 2查看 3编辑
      const { id, serviceCode, serviceName } = row || {}
      let query = {
        type
      }
      if (type != 1) {
        query.id = id
        query.serviceCode = serviceCode
        query.serviceName = serviceName
      }
      const queryStr = encodeURIComponent(JSON.stringify(query))
      this.$router.push('/serviceConfig/addService/' + queryStr)
    }
  }
}
</script>

<style lang="scss" scoped>
.container {
  background-color: #ffffff;
  padding: 20px;
  .statsu-circle {
    display: inline-block;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background-color: #fdb757;
    margin-right: 8px;
    vertical-align: middle;
  }
}
</style>