staffManage.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  1. // pages/welfareMall/staffManage/staffManage.js
  2. import WelfareMall from '../../../api/welfareMall'
  3. import { parseTime } from '../../../utils/util'
  4. import {getMobileCache, getPhoneNumber as getPhoneNumberSync} from '../../../utils/user'
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. isLogin: false,
  11. lock: false,
  12. noResult: false,
  13. noMore: false,
  14. hidden: true,
  15. mobileTop: 'TONY WU',
  16. storeStaffList: [],
  17. storeInfo: '',
  18. storeName: '',
  19. storeNo: '',
  20. storePhone: '',
  21. inputName: '',
  22. inputPhone: '',
  23. ajxtrue: false,
  24. },
  25. /**
  26. * 生命周期函数--监听页面加载
  27. */
  28. onLoad: function (options) {
  29. wx.hideShareMenu();
  30. },
  31. /**
  32. * 生命周期函数--监听页面初次渲染完成
  33. */
  34. onReady: function () {
  35. },
  36. /**
  37. * 生命周期函数--监听页面显示
  38. */
  39. onShow: function () {
  40. this.setData({
  41. isLogin: getMobileCache() != ''
  42. })
  43. if(this.data.isLogin){
  44. this.getStoreStaffList();
  45. } else {
  46. wx.switchTab({
  47. url:"/pages/welfareMall/personal/personal",
  48. })
  49. }
  50. },
  51. /**
  52. * 生命周期函数--监听页面隐藏
  53. */
  54. onHide: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面卸载
  58. */
  59. onUnload: function () {
  60. },
  61. /**
  62. * 页面相关事件处理函数--监听用户下拉动作
  63. */
  64. onPullDownRefresh: function () {
  65. },
  66. /**
  67. * 页面上拉触底事件的处理函数
  68. */
  69. onReachBottom: function () {
  70. },
  71. /**
  72. * 用户点击右上角分享
  73. */
  74. onShareAppMessage: function () {
  75. },
  76. // 根据登录手机号获取职员列表
  77. getStoreStaffList: function() {
  78. WelfareMall.getStoreStaffList({
  79. mobile: getMobileCache(),
  80. }).then(res => {
  81. if (res.code == 200) {
  82. this.userStoreStaffListView(res.data)
  83. }
  84. this.data.lock = false
  85. }).catch(_ => {
  86. console.log(_)
  87. this.data.lock = false
  88. })
  89. },
  90. userStoreStaffListView: function(data) {
  91. if (!Array.isArray(data) || data.length == 0) {
  92. console.log("职员列表数据为空");
  93. if (this.data.page == 1) {
  94. this.setData({
  95. mobileTop:getMobileCache(),
  96. noResult: true
  97. })
  98. } else {
  99. this.setData({
  100. mobileTop:getMobileCache(),
  101. noMore: true
  102. })
  103. }
  104. return
  105. }
  106. this.data.storeStaffList = data
  107. this.setData({
  108. mobileTop:getMobileCache(),
  109. storeStaffList: this.data.storeStaffList
  110. })
  111. },
  112. /**
  113. * 新增店员
  114. */
  115. toStaffAdd: function(e){
  116. this.setData({
  117. hidden: false,
  118. storeValue: e.currentTarget.dataset.storename,
  119. storeNo: e.currentTarget.dataset.storeno,
  120. storeName: '',
  121. storePhone: '',
  122. });
  123. },
  124. /**
  125. * 取消
  126. */
  127. cancel: function(){
  128. this.setData({
  129. hidden: true,
  130. storeName: '',
  131. storePhone: '',
  132. inputName: '',
  133. inputPhone: '',
  134. });
  135. },
  136. /**
  137. * 提交
  138. */
  139. confirm: function(){
  140. let that = this
  141. var resName = this.data.inputName;
  142. var resPhone = this.data.inputPhone;
  143. if(resName == null || resName =='' || resName == undefined){
  144. wx.showToast({
  145. title: '店员名字必填',
  146. icon: 'none',
  147. duration: 1500
  148. })
  149. }else if(resPhone == null || resPhone =='' || resPhone == undefined){
  150. wx.showToast({
  151. title: '店员手机号码必填',
  152. icon: 'none',
  153. duration: 1500
  154. })
  155. } else if (!this.data.ajxtrue) {
  156. wx.showToast({
  157. title: '手机号有误,请重新输入',
  158. icon: 'none',
  159. duration: 1500
  160. })
  161. } else {
  162. this.setData({
  163. hidden: true
  164. });
  165. wx.showToast({
  166. title: '新增店员已提交',
  167. icon: 'none',
  168. duration: 1500,
  169. success: function(){
  170. that.goAddStaff(resName,resPhone);
  171. }
  172. });
  173. }
  174. },
  175. /**
  176. * 店员名称
  177. */
  178. getName: function(e){
  179. this.setData({
  180. inputName: e.detail.value
  181. })
  182. },
  183. /**
  184. * 店员手机号
  185. */
  186. getPhone: function(e){
  187. var phone = e.detail.value;
  188. if (!(/^1[3456789]\d{9}$/.test(phone))) {
  189. this.setData({
  190. ajxtrue: false,
  191. inputPhone: e.detail.value
  192. })
  193. } else {
  194. this.setData({
  195. ajxtrue: true,
  196. inputPhone: e.detail.value
  197. })
  198. }
  199. },
  200. /**
  201. *
  202. * 提交人员信息
  203. */
  204. goAddStaff: async function(resName,resPhone) {
  205. var that = this;
  206. await WelfareMall.addStoreStaff({
  207. storeNo: that.data.storeNo,
  208. staffName: resName,
  209. staffMobile: resPhone,
  210. }).then(res => {
  211. if (res.code == 200) {
  212. that.cancel();
  213. that.getStoreStaffList();
  214. }
  215. }).catch(_ => {
  216. console.log(_)
  217. });
  218. },
  219. /**
  220. *
  221. * 删除人员信息
  222. */
  223. toDelete: function(e) {
  224. let staffId = e.currentTarget.dataset.id;
  225. let that = this
  226. wx.showModal({
  227. title: '删除员工',
  228. content: '',
  229. showCancel: true,//是否显示取消按钮
  230. cancelText:"取消",//默认是“取消”
  231. cancelColor:'#00000',//取消文字的颜色
  232. confirmText:"确定",//默认是“确定”
  233. confirmColor: '#00000',//确定文字的颜色
  234. success: res => {if (res.cancel) {
  235. //点击取消,默认隐藏弹框
  236. } else {
  237. //点击确定
  238. WelfareMall.delStoreStaff({
  239. mobile: getMobileCache(),
  240. staffId: staffId,
  241. }).then(res => {
  242. if (res.code == 200) {
  243. that.cancel();
  244. wx.showToast({
  245. title: '员工已删除',
  246. icon: 'none',
  247. duration: 1500,
  248. success: function(){
  249. that.getStoreStaffList();
  250. }
  251. });
  252. }
  253. that.data.lock = false
  254. }).catch(_ => {
  255. console.log(_)
  256. that.data.lock = false
  257. })
  258. }
  259. },
  260. fail: function (res) {
  261. console.log(res)
  262. },//接口调用失败的回调函数
  263. })
  264. },
  265. })