refundDetail.vue 4.44 KB
<template>
  <el-dialog
    title="请选择退款明细"
    :visible.sync="refundVisible"
    :before-close="handleClose"
    :close-on-click-modal="false"
    width="70%"
    class="relateStore"
  >
    <div>
      <el-table
        ref="seletingTable"
        :data="tableData"
        class="table"
        border
        @select="handleChange"
        @select-all="handleAll"
      >
        <el-table-column
          :selectable="selectableFn"
          type="selection"
          width="55"
          align="center"
        />
        <template v-for="item in tableColumn">
          <el-table-column :prop="item.prop" :label="item.label" align="center">
            <span slot-scope="scope">
              {{
                scope.row[item.prop]
                  ? item.unit
                    ? item.unit + scope.row[item.prop]
                    : scope.row[item.prop]
                  : "-"
              }}
            </span>
          </el-table-column>
        </template>
      </el-table>
      <div class="total">
        可选可退总价:
        <div class="price">¥{{ total }}</div>
      </div>
    </div>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button
        type="primary"
        @click="handleConfirm"
        :disabled="!refundSubOrderCode"
        >下一步</el-button
      >
    </span>
  </el-dialog>
</template>

<script>
import { goodsSubOrder } from "@api/order"
export default {
  name: "refundDetail",
  data() {
    return {
      tableData: [],
      tableColumn: [
        {
          label: "子订单编码",
          prop: "subOrderCode"
        },
        {
          label: "商品名称",
          prop: "goodsName"
        },
        {
          label: "商品别名",
          prop: "goodsAlias"
        },
        {
          label: "商品ID",
          prop: "goodsCommodityCode"
        },
        {
          label: "分类",
          prop: "upgradeGoodsTypeName"
        },
        {
          label: "售价",
          prop: "upgradePrice",
          unit: "¥"
        },
        {
          label: "数量/件",
          prop: "number"
        },
        {
          label: "支付金额",
          prop: "finalPrice",
          unit: "¥"
        }
      ],
      total: 0,
      refundSubOrderCode: "",
      refundApplyDetailList: [],
      isAll: false,
      // 是否只有一个子订单并且未退过款的
      isOneSubFirst: false
    }
  },
  props: {
    refundVisible: {
      type: Boolean,
      default: false
    },
    dataInfo: {
      type: Object,
      default: {}
    }
  },
  watch: {
    dataInfo(val) {
      console.log(val)
      if (val && val.orderCode) this.getList(val.orderCode)
    }
  },
  methods: {
    // 设置禁用
    selectableFn(row) {
      console.log(row)
      if (row.status == 2) return false
      else return true
    },
    async getList(orderCode) {
      const res = await goodsSubOrder({ orderCode })
      this.tableData = res
      this.isOneSubFirst = this.tableData.length == 1 && this.tableData.every(item => item.status == 1)
      this.$refs.seletingTable.toggleAllSelection()
    },
    handleChange(selection) {
      console.log(selection)
      this.isAll = selection.length == this.tableData.length
      this.getParams(selection)
    },
    handleAll(selection) {
      console.log(selection)
      this.isAll = selection.length == this.tableData.length
      this.getParams(selection)
    },
    getParams(selection) {
      let _total = 0
      let _refundSubOrderCode = []
      selection.forEach((item, idx) => {
        _total += item.finalPrice
        _refundSubOrderCode.push(item.subOrderCode)
        this.$set(selection[idx], 'refundAmount', item.finalPrice)
      })
      this.total = parseFloat(_total.toFixed(2))
      this.refundSubOrderCode = _refundSubOrderCode.join("/")
      this.refundApplyDetailList = selection
      console.log(this.refundSubOrderCode)
    },
    handleConfirm() {
      const { refundSubOrderCode, refundApplyDetailList, total, isAll, isOneSubFirst } = this
      this.$emit("handleConfirm", {
        total,
        refundSubOrderCode,
        isAll,
        refundApplyDetailList,
        isOneSubFirst
      })
    },
    handleClose() {
      this.$emit("handleClose")
    }
  }
}
</script>

<style lang="scss" scoped>
.total {
  display: flex;
  align-items: center;
  color: #666666;
  font-size: 14px;
  .price {
    color: #2a58ad;
    margin-left: 10px;
  }
}
</style>