quanwei
18 hours ago c441dea81bd86bdfb12dff35821fed51f4cc91c2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<template>
  <div>
    <el-dialog title="退款" :visible.sync="dialogVisible" @close='dialogFormVisible' :close-on-click-modal="false"
      :close-on-press-escape="false">
      <el-form size="small" ref="form" :model="form">
        <el-form-item label="订单号" :label-width="formLabelWidth" prop="order_no">
          {{ refundOrder.order_no }}
        </el-form-item>
        <el-form-item label="如何退" :label-width="formLabelWidth">
          <el-radio-group v-model="form.refund_type" @change="changeRefundType">
            <el-radio :label="10">整单退</el-radio>
            <el-radio :label="20">部分退</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="退款商品" :label-width="formLabelWidth" v-if="form.refund_type==20">
          <div class="table-wrap">
            <el-table size="small" :data="product" border style="width: 100%" highlight-current-row v-loading="loading" @selection-change="tableCurrentChange">
              <el-table-column type="selection" width="44"></el-table-column>
              <el-table-column prop="product_name" width="70" label="商品图片">
                <template slot-scope="scope">
                  <img :src="scope.row.image.file_path" width="30" height="30" />
                </template>
              </el-table-column>
              <el-table-column prop="product_name" label="商品名称"></el-table-column>
              <el-table-column prop="product_attr" width="300" label="规格"></el-table-column>
              <el-table-column prop="total_num" width="100" label="数量"></el-table-column>
              <el-table-column prop="total_pay_price" width="100" label="实际付款"></el-table-column>
              <!-- <el-table-column prop="is_refund" width="80" label="状态">
                <template slot-scope="scope">
                  <span class="red" v-if="scope.row.is_refund">已退</span>
                  <span v-else>可退</span>
                </template>
              </el-table-column> -->
            </el-table>
          </div>
        </el-form-item>
        <el-form-item label="退款金额" :label-width="formLabelWidth" prop="refund_money"
          :rules="[{required: true,message: ' '}]">
          <el-input type="number" v-model="form.refund_money" placeholder="请输入退款金额"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible">取 消</el-button>
        <el-button type="primary" @click="submit" :loading="loading">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
  import OrderApi from '@/api/order.js';
  import draggable from 'vuedraggable';
  export default {
    components: {
      draggable
    },
    data() {
      return {
        loading: false,
        /*左边长度*/
        formLabelWidth: '120px',
        /*是否显示*/
        dialogVisible: false,
        form: {
          order_id: '',
          refund_money: '',
          // 退款的商品id
          product_ids: [],
          // 如何退 10整单 20部分
          refund_type: 10
        },
        order: [],
        product: []
      };
    },
    props: ['open_edit', 'refundOrder'],
    created() {
      this.dialogVisible = this.open_edit;
      this.form.order_id = this.refundOrder.order_id;
      this.form.refund_money = this.refundOrder.pay_price;
      for (let i = 0; i < this.refundOrder.product.length; i++) {
        let item = this.refundOrder.product[i];
        if (item.is_refund == 0) {
          this.product.push(item);
        }
      }
      this.changeRefundType(this.form.refund_type);
    },
    methods: {
      /*处理*/
      submit() {
        let self = this;
        let form = self.form;
        self.$refs.form.validate((valid) => {
          if (valid) {
            this.$confirm('确认退款?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
              self.loading = true;
              OrderApi.takeRefund(form, true).then(data => {
                  self.loading = false;
                  self.$message({
                    message: data.msg,
                    type: 'success'
                  });
                  self.dialogFormVisible(true);
                })
                .catch(error => {
                  self.loading = false;
                });
            }).catch(() => {
              this.$message({
                type: 'info',
                message: '已取消退款'
              });
            });
 
          }
        });
      },
      /*关闭弹窗*/
      dialogFormVisible(e) {
        if (e) {
          this.$emit('closeDialog', {
            type: 'success',
            openDialog: false
          })
        } else {
          this.$emit('closeDialog', {
            type: 'error',
            openDialog: false
          })
        }
      },
      /*监听复选按钮选中事件*/
      tableCurrentChange(val) {
        this.multipleSelection = val;
        this.form.product_ids = [];
        this.form.refund_money = 0;
        for (let i = 0; i < this.multipleSelection.length; i++) {
          let item = this.multipleSelection[i];
          this.form.product_ids.push(item.product_id);
          this.form.refund_money += parseFloat(item.total_pay_price);
        }
        // 如果选择所有
        if (this.multipleSelection.length == this.product.length) {
          this.form.refund_money = this.refundOrder.pay_price;
          this.form.refund_type = 10;
        }
      },
      /*退单类型*/
      changeRefundType(e) {
        this.form.product_ids = [];
        if (e == 10) {
          this.form.refund_money = this.refundOrder.pay_price;
          for (let i = 0; i < this.product.length; i++) {
            let item = this.product[i];
            this.form.product_ids.push(item.product_id);
          }
        } else {
          this.form.refund_money = '';
        }
      },
    }
  };
</script>
 
<style>
  .edit_container {
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    line-height: 20px;
    color: #2c3e50;
  }
 
  .ql-editor {
    height: 400px;
  }
 
  .draggable-list {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
 
  .draggable-list .wrapper>span {
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
  }
 
  .draggable-list .item {
    position: relative;
    width: 110px;
    height: 110px;
    margin-top: 10px;
    margin-right: 10px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #dddddd;
  }
 
  .draggable-list .delete-btn {
    position: absolute;
    top: 0;
    right: 0;
    width: 16px;
    height: 16px;
    background: red;
    line-height: 16px;
    font-size: 16px;
    color: #ffffff;
    display: none;
  }
 
  .draggable-list .item:hover .delete-btn {
    display: block;
  }
 
  .draggable-list .item img {
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    max-height: 100%;
    max-width: 100%;
  }
 
  .draggable-list .img-select {
    display: flex;
    justify-content: center;
    align-items: center;
    border: 1px dashed #dddddd;
    font-size: 30px;
  }
 
  .draggable-list .img-select i {
    color: #409eff;
  }
</style>