ApprovalModal.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <div class="view-product" v-cloak>
  3. <div class="animated">
  4. <div class="ibox-content" style="padding-right: 20px;padding-top: 20px">
  5. <layui-form>
  6. <layui-item v-if="nextTaskName && approveStatus != 6">
  7. <layui-inline-input
  8. label="审批环节"
  9. :value="nextTaskName"
  10. :readonly="true"
  11. :block='true'></layui-inline-input>
  12. </layui-item>
  13. <layui-item v-if="selectApproverType != 'none' && (submitFlow || approveStatus == 4 || approveStatus == 7)">
  14. <select-user-input
  15. v-if="selectApproverType == 'one'"
  16. label="审批人"
  17. :block='true'
  18. lay-verify='required'
  19. v-model="approver"></select-user-input>
  20. </layui-item>
  21. <layui-item v-if="!submitFlow">
  22. <layui-inline-textarea
  23. label="意见"
  24. v-model="comment"
  25. :disabled="false"
  26. :lay-verify='(approveStatus == 3 || approveStatus == 5) ? "required" : ""'
  27. placeholder="请输入意见"></layui-inline-textarea>
  28. </layui-item>
  29. <layui-inline v-show="false" class="btn-group-center">
  30. <button ref="approveBtn" class="layui-btn layui-btn-lg layui-btn-blue" lay-submit lay-filter="approveBtn"><i class="fa fa-save"></i> 保存</button>
  31. <button @click="close" class="layui-btn layui-btn-lg layui-btn-red"><i class="fa fa-times"></i> 关闭</button>
  32. </layui-inline>
  33. </layui-form>
  34. </div>
  35. <div class="layui-footer">
  36. <button v-if="submitFlow" @click="toClick('approveBtn')" class="layui-btn layui-btn-lg layui-btn-red" style="background-color: #28d88b"><i class="fa fa-check"></i> 提交</button>
  37. <button v-if="approveStatus == 4" @click="toClick('approveBtn')" class="layui-btn layui-btn-lg layui-btn-red" style="background-color: #28d88b"><i class="fa fa-check"></i> 通过</button>
  38. <button v-if="approveStatus == 5" @click="toClick('approveBtn')" class="layui-btn layui-btn-lg layui-btn-red" style="background-color: #ed4014"><i class="iconfont icon-bohui"></i> 驳回</button>
  39. <button v-if="approveStatus == 7" @click="toClick('approveBtn')" class="layui-btn layui-btn-lg layui-btn-red" style="background-color: #1e88f5"><i class="iconfont icon-zhongxintijiao"></i> 重新提交</button>
  40. <button v-if="approveStatus == 6" @click="toClick('approveBtn')" class="layui-btn layui-btn-lg layui-btn-red" style="background-color: #ffa024"><i class="iconfont icon-3"></i> 取消申请</button>
  41. <button v-if="approveStatus == 3" @click="toClick('approveBtn')" class="layui-btn layui-btn-lg layui-btn-red" style="background-color: #fb8f76"><i class="iconfont icon-butongguo"></i> 不通过</button>
  42. <button @click="close()" class="layui-btn layui-btn-lg layui-btn-red" style="margin-left: 20px;"><i class="fa fa-times"></i> 关闭</button>
  43. </div>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import { getDicts } from '@/api/dict'
  49. import BaseModal from "@/pages/base/BaseModal"
  50. import request from '@/utils/request'
  51. import bus from '@/assets/js/event.js'
  52. import qs from 'qs'
  53. export default {
  54. extends: BaseModal,
  55. data () {
  56. return {
  57. initAfter: false,
  58. approver: '',
  59. comment: this.approveStatus == 4 ? '同意。' : '',
  60. nextTaskName: this.submitFlow ? this.taskName : '',
  61. selectApproverType: 'one'
  62. }
  63. },
  64. props: {
  65. layerid: {
  66. type: String,
  67. default: null
  68. },
  69. approveStatus: {
  70. type: [Number, String],
  71. default: null
  72. },
  73. task: {
  74. type: Object,
  75. default: () => {
  76. return {};
  77. }
  78. },
  79. processKey: {
  80. type: String,
  81. default: ""
  82. },
  83. businessKey: {
  84. type: String,
  85. default: ""
  86. },
  87. submitFlow: {
  88. type: Boolean,
  89. default: false
  90. },
  91. taskName: {
  92. type: String,
  93. default: ""
  94. },
  95. },
  96. computed: {
  97. },
  98. watch: {
  99. },
  100. mounted () {
  101. this.initData();
  102. this.$nextTick(() => {
  103. this.layuiInit();
  104. });
  105. },
  106. methods: {
  107. approve: function() {
  108. if (this.submitFlow) {
  109. if (this.$parent.trueSelectApproverAfter) {
  110. this.$parent.trueSelectApproverAfter(this.approver, this.layerid);
  111. }
  112. return;
  113. }
  114. // 重新提交
  115. if (this.approveStatus == 7) {
  116. confirm('确定重新提交吗?', () => {
  117. let parent = this.$parent;
  118. while(parent) {
  119. if (parent.save) {
  120. parent.submitStatus = 2;
  121. parent.approver = this.approver;
  122. parent.taskComment = this.comment;
  123. parent.save();
  124. return;
  125. }
  126. parent = parent.$parent;
  127. }
  128. });
  129. return;
  130. }
  131. confirm("确定提交吗?", () => {
  132. this.submitHandler((token) => {
  133. loading();
  134. return new request({
  135. url: '/workflow/tasks/' + this.task.id + "/complete",
  136. method: 'post',
  137. data: qs.stringify({
  138. comment: this.comment,
  139. assignee: this.approver,
  140. approved: this.approveStatus,
  141. }),
  142. headers: {
  143. token
  144. },
  145. }).then(res => {
  146. alert(res.msg);
  147. this.refreshFormView();
  148. closeLoading();
  149. this.$layer.close(this.layerid);
  150. }).catch(error => {
  151. closeLoading();
  152. this.resetToken();
  153. });
  154. });
  155. });
  156. },
  157. refreshFormView: function() {
  158. this.$parent.init();
  159. let parent = this.$parent;
  160. while(parent && !parent.initData) {
  161. parent = parent.$parent;
  162. }
  163. if (parent) {
  164. parent.initData();
  165. }
  166. bus.$emit('flowRefresh', {
  167. processKey: this.processKey,
  168. businessKey: this.businessKey
  169. });
  170. },
  171. initData: function() {
  172. let configInfo = this.task.description || "{}";
  173. let config = JSON.parse(configInfo);
  174. let approveConfig = config[this.approveStatus];
  175. if (approveConfig) {
  176. this.selectApproverType = approveConfig['approver'] || 'one';
  177. this.nextTaskName = approveConfig['nextTaskName'];
  178. }
  179. if (false) {
  180. } else {
  181. this.initAfter = true;
  182. }
  183. },
  184. layuiInit: function(){
  185. var _this = this;
  186. layui.use(['element', 'form'], function(){
  187. var element = element
  188. ,form = layui.form;
  189. //自定义验证规则
  190. form.verify({
  191. title: function(value){
  192. if(value.length < 10){
  193. return '标题至少得10个字符哟';
  194. }
  195. }
  196. ,content: function(value){
  197. layedit.sync(editIndex);
  198. }
  199. });
  200. form.on('submit(approveBtn)', function(data){
  201. _this.approve();
  202. return false;
  203. });
  204. });
  205. }
  206. }
  207. }
  208. </script>
  209. <style scoped>
  210. .layui-footer {
  211. width: 100%;
  212. text-align: center;
  213. position: fixed;
  214. bottom: 0;
  215. height: 44px;
  216. line-height: 44px;
  217. padding: 0 15px;
  218. background-color: #eee;
  219. }
  220. .view-product /deep/ .layui-form-item.layui-form-text, .view-product /deep/ .layui-form-item.layui-form-text {
  221. padding-right: 0px!important;
  222. }
  223. </style>