addDeduction.vue 8.05 KB
<template>
  <div class="revocation-wrap">
    <div class="content">
      <div class="title">新增抵扣</div>
      <div class="form-wrap">
        <glsx-combi-form
          class="form-container"
          ref="formRef"
          label-width="154px"
          :isBlock="true"
          :form-ref="childRef"
          :form-obj="formObj"
          :form-data="formData"
          :form-rules="formRule"
        >
          <div slot="orderData">
            <div class="order-btn" @click="handleChooseOrder">选择订单</div>
            <d2-table
              :table-params="tableParams"
              :table-data="formObj.orderData"
              :has-page="false"
            >
              <div slot="orderGoodsName" slot-scope="scope">
                <span
                  v-for="(item, index) in scope.scope.subOrderList"
                  :key="index"
                >
                  <p v-if="item.upgradeGoodsId">
                    <el-tooltip
                      class="item"
                      :content="item.upgradeGoodsName"
                      placement="right"
                    >
                      <span>
                        {{
                          item.upgradeGoodsName
                            ? item.upgradeGoodsName.length > 10
                              ? item.upgradeGoodsName.substring(0, 10) + "..."
                              : item.upgradeGoodsName
                            : "-"
                        }}
                      </span>
                    </el-tooltip>
                  </p>
                  <p v-else>{{ item.baseGoodsName }}</p>
                </span>
              </div>
              <div slot="auth-button" slot-scope="scope">
                <el-button type="text" @click="deleteTable(scope.scope)"
                  >删除</el-button
                >
              </div>
            </d2-table>
          </div>
        </glsx-combi-form>
      </div>
    </div>
    <div class="btn-wrap">
      <div class="btn btn-wrap-left" @click="submit">提交</div>
      <div class="btn btn-wrap-right" @click="cancel">取消</div>
    </div>
    <!-- 选择订单 -->
    <choose-order-dialog
      :visible="orderDialogVisible"
      v-if="orderDialogVisible"
      :choose-order-data="formObj.orderData"
      @dialogClose="handleClose"
      @chooseOrder="chooseOrder"
    >
    </choose-order-dialog>
    <!-- 确认提醒 -->
    <confirm-dialog
      :visible="confirmDialogVisible"
      v-if="confirmDialogVisible"
      :data-info="formObj"
      @dialogClose="handleConfirmClose"
      @handleConfirm="handleComfirm"
    ></confirm-dialog>
  </div>
</template>
<script>
import { Util } from "@/common/util"
import { manualDeduct } from "@api/point"
import ChooseOrderDialog from "./components/chooseOrderDialog"
import ConfirmDialog from "./components/ConfirmDialog"
export default {
  components: {
    ChooseOrderDialog,
    ConfirmDialog
  },
  data() {
    function checkPrice(rule, value, callback) {
      if (!Util.validateNumber(value)) {
        callback(new Error("输入范围为大于0的数字,至少支持小数点后两位"))
        return false
      }
      callback()
    }
    return {
      orderDialogVisible: false,
      confirmDialogVisible: false, //确认提醒
      formObj: {
        score: "",
        orderData: [],
        orderCode: "",
        remark: "",
        operator: ""
      },
      confirmData: {},
      formData: [
        {
          label: "选择订单",
          name: "orderData",
          addHtml: "orderData"
        },
        {
          label: "扣减积分",
          name: "score",
          type: "input",
          maxlength: 20,
          placeholder: "请输入",
          tips: "此订单需要在员工账户里扣除的积分",
          width: "136px"
        },
        {
          label: "备注",
          name: "remark",
          type: "input",
          maxlength: 100,
          placeholder: "请输入",
          inputType: "textarea",
          width: "580px",
          rows: 3
        }
      ],
      formRule: {
        orderData: [
          {
            required: true,
            message: "选择需要关联的已退款或已付款订单",
            trigger: "change"
          }
        ],
        score: [
          { required: true, message: "请输入积分", trigger: "change" },
          { validator: checkPrice, trigger: "blur" }
        ]
      },
      tableParams: {
        tableOption: true,
        tableColumns: [
          {
            label: "订单编号",
            prop: "orderCode",
            width: "150px"
          },
          {
            label: "订单时间",
            prop: "orderTimeStr",
            width: "200px"
          },
          {
            label: "客户姓名",
            prop: "customerName",
            width: "120px"
          },
          {
            label: "商品名称",
            prop: "orderGoodsName",
            addHtml: "orderGoodsName",
            width: 240
          },
          {
            label: "总价",
            prop: "totalPrice",
            width: "120px",
            formatter: (cellValue) => {
              return cellValue.totalPrice ? "¥" + cellValue.totalPrice : "0"
            }
          }
        ]
      },
      childRef: "editChildRef"
    }
  },
  created() {},
  methods: {
    //订单选择成功
    chooseOrder(data) {
      console.log(data,'99999')
      if (data.length) {
        this.$refs.formRef.$refs[this.childRef].clearValidate("orderData")
      }
      this.formObj.orderData = data
      this.orderDialogVisible = false
    },
    handleClose() {
      this.orderDialogVisible = false
    },
    handleConfirmClose() {
      this.confirmDialogVisible = false
    },
    handleComfirm() {
      let params = {
        orderCode: this.formObj.orderData[0].orderCode,
        score: this.formObj.score,
        remark: this.formObj.remark,
        operator: this.formObj.operator
      }
      manualDeduct(params)
        .then((result) => {
          console.log(result)
          if (result) {
            this.$router.go(-1)
            this.$notify({
              type: "success",
              title: "新增成功"
            })

            this.confirmDialogVisible = false
          }
        })
        .catch((err) => {
          // console.error(err)
          // this.$message.error(err)
        })
    },

    submit() {
      this.$refs.formRef.$refs[this.childRef].validate((valid) => {
        if (valid) {
          this.confirmDialogVisible = true
        }
      })
    },
    cancel() {
      this.$router.go(-1)
    },
    handleChooseOrder() {
      this.orderDialogVisible = true
    },
    deleteTable() {
      this.formObj.orderData = []
    }
  }
}
</script>
<style lang="scss" scoped>
.revocation-wrap {
  margin: 16px 24px;
  .content {
    background-color: #fff;
    .title {
      padding: 12px 16px;
      font-weight: 500;
      font-size: 18px;
      color: #333333;
      line-height: 24px;
      border-bottom: 1px solid #e8e8ea;
    }

    .title::before {
      display: inline-block;
      vertical-align: middle;
      margin-right: 8px;
      content: "";
      width: 4px;
      height: 16px;
      background: #185efe;
      border-radius: 2px;
    }
    .form-wrap {
      padding: 16px 0;
      min-height: 500px;
      .order-btn {
        width: 88px;
        height: 32px;
        background: #f8f8f8;
        border: 1px solid #e6e6e6;
        border-radius: 4px;
        font-size: 14px;
        color: #666666;
        text-align: center;
        line-height: 32px;
        cursor: pointer;
      }
    }
  }
  .btn-wrap {
    display: flex;
    align-items: center;
    padding: 16px 154px;
    .btn {
      width: 104px;
      height: 36px;
      border-radius: 4px;
      font-weight: 500;
      font-size: 16px;
      text-align: center;
      line-height: 36px;
    }
    &-right {
      color: #666666;
      background: #e8e8e8;
      margin-left: 16px;
    }
    &-left {
      background: #185efe;
      color: #ffffff;
    }
  }
}
::v-deep .form-container {
  .tips-icon {
    border: none;
  }
  .el-form-item__error {
    width: 300px;
  }
}
</style>