mixin.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import {
  2. getDataInterfaceRes
  3. } from '@/api/common'
  4. export default {
  5. data() {
  6. return {
  7. ids: [],
  8. selectItems: []
  9. }
  10. },
  11. methods: {
  12. checkboxChange(e, item) {
  13. this.$nextTick(() => {
  14. if (e.value) {
  15. this.selectItems.push(item)
  16. } else {
  17. const i = this.selectItems.findIndex(o => !o.checked)
  18. this.selectItems.splice(i, 1)
  19. }
  20. })
  21. },
  22. openSelectDialog(item) {
  23. if (this.checkNumLimit()) return;
  24. let actionConfig = item.actionConfig
  25. const data = {
  26. actionConfig,
  27. formData: this.formData,
  28. tableVmodel: this.config.__vModel__
  29. }
  30. if (item.actionType == 1) return uni.navigateTo({
  31. url: '/pages/apply/tableLinkage/index?data=' + JSON.stringify(data)
  32. })
  33. if (!this.tableFormData.some(item => item.checked)) return this.$u.toast('至少选中一条数据');
  34. if (item.actionType == 2) {
  35. if (actionConfig.executeType == 2) {
  36. this.handleScriptFunc(actionConfig)
  37. } else {
  38. this.handleInterface(actionConfig)
  39. }
  40. }
  41. },
  42. //自定义按钮JS操作
  43. handleScriptFunc(item) {
  44. let data = this.selectItems.map(child => {
  45. let obj = {};
  46. child.forEach(item => {
  47. obj[item.__vModel__] = item.value;
  48. });
  49. return obj;
  50. });
  51. const parameter = {
  52. data,
  53. refresh: this.initData,
  54. onlineUtils: this.jnpf.onlineUtils,
  55. }
  56. const func = this.jnpf.getScriptFunc.call(this, item.executeFunc)
  57. if (!func) return
  58. func.call(this, parameter)
  59. },
  60. //自定义按钮接口操作
  61. handleInterface(item) {
  62. let data = this.selectItems.flatMap(child => {
  63. return child.map(item => ({
  64. [item.__vModel__]: item.value
  65. }));
  66. });
  67. const handlerInterface = (data) => {
  68. let query = {
  69. paramList: this.getBatchParamList(item.executeTemplateJson, data) || [],
  70. }
  71. getDataInterfaceRes(item.executeInterfaceId, query).then(res => {
  72. uni.showToast({
  73. title: res.msg,
  74. icon: 'none'
  75. })
  76. })
  77. }
  78. if (!item.executeUseConfirm) return handlerInterface(data)
  79. uni.showModal({
  80. title: this.$t('common.tipTitle'),
  81. content: item.executeConfirmTitle || '确认执行此操作?',
  82. showCancel: true,
  83. confirmText: '确定',
  84. success: function(res) {
  85. if (res.confirm) {
  86. handlerInterface(data)
  87. }
  88. }
  89. });
  90. },
  91. getBatchParamList(templateJson, data) {
  92. if (!templateJson || !templateJson.length) return [];
  93. for (let i = 0; i < templateJson.length; i++) {
  94. const e = templateJson[i];
  95. let defaultValue = [];
  96. if (e.sourceType === 1 && data.length) {
  97. data.forEach(o => {
  98. if (o.hasOwnProperty(e.relationField)) {
  99. defaultValue.push(o[e.relationField]);
  100. }
  101. });
  102. }
  103. e.defaultValue = defaultValue;
  104. if (e.sourceType === 4 && e.relationField === '@formId' && data.id !== undefined) {
  105. e.defaultValue = [data.id];
  106. } else if (e.sourceType !== 1) {
  107. e.defaultValue = [];
  108. }
  109. }
  110. return templateJson;
  111. },
  112. // 校验限制条数
  113. checkNumLimit() {
  114. if (this.config.isNumLimit && this.tableFormData.length >= this.config.numLimit) {
  115. this.$u.toast(`${this.config.__config__.label}超出条数限制`);
  116. return true;
  117. }
  118. return false;
  119. }
  120. }
  121. }