one.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681
  1. <template>
  2. <div class="m-container">
  3. <div class="m-core">
  4. <div @click="chargeOperation('create')" v-permission="'paymentConfig/add'" class="newBand">添加</div>
  5. <!-- 列表 -->
  6. <div class="tableWrap">
  7. <el-table :data="tableList" :header-cell-style="{background:'#EDEEF0',color:'#444'}">
  8. <el-table-column align="center" prop="organName" label="分部"></el-table-column>
  9. <el-table-column align="center" label="收款方式">
  10. <template slot-scope="scope">{{ scope.row.payType | paymentChannelStatus }}</template>
  11. </el-table-column>
  12. <el-table-column align="center" label="账户类型">
  13. <template slot-scope="scope">{{ scope.row.accountType | accountTypeFormat }}</template>
  14. </el-table-column>
  15. <el-table-column align="center" prop="hfMerNo" label="汇付商户号"></el-table-column>
  16. <el-table-column align="center" prop="yqMerNo" label="双乾商户号"></el-table-column>
  17. <el-table-column align="center" label="收款比例">
  18. <template slot-scope="scope">
  19. {{ scope.row.type == 1 ? '笔数比例' : null }}
  20. {{ scope.row.type == 2 ? '金额比例' : null }}
  21. </template>
  22. </el-table-column>
  23. <el-table-column align="center" width="250px" label="操作">
  24. <template slot-scope="scope">
  25. <el-button
  26. @click="chargeOperation('update', scope.row)"
  27. v-permission="'paymentConfig/update'"
  28. type="text"
  29. >修改</el-button>
  30. <!-- <el-button
  31. @click="chargeDel(scope.row)"
  32. v-permission="'paymentConfig/del'"
  33. type="text"
  34. >删除</el-button> -->
  35. </template>
  36. </el-table-column>
  37. </el-table>
  38. <pagination
  39. :total="pageInfo.total"
  40. :page.sync="pageInfo.page"
  41. :limit.sync="pageInfo.limit"
  42. :page-sizes="pageInfo.page_size"
  43. @pagination="getList"
  44. />
  45. </div>
  46. </div>
  47. <el-dialog
  48. :title="formTitle[formActionTitle]"
  49. :visible.sync="chargeStatus"
  50. @close="onFormClose('ruleForm')"
  51. width="700px"
  52. >
  53. <el-form :model="form" :rules="rules" ref="ruleForm">
  54. <el-form-item label="所属分部" prop="organId" :label-width="formLabelWidth">
  55. <el-select v-model.trim="form.organId" :disabled="formActionTitle === 'update'" placeholder="请选择所属分部">
  56. <el-option
  57. v-for="(item, index) in branchList"
  58. :key="index"
  59. :label="item.label"
  60. :value="item.value"
  61. ></el-option>
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item label="收款方式" prop="payType" :label-width="formLabelWidth">
  65. <el-select v-model.trim="form.payType" @change="onPayTypeChange" placeholder="请选择收款方式">
  66. <el-option value="ADAPAY" label="汇付"></el-option>
  67. <el-option value="YQPAY" label="双乾"></el-option>
  68. </el-select>
  69. </el-form-item>
  70. <el-form-item label="账户类型" prop="accountType" :label-width="formLabelWidth">
  71. <el-select v-model.trim="form.accountType" placeholder="请选择账户类型">
  72. <el-option :value="0" label="对内"></el-option>
  73. <el-option :value="1" label="对外"></el-option>
  74. </el-select>
  75. </el-form-item>
  76. <!-- prop="yqMerNo" :error="result.yqError" -->
  77. <el-form-item
  78. label="双乾商户号"
  79. :required="form.payType === 'YQPAY'"
  80. :label-width="formLabelWidth"
  81. >
  82. <el-input
  83. type="text"
  84. @blur="onMerNoBlur('YQPAY')"
  85. placeholder="请输入双乾商户号"
  86. v-model.trim="form.yqMerNo"
  87. ></el-input>
  88. </el-form-item>
  89. <!-- prop="hfMerNo" :error="result.hfError" -->
  90. <el-form-item
  91. label="汇付商户号"
  92. :required="form.payType === 'ADAPAY'"
  93. :label-width="formLabelWidth"
  94. >
  95. <el-input
  96. type="text"
  97. @blur="onMerNoBlur('ADAPAY')"
  98. placeholder="请输入汇付商户号"
  99. v-model.trim="form.hfMerNo"
  100. ></el-input>
  101. </el-form-item>
  102. <el-form-item label="收费比例" required :label-width="formLabelWidth">
  103. <el-radio
  104. v-model.trim.number="form.type"
  105. @change="onRadioChange('ruleForm')"
  106. :label="2"
  107. >金额比例</el-radio>
  108. <el-radio
  109. v-model.trim.number="form.type"
  110. @change="onRadioChange('ruleForm')"
  111. :label="1"
  112. >笔数比例</el-radio>
  113. </el-form-item>
  114. <el-form-item class="moreRule" :label-width="formLabelWidth" style="margin-bottom: 0;">
  115. <span class="min">分部</span>
  116. <span class="min">比例</span>
  117. <span class="max">是否承担手续费</span>
  118. </el-form-item>
  119. <div class="moreRule">
  120. <div class="moreRuleIn" v-for="(domain, index) in result.domains" :key="domain.key">
  121. <el-form-item class="setWidth" :label="'第' + (index + 1)" :label-width="formLabelWidth">
  122. <!-- @change="onBranchChange" -->
  123. <el-select
  124. v-model.trim="domain.organId"
  125. placeholder="请选择分部"
  126. clearable
  127. >
  128. <el-option
  129. v-for="(item, index) in calcBranchList"
  130. :key="index"
  131. :label="item.label"
  132. :value="item.value"
  133. :disabled="item.disabled"
  134. ></el-option>
  135. </el-select>
  136. </el-form-item>
  137. <el-form-item class="setWidth">
  138. <el-input
  139. type="number"
  140. v-number
  141. min="0"
  142. clearable
  143. :max="form.type === 1 ? 10 : 100"
  144. placeholder="请输入比例"
  145. @mousewheel.native.prevent
  146. v-model.trim="domain.scale"
  147. >
  148. <template v-if="form.type === 2" slot="append">%</template>
  149. </el-input>
  150. </el-form-item>
  151. <el-form-item>
  152. <el-select
  153. v-model.trim="domain.feeFlag"
  154. placeholder="请选择是否承担手续费"
  155. style="width: 150px !important;"
  156. clearable
  157. >
  158. <el-option value="Y" label="是"></el-option>
  159. <el-option value="N" label="否"></el-option>
  160. </el-select>
  161. <el-button
  162. v-if="index != 0"
  163. @click.prevent="removeDomain(result, domain)"
  164. >删除</el-button>
  165. </el-form-item>
  166. </div>
  167. <div class="el-form-item__error" v-if="result.errorText">{{ result.errorText }}</div>
  168. </div>
  169. <el-form-item class="add" :label-width="formLabelWidth">
  170. <el-button icon="el-icon-plus" @click="addDomain(result)">新增</el-button>
  171. </el-form-item>
  172. </el-form>
  173. <span slot="footer" class="dialog-footer">
  174. <el-button @click="chargeStatus = false">取 消</el-button>
  175. <el-button @click="onChargeSubmit('ruleForm')" type="primary">确 定</el-button>
  176. </span>
  177. </el-dialog>
  178. </div>
  179. </template>
  180. <script>
  181. import pagination from "@/components/Pagination/index";
  182. import {
  183. paymentConfigQueryPage,
  184. paymentConfigAdd,
  185. paymentConfigUpdate,
  186. paymentConfigDel
  187. } from "@/api/systemManage";
  188. import { getPaymentConfigs } from "./api";
  189. import { branchQueryPage } from "@/api/specialSetting";
  190. import store from "@/store";
  191. export default {
  192. name: "chargeProfitManager",
  193. components: { pagination },
  194. data() {
  195. return {
  196. tableList: [],
  197. pageInfo: {
  198. // 分页规则
  199. limit: 10, // 限制显示条数
  200. page: 1, // 当前页
  201. total: 0, // 总条数
  202. page_size: [10, 20, 40, 50] // 选择限制显示条数
  203. },
  204. chargeStatus: false,
  205. branchList: [], // 分部列表
  206. calcBranchList: [], // 可选比例分部
  207. formActionTitle: "create",
  208. formLabelWidth: "100px",
  209. formTitle: {
  210. create: "添加收费比例",
  211. update: "修改收费比例"
  212. },
  213. form: {
  214. organId: null,
  215. hfMerNo: null,
  216. yqMerNo: null,
  217. payType: null, // 支付渠道
  218. accountType: null,
  219. type: 2,
  220. routeScale: []
  221. },
  222. rules: {
  223. hfMerNo: [
  224. { required: true, message: "请输入汇付商户号", trigger: "blur" }
  225. ],
  226. yqMerNo: [
  227. { required: true, message: "请输入双乾商户号", trigger: "blur" }
  228. ],
  229. organId: [
  230. { required: true, message: "请选择所属分部", trigger: "change" }
  231. ],
  232. payType: [
  233. { required: true, message: "请选择收款方式", trigger: "change" }
  234. ],
  235. accountType: [
  236. { required: true, message: "请选择账户类型", trigger: "change" }
  237. ]
  238. },
  239. result: {
  240. domains: [
  241. {
  242. organId: null,
  243. scale: null,
  244. feeFlag: null,
  245. disabled: false,
  246. key: Date.now()
  247. }
  248. ],
  249. errorText: null,
  250. yqError: null,
  251. hfError: null
  252. }
  253. };
  254. },
  255. mounted() {
  256. this.getList();
  257. this.getRoleList();
  258. },
  259. methods: {
  260. async onPayTypeChange(val) {
  261. if (!val) {
  262. return;
  263. }
  264. this.calcBranchList = [];
  265. this.result.domains = [
  266. {
  267. organId: null,
  268. scale: null,
  269. feeFlag: null,
  270. disabled: false,
  271. key: Date.now()
  272. }
  273. ];
  274. this.result.errorText = null;
  275. await getPaymentConfigs({ payType: val }).then(res => {
  276. if (res.code == 200 && res.data) {
  277. res.data.forEach(item => {
  278. this.calcBranchList.push({
  279. label: item.organName,
  280. value: item.organId
  281. });
  282. });
  283. }
  284. });
  285. },
  286. onRadioChange(formName) {
  287. this.$refs[formName].clearValidate();
  288. },
  289. onMerNoBlur(type) {
  290. let form = this.form;
  291. let result = this.result;
  292. if (type === "YQPAY" && form.payType === "YQPAY") {
  293. if (form.yqMerNo) {
  294. result.yqError = null;
  295. } else {
  296. result.yqError = "请输入双乾商户号";
  297. }
  298. } else if (type === "ADAPAY" && form.payType === "ADAPAY") {
  299. if (form.hfMerNo) {
  300. result.hfError = null;
  301. } else {
  302. result.hfError = "请输入汇付商户号";
  303. }
  304. }
  305. },
  306. onChargeSubmit(formName) {
  307. this.$refs[formName].validate(valid => {
  308. let params = JSON.parse(JSON.stringify(this.form));
  309. let result = this.result;
  310. params.routeScale = null;
  311. // if (params.payType === "YQPAY" && !params.yqMerNo) {
  312. // result.yqError = "请输入双乾商户号";
  313. // return;
  314. // } else if (params.payType === "ADAPAY" && !params.hfMerNo) {
  315. // result.hfError = "请输入汇付商户号";
  316. // return;
  317. // }
  318. this.addDomain(result, true);
  319. if (valid && !result.errorText) {
  320. let tempResult = [];
  321. result.domains.forEach(item => {
  322. if (item.organId) {
  323. tempResult.push({
  324. organId: item.organId,
  325. scale: item.scale,
  326. feeFlag: item.feeFlag
  327. });
  328. }
  329. });
  330. params.routeScale =
  331. tempResult.length > 0 ? JSON.stringify(tempResult) : null;
  332. if (params.payType === "YQPAY" && !params.yqMerNo && !params.routeScale) {
  333. // result.yqError = "请输入双乾商户号";
  334. this.$message.error('请输入双乾商户号或比例')
  335. return;
  336. } else if (params.payType === "ADAPAY" && !params.hfMerNo && !params.routeScale) {
  337. // result.hfError = "请输入汇付商户号";
  338. this.$message.error('请输入汇付商户号或比例')
  339. return;
  340. }
  341. if (this.formActionTitle == "create") {
  342. if (params.id) {
  343. // 判断有没有Id,如果有则删除
  344. delete params.id;
  345. }
  346. paymentConfigAdd(params).then(res => {
  347. this.messageTips("添加", res);
  348. });
  349. } else if (this.formActionTitle == "update") {
  350. paymentConfigUpdate(params).then(res => {
  351. this.messageTips("修改", res);
  352. });
  353. }
  354. } else {
  355. return;
  356. }
  357. });
  358. },
  359. messageTips(title, res) {
  360. if (res.code == 200) {
  361. this.$message.success(title + "成功");
  362. this.chargeStatus = false;
  363. this.getList();
  364. } else {
  365. this.$message.error(res.msg);
  366. }
  367. },
  368. // onBranchChange(val) {
  369. // this.calcBranchList.forEach(item => {
  370. // if (val == item.value) {
  371. // item.disabled = true;
  372. // } else {
  373. // item.disabled = false;
  374. // }
  375. // });
  376. // },
  377. addDomain(form, checked) {
  378. let domains = form.domains,
  379. forms = this.form,
  380. singleLength = domains.length,
  381. lastDate = domains[singleLength - 1]; // 获取倒数一个对象
  382. // 如果三个值都为空,则不用检验
  383. if (!lastDate.organId && !lastDate.scale && !lastDate.feeFlag && checked) {
  384. form.errorText = ''
  385. return;
  386. }
  387. let num = 0;
  388. if (forms.type === 2) {
  389. num = 100;
  390. } else if (forms.type === 1) {
  391. num = 10;
  392. }
  393. let countScale = 0;
  394. let selectFeeCount = 0,
  395. selectFeeCount2 = 0
  396. let isFeeFlag = false,
  397. isOrganId = false,
  398. isScale = false
  399. domains.forEach(item => {
  400. countScale += Number(item.scale);
  401. if(forms.type == 2) {
  402. if(item.feeFlag == 'Y') {
  403. selectFeeCount++
  404. }
  405. } else if(forms.type == 1) {
  406. if(item.feeFlag == 'N') {
  407. selectFeeCount2++
  408. }
  409. }
  410. if(!isFeeFlag) {
  411. isFeeFlag = !item.feeFlag ? true : false
  412. }
  413. if(!isOrganId) {
  414. isOrganId = !item.organId ? true : false
  415. }
  416. if(!isScale) {
  417. isScale = !item.scale ? true: false
  418. }
  419. });
  420. if(selectFeeCount > 1) {
  421. form.errorText = `承担手续费只能设置一次“是”`;
  422. return
  423. } else if(selectFeeCount2 > 0) {
  424. form.errorText = `承担手续费只能设置“是”`;
  425. return
  426. }
  427. if (!lastDate.organId) {
  428. form.errorText = "选择分部不能为空";
  429. return;
  430. }
  431. if (!parseInt(lastDate.scale)) {
  432. form.errorText = "比例不能为空";
  433. return;
  434. } else if (parseInt(lastDate.scale) > num) {
  435. form.errorText = "比例不能超过" + num;
  436. return;
  437. } else if (parseInt(countScale) > num) {
  438. form.errorText = "比例总和应为" + num;
  439. return;
  440. }
  441. if (!lastDate.feeFlag) {
  442. form.errorText = "请选择是否承担手续费";
  443. return;
  444. }
  445. form.errorText = null;
  446. if (!checked) {
  447. lastDate.disabled = true;
  448. domains.push({
  449. organId: null,
  450. scale: null,
  451. feeFlag: null,
  452. disabled: false,
  453. key: Date.now()
  454. });
  455. } else {
  456. if (isOrganId) {
  457. form.errorText = "选择分部不能为空";
  458. return;
  459. }
  460. if (isScale) {
  461. form.errorText = "比例不能为空";
  462. return;
  463. }
  464. if (parseInt(countScale) != num) {
  465. form.errorText = "比例总和应为" + num;
  466. return;
  467. }
  468. if(isFeeFlag) {
  469. form.errorText = "请选择是否承担手续费";
  470. return;
  471. }
  472. if(forms.type == 2) {
  473. if(selectFeeCount != 1) {
  474. form.errorText = "承担手续费必须设置一次“是”"
  475. return;
  476. }
  477. }
  478. }
  479. },
  480. removeDomain(form, item) {
  481. // this.calcBranchList.forEach(organ => {
  482. // if (item.organId == organ.value) {
  483. // console.log(true)
  484. // organ.disabled = false;
  485. // }
  486. // });
  487. var index = form.domains.indexOf(item);
  488. if (index !== -1) {
  489. form.domains.splice(index, 1);
  490. // 取消最后一个数据的禁用状态
  491. form.domains[form.domains.length - 1].disabled = false;
  492. form.errorText = null;
  493. }
  494. },
  495. getList() {
  496. let params = {};
  497. params.rows = this.pageInfo.limit;
  498. params.page = this.pageInfo.page;
  499. paymentConfigQueryPage(params).then(res => {
  500. if (res.code == 200 && res.data) {
  501. this.tableList = res.data.rows;
  502. this.pageInfo.total = res.data.total;
  503. }
  504. });
  505. },
  506. getRoleList() {
  507. //
  508. branchQueryPage({
  509. // 获取分部
  510. delFlag: 0,
  511. rows: 9999
  512. }).then(res => {
  513. if (res.code == 200 && res.data && res.data.rows) {
  514. res.data.rows.forEach(item => {
  515. this.branchList.push({
  516. label: item.name,
  517. value: item.id
  518. });
  519. });
  520. }
  521. });
  522. },
  523. chargeOperation(type, data) {
  524. this.formActionTitle = type;
  525. this.chargeStatus = true;
  526. // 修改的时候
  527. if (type == "update") {
  528. this.onPayTypeChange(data.payType);
  529. this.form = {
  530. id: data.id,
  531. type: Number(data.type),
  532. hfMerNo: data.hfMerNo,
  533. accountType: data.accountType,
  534. yqMerNo: data.yqMerNo,
  535. payType: data.payType,
  536. organId: data.organId
  537. };
  538. if (data.routeScale) {
  539. this.result.domains = [];
  540. let scaleJson = JSON.parse(data.routeScale);
  541. let scaleLength = scaleJson.length;
  542. scaleJson.forEach((item, index) => {
  543. let temp = {};
  544. if (scaleLength == index + 1) {
  545. temp.disabled = false;
  546. } else {
  547. temp.disabled = true;
  548. }
  549. temp.organId = item.organId;
  550. temp.scale = item.scale;
  551. temp.feeFlag = item.feeFlag;
  552. this.result.domains.push(temp);
  553. });
  554. }
  555. }
  556. },
  557. chargeDel(row) {
  558. // 删除数据
  559. // paymentConfigDel
  560. this.$confirm("你确定删除?", "提示", {
  561. confirmButtonText: "确定",
  562. cancelButtonText: "取消",
  563. type: "warning"
  564. })
  565. .then(() => {
  566. paymentConfigDel({ id: row.id }).then(res => {
  567. this.messageTips("删除", res);
  568. });
  569. })
  570. .catch();
  571. },
  572. onFormClose(formName) {
  573. // 关闭弹窗重置验证
  574. this.form = {
  575. organId: null,
  576. hfMerNo: null,
  577. yqMerNo: null,
  578. accountType: null,
  579. payType: null, // 支付渠道
  580. type: 2,
  581. routeScale: []
  582. };
  583. this.result = {
  584. domains: [
  585. {
  586. organId: null,
  587. scale: null,
  588. feeFlag: null,
  589. disabled: false,
  590. key: Date.now()
  591. }
  592. ],
  593. errorText: null,
  594. yqError: null,
  595. hfError: null
  596. }
  597. this.$refs[formName].resetFields();
  598. }
  599. }
  600. };
  601. </script>
  602. <style lang="scss" scoped>
  603. /deep/.el-button--primary {
  604. background: #14928a;
  605. border-color: #14928a;
  606. color: #fff;
  607. &:hover,
  608. &:active,
  609. &:focus {
  610. background: #14928a;
  611. border-color: #14928a;
  612. color: #fff;
  613. }
  614. }
  615. /deep/.el-dialog__body {
  616. padding: 0 20px;
  617. }
  618. /deep/.el-select,
  619. /deep/.el-date-editor.el-input {
  620. width: 100% !important;
  621. }
  622. .moreRule {
  623. background: #f0f0f0;
  624. position: relative;
  625. .el-form-item__error {
  626. color: #f56c6c;
  627. font-size: 12px;
  628. line-height: 1;
  629. position: absolute;
  630. left: 100px;
  631. top: 100%;
  632. margin-top: -21px;
  633. }
  634. }
  635. .add {
  636. margin-bottom: 22px;
  637. background: #f0f0f0;
  638. padding-bottom: 22px;
  639. }
  640. .moreRuleIn {
  641. .el-form-item {
  642. display: inline-block;
  643. &:first-child {
  644. /deep/.el-form-item__content {
  645. margin-left: 100px !important;
  646. }
  647. }
  648. /deep/.el-form-item__content {
  649. margin-left: 0 !important;
  650. }
  651. }
  652. .setWidth {
  653. /deep/.el-form-item__content {
  654. width: 150px;
  655. }
  656. }
  657. /deep/.el-input-group__append {
  658. padding: 0 8px;
  659. }
  660. }
  661. .min,
  662. .max {
  663. display: inline-block;
  664. width: 150px;
  665. text-align: center;
  666. }
  667. </style>