review.js 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. var app = getApp()
  2. var that;
  3. var socket = null;
  4. var setTime;
  5. Page({
  6. data: {
  7. date: app.globalData.month,
  8. activeIndex: 1,
  9. keyword: '',
  10. page: 1,
  11. isBh: false,//是否显示驳回弹窗
  12. textArea: "",
  13. disabled: false,
  14. isPl:false,
  15. objectArray: [{id:'[1,2]',name: '全部'},{ id: '[1]',name: '通过'},{id: '[2]', name: '不通过'}],
  16. arrIndex: 0,
  17. isAll: true,
  18. minuteIndex: 0,//条件选择
  19. minuteArray: [
  20. { id: 1, name: '待复核' },
  21. { id: 2, name: '已复核' },
  22. ],
  23. // 长连接结果
  24. results: [], //提交的返回结果集合
  25. isResult: false,
  26. percentage: 0,
  27. resultList: [],//要发送数据的集合
  28. resultIndex: 0,
  29. isShowError: false,
  30. popupCx: '',
  31. config: {},
  32. showStaff: false,//显示员工选择
  33. staffVal: '人员',
  34. },
  35. onLoad() {
  36. that = this;
  37. dd.setNavigationBar({ title: "复核" });
  38. },
  39. onShow() {
  40. if (app.globalData.userData) {
  41. that.refreshData();
  42. } else {
  43. app.login(app.globalData.corpId, function (is) {
  44. if (is) {
  45. that.refreshData();
  46. } else {
  47. dd.reLaunch({
  48. url: '../../noJurisdiction/noJurisdiction'
  49. })
  50. }
  51. },function(){})
  52. }
  53. },
  54. //选择员工
  55. onConfirmStaff(data) {
  56. if (!data) {
  57. this.setData({ staffVal: '人员', employee_ids: '', page: 1 })
  58. this.getData();
  59. return false;
  60. }
  61. if (data.length > 0) {
  62. if (data.length > 1) {
  63. var str = "";
  64. var arr = [];
  65. data.forEach((item) => {
  66. str += item.name + ','
  67. arr.push(item.id);
  68. })
  69. var employee_ids = arr.join(',');
  70. this.setData({ staffVal: str.substring(0, str.length - 1), employee_ids: employee_ids, page: 1 })
  71. } else {
  72. this.setData({ staffVal: data[0].name, employee_ids: [data[0].id], page: 1 })
  73. }
  74. } else {
  75. this.setData({ staffVal: '人员', employee_ids: [], page: 1 })
  76. }
  77. this.getData();
  78. },
  79. //显示选择员工
  80. selectStaff() {
  81. this.setData({
  82. popupCx: 'container__mask',
  83. showStaff: true
  84. })
  85. },
  86. //关闭弹窗
  87. onClose() {
  88. this.setData({
  89. showStaff: false,
  90. popupCx: ''
  91. })
  92. },
  93. openPl(){
  94. this.setData({
  95. isPl: !that.data.isPl
  96. })
  97. },
  98. // 通过
  99. openTg() {
  100. let that = this;
  101. let selectIds = [];
  102. this.data.dataList.forEach(item => {
  103. if(item.checked){
  104. selectIds.push({
  105. type:'event_check',
  106. action:'agree',
  107. event_id:item.id,
  108. point:item.point,
  109. remark:item.remark,
  110. name:item.employee_name,
  111. pt_id:item.pt_id
  112. });
  113. }
  114. })
  115. if (selectIds.length == 0) {
  116. app.globalData.showToast("请先选择复核单");
  117. return false
  118. }
  119. dd.confirm({
  120. title: '批量通过',
  121. content: `已选中${selectIds.length}条复核单,确认全部通过?`,
  122. confirmButtonText: '确定',
  123. cancelButtonText: '取消',
  124. success: (result) => {
  125. if (result.confirm) {
  126. that.webSocket(selectIds,true);
  127. }
  128. },
  129. });
  130. },
  131. selectAll() {
  132. let dataList = this.data.dataList.map(item => {
  133. item.checked = this.data.isAll;
  134. return item;
  135. })
  136. this.setData({
  137. dataList: dataList,
  138. isAll:!this.data.isAll,
  139. })
  140. },
  141. //选择规则分类
  142. bindKeyInput(e) {
  143. this.setData({
  144. keyword: e.detail.value,
  145. page: 1,
  146. isVal: e.detail.value ? true : false,
  147. });
  148. this.getData();
  149. },
  150. bindObjPickerChange(e) {
  151. this.setData({
  152. arrIndex: e.detail.value,
  153. page: 1,
  154. isPl:false,
  155. })
  156. this.getData();
  157. },
  158. //当在详情返回时刷新列表,但你请求接口
  159. refreshData(id) {
  160. if (this.data.page == 1) {
  161. dd.hideLoading();
  162. that.getData();
  163. } else {
  164. if (id) {//当page不为一并下一页返回上一页不执行onshow()
  165. var arr = this.data.dataList;
  166. arr.forEach((element, index) => {
  167. if (element.id == id) {
  168. arr.splice(index, 1);
  169. }
  170. });
  171. this.setData({
  172. dataList: arr
  173. })
  174. }
  175. }
  176. },
  177. bindTextAreaBlur(e) {
  178. this.setData({
  179. textArea: e.detail.value
  180. });
  181. },
  182. confirmBh() {
  183. if (that.data.textArea == '') {
  184. app.globalData.showToast("请输入不通过原因");
  185. return;
  186. }
  187. let noData={
  188. type:'event_check',
  189. action:'disagree',
  190. event_id:that.data.bhItem.id,
  191. comment:that.data.textArea,
  192. }
  193. this.setData({ disabled: true });
  194. this.webSocket(noData)
  195. },
  196. closeBh() {
  197. this.setData({ isBh: false, textArea: '' })
  198. },
  199. openBh(e) {
  200. var item = e.target.dataset.item;
  201. var index = e.target.dataset.index;
  202. if(index=='1'){
  203. let data={
  204. type:'event_check',
  205. action:'agree',
  206. event_id:item.id,
  207. point:item.point
  208. }
  209. this.webSocket(data)
  210. }else{
  211. this.setData({
  212. isBh: true,
  213. bhItem: item
  214. })
  215. }
  216. },
  217. webSocket(data,is) {
  218. let resultList=is? data:[data];
  219. this.setData({
  220. resultList:resultList,
  221. resultIndex: 0,
  222. percentage: 0,
  223. results: [],
  224. isResult:resultList.length!=1,
  225. })
  226. this.opneWebSocket()
  227. },
  228. opneWebSocket() {
  229. let wsData = this.data.resultList;
  230. if (wsData[this.data.resultIndex]) {
  231. setTime = setTimeout(() => {
  232. dd.alert({
  233. title: '温馨提示',
  234. content: '网络异常,请检查网络',
  235. buttonText: '我知道了',
  236. success: () => {
  237. clearTimeout(setTime);
  238. app.globalData.socketApi.closewebsocket();
  239. that.closeTc();
  240. },
  241. });
  242. }, 15000)
  243. app.globalData.socketApi.sendData(wsData[this.data.resultIndex],this.onmessageWS,true);
  244. }
  245. },
  246. onmessageWS(e) {
  247. // 因为作用域问题,这个函数不能使用this
  248. if (e.type == 'event_check') {
  249. clearTimeout(setTime);
  250. if(that.data.resultList.length==1){ //单条
  251. if(e.code==1){
  252. app.globalData.showToast("提交成功");
  253. that.setData({
  254. disabled: false,
  255. isBh: false,
  256. textArea: '',
  257. });
  258. that.refreshData(e.result.task.msg.event_id);
  259. return false;
  260. }else{
  261. that.setData({
  262. disabled: false,
  263. });
  264. app.globalData.showToast(e.msg)
  265. return false;
  266. }
  267. }
  268. let user;
  269. if(e.code==1){
  270. user={
  271. name:e.result.task.msg.name,
  272. point:e.result.task.msg.point,
  273. remark:e.result.task.msg.remark,
  274. pt_id:e.result.task.msg.pt_id,
  275. msg:'提交成功'
  276. }
  277. }else{
  278. user={
  279. name:e.result.task.msg.name,
  280. point:e.result.task.msg.point,
  281. remark:e.result.task.msg.remark,
  282. pt_id:e.result.task.msg.pt_id,
  283. msg:e.msg
  284. }
  285. }
  286. let results=that.data.results
  287. results.push(user);
  288. that.setData({
  289. results: results,
  290. resultIndex: that.data.resultIndex + 1
  291. })
  292. that.opneWebSocket();
  293. // 进度条
  294. let lng = that.data.resultList.length;
  295. that.setData({
  296. percentage: that.data.percentage + Math.floor(100 / lng),
  297. })
  298. if (lng == that.data.results.length) {
  299. that.setData({
  300. percentage: 100,
  301. })
  302. }
  303. }
  304. if (e.type == 'error') {
  305. clearTimeout(setTime);
  306. that.setData({
  307. isShowError: true,
  308. })
  309. }
  310. },
  311. closeTc() {
  312. this.setData({
  313. results: [], //提交的返回结果集合
  314. isResult: false,
  315. percentage: 0,
  316. resultList: [],//要发送数据的集合
  317. resultIndex: 0,
  318. isBh: false,//是否显示驳回弹窗
  319. isShowError: false,
  320. textArea: '',
  321. page: 1,
  322. })
  323. app.globalData.socketApi.closewebsocket();
  324. this.getData();
  325. },
  326. activeItem(e) {
  327. this.setData({
  328. minuteIndex: e.detail.value,
  329. page: 1,
  330. dataList: [],
  331. isPl:false,
  332. })
  333. this.getData();
  334. },
  335. onReset() {
  336. this.setData({
  337. keyword: '',
  338. isVal: false,
  339. page: 1,
  340. })
  341. this.getData();
  342. },
  343. openDetail(e) {
  344. var item = e.target.dataset.item;
  345. if(this.data.isPl){
  346. let dataList = this.data.dataList.map(e => {
  347. if(item.id==e.id){
  348. e.checked = !e.checked;
  349. }
  350. return e;
  351. })
  352. this.setData({
  353. dataList: dataList,
  354. })
  355. return false
  356. }
  357. dd.navigateTo({
  358. url: '../reviewDetail/reviewDetail?id=' + item.id
  359. })
  360. },
  361. getData(type) {
  362. let dc_status=that.data.minuteIndex==0? "[0]":'[1,2]';
  363. if(that.data.minuteIndex=="1"){
  364. if(that.data.arrIndex==0){
  365. dc_status='[1,2]'
  366. }else if(that.data.arrIndex==1){
  367. dc_status='[1]'
  368. }else{
  369. dc_status='[2]'
  370. }
  371. }
  372. let data={
  373. dc_status:dc_status,
  374. page: that.data.page,
  375. order_key:that.data.minuteIndex=='0'? 'create_time':'update_time',
  376. page_size: 20,
  377. keyword: that.data.keyword,
  378. employee_ids:this.data.employee_ids
  379. }
  380. app.$get("api/integral/statistics/integral",data).then((res) => {
  381. var list = res.data.data.list || [];
  382. list.forEach(element => {
  383. element.checked = false
  384. });
  385. if(that.data.page==1){
  386. this.setData({
  387. dataList:[]
  388. })
  389. }
  390. var dataList = that.data.dataList || [];
  391. if (type == '2') {
  392. this.setData({
  393. dataList: dataList.concat(list),
  394. isData: list.length < 20
  395. })
  396. } else {
  397. this.setData({ dataList: list, isData: false })
  398. }
  399. })
  400. },
  401. //上啦加载
  402. onScrollToLower() {
  403. if (!that.data.isData) {
  404. this.setData({ page: ++that.data.page })
  405. this.getData("2");
  406. }
  407. },
  408. });