customerSetting.vue 7.19 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
<template>
  <el-dialog append-to-body :title="$t('设置')" :visible.sync="dialogVisible" width="900px">
    <el-form ref="form" :model="form" label-width="150px">
      <el-row :gutter="10">
        <el-col :span="12">
          <el-form-item :label="$t('是否显示提单价格')" prop="isShowTidanPrice">
            <el-switch v-model="form.isShowTidanPrice"></el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('到仓确认')" prop="arrivalConfirm">
332784038@qq.com's avatar
6  
332784038@qq.com committed
12
            <el-switch v-model="form.arrivalConfirm" :active-value="1" :inactive-value="0" />
13 14 15 16 17
          </el-form-item>
        </el-col>

        <el-col :span="13">
          <el-form-item :label="$t('重货标准')" prop="weightUnit">
18 19
            <el-switch v-model="showZhong" />
            <el-input v-model="form.weightUnit" :placeholder="$t('请输入重货标准')" v-show="showZhong">
20 21 22 23 24 25 26
              <template slot="append">kg/cbm</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-show="showZhong">
          <el-form-item :label="$t('指定线路')" prop="line">
            <el-switch v-model="showZhong1"></el-switch>
332784038@qq.com's avatar
6  
332784038@qq.com committed
27
            <customer-line-table v-if="showZhong1" :warehouse-list="warehouseList" :import-city-list="importCityList" v-model="zhongLines" :zhong-pao-type="1"></customer-line-table>
28 29 30 31 32
          </el-form-item>
        </el-col>

        <el-col :span="13">
          <el-form-item :label="$t('泡货标准')" prop="lightUnit">
33 34
            <el-switch v-model="showPao" />
            <el-input v-model="form.lightUnit" :placeholder="$t('请输入泡货标准')" v-show="showPao">
35 36 37 38 39 40 41
              <template slot="append">kg/cbm</template>
            </el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-show="showPao">
          <el-form-item :label="$t('指定线路')" prop="line">
            <el-switch v-model="showPao1"></el-switch>
332784038@qq.com's avatar
6  
332784038@qq.com committed
42
            <customer-line-table v-if="showPao1" :warehouse-list="warehouseList" :import-city-list="importCityList" v-model="paoLines" :zhong-pao-type="2"></customer-line-table>
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
          </el-form-item>
        </el-col>

        <el-col :span="12">
          <el-form-item :label="$t('控货无收货人')">
            <el-switch v-model="form.noConsignee" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('默认付款')">
            <el-switch v-model="form.defaultPay" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('默认开票')">
            <el-switch v-model="form.defaultBilling" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
332784038@qq.com's avatar
6  
332784038@qq.com committed
64 65
      <el-button type="warning" @click="handleClose">{{ $t("关 闭") }}</el-button>
      <el-button type="primary" @click="handerSubmit">{{ $t("保 存") }}</el-button>
66 67 68 69 70
    </div>
  </el-dialog>
</template>

<script>
332784038@qq.com's avatar
6  
332784038@qq.com committed
71 72 73 74 75
import CustomerLineTable from "@/components/CustomerLineTable"
import { getWarehouseList } from "@/api/ecw/warehouse"
import { getTradeCityList } from "@/api/ecw/region"
import { getZhongPaoBest, getZhongPaoPage } from "@/api/ecw/zhongPao"
import { getCustomer, getCustomerLines, customerSettingButton } from "@/api/ecw/customer"
76 77 78 79 80 81 82 83 84
export default {
  name: "CustomerSetting",
  components: {
    CustomerLineTable
  },
  data() {
    return {
      dialogVisible: false,
      form: {
yujinyao's avatar
yujinyao committed
85
        id: 0,
86 87 88 89 90 91 92 93 94
        isShowTidanPrice: false,
        arrivalConfirm: 0,
        weightUnit: null,
        lightUnit: null,
        customerLines: [],
        noConsignee: false,
        defaultPay: false,
        defaultBilling: false
      },
95
      showZhong: false,
96
      showZhong1: false,
97
      showPao: false,
98 99 100 101
      showPao1: false,
      zhongLines: [],
      warehouseList: [], // 仓库列表
      importCityList: [], // 进口地址
332784038@qq.com's avatar
6  
332784038@qq.com committed
102
      paoLines: []
103 104 105 106
    }
  },
  created() {
    getWarehouseList().then((r) => {
332784038@qq.com's avatar
6  
332784038@qq.com committed
107 108
      this.warehouseList = r.data
    })
109
    getTradeCityList({ type: 1 }).then((r) => {
332784038@qq.com's avatar
6  
332784038@qq.com committed
110 111
      this.importCityList = r.data.filter((item) => item.type === "1")
    })
112 113 114 115
  },
  methods: {
    init(id) {
      this.customerId = id
116 117 118 119
      this.showZhong = false
      this.showPao = false
      this.showZhong1 = false
      this.showPao1 = false
120 121 122
      getCustomer(this.customerId).then((response) => {
        const row = response.data
        this.form = {
yujinyao's avatar
yujinyao committed
123
          id: row.id,
124 125 126 127 128 129 130 131 132 133 134
          isShowTidanPrice: row.isShowTidanPrice,
          arrivalConfirm: row.arrivalConfirm,
          weightUnit: row.weightUnit,
          lightUnit: row.lightUnit,
          customerLines: [],
          noConsignee: row.noConsignee,
          defaultPay: row.defaultPay,
          defaultBilling: row.defaultBilling
        }
        // 打开重泡货开关
        if (this.form.weightUnit) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
135
          this.showZhong = true
136 137
        }
        if (this.form.lightUnit) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
138
          this.showPao = true
139 140
        }
        getCustomerLines(this.customerId).then((res) => {
332784038@qq.com's avatar
6  
332784038@qq.com committed
141 142 143 144 145
          this.zhongLines = res.data.filter((item) => item.zhongPaoType == 1)
          this.paoLines = res.data.filter((item) => item.zhongPaoType == 2)
          if (this.zhongLines.length) this.showZhong1 = true
          if (this.paoLines.length) this.showPao1 = true
        })
146 147 148
        this.getZhongPao()
      })
    },
149 150
    getZhongPao() {
      getZhongPaoBest({
332784038@qq.com's avatar
6  
332784038@qq.com committed
151
        customerId: this.customerId
152 153 154
        // departureId: this.departureId,
        // objectiveId: this.objectiveId
      }).then((r) => {
332784038@qq.com's avatar
6  
332784038@qq.com committed
155 156 157
        if (!this.form.weightUnit) this.form.weightUnit = r.data.zhongEdge
        if (!this.form.lightUnit) this.form.lightUnit = r.data.paoEdge
      })
158
    },
159 160 161 162 163 164 165 166
    handleClose() {
      this.resetForm("form")
      this.dialogVisible = false
    },
    handerSubmit() {
      this.$refs["form"].validate((valid, err) => {
        // 重货标准和泡货标准,未打开就不传,提交前清空一下
        if (!this.showZhong) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
167 168
          this.form.weightUnit = null
          this.zhongLines = []
169 170
        }
        if (!this.showZhong1) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
171
          this.zhongLines = []
172 173
        }
        if (!this.showPao) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
174 175
          this.form.lightUnit = null
          this.paoLines = []
176 177
        }
        if (!this.showPao1) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
178
          this.paoLines = []
179
        }
332784038@qq.com's avatar
6  
332784038@qq.com committed
180
        this.updateCustomerLines()
181 182

        // 检查路线是否启用了但是没选择目的仓
332784038@qq.com's avatar
6  
332784038@qq.com committed
183
        let errors = 0
184 185
        this.form.customerLines.forEach((line) => {
          if (!line.objectiveIds || line.objectiveIds == "") {
332784038@qq.com's avatar
6  
332784038@qq.com committed
186
            errors++
187
          }
332784038@qq.com's avatar
6  
332784038@qq.com committed
188
        })
189
        if (errors) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
190
          return this.$message.error("有两条路线未选择目的地")
191 192 193
        }

        customerSettingButton(this.form).then((response) => {
332784038@qq.com's avatar
6  
332784038@qq.com committed
194 195 196 197 198 199
          this.$modal.msgSuccess(this.$t("操作成功"))
          this.dialogVisible = false
          const obj = { path: "/customer/customer" }
          this.$emit("refresh")
        })
      })
200 201 202
    },
    updateCustomerLines() {
      let zhongLines = [],
332784038@qq.com's avatar
6  
332784038@qq.com committed
203
        paoLines = []
204
      if (this.zhongLines.length > 0) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
205
        zhongLines = this.zhongLines
206 207
      }
      if (this.paoLines.length > 0) {
332784038@qq.com's avatar
6  
332784038@qq.com committed
208
        paoLines = this.paoLines
209
      }
332784038@qq.com's avatar
6  
332784038@qq.com committed
210 211
      this.form.customerLines = [...zhongLines, ...paoLines]
    }
212 213 214
  }
}
</script>