addEdit.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. <template>
  2. <el-dialog
  3. v-loading="loading"
  4. :title="title"
  5. :center="true"
  6. align="left"
  7. top="18vh"
  8. width="1040px"
  9. :close-on-click-modal="false"
  10. :visible.sync="showModelThis"
  11. element-loading-text="拼命加载中"
  12. element-loading-spinner="el-icon-loading"
  13. element-loading-background="rgba(0, 0, 0, 0.8)"
  14. @close="showModelThis = false"
  15. >
  16. <el-card style="margin: -20px 0 0 0">
  17. <el-row :gutter="10">
  18. <el-col :span="24">
  19. <el-form
  20. ref="ruleForm"
  21. :model="ruleForm"
  22. status-icon
  23. size="mini"
  24. :rules="rulesThis"
  25. label-width="80px"
  26. class="demo-ruleForm"
  27. >
  28. <el-row>
  29. <el-col :span="24">
  30. <el-form-item label="平台名称" prop="platform_name">
  31. <el-input
  32. v-model="ruleForm.platform_name"
  33. :disabled="id == '007'"
  34. placeholder="平台名称"
  35. maxlength="20"
  36. />
  37. </el-form-item>
  38. </el-col>
  39. <el-col :span="8">
  40. <el-form-item label="平台类型" prop="use_type">
  41. <el-select
  42. v-model="ruleForm.use_type"
  43. style="width: 100%"
  44. :disabled="id == '007' || isUpdate"
  45. placeholder="请选择平台类型"
  46. @change="set_required"
  47. >
  48. <el-option
  49. v-for="item in use_type_options"
  50. :key="item.value"
  51. :label="item.label"
  52. :value="item.value"
  53. />
  54. </el-select> </el-form-item
  55. ></el-col>
  56. <el-col :span="8">
  57. <el-form-item label="对接平台" prop="platform_type">
  58. <el-select
  59. v-model="ruleForm.platform_type"
  60. style="width: 100%"
  61. :disabled="id == '007' || isUpdate"
  62. placeholder="请选择对接平台"
  63. @change="set_required"
  64. >
  65. <el-option
  66. v-for="item in options"
  67. :key="item.value"
  68. :label="item.label"
  69. :value="item.value"
  70. />
  71. </el-select> </el-form-item
  72. ></el-col>
  73. <!-- v-show="ruleForm.use_type === '1' && ruleForm.platform_type === '0'" -->
  74. <el-col :span="8">
  75. <el-form-item
  76. label="是否开启支付渠道"
  77. prop="is_select_pay_rate"
  78. label-width="140px"
  79. >
  80. <el-select
  81. v-model="ruleForm.is_select_pay_rate"
  82. style="width: 100%"
  83. :disabled="id == '007' || isUpdate"
  84. placeholder="是否开启"
  85. @change="set_required"
  86. >
  87. <el-option
  88. v-for="item in is_select_pay_rate_options"
  89. :key="item.value"
  90. :label="item.label"
  91. :value="item.value"
  92. />
  93. </el-select> </el-form-item
  94. ></el-col>
  95. <!-- v-show="
  96. ruleForm.use_type === '1' &&
  97. ruleForm.platform_type === '0' &&
  98. ruleForm.is_select_pay_rate === '1'
  99. " -->
  100. <el-col :span="24" v-show="ruleForm.is_select_pay_rate === '1'">
  101. <el-form-item label="支付渠道" prop="pay_list">
  102. <el-table size="mini" border :data="ruleForm.pay_list">
  103. <el-table-column label="渠道名称" prop="channel_name" />
  104. <el-table-column label="业务公司" prop="companyName" />
  105. <el-table-column v-if="id === '003'" label="操作" width="80px">
  106. <template slot="header">
  107. <span>操作</span>
  108. <el-tooltip
  109. style="margin: 3px 0 0 0"
  110. effect="dark"
  111. class="fr"
  112. content="添加"
  113. placement="top"
  114. >
  115. <i
  116. class="el-icon-circle-plus-outline tb-icon"
  117. style="color: #6954f0; magin: 0 0 0 10px"
  118. @click="visible = true"
  119. />
  120. </el-tooltip>
  121. </template>
  122. <template slot-scope="scope">
  123. <el-tooltip
  124. effect="dark"
  125. class="fr"
  126. content="删除"
  127. placement="top"
  128. >
  129. <i
  130. class="el-icon-delete tb-icon"
  131. @click="ruleForm.pay_list.splice(scope.$index, 1)"
  132. />
  133. </el-tooltip>
  134. </template>
  135. </el-table-column>
  136. </el-table>
  137. </el-form-item>
  138. </el-col>
  139. </el-row>
  140. </el-form>
  141. </el-col>
  142. <el-col :span="24" style="text-align: right">
  143. <el-button
  144. v-if="id !== '007'"
  145. size="mini"
  146. type="primary"
  147. :loading="loading"
  148. @click="submitForm"
  149. >保 存
  150. </el-button>
  151. <el-button size="mini" @click="showModelThis = false">{{
  152. id == "007" ? "关 闭" : "取 消"
  153. }}</el-button>
  154. </el-col>
  155. </el-row>
  156. </el-card>
  157. <search-company-modal
  158. :visible.sync="visible"
  159. @updatePaymentChannel="onUpdatePaymentChannel"
  160. />
  161. </el-dialog>
  162. </template>
  163. <script>
  164. import asyncRequest from "@/apis/service/serviceParam/terrace";
  165. import resToken from "@/mixins/resToken";
  166. import SearchCompanyModal from "./searchCompanyModal.vue";
  167. export default {
  168. name: "Terrace",
  169. components: { SearchCompanyModal },
  170. mixins: [resToken],
  171. props: ["showModel", "id", "sitem"],
  172. data() {
  173. return {
  174. loading: false,
  175. visible: false,
  176. sourcePaymentChannel: [],
  177. title: "添加平台",
  178. showModelThis: this.showModel,
  179. rateBefore: {
  180. companyNo: "GYS",
  181. companyName: "供应商",
  182. rate: "0",
  183. is_cgd: "0",
  184. is_qrd: "1",
  185. },
  186. rateAfter: {
  187. companyNo: "KH",
  188. companyName: "客户",
  189. rate: "0",
  190. is_cgd: "0",
  191. is_qrd: "0",
  192. },
  193. options: [
  194. { value: "0", label: "无对接" }, //
  195. { value: "1", label: "有赞平台" },
  196. ],
  197. is_select_pay_rate_options: [
  198. { value: "0", label: "不选支付渠道" }, //
  199. { value: "1", label: "选择支付渠道" },
  200. ],
  201. use_type_options: [
  202. { value: "1", label: "ToB" }, //
  203. { value: "2", label: "ToC" },
  204. ],
  205. ruleForm: {
  206. id: "",
  207. platform_name: "",
  208. platform_type: "0",
  209. use_type: "1",
  210. pay_name: "",
  211. is_select_pay_rate: "0",
  212. pay_list: [],
  213. },
  214. rules: {
  215. platform_name: [{ required: true, message: "平台名称不能为空", trigger: "blur" }],
  216. platform_type: [{ required: true, message: "请选择对接平台", trigger: "change" }],
  217. use_type: [{ required: true, message: "请选择平台类型", trigger: "change" }],
  218. is_select_pay_rate: [
  219. { required: true, message: "请选择是否开启支付渠道", trigger: "change" },
  220. ],
  221. pay_list: [
  222. {
  223. type: "array",
  224. required: true,
  225. message: "内容配置不能为空",
  226. trigger: "change",
  227. },
  228. ],
  229. },
  230. rulesThis: this.rules,
  231. };
  232. },
  233. computed: {
  234. isUpdate() {
  235. return this.id === "005";
  236. },
  237. },
  238. watch: {
  239. showModel: function (val) {
  240. this.showModelThis = val;
  241. if (val) {
  242. this.initForm();
  243. }
  244. },
  245. showModelThis(val) {
  246. if (!val) {
  247. this.ruleForm = {
  248. id: "",
  249. platform_name: "",
  250. platform_type: "0",
  251. use_type: "1",
  252. pay_name: "",
  253. is_select_pay_rate: "0",
  254. pay_list: [],
  255. };
  256. this.sourcePaymentChannel = [];
  257. this.$emit("cancel");
  258. }
  259. },
  260. },
  261. methods: {
  262. async initForm() {
  263. this.loading = true;
  264. if (this.id === "003") {
  265. this.title = "添加平台";
  266. this.rulesThis = this.rules;
  267. } else if (this.id === "005") {
  268. this.title = "修改平台";
  269. this.rulesThis = this.rules;
  270. } else {
  271. this.title = "平台详情";
  272. this.rulesThis = {};
  273. }
  274. await this.resetForm();
  275. this.loading = false;
  276. },
  277. async resetForm() {
  278. // 重置
  279. await this.$nextTick(() => {
  280. if (this.$refs.ruleForm) {
  281. this.$refs.ruleForm.resetFields();
  282. this.$refs.ruleForm.clearValidate();
  283. }
  284. });
  285. const isAllowLoadDetail = this.id === "005" || this.id === "007";
  286. if (isAllowLoadDetail) await this.loadDetail();
  287. this.set_required();
  288. },
  289. uniquePaymentChannel(values) {
  290. const map = new Map();
  291. const pay_list = values.map((value) => {
  292. const channel_id = value.id;
  293. delete value["id"];
  294. return { ...value, channel_id };
  295. });
  296. return [...this.ruleForm.pay_list, ...pay_list].filter(
  297. (item) => !map.has(item.channel_id) && map.set(item.channel_id, 1)
  298. );
  299. },
  300. onUpdatePaymentChannel(values) {
  301. this.ruleForm.pay_list = this.uniquePaymentChannel(values);
  302. console.log(this.ruleForm);
  303. },
  304. async loadDetail() {
  305. this.loading = true;
  306. const platformResponse = await asyncRequest.detail({ id: this.sitem.id });
  307. const {
  308. platform_name,
  309. platform_type,
  310. is_select_pay_rate,
  311. use_type,
  312. pay_list,
  313. } = platformResponse.data;
  314. this.loading = false;
  315. this.ruleForm = {
  316. platform_name: platform_name || "",
  317. platform_type: String(platform_type) ? String(platform_type) : "0",
  318. use_type: String(use_type) ? String(use_type) : "1",
  319. is_select_pay_rate: String(is_select_pay_rate) ? String(is_select_pay_rate) : "",
  320. pay_list,
  321. };
  322. this.sourcePaymentChannel = JSON.parse(JSON.stringify(pay_list || "[]"));
  323. },
  324. async submitForm() {
  325. const { pay_list, is_select_pay_rate } = this.ruleForm;
  326. const isPayRateSave = pay_list.every(({ isEdit }) => !isEdit);
  327. if (!isPayRateSave && is_select_pay_rate === "1")
  328. return this.$message.warning("未完成内容配置编辑");
  329. await this.$refs.ruleForm.validate(async (valid) => {
  330. if (valid) {
  331. if (this.loading) {
  332. return;
  333. }
  334. this.loading = true;
  335. const {
  336. pay_list,
  337. platform_type,
  338. platform_name,
  339. is_select_pay_rate,
  340. use_type,
  341. } = this.ruleForm;
  342. const model = {
  343. id: this.sitem.id,
  344. pay_list: pay_list, // 渠道配置集合
  345. is_select_pay_rate, // 是否开启渠道
  346. platform_type, // 对接类型 0 无 1 toB 2 ToC
  347. platform_name, // 平台名称
  348. use_type, // 平台性质,0内部使用,1对接有赞平台
  349. };
  350. // model.is_select_pay_rate =
  351. // use_type === "1" && platform_type === "0" ? is_select_pay_rate : "0";
  352. this.loading = false;
  353. if (model.is_select_pay_rate !== "1") {
  354. delete model["pay_list"];
  355. }
  356. // if (model['pay_list'] && model['pay_list']['length'] === 0) {
  357. // this.$message.warning('支付渠道不能为空')
  358. // return
  359. // }
  360. if (this.id !== "003" && model.pay_list) {
  361. const currentPaymentChannelIDSet = model.pay_list.map(
  362. ({ channel_id }) => channel_id
  363. );
  364. // 删除的渠道
  365. const delChannel = this.sourcePaymentChannel
  366. .filter(
  367. ({ channel_id }) =>
  368. !currentPaymentChannelIDSet.includes(String(channel_id))
  369. )
  370. .map(({ channel_id, id }) => ({
  371. channel_id,
  372. id,
  373. is_del: 1,
  374. }));
  375. // 原始的渠道
  376. const originChannel = this.sourcePaymentChannel
  377. .filter(({ channel_id }) =>
  378. currentPaymentChannelIDSet.includes(String(channel_id))
  379. )
  380. .map(({ channel_id, id }) => ({
  381. channel_id,
  382. id,
  383. is_del: 0,
  384. }));
  385. // 添加的渠道
  386. const addChannel = this.ruleForm.pay_list
  387. .filter(
  388. ({ channel_id: _channel_id }) =>
  389. !originChannel.find(
  390. ({ channel_id }) => String(channel_id) === String(_channel_id)
  391. ) &&
  392. !delChannel.find(
  393. ({ channel_id }) => String(channel_id) === String(_channel_id)
  394. )
  395. )
  396. .map(({ channel_id }) => ({
  397. channel_id: Number(channel_id),
  398. is_del: 0,
  399. id: null,
  400. }));
  401. model.pay_list = [...delChannel, ...originChannel, ...addChannel];
  402. }
  403. let res = {};
  404. if (this.id === "003") {
  405. delete model["id"];
  406. res = await asyncRequest.add(model);
  407. } else {
  408. res = await asyncRequest.update(model);
  409. }
  410. this.loading = false;
  411. if (res && res.code === 0) {
  412. const title = this.id === "003" ? "添加成功!" : "修改成功!";
  413. this.$notify.success({
  414. title,
  415. message: "",
  416. });
  417. this.showModelThis = false;
  418. // 刷新
  419. this.$emit("refresh");
  420. } else if (res && res.code >= 100 && res.code <= 104) {
  421. await this.logout();
  422. } else {
  423. this.$message.warning(res.message);
  424. }
  425. } else {
  426. console.log("error submit!!");
  427. return false;
  428. }
  429. });
  430. },
  431. set_required() {
  432. const { platform_type, use_type, is_select_pay_rate } = this.ruleForm;
  433. this.rulesThis.is_select_pay_rate[0].required =
  434. use_type === "1" && platform_type === "0";
  435. this.rulesThis.pay_list[0].required =
  436. use_type === "1" && platform_type === "0" && is_select_pay_rate === "1";
  437. },
  438. handleCompanyChange(e, index) {
  439. const { code, label } = e;
  440. const companyInfo = {
  441. companyNo: code,
  442. companyName: label,
  443. };
  444. this.$set(this.ruleForm.pay_list, index, {
  445. ...this.ruleForm.pay_list[index],
  446. ...companyInfo,
  447. });
  448. },
  449. },
  450. };
  451. </script>
  452. <style lang="scss" scoped>
  453. .terrace {
  454. }
  455. </style>