333
schangxiang@126.com
2025-09-19 18966e02fb573c7e2bb0c6426ed792b38b910940
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
<template>
  <div class="setting-container">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>货主收费模板设置</span>
      </div>
      <el-form :inline="true" :model="formData" class="demo-form-inline">
        <el-form-item label="口岸">
          <el-select v-model="formData.port_Id" placeholder="请选择口岸" @change="changePort">
            <el-option v-for="(item, index) in portList" :key="index" :label="item.portName" :value="item.port_Id"></el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <el-table :data="tableData" style="width: 100%">
        <el-table-column prop="expressCorpName" label="快递公司" width="180">
        </el-table-column>
        <el-table-column prop="feeRate" label="费率" width="180">
          <template slot-scope="{row}">
            <el-input-number v-model="row.feeRate" size="mini" controls-position="right" class="w-120"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column prop="unit" label="单位" width="180">
          <template slot-scope="{row}">
            <el-select v-model="row.unit_Id">
              <el-option v-for="(item, index) in unitList" :key="index" :label="item.unit" :value="item.unit_Id"></el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="enable" label="是否可用">
          <template slot-scope="{row}">
            <el-switch v-model="row.enable" :active-value="1" :inactive-value="0"></el-switch>
          </template>
        </el-table-column>
      </el-table>
      <div class="padding-20">
        <el-button type="primary" icon="el-icon-yrt-baocun" @click="btnSave">保存</el-button>
      </div>
    </el-card>
  </div>
</template>
<script>
export default {
  name: "tms-basic-freight-price-setting",
  components: {},
  data() {
    return {
      // 表单数据
      formData: {},
      // 快递公司下拉框值
      portList: [],
      // 表格数据
      tableData: [],
      // 单位数据
      unitList: []
    };
  },
  created() {
    this.getPortList();
    this.getUnitList();
  },
  activated() {
    this.init();
  },
  methods: {
    changePort() {
      this.getTemplateSettingList();
    },
    // 获得口岸列表
    getPortList() {
      var url = "/api/basicInfo/base/port/getList";
      var params = {};
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          if (res.result) {
            this.portList = res.data;
          }
        },
        true
      );
    },
    // 初始化数据
    init() {
      var params = localStorage.getItem("freight-price");
      if (params) {
        params = JSON.parse(params);
        this.$set(this.formData, "port_Id", params.port_Id);
        this.$set(this.formData, "portName", params.portName);
      }
      this.tableData = [];
      this.getexpressCorpNameList();
    },
    // 获取单位列表
    getUnitList() {
      var url = "/api/tms/feeTemplate/getUnitList";
      var params = {};
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          if (res.result) {
            this.unitList = res.data;
          }
        },
        true
      );
    }, // 获取快递公司信息
    getexpressCorpNameList() {
      var url = "/api/basicInfo/base/expressCorp/getList";
      var params = {};
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          if (res.result) {
            if (res.data.length) {
              res.data.forEach(item => {
                var obj = {
                  expressCorp_Id: item.expressCorp_Id,
                  expressCorpName: item.expressCorpName,
                  feeRate: 0,
                  unit: null,
                  enable: 0
                };
                this.$set(this.tableData, this.tableData.length, obj);
              });
              var parms = JSON.parse(localStorage.getItem("freight-price"));
              if (parms) {
                this.getTemplateSettingList();
              }
            }
            localStorage.removeItem("freight-price");
          }
        },
        true
      );
    },
    // 获取运费模板中的数据
    getTemplateSettingList() {
      var userInfo = this.common.getUserInfo();
      var url = "/api/tms/freightPrice/getFreightPriceList";
      var params = {
        userProduct_Id: userInfo.userProduct_Id,
        port_Id: this.formData.port_Id
      };
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          if (res.result) {
            if (res.data.length) {
              res.data.forEach(item => {
                this.tableData.forEach(temp => {
                  if (item.expressCorpName === temp.expressCorpName) {
                    // 如果有给其重新赋值
                    this.$set(temp, "expressCorpName", item.expressCorpName);
                    this.$set(temp, "expressCorp_Id", item.expressCorp_Id);
                    this.$set(temp, "feeRate", item.feeRate);
                    this.$set(temp, "enable", item.enable);
                    this.$set(temp, "FreightPrice_Id", item.FreightPrice_Id);
                    this.unitList.forEach(index => {
                      // 单位赋值
                      if (item.unit === index.unit) {
                        this.$set(temp, "unit", index.unit);
                        this.$set(temp, "unit_Id", index.unit_Id);
                      }
                    });
                  }
                  this.$set(temp, "port_Id", item.port_Id);
                  this.$set(temp, "portName", item.portName);
                  this.$set(temp, "orderNo", item.orderNo);
                  this.$set(temp, "remark", item.remark);
                  this.$set(temp, "createID", item.createID);
                  this.$set(temp, "creator", item.creator);
                  this.$set(temp, "platUser_Id", item.platUser_Id);
                  this.$set(temp, "userProduct_Id", item.userProduct_Id);
                  this.$set(temp, "userProductCode", item.userProductCode);
                  this.$set(temp, "userProductAlias", item.userProductAlias);
                });
              });
            } else {
              this.tableData = [];
              this.getexpressCorpNameList();
            }
          }
        },
        true
      );
    },
    // 保存
    btnSave() {
      var url = "/api/tms/freightPrice/saveTemplateSettingList";
      if (this.tableData.length) {
        this.tableData.forEach(item => {
          this.$set(item, "port_Id", this.formData.port_Id);
          this.portList.forEach(port => {
            if (item.port_Id === port.port_Id) {
              item.portName = port.portName;
            }
          });
          this.$set(item, "consignor_Id", this.formData.consignor_Id);
          this.unitList.forEach(temp => {
            if (item.unit_Id === temp.unit_Id) {
              item.unit = temp.unit;
            }
          });
        });
      }
      var params = {
        dataList: this.tableData,
        port_Id: this.formData.port_Id
      };
      this.common.ajax(url, params, res => {
        this.common.showMsg(res);
      });
    }
  }
};
</script>