carDamage.vue 10.2 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>
    <GLDialog :destroy-on-close="isdestroy" :hasFooter="false" :close-on-click-modal="false" title="修改记录" mode="mid" :visible.sync="isRecordSync" :before-close="handleCancel">
      <div class="record-dialog">
        <el-timeline>
          <el-timeline-item :class="[{ spec: !index }]" v-for="(item, index) in operationRecordData" :key="index" :timestamp="item.createdDateStr">
            {{ item.content }}
          </el-timeline-item>
        </el-timeline>
        <div class="noData" v-if="operationRecordData.length == 0">
          <img class="noDataImg" :src="url" v-if="url" alt="" />
          <div>暂无数据</div>
        </div>
      </div>
    </GLDialog>
  </div>
</template>

<script>
import * as dayjs from 'dayjs'
import utils from '../../util/util'
import url from '@/assets/empty.png'
export default {
  name: 'CarDamage',
  components: {},
  data() {
    return {
      url,
      isdestroy: true,
      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)
          }
        },
        {
          type: 'el-button',
          name: row => {
            return '修改记录'
          },
          attrs: {
            type: 'text'
          },
          listeners: {
            click: row => this.operationRecord(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' },
      operationRecordData: [],
      isRecordSync: false
    }
  },

  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)
    },
    // 操作记录
    operationRecord(row) {
      let params = {
        pageNum: 1,
        pageSize: 10000,
        serviceCode: row.serviceCode
      }
      this.$apis.serviceConfig.getServiceRecordApi(params).then(res => {
        const spaces = ' '.repeat(3)
        res?.list?.forEach(val => {
          val.createdDateStr = `${val.createdBy}${spaces}${dayjs(val.createdDate).format('YYYY-MM-DD HH:mm:ss')}`
          val.content = `规格${val.serviceGrade},服务年限${val.servicePeriod}年,`
          let childContent = ''
          val?.detailList?.forEach((v, index) => {
            const unit = ['maxPrice', 'minPrice']?.includes(v.field) ? '万元' : ['priceCoefficient']?.includes(v.field) ? '' : '元'
            childContent = `${v.fieldName}由${v.beforeValue}${unit}变为${v.afterValue}${unit}${index < val?.detailList?.length - 1 ? ',' : ''}`
            val.content += childContent
          })
        })
        this.operationRecordData = res?.list || []
        this.handleCancel()
      })
    },
    handleCancel() {
      this.isRecordSync = !this.isRecordSync
    }
  }
}
</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;
  }
}
.record-dialog {
  max-height: calc(80vh - 60px);
  padding-left: 12px;
  .el-timeline-item {
    /deep/ .el-timeline-item__node {
      width: 8px;
      height: 8px;
    }
    /deep/ .el-timeline-item__tail {
      left: 2px;
    }
    /deep/ .el-timeline-item__wrapper {
      .el-timeline-item__content {
        color: #333333;
        line-height: 23px;
        font-size: 14px;
      }
      .el-timeline-item__timestamp {
        color: #999999;
        font-size: 12px;
      }
    }
  }
  .el-timeline-item:first-child {
    /deep/ .el-timeline-item__node {
      background: #2a58ad !important;
    }
  }
  .noData {
    display: flex;
    flex-flow: column;
    align-items: center;
    justify-content: center;
    padding: 104px;
  }
}
</style>