123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474 |
- <template>
- <el-dialog
- v-loading="loading"
- :title="title"
- :center="true"
- align="left"
- top="18vh"
- width="1040px"
- :close-on-click-modal="false"
- :visible.sync="showModelThis"
- element-loading-text="拼命加载中"
- element-loading-spinner="el-icon-loading"
- element-loading-background="rgba(0, 0, 0, 0.8)"
- @close="showModelThis = false"
- >
- <el-card style="margin: -20px 0 0 0">
- <el-row :gutter="10">
- <el-col :span="24">
- <el-form
- ref="ruleForm"
- :model="ruleForm"
- status-icon
- size="mini"
- :rules="rulesThis"
- label-width="80px"
- class="demo-ruleForm"
- >
- <el-row>
- <el-col :span="24">
- <el-form-item label="平台名称" prop="platform_name">
- <el-input
- v-model="ruleForm.platform_name"
- :disabled="id == '007'"
- placeholder="平台名称"
- maxlength="20"
- />
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="平台类型" prop="use_type">
- <el-select
- v-model="ruleForm.use_type"
- style="width: 100%"
- :disabled="id == '007' || isUpdate"
- placeholder="请选择平台类型"
- @change="set_required"
- >
- <el-option
- v-for="item in use_type_options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select> </el-form-item
- ></el-col>
- <el-col :span="8">
- <el-form-item label="对接平台" prop="platform_type">
- <el-select
- v-model="ruleForm.platform_type"
- style="width: 100%"
- :disabled="id == '007' || isUpdate"
- placeholder="请选择对接平台"
- @change="set_required"
- >
- <el-option
- v-for="item in options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select> </el-form-item
- ></el-col>
- <!-- v-show="ruleForm.use_type === '1' && ruleForm.platform_type === '0'" -->
- <el-col :span="8">
- <el-form-item
- label="是否开启支付渠道"
- prop="is_select_pay_rate"
- label-width="140px"
- >
- <el-select
- v-model="ruleForm.is_select_pay_rate"
- style="width: 100%"
- :disabled="id == '007' || isUpdate"
- placeholder="是否开启"
- @change="set_required"
- >
- <el-option
- v-for="item in is_select_pay_rate_options"
- :key="item.value"
- :label="item.label"
- :value="item.value"
- />
- </el-select> </el-form-item
- ></el-col>
- <!-- v-show="
- ruleForm.use_type === '1' &&
- ruleForm.platform_type === '0' &&
- ruleForm.is_select_pay_rate === '1'
- " -->
- <el-col :span="24" v-show="ruleForm.is_select_pay_rate === '1'">
- <el-form-item label="支付渠道" prop="pay_list">
- <el-table size="mini" border :data="ruleForm.pay_list">
- <el-table-column label="渠道名称" prop="channel_name" />
- <el-table-column label="业务公司" prop="companyName" />
- <el-table-column v-if="id === '003'" label="操作" width="80px">
- <template slot="header">
- <span>操作</span>
- <el-tooltip
- style="margin: 3px 0 0 0"
- effect="dark"
- class="fr"
- content="添加"
- placement="top"
- >
- <i
- class="el-icon-circle-plus-outline tb-icon"
- style="color: #6954f0; magin: 0 0 0 10px"
- @click="visible = true"
- />
- </el-tooltip>
- </template>
- <template slot-scope="scope">
- <el-tooltip
- effect="dark"
- class="fr"
- content="删除"
- placement="top"
- >
- <i
- class="el-icon-delete tb-icon"
- @click="ruleForm.pay_list.splice(scope.$index, 1)"
- />
- </el-tooltip>
- </template>
- </el-table-column>
- </el-table>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- </el-col>
- <el-col :span="24" style="text-align: right">
- <el-button
- v-if="id !== '007'"
- size="mini"
- type="primary"
- :loading="loading"
- @click="submitForm"
- >保 存
- </el-button>
- <el-button size="mini" @click="showModelThis = false">{{
- id == "007" ? "关 闭" : "取 消"
- }}</el-button>
- </el-col>
- </el-row>
- </el-card>
- <search-company-modal
- :visible.sync="visible"
- @updatePaymentChannel="onUpdatePaymentChannel"
- />
- </el-dialog>
- </template>
- <script>
- import asyncRequest from "@/apis/service/serviceParam/terrace";
- import resToken from "@/mixins/resToken";
- import SearchCompanyModal from "./searchCompanyModal.vue";
- export default {
- name: "Terrace",
- components: { SearchCompanyModal },
- mixins: [resToken],
- props: ["showModel", "id", "sitem"],
- data() {
- return {
- loading: false,
- visible: false,
- sourcePaymentChannel: [],
- title: "添加平台",
- showModelThis: this.showModel,
- rateBefore: {
- companyNo: "GYS",
- companyName: "供应商",
- rate: "0",
- is_cgd: "0",
- is_qrd: "1",
- },
- rateAfter: {
- companyNo: "KH",
- companyName: "客户",
- rate: "0",
- is_cgd: "0",
- is_qrd: "0",
- },
- options: [
- { value: "0", label: "无对接" }, //
- { value: "1", label: "有赞平台" },
- ],
- is_select_pay_rate_options: [
- { value: "0", label: "不选支付渠道" }, //
- { value: "1", label: "选择支付渠道" },
- ],
- use_type_options: [
- { value: "1", label: "ToB" }, //
- { value: "2", label: "ToC" },
- ],
- ruleForm: {
- id: "",
- platform_name: "",
- platform_type: "0",
- use_type: "1",
- pay_name: "",
- is_select_pay_rate: "0",
- pay_list: [],
- },
- rules: {
- platform_name: [{ required: true, message: "平台名称不能为空", trigger: "blur" }],
- platform_type: [{ required: true, message: "请选择对接平台", trigger: "change" }],
- use_type: [{ required: true, message: "请选择平台类型", trigger: "change" }],
- is_select_pay_rate: [
- { required: true, message: "请选择是否开启支付渠道", trigger: "change" },
- ],
- pay_list: [
- {
- type: "array",
- required: true,
- message: "内容配置不能为空",
- trigger: "change",
- },
- ],
- },
- rulesThis: this.rules,
- };
- },
- computed: {
- isUpdate() {
- return this.id === "005";
- },
- },
- watch: {
- showModel: function (val) {
- this.showModelThis = val;
- if (val) {
- this.initForm();
- }
- },
- showModelThis(val) {
- if (!val) {
- this.ruleForm = {
- id: "",
- platform_name: "",
- platform_type: "0",
- use_type: "1",
- pay_name: "",
- is_select_pay_rate: "0",
- pay_list: [],
- };
- this.sourcePaymentChannel = [];
- this.$emit("cancel");
- }
- },
- },
- methods: {
- async initForm() {
- this.loading = true;
- if (this.id === "003") {
- this.title = "添加平台";
- this.rulesThis = this.rules;
- } else if (this.id === "005") {
- this.title = "修改平台";
- this.rulesThis = this.rules;
- } else {
- this.title = "平台详情";
- this.rulesThis = {};
- }
- await this.resetForm();
- this.loading = false;
- },
- async resetForm() {
- // 重置
- await this.$nextTick(() => {
- if (this.$refs.ruleForm) {
- this.$refs.ruleForm.resetFields();
- this.$refs.ruleForm.clearValidate();
- }
- });
- const isAllowLoadDetail = this.id === "005" || this.id === "007";
- if (isAllowLoadDetail) await this.loadDetail();
- this.set_required();
- },
- uniquePaymentChannel(values) {
- const map = new Map();
- const pay_list = values.map((value) => {
- const channel_id = value.id;
- delete value["id"];
- return { ...value, channel_id };
- });
- return [...this.ruleForm.pay_list, ...pay_list].filter(
- (item) => !map.has(item.channel_id) && map.set(item.channel_id, 1)
- );
- },
- onUpdatePaymentChannel(values) {
- this.ruleForm.pay_list = this.uniquePaymentChannel(values);
- console.log(this.ruleForm);
- },
- async loadDetail() {
- this.loading = true;
- const platformResponse = await asyncRequest.detail({ id: this.sitem.id });
- const {
- platform_name,
- platform_type,
- is_select_pay_rate,
- use_type,
- pay_list,
- } = platformResponse.data;
- this.loading = false;
- this.ruleForm = {
- platform_name: platform_name || "",
- platform_type: String(platform_type) ? String(platform_type) : "0",
- use_type: String(use_type) ? String(use_type) : "1",
- is_select_pay_rate: String(is_select_pay_rate) ? String(is_select_pay_rate) : "",
- pay_list,
- };
- this.sourcePaymentChannel = JSON.parse(JSON.stringify(pay_list || "[]"));
- },
- async submitForm() {
- const { pay_list, is_select_pay_rate } = this.ruleForm;
- const isPayRateSave = pay_list.every(({ isEdit }) => !isEdit);
- if (!isPayRateSave && is_select_pay_rate === "1")
- return this.$message.warning("未完成内容配置编辑");
- await this.$refs.ruleForm.validate(async (valid) => {
- if (valid) {
- if (this.loading) {
- return;
- }
- this.loading = true;
- const {
- pay_list,
- platform_type,
- platform_name,
- is_select_pay_rate,
- use_type,
- } = this.ruleForm;
- const model = {
- id: this.sitem.id,
- pay_list: pay_list, // 渠道配置集合
- is_select_pay_rate, // 是否开启渠道
- platform_type, // 对接类型 0 无 1 toB 2 ToC
- platform_name, // 平台名称
- use_type, // 平台性质,0内部使用,1对接有赞平台
- };
- // model.is_select_pay_rate =
- // use_type === "1" && platform_type === "0" ? is_select_pay_rate : "0";
- this.loading = false;
- if (model.is_select_pay_rate !== "1") {
- delete model["pay_list"];
- }
- // if (model['pay_list'] && model['pay_list']['length'] === 0) {
- // this.$message.warning('支付渠道不能为空')
- // return
- // }
- if (this.id !== "003" && model.pay_list) {
- const currentPaymentChannelIDSet = model.pay_list.map(
- ({ channel_id }) => channel_id
- );
- // 删除的渠道
- const delChannel = this.sourcePaymentChannel
- .filter(
- ({ channel_id }) =>
- !currentPaymentChannelIDSet.includes(String(channel_id))
- )
- .map(({ channel_id, id }) => ({
- channel_id,
- id,
- is_del: 1,
- }));
- // 原始的渠道
- const originChannel = this.sourcePaymentChannel
- .filter(({ channel_id }) =>
- currentPaymentChannelIDSet.includes(String(channel_id))
- )
- .map(({ channel_id, id }) => ({
- channel_id,
- id,
- is_del: 0,
- }));
- // 添加的渠道
- const addChannel = this.ruleForm.pay_list
- .filter(
- ({ channel_id: _channel_id }) =>
- !originChannel.find(
- ({ channel_id }) => String(channel_id) === String(_channel_id)
- ) &&
- !delChannel.find(
- ({ channel_id }) => String(channel_id) === String(_channel_id)
- )
- )
- .map(({ channel_id }) => ({
- channel_id: Number(channel_id),
- is_del: 0,
- id: null,
- }));
- model.pay_list = [...delChannel, ...originChannel, ...addChannel];
- }
- let res = {};
- if (this.id === "003") {
- delete model["id"];
- res = await asyncRequest.add(model);
- } else {
- res = await asyncRequest.update(model);
- }
- this.loading = false;
- if (res && res.code === 0) {
- const title = this.id === "003" ? "添加成功!" : "修改成功!";
- this.$notify.success({
- title,
- message: "",
- });
- this.showModelThis = false;
- // 刷新
- this.$emit("refresh");
- } else if (res && res.code >= 100 && res.code <= 104) {
- await this.logout();
- } else {
- this.$message.warning(res.message);
- }
- } else {
- console.log("error submit!!");
- return false;
- }
- });
- },
- set_required() {
- const { platform_type, use_type, is_select_pay_rate } = this.ruleForm;
- this.rulesThis.is_select_pay_rate[0].required =
- use_type === "1" && platform_type === "0";
- this.rulesThis.pay_list[0].required =
- use_type === "1" && platform_type === "0" && is_select_pay_rate === "1";
- },
- handleCompanyChange(e, index) {
- const { code, label } = e;
- const companyInfo = {
- companyNo: code,
- companyName: label,
- };
- this.$set(this.ruleForm.pay_list, index, {
- ...this.ruleForm.pay_list[index],
- ...companyInfo,
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .terrace {
- }
- </style>
|