more-merchant.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template id="more-merchant">
  2. <div class="more-merchant">
  3. <el-dialog append-to-body title="添加商户" :visible.sync="visible" :close-on-click-modal="false"
  4. custom-class="more-merchant-dialog" width="35%">
  5. <el-form :model="ruleForm" ref="ruleForm" size="small" label-width="180px">
  6. <el-form-item :prop="item.key" :label="item.title" :rules="{required: item.required != undefined && item.required, message: '请输入' + item.title}" v-for="item in fields">
  7. <el-input v-model="ruleForm[item.key]" :placeholder="item.placeholder != undefined ? item.placeholder : item.title"></el-input>
  8. </el-form-item>
  9. </el-form>
  10. <span slot="footer" class="dialog-footer">
  11. <el-button size="small" @click="visible = false">取 消</el-button>
  12. <el-button size="small" type="primary" @click="confirm" :loading="submitLoading">确 定</el-button>
  13. </span>
  14. </el-dialog>
  15. <el-button type="primary" size="mini" @click="click">添加商户</el-button>
  16. <el-table :data="value" size="mini" border style="margin-top: 15px;" :style="{marginTop: '15px', width: (fields.length * 250) + 320 + 'px'}">
  17. <el-table-column prop="merchant_id" label="商户ID" width="200"></el-table-column>
  18. <el-table-column :prop="item.key" :key="item.key" :label="item.title" v-for="item in fields"></el-table-column>
  19. <el-table-column prop="opt" label="操作" width="120" align="center">
  20. <template slot-scope="scope">
  21. <el-button type="text" @click="handleEdit(scope.$index, scope.row)" :disabled="scope.row.is_sys != undefined && scope.row.is_sys">编辑</el-button>
  22. <el-button type="text" @click="handleDelete(scope.$index)" :disabled="scope.row.is_sys != undefined && scope.row.is_sys">删除</el-button>
  23. </template>
  24. </el-table-column>
  25. </el-table>
  26. </div>
  27. </template>
  28. <script>
  29. Vue.component('more-merchant', {
  30. template: '#more-merchant',
  31. props: {
  32. value: {
  33. type: Array,
  34. default: []
  35. },
  36. fields: {
  37. type: Array,
  38. default: []
  39. }
  40. },
  41. data() {
  42. return {
  43. visible: false,
  44. submitLoading: false,
  45. editIndex: null,
  46. ruleForm: {}
  47. };
  48. },
  49. methods: {
  50. click() {
  51. this.initForm();
  52. this.visible = !this.visible;
  53. },
  54. initForm() {
  55. this.$set(this.ruleForm, 'merchant_id', '');
  56. if(this.fields.length > 0) {
  57. this.fields.forEach(item => {
  58. this.$set(this.ruleForm, item.key, '');
  59. });
  60. }
  61. },
  62. confirm() {
  63. this.$refs['ruleForm'].validate((valid) => {
  64. if (!valid) {
  65. return false;
  66. }
  67. if (this.ruleForm.merchant_id == '') {
  68. this.submitLoading = true;
  69. request({
  70. method: 'get',
  71. params: { r: 'huifu-pay/default/get-merchant-id'}
  72. }).then(res => {
  73. this.submitLoading = false;
  74. if(res.data.code == 0) {
  75. if(res.data.data != undefined && res.data.data != '') {
  76. this.ruleForm.merchant_id = res.data.data;
  77. this.value.push(JSON.parse(JSON.stringify(this.ruleForm)));
  78. this.visible = false;
  79. this.initForm();
  80. this.$refs.ruleForm.resetFields();
  81. this.$emit('input', this.value);
  82. }
  83. }else {
  84. this.$message.error(res.data.msg);
  85. }
  86. })
  87. }else {
  88. this.$set(this.value, this.editIndex, JSON.parse(JSON.stringify(this.ruleForm)));
  89. this.visible = false;
  90. this.initForm();
  91. this.$refs.ruleForm.resetFields();
  92. this.$emit('input', this.value);
  93. }
  94. });
  95. },
  96. handleEdit(index, row) {
  97. this.visible = !this.visible;
  98. this.editIndex = index;
  99. this.ruleForm = JSON.parse(JSON.stringify(row));
  100. },
  101. handleDelete(index) {
  102. this.value.splice(index, 1);
  103. this.$emit('input', this.value);
  104. }
  105. }
  106. });
  107. </script>
  108. <style lang="scss" scoped>
  109. .el-table__body-wrapper {
  110. height: auto !important;
  111. }
  112. .more-merchant-dialog{
  113. .el-pagination {
  114. display: flex;
  115. justify-content: flex-end;
  116. margin-top: 8px;
  117. }
  118. .el-input {
  119. max-width: 350px;
  120. }
  121. }
  122. </style>