ApproveForm.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /** 审批表单 */
  2. <template>
  3. <div>
  4. <div v-if="form != null && form.fields != null && form.fields.length > 0">
  5. <template v-for="field in form.fields">
  6. <div
  7. v-if="field.displayType == 'IntegerBoxEditor'"
  8. :key="field.fieldName"
  9. class="form-group"
  10. :for="field.fieldName"
  11. >
  12. <label>
  13. {{ field.displayName }}
  14. <span
  15. v-if="field.required == true"
  16. class="text-danger"
  17. >*</span>
  18. </label>
  19. <input
  20. :id="field.fieldName"
  21. v-model="field.fieldValue"
  22. autocomplete="off"
  23. type="number"
  24. class="form-control"
  25. :readonly="field.readonly"
  26. :disabled="field.readonly"
  27. :placeholder="field.placeholder"
  28. />
  29. </div>
  30. <div
  31. v-else-if="field.displayType == 'TextBoxEditor'"
  32. :key="field.fieldName"
  33. class="form-group"
  34. :for="field.fieldName"
  35. >
  36. <label>
  37. {{ field.displayName }}
  38. <span
  39. v-if="field.required == true"
  40. class="text-danger"
  41. >*</span>
  42. </label>
  43. <input
  44. :id="field.fieldName"
  45. v-model="field.fieldValue"
  46. autocomplete="off"
  47. type="text"
  48. class="form-control"
  49. :readonly="field.readonly"
  50. :disabled="field.readonly"
  51. :placeholder="field.placeholder"
  52. />
  53. </div>
  54. <div
  55. v-else-if="field.displayType == 'CheckBoxEditor'"
  56. :key="field.fieldName"
  57. class="form-group"
  58. :for="field.fieldName"
  59. >
  60. <label>
  61. {{ field.displayName }}
  62. <span
  63. v-if="field.required == true"
  64. class="text-danger"
  65. >*</span>
  66. </label>
  67. <div class="input-group">
  68. <Switches
  69. v-model="field.fieldValue"
  70. :selected="field.fieldValue"
  71. color="green"
  72. :readonly="field.readonly"
  73. :disabled="field.readonly"
  74. type-bold="true"
  75. />
  76. </div>
  77. </div>
  78. <div
  79. v-else
  80. :key="field.fieldName"
  81. class="form-group"
  82. :for="field.fieldName"
  83. >
  84. <label>
  85. {{ field.displayName }}
  86. <span
  87. v-if="field.required == true"
  88. class="text-danger"
  89. >*</span>
  90. </label>
  91. <input
  92. :id="field.fieldName"
  93. v-model="field.fieldValue"
  94. autocomplete="off"
  95. type="text"
  96. class="form-control"
  97. :readonly="field.readonly"
  98. :disabled="field.readonly"
  99. :placeholder="field.placeholder"
  100. />
  101. </div>
  102. </template>
  103. </div>
  104. </div>
  105. </template>
  106. <script>
  107. import Common from '../common/Common.js';
  108. import WorkflowResource from '../api/workflow/WorkflowResource.js';
  109. import { Notify, Uuid } from 'pc-component-v3';
  110. export default {
  111. components: {
  112. },
  113. props: {
  114. processInstanceId: {
  115. type: String,
  116. default: null,
  117. },
  118. taskId: {
  119. type: String,
  120. default: null,
  121. },
  122. workflow: {
  123. type: Object,
  124. default : function(){
  125. return null;
  126. },
  127. },
  128. },
  129. emits: ['valueChanged'],
  130. data: function () {
  131. return {
  132. 'form': null,
  133. };
  134. },
  135. watch: {
  136. workflow: function () {
  137. this.findForm();
  138. },
  139. taskId: function () {
  140. this.findForm();
  141. },
  142. form: {
  143. handler(newValue, oldValue) {
  144. var data = this.getData();
  145. this.$emit('valueChanged', data);
  146. },
  147. // immediate: true,
  148. deep: true,
  149. },
  150. },
  151. mounted: function () {
  152. this.findForm();
  153. },
  154. methods: {
  155. /**
  156. * 查找任务的表单定义
  157. */
  158. findForm: function () {
  159. if (this.taskId == null || this.workflow == null || this.workflow.id == null) {
  160. return;
  161. }
  162. let formRequest = {
  163. 'taskId': this.taskId,
  164. 'workflowId': this.workflow.id,
  165. 'processInstanceId': this.processInstanceId,
  166. };
  167. WorkflowResource.findForm(formRequest).then(successData => {
  168. if (successData != null && successData.fields != null && successData.fields.length > 0) {
  169. successData.fields.forEach(field => {
  170. field.fieldValue = null;
  171. if (field.displayType == 'CheckBoxEditor') {
  172. field.fieldValue = false;
  173. }
  174. });
  175. }
  176. this.form = successData;
  177. }, errorData => {
  178. Common.processException(errorData);
  179. });
  180. },
  181. /**
  182. * 获取界面的数据
  183. */
  184. getData: function () {
  185. if (this.form == null || this.form.fields == null || this.form.fields.length == 0) {
  186. return null;
  187. }
  188. // 强制字段检测
  189. let message = '';
  190. this.form.fields.forEach(field => {
  191. if (field.required == true && field.readonly === false && (field.fieldValue === null || field.fieldValue === '')) {
  192. message += ('字段:' + field.displayName + '是强制字段,请填写数据\r\n');
  193. }
  194. });
  195. if (message.length > 0) {
  196. Notify.error('数据校验异常', message, false);
  197. throw new Error('数据校验异常', message);
  198. }
  199. let results = [];
  200. this.form.fields.forEach(field => {
  201. if (field.readonly === false) {
  202. let result = {
  203. key: field.fieldName,
  204. };
  205. if (field.displayType == 'IntegerBoxEditor') {
  206. result.valueDouble = Number(field.fieldValue);
  207. } else if (field.displayType == 'CheckBoxEditor') {
  208. result.valueBoolean = field.fieldValue;
  209. } else if (field.displayType == 'TextBoxEditor') {
  210. result.valueString = field.fieldValue;
  211. }
  212. results.push(result);
  213. }
  214. });
  215. return results;
  216. },
  217. },
  218. };
  219. </script>
  220. <style scoped>
  221. </style>