Browse Source

修改平台设置,允许C端平台使用支付渠道

xiaodai2022 1 year ago
parent
commit
36fad9d30a
1 changed files with 211 additions and 167 deletions
  1. 211 167
      src/views/serviceParam/terrace/addEdit.vue

+ 211 - 167
src/views/serviceParam/terrace/addEdit.vue

@@ -30,7 +30,7 @@
                 <el-form-item label="平台名称" prop="platform_name">
                   <el-input
                     v-model="ruleForm.platform_name"
-                    :disabled="id == '007' "
+                    :disabled="id == '007'"
                     placeholder="平台名称"
                     maxlength="20"
                   />
@@ -51,7 +51,8 @@
                       :label="item.label"
                       :value="item.value"
                     />
-                  </el-select> </el-form-item></el-col>
+                  </el-select> </el-form-item
+              ></el-col>
               <el-col :span="8">
                 <el-form-item label="对接平台" prop="platform_type">
                   <el-select
@@ -67,12 +68,15 @@
                       :label="item.label"
                       :value="item.value"
                     />
-                  </el-select> </el-form-item></el-col>
-              <el-col
-                v-show="ruleForm.use_type === '1' && ruleForm.platform_type === '0'"
-                :span="8"
-              >
-                <el-form-item label="是否开启支付渠道" prop="is_select_pay_rate" label-width="140px">
+                  </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%"
@@ -86,15 +90,14 @@
                       :label="item.label"
                       :value="item.value"
                     />
-                  </el-select> </el-form-item></el-col>
-              <el-col
-                v-show="
+                  </el-select> </el-form-item
+              ></el-col>
+              <!-- v-show="
                   ruleForm.use_type === '1' &&
-                    ruleForm.platform_type === '0' &&
-                    ruleForm.is_select_pay_rate === '1'
-                "
-                :span="24"
-              >
+                  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" />
@@ -118,10 +121,15 @@
                       </template>
 
                       <template slot-scope="scope">
-                        <el-tooltip effect="dark" class="fr" content="删除" placement="top">
+                        <el-tooltip
+                          effect="dark"
+                          class="fr"
+                          content="删除"
+                          placement="top"
+                        >
                           <i
                             class="el-icon-delete tb-icon"
-                            @click="ruleForm.pay_list.splice(scope.$index,1)"
+                            @click="ruleForm.pay_list.splice(scope.$index, 1)"
                           />
                         </el-tooltip>
                       </template>
@@ -139,7 +147,7 @@
             type="primary"
             :loading="loading"
             @click="submitForm"
-          >保 存
+            >保 存
           </el-button>
           <el-button size="mini" @click="showModelThis = false">{{
             id == "007" ? "关 闭" : "取 消"
@@ -148,176 +156,196 @@
       </el-row>
     </el-card>
 
-    <search-company-modal :visible.sync="visible" @updatePaymentChannel="onUpdatePaymentChannel" />
+    <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'
+import asyncRequest from "@/apis/service/serviceParam/terrace";
+import resToken from "@/mixins/resToken";
+import SearchCompanyModal from "./searchCompanyModal.vue";
 export default {
-  name: 'Terrace',
+  name: "Terrace",
   components: { SearchCompanyModal },
   mixins: [resToken],
-  props: ['showModel', 'id', 'sitem'],
+  props: ["showModel", "id", "sitem"],
   data() {
     return {
       loading: false,
       visible: false,
       sourcePaymentChannel: [],
-      title: '添加平台',
+      title: "添加平台",
       showModelThis: this.showModel,
       rateBefore: {
-        companyNo: 'GYS',
-        companyName: '供应商',
-        rate: '0',
-        is_cgd: '0',
-        is_qrd: '1'
+        companyNo: "GYS",
+        companyName: "供应商",
+        rate: "0",
+        is_cgd: "0",
+        is_qrd: "1",
       },
       rateAfter: {
-        companyNo: 'KH',
-        companyName: '客户',
-        rate: '0',
-        is_cgd: '0',
-        is_qrd: '0'
+        companyNo: "KH",
+        companyName: "客户",
+        rate: "0",
+        is_cgd: "0",
+        is_qrd: "0",
       },
       options: [
-        { value: '0', label: '无对接' }, //
-        { value: '1', label: '有赞平台' }
+        { value: "0", label: "无对接" }, //
+        { value: "1", label: "有赞平台" },
       ],
       is_select_pay_rate_options: [
-        { value: '0', label: '不选支付渠道' }, //
-        { value: '1', label: '选择支付渠道' }
+        { value: "0", label: "不选支付渠道" }, //
+        { value: "1", label: "选择支付渠道" },
       ],
       use_type_options: [
-        { value: '1', label: 'ToB' }, //
-        { value: '2', label: 'ToC' }
+        { 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: []
+        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' }],
+        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' }
+          { required: true, message: "请选择是否开启支付渠道", trigger: "change" },
         ],
         pay_list: [
           {
-            type: 'array',
+            type: "array",
             required: true,
-            message: '内容配置不能为空',
-            trigger: 'change'
-          }
-        ]
+            message: "内容配置不能为空",
+            trigger: "change",
+          },
+        ],
       },
-      rulesThis: this.rules
-    }
+      rulesThis: this.rules,
+    };
   },
   computed: {
     isUpdate() {
-      return this.id === '005'
-    }
+      return this.id === "005";
+    },
   },
   watch: {
-    showModel: function(val) {
-      this.showModelThis = val
+    showModel: function (val) {
+      this.showModelThis = val;
       if (val) {
-        this.initForm()
+        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')
+          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
+      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 = {}
+        this.title = "平台详情";
+        this.rulesThis = {};
       }
-      await this.resetForm()
-      this.loading = false
+      await this.resetForm();
+      this.loading = false;
     },
     async resetForm() {
       // 重置
       await this.$nextTick(() => {
         if (this.$refs.ruleForm) {
-          this.$refs.ruleForm.resetFields()
-          this.$refs.ruleForm.clearValidate()
+          this.$refs.ruleForm.resetFields();
+          this.$refs.ruleForm.clearValidate();
         }
-      })
+      });
 
-      const isAllowLoadDetail = this.id === '005' || this.id === '007'
-      if (isAllowLoadDetail) await this.loadDetail()
-      this.set_required()
+      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 })
-      })
+      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))
+      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)
+      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 = 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.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
-      }
+        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 || '[]'))
+      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('未完成内容配置编辑')
+      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) => {
+      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
+          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,
@@ -325,14 +353,15 @@ export default {
             is_select_pay_rate, // 是否开启渠道
             platform_type, //  对接类型 0 无 1 toB 2 ToC
             platform_name, // 平台名称
-            use_type // 平台性质,0内部使用,1对接有赞平台
-          }
+            use_type, // 平台性质,0内部使用,1对接有赞平台
+          };
 
-          model.is_select_pay_rate = use_type === '1' && platform_type === '0' ? is_select_pay_rate : '0'
-          this.loading = false
+          // model.is_select_pay_rate =
+          //   use_type === "1" && platform_type === "0" ? is_select_pay_rate : "0";
+          this.loading = false;
 
-          if (model.use_type !== '1' || model.platform_type !== '0' || model.is_select_pay_rate !== '1') {
-            delete model['pay_list']
+          if (model.is_select_pay_rate !== "1") {
+            delete model["pay_list"];
           }
 
           // if (model['pay_list'] && model['pay_list']['length'] === 0) {
@@ -340,88 +369,103 @@ export default {
           //   return
           // }
 
-          if (this.id !== '003' && model.pay_list) {
-            const currentPaymentChannelIDSet = model.pay_list.map(({ channel_id }) => channel_id)
+          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)))
+              .filter(
+                ({ channel_id }) =>
+                  !currentPaymentChannelIDSet.includes(String(channel_id))
+              )
               .map(({ channel_id, id }) => ({
                 channel_id,
                 id,
-                is_del: 1
-              }))
+                is_del: 1,
+              }));
 
             // 原始的渠道
             const originChannel = this.sourcePaymentChannel
-              .filter(({ channel_id }) => currentPaymentChannelIDSet.includes(String(channel_id)))
+              .filter(({ channel_id }) =>
+                currentPaymentChannelIDSet.includes(String(channel_id))
+              )
               .map(({ channel_id, id }) => ({
                 channel_id,
                 id,
-                is_del: 0
-              }))
+                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)))
+              .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
-              }))
+                id: null,
+              }));
 
-            model.pay_list = [...delChannel, ...originChannel, ...addChannel]
+            model.pay_list = [...delChannel, ...originChannel, ...addChannel];
           }
 
-          let res = {}
-          if (this.id === '003') {
-            delete model['id']
-            res = await asyncRequest.add(model)
+          let res = {};
+          if (this.id === "003") {
+            delete model["id"];
+            res = await asyncRequest.add(model);
           } else {
-            res = await asyncRequest.update(model)
+            res = await asyncRequest.update(model);
           }
-          this.loading = false
+          this.loading = false;
           if (res && res.code === 0) {
-            const title = this.id === '003' ? '添加成功!' : '修改成功!'
+            const title = this.id === "003" ? "添加成功!" : "修改成功!";
             this.$notify.success({
               title,
-              message: ''
-            })
-            this.showModelThis = false
+              message: "",
+            });
+            this.showModelThis = false;
             // 刷新
-            this.$emit('refresh')
+            this.$emit("refresh");
           } else if (res && res.code >= 100 && res.code <= 104) {
-            await this.logout()
+            await this.logout();
           } else {
-            this.$message.warning(res.message)
+            this.$message.warning(res.message);
           }
         } else {
-          console.log('error submit!!')
-          return false
+          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'
+      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 { code, label } = e;
 
       const companyInfo = {
         companyNo: code,
-        companyName: label
-      }
+        companyName: label,
+      };
 
       this.$set(this.ruleForm.pay_list, index, {
         ...this.ruleForm.pay_list[index],
-        ...companyInfo
-      })
-    }
-  }
-}
+        ...companyInfo,
+      });
+    },
+  },
+};
 </script>
 
 <style lang="scss" scoped>