approval_batch.js 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. var app = getApp()
  2. var that;
  3. var socket = null;
  4. var setTime;
  5. Page({
  6. data: {
  7. date: app.globalData.month,
  8. httpType: 'waiting',
  9. keyword: '',
  10. page: 1,
  11. isBh: false,//是否显示驳回弹窗
  12. textArea: "",
  13. showStaff: false,//显示员工选择
  14. staffVal: '奖扣对象',
  15. target_id: '',
  16. selectIds: [],//选择的人员
  17. dataList: [],
  18. isAll: true,
  19. // 长连接结果
  20. results: [], //提交的返回结果集合
  21. isResult: false,
  22. percentage: 0,
  23. resultList: [],//要发送数据的集合
  24. resultIndex: 0,
  25. isShowError: false,
  26. },
  27. onLoad() {
  28. that = this;
  29. dd.setNavigationBar({ title: "批量审批" });
  30. },
  31. // 页面被关闭
  32. onUnload() {
  33. },
  34. onShow() {
  35. if (app.globalData.userData) {
  36. that.refreshData();
  37. } else {
  38. app.login(app.globalData.corpId, function (is) {
  39. if (is) {
  40. that.refreshData();
  41. } else {
  42. dd.reLaunch({
  43. url: '../../noJurisdiction/noJurisdiction'
  44. })
  45. }
  46. }, function () { })
  47. }
  48. },
  49. closeTc() {
  50. this.setData({
  51. results: [], //提交的返回结果集合
  52. isResult: false,
  53. percentage: 0,
  54. resultList: [],//要发送数据的集合
  55. resultIndex: 0,
  56. selectIds: [],
  57. isBh: false,//是否显示驳回弹窗
  58. isShowError: false,
  59. textArea: '',
  60. page: 1,
  61. })
  62. app.globalData.socketApi.closewebsocket();
  63. this.getData();
  64. },
  65. // 驳回
  66. openBh() {
  67. if (this.data.selectIds.length == 0) {
  68. app.globalData.showToast("请先选择审批单");
  69. return false
  70. }
  71. this.setData({
  72. isBh: true,
  73. })
  74. },
  75. // 通过
  76. openTg() {
  77. let that = this;
  78. if (this.data.selectIds.length == 0) {
  79. app.globalData.showToast("请先选择审批单");
  80. return false
  81. }
  82. dd.confirm({
  83. title: '批量通过',
  84. content: `已选中${this.data.selectIds.length}条审批单,确认全部通过?`,
  85. confirmButtonText: '确定',
  86. cancelButtonText: '取消',
  87. success: (result) => {
  88. if (result.confirm) {
  89. that.webSocket(true);
  90. }
  91. },
  92. });
  93. },
  94. webSocket(is) {
  95. let arr = [];
  96. let wsData;
  97. this.data.selectIds.forEach(item => {
  98. if (is) {
  99. wsData = {
  100. type: 'review',
  101. action: 'complete',
  102. review_id: item,
  103. };
  104. } else {
  105. wsData = {
  106. type: 'review',
  107. action: 'refuse',
  108. review_id: item,
  109. remark: this.data.textArea,
  110. };
  111. }
  112. arr.push(wsData);
  113. });
  114. this.setData({
  115. resultList: arr,
  116. resultIndex: 0,
  117. percentage: 0,
  118. results: [],
  119. isResult: true,
  120. })
  121. this.opneWebSocket()
  122. },
  123. opneWebSocket() {
  124. let wsData = this.data.resultList;
  125. if (wsData[this.data.resultIndex]) {
  126. setTime = setTimeout(() => {
  127. dd.alert({
  128. title: '温馨提示',
  129. content: '网络异常,请检查网络',
  130. buttonText: '我知道了',
  131. success: (result) => {
  132. clearTimeout(setTime);
  133. app.globalData.socketApi.closewebsocket();
  134. that.closeTc();
  135. },
  136. });
  137. }, 15000)
  138. app.globalData.socketApi.sendData(wsData[this.data.resultIndex], this.onmessageWS,true);
  139. } else {
  140. // console.log(this.data.results)
  141. }
  142. },
  143. onmessageWS(e) {
  144. // 因为作用域问题,这个函数不能使用this
  145. if (e.type == 'review') {
  146. clearTimeout(setTime);
  147. let data = e.result;
  148. let employee = that.returnResult(e.result.source_msg.review_id)[0]
  149. data.target = employee.employee_name;
  150. data.remark = employee.remark;
  151. data.point = employee.point;
  152. data.pt_name = employee.pt_name;
  153. // console.log(employee)
  154. // data.msg=e.msg
  155. let results = that.data.results;//结果集
  156. results.unshift(e.result);
  157. let lng = that.data.resultList.length;// 进度条
  158. that.setData({
  159. percentage: Math.floor(that.data.percentage += (100 / lng)),
  160. results: results,
  161. resultIndex: that.data.resultIndex + 1
  162. })
  163. that.opneWebSocket();
  164. if (lng == that.data.results.length) {
  165. that.setData({
  166. percentage: 100,
  167. })
  168. }
  169. }
  170. if (e.type == 'error') {
  171. clearTimeout(setTime);
  172. that.setData({
  173. isShowError: true,
  174. })
  175. }
  176. },
  177. returnResult(id) {
  178. return this.data.dataList.filter(item => {
  179. return item.id == id;
  180. })
  181. },
  182. confirmBh() {
  183. if (that.data.textArea == '') {
  184. app.globalData.showToast("请输入审批意见");
  185. return;
  186. }
  187. this.setData({ isBh: false })
  188. that.webSocket(false);
  189. },
  190. onChange(e) {
  191. if (e) {
  192. this.setData({
  193. selectIds: e.detail.value
  194. })
  195. }
  196. },
  197. selectAll() {
  198. let selectIds = [];
  199. let dataList = this.data.dataList.map(item => {
  200. item.checked = this.data.isAll;
  201. selectIds.push(item.id);
  202. return item;
  203. })
  204. this.setData({
  205. dataList: dataList,
  206. selectIds: this.data.isAll ? selectIds : [],
  207. isAll: !this.data.isAll,
  208. })
  209. },
  210. bindKeyInput(e) {
  211. this.setData({
  212. page: 1,
  213. isVal: e.detail.value ? true : false,
  214. keyword: e.detail.value ? e.detail.value : '',
  215. })
  216. this.getData();
  217. },
  218. //关闭弹窗
  219. onClose() {
  220. this.setData({
  221. showStaff: false,
  222. })
  223. },
  224. //选择员工
  225. onConfirmStaff(data) {
  226. if (!data) {
  227. this.setData({ staffVal: '奖扣对象', target_id: '', page: 1 })
  228. this.getData();
  229. return false;
  230. }
  231. if (data.length > 0) {
  232. this.setData({ staffVal: data[0].name, target_id: data[0].id, page: 1 })
  233. } else {
  234. this.setData({ staffVal: '奖扣对象', target_id: '', page: 1 })
  235. }
  236. this.getData();
  237. },
  238. //显示选择员工
  239. selectStaff() {
  240. this.setData({
  241. showStaff: true
  242. })
  243. },
  244. openDetail(e) {
  245. var id = e.target.dataset.item.id;
  246. dd.navigateTo({
  247. url: '../approveDetail/approveDetail?id=' + id
  248. })
  249. },
  250. showText() {
  251. dd.alert({
  252. title: '温馨提示',
  253. content: '批量审批仅支持快速处理任务审批和已指定规则的积分审批,其余情况的审批单请到【待我审批】处理,权限分不足时,请进入【审批详情】→【通过】→【递交审批】给上级',
  254. buttonText: '我知道了',
  255. success: (result) => { },
  256. });
  257. },
  258. //当在详情返回时刷新列表,但你请求接口
  259. refreshData(id) {
  260. if (this.data.page == 1) {
  261. dd.hideLoading();
  262. that.getData();
  263. } else {
  264. if (id) {//当page不为一并下一页返回上一页不执行onshow()
  265. var arr = this.data.dataList;
  266. arr.forEach((element, index) => {
  267. if (element.id == id) {
  268. arr.splice(index, 1);
  269. }
  270. });
  271. this.setData({
  272. dataList: arr
  273. })
  274. }
  275. }
  276. },
  277. bindTextAreaBlur(e) {
  278. this.setData({
  279. textArea: e.detail.value
  280. });
  281. },
  282. closeBh() {
  283. this.setData({ isBh: false, textArea: '' })
  284. },
  285. onReset() {
  286. this.setData({
  287. keyword: '',
  288. isVal: false,
  289. page: 1,
  290. })
  291. this.getData();
  292. },
  293. getData(type) {
  294. let data = {
  295. source_type: '0',
  296. batch: 1,
  297. type: 'waiting',
  298. page: that.data.page,
  299. pt_id: 0,
  300. page_size: 20,
  301. keyword: that.data.keyword
  302. }
  303. if (that.data.target_id) {
  304. data.target_id = that.data.target_id;
  305. }
  306. app.$get("api/integral/review/list", data).then((res) => {
  307. var list = res.data.data.list || [];
  308. list.forEach(element => {
  309. if (element.pt_id) {
  310. element.pt_name = app.getTypesItem(element.pt_id).name
  311. }
  312. });
  313. if (that.data.page == 1) {
  314. this.setData({
  315. dataList: []
  316. })
  317. }
  318. var data = list;
  319. var dataList = that.data.dataList || [];
  320. if (type == '2') {
  321. if (data.length < 20) {
  322. this.setData({
  323. dataList: dataList.concat(data),
  324. isData: true
  325. })
  326. } else {
  327. this.setData({
  328. dataList: dataList.concat(data),
  329. })
  330. }
  331. } else {
  332. this.setData({ dataList: data, isData: false })
  333. }
  334. })
  335. },
  336. //上啦加载
  337. onScrollToLower() {
  338. if (!that.data.isData) {
  339. this.setData({ page: ++that.data.page })
  340. this.getData("2");
  341. }
  342. },
  343. });