index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <div>
  3. <el-button
  4. :disabled="disabled ? disabled : false"
  5. :type="disabled?'':type ? type : 'primary'"
  6. :size="size ? size : 'mini'"
  7. @click="submit"
  8. >{{ $t(btnName) }}</el-button>
  9. <el-dialog
  10. v-if="dialogNoteLabel"
  11. :title="$t('提示')"
  12. :visible.sync="noteDialogVisible"
  13. width="400px"
  14. :append-to-body="true"
  15. >
  16. <div>
  17. <div style="margin-bottom: 5px; font-size: 14px; color: #606266;">{{ $t(dialogTitle) }}</div>
  18. <el-input v-model="dialogAmount"></el-input>
  19. <div style="margin: 10px 0 5px; font-size: 14px; color: #606266;">{{ $t(dialogNoteLabel) }}</div>
  20. <el-input v-model="dialogNote"></el-input>
  21. </div>
  22. <span slot="footer" class="dialog-footer">
  23. <el-button @click="noteDialogVisible = false">{{ $t('取消') }}</el-button>
  24. <el-button type="primary" @click="confirmNoteDialog">{{ confirmButtonText ? $t(confirmButtonText) : $t('确定') }}</el-button>
  25. </span>
  26. </el-dialog>
  27. </div>
  28. </template>
  29. <script>
  30. export default {
  31. name: "",
  32. props: {
  33. type: String,
  34. btnName: String,
  35. message: String,
  36. idName: String,
  37. keyName: String,
  38. id: [String, Number, Array],
  39. disabled: Boolean,
  40. idIsArr: Boolean,
  41. paramData: {
  42. type: Array,
  43. default() {
  44. return [];
  45. },
  46. },
  47. dialog: Boolean,
  48. dialogTitle: String,
  49. dialogKey: String,
  50. checkContent: Boolean,
  51. checkString: Boolean,
  52. size: String,
  53. delType: String,
  54. errorMessage:String,
  55. confirmButtonText:String,
  56. dialogNoteLabel: String,
  57. dialogNoteKey: { type: String, default: 'note' }
  58. },
  59. data() {
  60. return {
  61. dialogAmount: '',
  62. dialogNote: '',
  63. noteDialogVisible: false
  64. };
  65. },
  66. computed: {},
  67. watch: {},
  68. methods: {
  69. submit() {
  70. if (this.dialog) {
  71. if (this.dialogNoteLabel) {
  72. this.dialogAmount = '';
  73. this.dialogNote = '';
  74. this.noteDialogVisible = true;
  75. } else {
  76. this.$prompt(this.$t(this.dialogTitle), this.$t("提示"), {
  77. confirmButtonText: this.confirmButtonText?this.$t(this.confirmButtonText):this.$t("确定"),
  78. cancelButtonText: this.$t("取消"),
  79. inputPattern: this.checkContent ? /^[\d.]+$/ : this.checkString ? /^\S.*$/ : "",
  80. inputErrorMessage: this.$t(this.errorMessage)
  81. }).then(async ({ value }) => {
  82. let param = {
  83. content: {},
  84. };
  85. param.id = this.idName;
  86. param.content[this.keyName] = this.idIsArr ? [this.id] : this.id;
  87. this.paramData.forEach((item) => {
  88. param.content[item.key] = item.value;
  89. });
  90. param.content[this.dialogKey] = value;
  91. let res = await this.$api.requested(param);
  92. if (this.delType === "合作伙伴") {
  93. if (res.code === 0) {
  94. this.$message({
  95. message: res.data[0].errmsg,
  96. type: "error",
  97. });
  98. } else {
  99. this.tool.showMessage(res, () => {
  100. this.$emit("onSuccess", res.data);
  101. });
  102. }
  103. } else {
  104. this.tool.showMessage(res, () => {
  105. this.$emit("onSuccess", res.data);
  106. });
  107. }
  108. }).catch(() => {
  109. this.$message({
  110. type: 'info',
  111. message: this.$t('已取消')
  112. });
  113. });
  114. }
  115. } else {
  116. this.$confirm(this.$t(this.message), this.$t("提示"), {
  117. confirmButtonText: this.confirmButtonText?this.$t(this.confirmButtonText):this.$t("确定"),
  118. cancelButtonText: this.$t("取消"),
  119. type: "warning",
  120. }).then(async () => {
  121. let param = {
  122. content: {},
  123. };
  124. param.id = this.idName;
  125. param.content[this.keyName] = this.idIsArr ? [this.id] : this.id;
  126. this.paramData.forEach((item) => {
  127. param.content[item.key] = item.value;
  128. });
  129. let res = await this.$api.requested(param);
  130. this.tool.showMessage(res, () => {
  131. this.$emit("onSuccess", res.data);
  132. });
  133. }).catch(() => {
  134. this.$message({
  135. type: 'info',
  136. message: this.$t('已取消')
  137. });
  138. });
  139. }
  140. },
  141. async confirmNoteDialog() {
  142. if (!this.dialogAmount) {
  143. this.$message({ message: this.$t('请输入金额'), type: 'warning' });
  144. return;
  145. }
  146. if (this.checkContent && !/^[\d.]+$/.test(this.dialogAmount)) {
  147. this.$message({ message: this.$t(this.errorMessage || '请输入正确的数字'), type: 'error' });
  148. return;
  149. }
  150. let param = {
  151. content: {},
  152. };
  153. param.id = this.idName;
  154. param.content[this.keyName] = this.idIsArr ? [this.id] : this.id;
  155. this.paramData.forEach((item) => {
  156. param.content[item.key] = item.value;
  157. });
  158. param.content[this.dialogKey] = this.dialogAmount;
  159. param.content[this.dialogNoteKey] = this.dialogNote;
  160. let res = await this.$api.requested(param);
  161. if (this.delType === '合作伙伴') {
  162. if (res.code === 0) {
  163. this.$message({ message: res.data[0].errmsg, type: 'error' });
  164. return;
  165. } else {
  166. this.noteDialogVisible = false;
  167. this.tool.showMessage(res, () => {
  168. this.$emit('onSuccess', res.data);
  169. });
  170. }
  171. } else {
  172. this.noteDialogVisible = false;
  173. this.tool.showMessage(res, () => {
  174. this.$emit('onSuccess', res.data);
  175. });
  176. }
  177. }
  178. },
  179. };
  180. </script>
  181. <style scoped>
  182. </style>