el-table template 支持 formater

         <el-table
              v-loading="listLoading" row-key="id" :data="tableData"
              element-loading-text="正在加载中..."
              stripe fit highlight-current-row @selection-change="handleSelectionChange"
              :height="tableHeight">
              <el-table-column type="selection" width="50"></el-table-column>
              <el-table-column type="index" label="序号" width="50"></el-table-column>
              <el-table-column :key="key" align="center" :width="value.width" v-for='(value,key) in tableHead'
                               :label="value.title" :prop="value.key" :formatter="value.formatter">
                <template slot-scope="scope">
                  <div v-if="value.key === 'orderCode'">
                    <el-popover
                      placement="bottom"
                      :width="230"
                      trigger="click"
                      :content="scope.row[value.key]">
                      <div slot="reference">{{scope.row[value.key].length>10?(scope.row[value.key].slice(0,10)+'...'):scope.row[value.key]}}</div>
                    </el-popover>
                  </div>
                  <!--主要下面这一段-->
                  <div v-else>{{formaterColumn(value.formatter,scope.row,scope.row[value.key])}}</div>
                </template>

              </el-table-column>
              <el-table-column label="操作"  fixed="right" align="center">
                <template slot-scope="scope">
                  <el-button  type="primary" size="mini" class="btn-edit" @click="dispatch(scope.row)">调度
                  </el-button>
                </template>
              </el-table-column>
            </el-table>

现在看计算属性使用闭包
 

  computed:{
    formaterColumn(){
      return function(flag,row,val){
        return flag ? flag(row,null,val) : val
      }
    },
  },

下面是我的所有字段仅供参考

const defaultTableHead = [
  { key: 'code', title: '运输单号', width: '180px' },
  { key: 'orderCode', title: '运输订单号', width: '180px' },
  { key: 'sourceLocation', title: '起运地', width: '180px' },
  { key: 'destLocation', title: '目的地', width: '180px' },
  { key: 'startTime', title: '开始时间', width: '' ,formatter:formatTime},
  { key: 'endTime', title: '结束时间', width: '' ,formatter:formatTime},
  { key: 'num', title: '途经点个数', width: '' },
  { key: 'totalAmount', title: '预计取货总数量', width: '180px' },
  { key: 'totalVolume', title: '预计取货总体积(m3)', width: '180px' },
  { key: 'totalWeight', title: '预计取货总重量(t)', width: '180px' },
  { key: 'totalTrust', title: '预计取货总托数', width: '180px' },
  { key: 'model', title: '配载车型', width: '180px' },
  { key: 'node', title: '路由节点', width: '180px' },
  { key: 'driverName', title: '司机姓名', width: '' },
  { key: 'driverPhone', title: '司机手机号码', width: '' },
  { key: 'driverLicense', title: '车牌号', width: '' },
  { key: 'status', title: '运输状态', width: '' , formatter: val => {
      switch (val.status) {
        case 10:
          return '未调度'
        case 20:
          return '已调度'
        case 25:
          return '未接单'
        case 30:
          return '已接单'
        case 40:
          return '已提货'
        case 50:
          return '运输中'
        case 60:
          return '已完成'
        case 70:
          return '超时完成'
        case 80:
          return '已取消'
        case 90:
          return '超时接单'
        default:
          return '未提货'
      }}},
  {
    key: 'dispatchStatus', title: '发运状态', width: '', formatter: val => {
      switch (val.dispatchStatus) {
        case 10:
          return '未发运'
        case 20:
          return '已发运'
      }
    }
  },
  { key: 'carrierName', title: '承运商', width: '' },
  { key: 'createUser', title: '创建用户', width: '' },
  { key: 'gmtCreate', title: '创建时间', width: '180px', formatter: formatTime },
  { key: 'modifiedUser', title: '修改用户', width: '' },
  { key: 'gmtModified', title: '修改时间', width: '180px', formatter: formatTime }
]

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值