grantAward.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. var app = getApp()
  2. var that;
  3. var typeArr = [];
  4. import { _debounce } from '../../../utils/util'
  5. Page({
  6. data: {
  7. date: app.globalData.month,
  8. minuteIndex: 2,//条件选择
  9. minuteArray: [
  10. { id: -1, name: '全部' },
  11. { id: 1, name: '已发放' },
  12. { id: 0, name: '未发放' },
  13. ],
  14. showDate: false,//是否显示时间组件
  15. selectDateVal: '本月',
  16. showStaff: false,//显示员工选择
  17. staffVal: '员工',
  18. types: [
  19. { id: 0, name: '全部事件' },
  20. { id: 1, name: '我奖扣的' },
  21. ],
  22. typesIndex: '0',
  23. showRuleTwo: false,
  24. page: 1,
  25. popupCx: '',
  26. isAll:true,
  27. isShowYy:false,
  28. },
  29. onLoad(e) {
  30. that = this;
  31. dd.setNavigationBar({ title: "发放奖票" });
  32. let isShowYy=false;
  33. app.globalData.userData.employee_detail.role_list.forEach(item=>{
  34. if(item.name=='admin'||item.name=='creator'|| item.name == 'point_manager'){
  35. isShowYy=true;
  36. }
  37. })
  38. this.setData({
  39. isShowYy:isShowYy,
  40. })
  41. },
  42. onShow() {
  43. typeArr = [{ id: 0, name: '全部' }];
  44. if (app.globalData.userData) {
  45. if (that.data.page == 1) {
  46. that.getData();
  47. }
  48. } else {
  49. app.login(app.globalData.corpId, function (is) {
  50. if (that.data.page == 1) {
  51. that.getData();
  52. }
  53. }, function () { })
  54. }
  55. },
  56. selectAll(e){
  57. let list=this.data.list
  58. list.map((item) => {
  59. if(!item.has_ticket){
  60. item.checked=this.data.isAll;
  61. }
  62. })
  63. this.setData({
  64. list:list,
  65. isAll:!this.data.isAll
  66. })
  67. },
  68. //提交
  69. sumbit(){
  70. let list=this.data.list
  71. let selectId=[];
  72. list.map((item) => {
  73. if(item.checked){
  74. selectId.push(item.id)
  75. }
  76. })
  77. if(selectId.length==0){
  78. app.globalData.showToast("请选择需要发放奖票的事件");
  79. return false
  80. }
  81. dd.confirm({
  82. title: '提示',
  83. content: '你确定发放奖票吗?',
  84. confirmButtonText: '确定',
  85. cancelButtonText: '取消',
  86. success: (result) => {
  87. if (result.confirm) {
  88. app.$post('api/integral/ticket/create',{event_ids:selectId.toString()},'application/vnd.test.v2+json').then((res) => {
  89. app.globalData.showToast("已发放");
  90. that.setData({ page: 1 })
  91. this.getData();
  92. })
  93. }
  94. },
  95. });
  96. },
  97. onChange(e) {
  98. let id=e.target.dataset.item.id;
  99. let list=this.data.list
  100. list.map((item) => {
  101. if(item.id==id){
  102. item.checked=e.detail.value;
  103. }
  104. })
  105. this.setData({
  106. list:list
  107. })
  108. },
  109. bingStatus(e){
  110. this.setData({
  111. minuteIndex: e.detail.value,
  112. page: 1,
  113. });
  114. this.getData();
  115. },
  116. bingIntegralType(e) {
  117. this.setData({
  118. typesIndex: e.detail.value,
  119. page: 1,
  120. });
  121. this.getData();
  122. },
  123. onReset() {
  124. this.setData({
  125. page: 1,
  126. isVal: false,
  127. keyword: ''
  128. })
  129. this.getData();
  130. },
  131. bindKeyInput:_debounce(function(e){
  132. this.setData({
  133. page: 1,
  134. isVal: e.detail.value ? true : false,
  135. keyword: e.detail.value ? e.detail.value : '',
  136. })
  137. this.getData();
  138. }),
  139. getData(is) {
  140. var data = {
  141. page: that.data.page,
  142. page_size: 20,
  143. employee_ids: that.data.employee_ids,
  144. dc_status: JSON.stringify([1]),
  145. keyword:this.data.keyword,
  146. add_subtract:1,
  147. has_ticket:this.data.minuteArray[this.data.minuteIndex].id
  148. }
  149. if (that.data.date_type == 2) {
  150. data.start_day = that.data.dateObj[0];
  151. data.end_day = that.data.dateObj[1];
  152. } else {
  153. data.month = that.data.dateObj || that.data.date;
  154. }
  155. if(this.data.isShowYy){
  156. if(this.data.typesIndex==1){
  157. data.recorder_id=app.globalData.userData.id
  158. }
  159. }else{
  160. data.recorder_id=app.globalData.userData.id
  161. }
  162. app.$get('api/integral/statistics/integral', data).then((res) => {
  163. var data = res.data.data.list;
  164. data.map((item) => {
  165. item.ptObj = app.getTypesItem(item.pt_id);
  166. item.checked=false;
  167. })
  168. if (is) {
  169. if (data.length == 0) {
  170. this.setData({
  171. isData: true
  172. })
  173. return;
  174. }
  175. var list = that.data.list;
  176. this.setData({
  177. list: list.concat(data)
  178. })
  179. } else {
  180. this.setData({ list: [] });
  181. this.setData({
  182. list: data,
  183. isData: false
  184. })
  185. }
  186. })
  187. },
  188. //上啦加载
  189. onScrollToLower() {
  190. if (!that.data.isData) {
  191. this.setData({ page: ++that.data.page })
  192. this.getData(true);
  193. }
  194. },
  195. //打开兴趣
  196. openDetail(e) {
  197. var item = e.target.dataset.item;
  198. dd.navigateTo({
  199. url: '../prizeBuckleDetail/prizeBuckleDetail?id=' + item.id+'&is=true'
  200. })
  201. },
  202. //显示选择时间组件
  203. selectDate() {
  204. this.setData({
  205. popupCx: 'container__mask',
  206. showDate: true
  207. })
  208. },
  209. //显示选择员工
  210. selectStaff() {
  211. this.setData({
  212. popupCx: 'container__mask',
  213. showStaff: true
  214. })
  215. },
  216. //选择时间
  217. onConfirmDate(data) {
  218. that.setData({
  219. defaultDate: data,
  220. dateObj: data.date,
  221. date_type: data.type == 1 ? 3 : data.type,
  222. page: 1,
  223. selectDateVal: data.type == 1 ? (data.date == that.data.date ? '本月' : '月') : '日',
  224. })
  225. this.getData();
  226. },
  227. //关闭弹窗
  228. onClose() {
  229. this.setData({
  230. showDate: false,
  231. showStaff: false,
  232. popupCx: '',
  233. })
  234. },
  235. //选择员工
  236. onConfirmStaff(data) {
  237. if (!data) {
  238. this.setData({ staffVal: '员工', employee_ids: '', page: 1 })
  239. this.getData();
  240. return false;
  241. }
  242. if (data.length > 0) {
  243. if (data.length > 1) {
  244. var str = "";
  245. var arr = [];
  246. data.forEach((item) => {
  247. str += item.name + ','
  248. arr.push(item.id);
  249. })
  250. var employee_ids = arr.join(',');
  251. this.setData({ staffVal: str.substring(0, str.length - 1), employee_ids: employee_ids, page: 1 })
  252. } else {
  253. this.setData({ staffVal: data[0].name, employee_ids: [data[0].id], page: 1 })
  254. }
  255. } else {
  256. this.setData({ staffVal: '员工', employee_ids: [], page: 1 })
  257. }
  258. this.getData();
  259. },
  260. });