two.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div class="m-container">
  3. <div class="m-core">
  4. <div @click="sporadicStatus = true" v-permission="'sysConfig/update'" class="newBand">零星收费设置</div>
  5. <p style="color: red; display: inline-block; padding-left: 10px">金额设置0则不做限制</p>
  6. <!-- 列表 -->
  7. <el-form :model="result" ref="ruleFormValid">
  8. <el-form-item class="moreRule" :label-width="formLabelWidth" style="margin-bottom: 0;">
  9. <span class="min">分部</span>
  10. <span class="min">收款分部</span>
  11. <span class="min">金额</span>
  12. <span class="max">购买类型</span>
  13. </el-form-item>
  14. <div class="moreRule">
  15. <div class="moreRuleIn" v-for="(domain, index) in result.domains" :key="index">
  16. <el-form-item class="setWidth"
  17. :label-width="formLabelWidth"
  18. :label="'第' + (index + 1)"
  19. :prop="'domains.' + index + '.organId'"
  20. :rules="{
  21. required: true, message: '请选择所属分部', trigger: 'change'
  22. }">
  23. <el-select v-model.trim="domain.organId" clearable :disabled="domain.disabled" placeholder="请选择所属分部">
  24. <el-option
  25. v-for="(item, index1) in selects.branchs"
  26. :key="index1"
  27. :label="item.name"
  28. :value="item.id"
  29. ></el-option>
  30. </el-select>
  31. </el-form-item>
  32. <el-form-item class="setWidth" :prop="'domains.' + index + '.routeOrganId'" :rules="[
  33. { required: true, message: '请选择收款分部', trigger: 'change' },
  34. ]">
  35. <el-select clearable v-model.trim="domain.routeOrganId" :disabled="domain.disabled" placeholder="请选择收款分部">
  36. <el-option
  37. v-for="(item, index) in calcBranchList"
  38. :key="index"
  39. :label="item.label"
  40. :value="item.value"
  41. ></el-option>
  42. </el-select>
  43. </el-form-item>
  44. <el-form-item class="setWidth" :prop="'domains.' + index + '.amount'" :rules="validAmount">
  45. <el-input
  46. type="age"
  47. clearable
  48. placeholder="请输入比例"
  49. :disabled="domain.disabled"
  50. @mousewheel.native.prevent
  51. v-model.number="domain.amount"
  52. >
  53. </el-input>
  54. </el-form-item>
  55. <el-form-item :prop="'domains.' + index + '.type'" :rules="[
  56. { required: true, message: '请选择购买类型', trigger: 'change' },
  57. ]">
  58. <el-select
  59. clearable
  60. v-model.trim="domain.type"
  61. placeholder="购买类型"
  62. style="width: 180px !important"
  63. :disabled="domain.disabled"
  64. >
  65. <el-option value="vipBuy" label="VIP课"></el-option>
  66. <el-option value="practiceBuy" label="网管课"></el-option>
  67. <el-option value="musicGroupBuy" label="乐团课"></el-option>
  68. </el-select>
  69. </el-form-item>
  70. <el-form-item>
  71. <el-button
  72. v-if="index != 0 && !domain.disabled"
  73. @click.prevent="removeDomain(result, domain)"
  74. >删除</el-button>
  75. </el-form-item>
  76. </div>
  77. <!-- <div class="el-form-item__error" v-if="result.errorText">{{ result.errorText }}</div> -->
  78. </div>
  79. <el-form-item class="add">
  80. <el-button icon="el-icon-plus" @click="addDomain(result)">新增</el-button>
  81. </el-form-item>
  82. </el-form>
  83. <el-button style="margin-left: 100px" @click="onSaveDomain" type="primary">保 存</el-button>
  84. </div>
  85. <el-dialog title="零星收费设置" :visible.sync="sporadicStatus" width="500px">
  86. <el-form :model="formSporadic" :rules="rulesSporadic" ref="ruleFormSporadic">
  87. <el-form-item label="收款分部" prop="organId" :label-width="formLabelWidth2">
  88. <el-select v-model.trim="formSporadic.organId">
  89. <el-option
  90. v-for="item in calcBranchList"
  91. :key="item.value"
  92. :label="item.label"
  93. :value="item.value.toString()"
  94. :disabled="item.disabled"
  95. ></el-option>
  96. </el-select>
  97. </el-form-item>
  98. <el-form-item label="金额(元)" prop="minReceipt" :label-width="formLabelWidth2">
  99. <el-input
  100. style="width: 100%;"
  101. @mousewheel.native.prevent
  102. v-model.number="formSporadic.minReceipt"
  103. ></el-input>
  104. </el-form-item>
  105. </el-form>
  106. <span slot="footer" class="dialog-footer">
  107. <el-button @click="sporadicStatus = false">取 消</el-button>
  108. <el-button @click="onSporadicSubmit('ruleFormSporadic')" type="primary">确 定</el-button>
  109. </span>
  110. </el-dialog>
  111. </div>
  112. </template>
  113. <script>
  114. import pagination from "@/components/Pagination/index";
  115. import { branchQueryPage } from "@/api/specialSetting";
  116. import { sysConfigList, sysConfigUpdate } from "@/api/generalSettings";
  117. import store from "@/store";
  118. import { getPaymentConfigs } from "./api";
  119. import { permission } from "@/utils/directivePage";
  120. let validAmount = (rule, value, callback) => {
  121. if (value != 0 && typeof value === 'string') {
  122. callback(new Error("请输入金额"));
  123. } else if (value < 0) {
  124. callback(new Error("输入金额必须大于或等于0"));
  125. } else if (value > 999999999) {
  126. callback(new Error("输入金额必须小于999999999"));
  127. } else {
  128. callback();
  129. }
  130. };
  131. export default {
  132. name: "chargeProfitManager",
  133. components: { pagination },
  134. data() {
  135. return {
  136. tableList: [],
  137. pageInfo: {
  138. // 分页规则
  139. limit: 10, // 限制显示条数
  140. page: 1, // 当前页
  141. total: 0, // 总条数
  142. page_size: [10, 20, 40, 50] // 选择限制显示条数
  143. },
  144. roleList: [], // 角色列表
  145. calcBranchList: [],
  146. formLabelWidth: "100px",
  147. result: {
  148. domains: [
  149. {
  150. organId: null,
  151. routeOrganId: null,
  152. amount: null,
  153. type: null
  154. }
  155. ],
  156. // errorText: null,
  157. },
  158. validAmount: [
  159. { required: true, validator: validAmount, trigger: 'blur' },
  160. { type: 'number', message: '金额必须为数字值' }],
  161. selectId: null, // 编号
  162. selectItem: {}, // 选中对象
  163. sporadicStatus: false, // {"organId":"2","minReceipt":"75000"}
  164. formLabelWidth2: "120px",
  165. sporadicId: null, // 零星收费编号
  166. formSporadic: {
  167. organId: null,
  168. minReceipt: null
  169. },
  170. rulesSporadic: {
  171. organId: [
  172. { required: true, message: "请选择所属分部", trigger: "change" }
  173. ],
  174. minReceipt: [
  175. { required: true, validator: validAmount, trigger: 'blur' },
  176. { type: 'number', message: '金额必须为数字值' }],
  177. }
  178. };
  179. },
  180. mounted() {
  181. this.__init()
  182. this.getList();
  183. },
  184. methods: {
  185. async __init() {
  186. this.$store.dispatch('setBranchs')
  187. await getPaymentConfigs().then(res => {
  188. if (res.code == 200 && res.data) {
  189. res.data.forEach(item => {
  190. this.calcBranchList.push({
  191. label: item.organName,
  192. value: item.organId
  193. });
  194. });
  195. }
  196. });
  197. },
  198. permission (str) {
  199. return permission(str)
  200. },
  201. onSporadicSubmit(formName) {
  202. this.$refs[formName].validate(valid => {
  203. if (valid) {
  204. let params = {
  205. id: this.sporadicId,
  206. paranValue: JSON.stringify(this.formSporadic),
  207. paramName: "sporadic_channel"
  208. };
  209. sysConfigUpdate(params).then(res => {
  210. if (res.code == 200) {
  211. this.messageTips("保存", res);
  212. }
  213. });
  214. } else {
  215. return;
  216. }
  217. });
  218. },
  219. messageTips(title, res) {
  220. if (res.code == 200) {
  221. this.$message.success(title + "成功");
  222. this.chargeStatus = false;
  223. this.sporadicStatus = false;
  224. this.getList();
  225. } else {
  226. this.$message.error(res.msg);
  227. }
  228. },
  229. async getList() {
  230. await sysConfigList({ group: "channel_config" }).then(res => {
  231. if (res.code == 200 && res.data.length > 0) {
  232. let tempResult = [];
  233. let paranValue = {};
  234. res.data.forEach((item, index) => {
  235. if (item.paramName === "amount_channel") {
  236. paranValue = item.paranValue ? JSON.parse(item.paranValue) : [];
  237. this.selectId = item.id;
  238. if(paranValue.length > 0) {
  239. this.result.domains = []
  240. paranValue.forEach((item, index) => {
  241. this.result.domains.push({
  242. organId: item.organId,
  243. routeOrganId: item.routeOrganId,
  244. amount: item.amount,
  245. type: item.type
  246. })
  247. })
  248. }
  249. }
  250. if (item.paramName === "sporadic_channel") {
  251. this.formSporadic = item.paranValue
  252. ? JSON.parse(item.paranValue)
  253. : { organId: null, minReceipt: null };
  254. this.sporadicId = item.id;
  255. }
  256. });
  257. }
  258. });
  259. },
  260. onSaveDomain() { // 保存设置
  261. this.$refs["ruleFormValid"].validate(valid => {
  262. if(valid) {
  263. const domain = this.result.domains
  264. let params = {
  265. id: this.selectId,
  266. paranValue: JSON.stringify(domain),
  267. paramName: "amount_channel"
  268. };
  269. sysConfigUpdate(params).then(res => {
  270. if (res.code == 200) {
  271. this.messageTips("保存", res);
  272. }
  273. });
  274. } else {
  275. return
  276. }
  277. })
  278. },
  279. addDomain(form, checked) {
  280. let domains = form.domains,
  281. forms = this.form,
  282. singleLength = domains.length,
  283. lastDate = domains[singleLength - 1]; // 获取倒数一个对象
  284. this.$refs["ruleFormValid"].validate(valid => {
  285. if(valid) {
  286. if (!checked) {
  287. // lastDate.disabled = true;
  288. domains.push({
  289. organId: null,
  290. routeOrganId: null,
  291. amount: null,
  292. type: null
  293. });
  294. }
  295. } else {
  296. return
  297. }
  298. })
  299. },
  300. removeDomain(form, item) {
  301. var index = form.domains.indexOf(item);
  302. if (index !== -1) {
  303. form.domains.splice(index, 1);
  304. // 取消最后一个数据的禁用状态
  305. form.domains[form.domains.length - 1].disabled = false;
  306. // form.errorText = null;
  307. }
  308. },
  309. }
  310. };
  311. </script>
  312. <style lang="scss" scoped>
  313. /deep/.el-button--primary {
  314. background: #14928a;
  315. border-color: #14928a;
  316. color: #fff;
  317. &:hover,
  318. &:active,
  319. &:focus {
  320. background: #14928a;
  321. border-color: #14928a;
  322. color: #fff;
  323. }
  324. }
  325. /deep/.el-dialog__body {
  326. // padding: 0 20px;
  327. }
  328. /deep/.el-select,
  329. /deep/.el-date-editor.el-input {
  330. width: 100% !important;
  331. }
  332. /deep/.el-input-number.is-controls-right .el-input__inner {
  333. text-align: left;
  334. }
  335. .newBand {
  336. display: inline-block;
  337. }
  338. .moreRule {
  339. background: #f8f8f8;
  340. position: relative;
  341. .el-form-item__error {
  342. color: #f56c6c;
  343. font-size: 12px;
  344. line-height: 1;
  345. position: absolute;
  346. left: 120px;
  347. top: 100%;
  348. margin-top: -21px;
  349. }
  350. }
  351. .add {
  352. margin-bottom: 22px;
  353. background: #f8f8f8;
  354. padding-bottom: 22px;
  355. padding-left: 100px;
  356. }
  357. .moreRuleIn {
  358. .el-form-item {
  359. display: inline-block;
  360. &:first-child {
  361. /deep/.el-form-item__content {
  362. margin-left: 100px !important;
  363. }
  364. }
  365. /deep/.el-form-item__content {
  366. margin-left: 0 !important;
  367. }
  368. }
  369. .setWidth {
  370. /deep/.el-form-item__content {
  371. width: 180px;
  372. }
  373. }
  374. /deep/.el-input-group__append {
  375. padding: 0 8px;
  376. }
  377. }
  378. .min,
  379. .max {
  380. display: inline-block;
  381. width: 180px;
  382. text-align: center;
  383. }
  384. </style>