review.js 11 KB

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