one.vue 20 KB

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