index.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. const app = getApp();
  2. const verify = require("../../../common/js/verify.js");
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. admin_id: 0,
  9. keyword: ['', '', '', ''],
  10. tab: 0,
  11. is_first: [true, true, true, true],
  12. list: [
  13. [],
  14. [],
  15. [],
  16. []
  17. ],
  18. no_more: [false, false, false, false],
  19. page: [1, 1, 1, 1],
  20. custombar: app.globalData.CustomBar,
  21. nav_top: 0,
  22. nav_fixed: false,
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad(options) {
  28. const admin_id = wx.getStorageSync('admin_id');
  29. if (verify.isEmpty(admin_id)) {
  30. wx.redirectTo({
  31. url: '/pages/talent/admin/login',
  32. })
  33. }
  34. this.setData({
  35. admin_id: admin_id
  36. });
  37. this.getList();
  38. },
  39. //tab切换
  40. tabSelect(e) {
  41. let tab = e.currentTarget.dataset.tab;
  42. this.setData({
  43. tab: tab
  44. });
  45. let is_first = this.data.is_first;
  46. if (is_first[tab]) {
  47. is_first[tab] = false;
  48. this.setData({
  49. is_first: is_first
  50. });
  51. this.getList();
  52. }
  53. },
  54. //搜索
  55. bindInput(e) {
  56. let keyword = this.data.keyword;
  57. keyword[this.data.tab] = e.detail.value;
  58. this.setData({
  59. keyword: keyword
  60. });
  61. },
  62. bindSearch() {
  63. this.resetParam();
  64. this.getList();
  65. },
  66. //获取数据
  67. getList() {
  68. let self = this;
  69. let tab = this.data.tab;
  70. let no_more = this.data.no_more;
  71. //没有下一页
  72. if (no_more[tab]) {
  73. return false;
  74. }
  75. //获取数据
  76. app.post('talent/admin/lists', {
  77. status: +tab + 1,
  78. page: self.data.page[tab],
  79. keyword: self.data.keyword[tab],
  80. }, function (res) {
  81. if (res.length < 10) {
  82. no_more[tab] = true;
  83. self.setData({
  84. no_more: no_more
  85. });
  86. }
  87. let list = self.data.list;
  88. list[tab] = list[tab].concat(res);
  89. let page = self.data.page;
  90. page[tab]++;
  91. self.setData({
  92. list: list,
  93. page: page
  94. });
  95. })
  96. },
  97. //重置参数
  98. resetParam() {
  99. let tab = this.data.tab;
  100. let list = this.data.list;
  101. list[tab] = [];
  102. let no_more = this.data.no_more;
  103. no_more[tab] = false;
  104. let page = this.data.page;
  105. page[tab] = 1;
  106. this.setData({
  107. list: list,
  108. no_more: no_more,
  109. page: page
  110. });
  111. },
  112. resetKeyword() {
  113. let keyword = this.data.keyword;
  114. keyword[this.data.tab] = '';
  115. this.setData({
  116. keyword: keyword
  117. });
  118. },
  119. //滚动事件
  120. onPageScroll(e) {
  121. if (e.scrollTop >= this.data.nav_top) {
  122. if (!this.data.nav_fixed) {
  123. this.setData({
  124. nav_fixed: true
  125. });
  126. }
  127. } else {
  128. if (this.data.nav_fixed) {
  129. this.setData({
  130. nav_fixed: false
  131. });
  132. }
  133. }
  134. },
  135. /**
  136. * 页面相关事件处理函数--监听用户下拉动作
  137. */
  138. onPullDownRefresh: function () {
  139. this.resetParam();
  140. this.resetKeyword();
  141. this.getList();
  142. wx.stopPullDownRefresh();
  143. },
  144. /**
  145. * 页面上拉触底事件的处理函数
  146. */
  147. onReachBottom: function () {
  148. this.getList();
  149. },
  150. logout() {
  151. wx.removeStorageSync('admin_id');
  152. wx.redirectTo({
  153. url: '/pages/talent/admin/login',
  154. })
  155. },
  156. scan() {
  157. const admin_id = this.data.admin_id;
  158. const self = this;
  159. wx.scanCode({
  160. success({
  161. result
  162. }) {
  163. app.post('talent/admin/scan', {
  164. code: result,
  165. admin_id: admin_id
  166. }, function (res) {
  167. app.confirm(`接站成功,姓名:${res.talent.name},班次:${res.appointment.shift},出行时间:${res.appointment.start_time}`, function () {
  168. self.resetParam();
  169. self.getList();
  170. });
  171. });
  172. },
  173. fail(res) {
  174. if (res.errMsg != "scanCode:fail cancel") {
  175. app.msg('扫码错误,请重新扫码!');
  176. }
  177. }
  178. });
  179. },
  180. confirmInfo(e) {
  181. const id = e.currentTarget.dataset.id;
  182. const self = this;
  183. app.confirm('是否确认信息', function () {
  184. app.post('talent/admin/confirm', {
  185. id: id,
  186. admin_id: self.data.admin_id
  187. }, function () {
  188. app.msg('操作成功');
  189. self.resetParam();
  190. self.getList();
  191. });
  192. })
  193. },
  194. applyByMobile(e) {
  195. const self = this;
  196. const id = e.currentTarget.dataset.id;
  197. wx.showModal({
  198. title: '请输入手机号',
  199. editable: true,
  200. placeholderText: '请输入手机号',
  201. success: (res) => {
  202. app.post('talent/admin/applyByMobile', {
  203. id: id,
  204. admin_id: self.data.admin_id,
  205. mobile: res.content
  206. }, function () {
  207. app.msg('操作成功');
  208. self.resetParam();
  209. self.getList();
  210. });
  211. }
  212. })
  213. },
  214. //拔打电话
  215. callMobile(e){
  216. let mobile = e.currentTarget.dataset.mobile;
  217. if (mobile == '') {
  218. app.msg('暂无联系方式!');
  219. return false;
  220. }
  221. wx.makePhoneCall({
  222. phoneNumber: mobile
  223. })
  224. },
  225. ViewImage(e) {
  226. wx.previewImage({
  227. urls: [e.currentTarget.dataset.url],
  228. });
  229. },
  230. })