more-merchant.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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" :key="item.key">
  7. <el-input v-model="ruleForm[item.key]" :placeholder="item.placeholder != undefined ? item.placeholder : item.title"></el-input>
  8. </el-form-item>
  9. <p :class="{tips: true, shake: validateError}" v-if="bottomTips != ''">{{bottomTips}}</p>
  10. </el-form>
  11. <span slot="footer" class="dialog-footer">
  12. <el-button size="small" @click="visible = false">取 消</el-button>
  13. <el-button size="small" type="primary" @click="confirm" :loading="submitLoading">确 定</el-button>
  14. </span>
  15. </el-dialog>
  16. <el-button type="primary" size="mini" @click="click">添加商户</el-button>
  17. <el-table :data="value" size="mini" border style="margin-top: 15px;" :style="{marginTop: '15px', width: (fields.length * 250) + 320 + 'px'}">
  18. <el-table-column prop="merchant_id" label="商户ID" width="200"></el-table-column>
  19. <el-table-column :prop="item.key" :key="item.key" :label="item.title" v-for="item in fields"></el-table-column>
  20. <el-table-column prop="opt" label="操作" width="120" align="center">
  21. <template slot-scope="scope">
  22. <el-button type="text" @click="handleEdit(scope.$index, scope.row)" :disabled="scope.row.is_sys != undefined && scope.row.is_sys">编辑</el-button>
  23. <el-button type="text" @click="handleDelete(scope.$index)" :disabled="scope.row.is_sys != undefined && scope.row.is_sys">删除</el-button>
  24. </template>
  25. </el-table-column>
  26. </el-table>
  27. </div>
  28. </template>
  29. <script>
  30. Vue.component('more-merchant', {
  31. template: '#more-merchant',
  32. props: {
  33. value: {
  34. type: Array,
  35. default: []
  36. },
  37. fields: {
  38. type: Array,
  39. default: []
  40. },
  41. bottomTips: {
  42. type: String,
  43. default: ''
  44. },
  45. validate: null
  46. },
  47. data() {
  48. return {
  49. visible: false,
  50. submitLoading: false,
  51. validateError: false,
  52. editIndex: null,
  53. ruleForm: {}
  54. };
  55. },
  56. methods: {
  57. click() {
  58. this.initForm();
  59. this.visible = !this.visible;
  60. },
  61. initForm() {
  62. this.$set(this.ruleForm, 'merchant_id', '');
  63. if(this.fields.length > 0) {
  64. this.fields.forEach(item => {
  65. this.$set(this.ruleForm, item.key, '');
  66. });
  67. }
  68. },
  69. confirm() {
  70. if (this.validate != undefined && !this.validate(this.ruleForm)) {
  71. this.testShakeController();
  72. return false;
  73. }
  74. this.$refs['ruleForm'].validate((valid) => {
  75. if (!valid) {
  76. return false;
  77. }
  78. if (this.ruleForm.merchant_id == '') {
  79. this.submitLoading = true;
  80. request({
  81. method: 'get',
  82. params: { r: 'join-pay/default/get-merchant-id'}
  83. }).then(res => {
  84. this.submitLoading = false;
  85. if(res.data.code == 0) {
  86. if(res.data.data != undefined && res.data.data != '') {
  87. this.ruleForm.merchant_id = res.data.data;
  88. this.value.push(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. }else {
  95. this.$message.error(res.data.msg);
  96. }
  97. })
  98. }else {
  99. this.$set(this.value, this.editIndex, JSON.parse(JSON.stringify(this.ruleForm)));
  100. this.visible = false;
  101. this.initForm();
  102. this.$refs.ruleForm.resetFields();
  103. this.$emit('input', this.value);
  104. }
  105. });
  106. },
  107. handleEdit(index, row) {
  108. this.visible = !this.visible;
  109. this.editIndex = index;
  110. this.ruleForm = JSON.parse(JSON.stringify(row));
  111. },
  112. handleDelete(index) {
  113. this.value.splice(index, 1);
  114. this.$emit('input', this.value);
  115. },
  116. testShakeController() {
  117. this.validateError = true;
  118. setTimeout(() => this.validateError = false, 800);
  119. }
  120. }
  121. });
  122. </script>
  123. <style lang="scss" scoped>
  124. .el-table__body-wrapper {
  125. height: auto !important;
  126. }
  127. .more-merchant-dialog{
  128. .el-pagination {
  129. display: flex;
  130. justify-content: flex-end;
  131. margin-top: 8px;
  132. }
  133. .el-input {
  134. max-width: 350px;
  135. }
  136. .tips {
  137. padding: 0 65px;
  138. color: #F44336;
  139. display: block;
  140. }
  141. .shake {
  142. animation: shake 0.5s 1;
  143. }
  144. }
  145. @keyframes shake {
  146. 0%, 100% { transform: translateX(0); }
  147. 10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
  148. 20%, 40%, 60%, 80% { transform: translateX(5px); }
  149. }
  150. </style>