clerk.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view class="clerk-page">
  3. <view scroll-y class="class-list">
  4. <view class="item" v-for="item in clerks" :key="item.storeUserId">
  5. <view class="row">
  6. <view class="name">{{ item.userName }}</view>
  7. <u-icon name="trash" size="26" color="#6c6c6c" @click="handItemRemove(item)"></u-icon>
  8. </view>
  9. <view class="row">
  10. <view class="phone">登录手机号: {{ item.tel }}</view>
  11. <u-icon name="edit-pen" size="26" color="#6c6c6c" @click="handItemEdit(item)"></u-icon>
  12. </view>
  13. </view>
  14. </view>
  15. <view class="add-clerk" @click="addCleak">
  16. 添加店员
  17. </view>
  18. <u-modal :show="deleteVisible" :title="modalTitle" closeOnClickOverlay showCancelButton confirmColor="#d64d3b"
  19. @confirm="handDelete" @cancel="cancelDelete" @close="deleteVisible = false">
  20. </u-modal>
  21. <u-modal :show="formVisible" :title="modalTitle" closeOnClickOverlay showCancelButton @confirm="handAdd"
  22. @cancel="cancelAdd" @close="closeAdd">
  23. <view class="container">
  24. <view class="name">
  25. <u-input border v-model="formItem.userName" placeholder="请输入店员姓名"></u-input>
  26. </view>
  27. <view class="phone">
  28. <u-input border v-model="formItem.tel" placeholder="请输入店员手机号"></u-input>
  29. </view>
  30. </view>
  31. </u-modal>
  32. </view>
  33. </template>
  34. <script>
  35. import { mapState } from 'vuex';
  36. export default {
  37. data() {
  38. return {
  39. clerkUrl: '/storeClerkManageApi/getStoreClerkList',
  40. updateUrl: '/storeClerkManageApi/update',
  41. deleteUrl: '/storeClerkManageApi/delete',
  42. getOneUrl: '/storeClerkManageApi/getStoreClerkById',
  43. modalTitle: '',
  44. deleteVisible: false,
  45. delItem: null,
  46. formItem: {
  47. storeUserId: '',
  48. userName: '',
  49. tel: ''
  50. },
  51. formVisible: '',
  52. clerks: [],
  53. triggered: false
  54. }
  55. },
  56. computed: {
  57. ...mapState(['storeInfo'])
  58. },
  59. methods: {
  60. loadData() {
  61. uni.showLoading({
  62. title: '加载中'
  63. })
  64. var dateStr = (new Date()).getTime();
  65. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  66. this.requst({
  67. url: this.clerkUrl,
  68. data: {
  69. timestamp: dateStr,
  70. sign: sign,
  71. storeId: this.storeInfo.storeId,
  72. storeUserId: this.storeInfo.storeUserId
  73. },
  74. success: res => {
  75. if (res.data.rtnBean.rtnCode == 0) {
  76. this.clerks = res.data.list;
  77. }
  78. uni.stopPullDownRefresh()
  79. uni.hideLoading()
  80. },
  81. fail: (e) => {
  82. console.log("接口调用失败:" + JSON.stringify(e));
  83. uni.stopPullDownRefresh()
  84. uni.hideLoading()
  85. }
  86. })
  87. },
  88. closeAdd () {
  89. this.formVisible = false
  90. this.formItem = {
  91. storeUserId: '',
  92. userName: '',
  93. tel: ''
  94. }
  95. },
  96. onPullDownRefresh() {
  97. this.loadData();
  98. },
  99. cancelAdd () {
  100. this.formVisible = false
  101. this.formItem = {
  102. storeUserId: '',
  103. userName: '',
  104. tel: ''
  105. }
  106. },
  107. onRestore () {
  108. this.triggered = 'restore'; // 需要重置
  109. console.log("onRestore");
  110. },
  111. getClerk(id) {
  112. uni.showLoading({
  113. title: '加载中'
  114. })
  115. var dateStr = (new Date()).getTime();
  116. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  117. this.requst({
  118. url: this.getOneUrl,
  119. data: {
  120. timestamp: dateStr,
  121. sign: sign,
  122. storeId: this.storeInfo.storeId,
  123. storeUserId: this.storeInfo.storeUserId,
  124. id: id
  125. },
  126. success: res => {
  127. if (res.data.rtnBean.rtnCode == 0) {
  128. this.formItem = res.data.obj;
  129. this.modalTitle = '添加/编辑店员'
  130. this.formVisible = true;
  131. }
  132. uni.hideLoading()
  133. },
  134. fail: (e) => {
  135. console.log("接口调用失败:" + JSON.stringify(e));
  136. uni.hideLoading()
  137. }
  138. })
  139. },
  140. close() {
  141. this.deleteVisible = false
  142. },
  143. handItemRemove(item) {
  144. this.modalTitle = `确定要删除店员 [${item.userName}] 吗?`
  145. this.delItem = item
  146. this.deleteVisible = true
  147. },
  148. handDelete() {
  149. uni.showLoading({
  150. title: '加载中'
  151. })
  152. var dateStr = (new Date()).getTime();
  153. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  154. this.requst({
  155. url: this.deleteUrl,
  156. data: {
  157. storeUserId: this.storeInfo.storeUserId,
  158. storeId: this.storeInfo.storeId,
  159. timestamp: dateStr,
  160. sign: sign,
  161. id: this.delItem.storeUserId
  162. },
  163. success: res => {
  164. if (res.data.rtnBean.rtnCode == 0) {
  165. this.delItem = null
  166. this.modalTitle = ''
  167. this.deleteVisible = false
  168. this.loadData();
  169. } else {
  170. if (res.data.rtnBean.rtnMsg != '') {
  171. this.$api.msg(res.data.rtnBean.rtnMsg);
  172. }
  173. }
  174. uni.hideLoading()
  175. },
  176. fail: (e) => {
  177. console.log("接口调用失败:" + JSON.stringify(e));
  178. uni.hideLoading()
  179. },
  180. });
  181. },
  182. cancelDelete() {
  183. this.delItem = null
  184. this.modalTitle = ''
  185. this.deleteVisible = false
  186. },
  187. handItemEdit(item) {
  188. console.log('item :>> ', item);
  189. // this.formItem = item
  190. this.getClerk(item.storeUserId)
  191. },
  192. refresherrefresh() {
  193. uni.showLoading({
  194. title: '加载中'
  195. })
  196. var dateStr = (new Date()).getTime();
  197. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  198. this.requst({
  199. url: this.clerkUrl,
  200. data: {
  201. timestamp: dateStr,
  202. sign: sign,
  203. storeId: this.storeInfo.storeId,
  204. storeUserId: this.storeInfo.storeUserId
  205. },
  206. success: res => {
  207. this.triggered = false;
  208. if (res.data.rtnBean.rtnCode == 0) {
  209. this.clerks = res.data.list;
  210. }
  211. uni.hideLoading()
  212. },
  213. fail: (e) => {
  214. console.log("接口调用失败:" + JSON.stringify(e));
  215. this.triggered = false;
  216. uni.hideLoading()
  217. }
  218. })
  219. },
  220. addCleak() {
  221. this.modalTitle = '添加/编辑店员'
  222. this.formVisible = true
  223. },
  224. handAdd() {
  225. let reg = /^[1][3,4,5,7,8,9][0-9]{9}$/
  226. if (!this.formItem.userName) {
  227. uni.showToast({
  228. title: '请输入店员姓名',
  229. icon: 'none'
  230. })
  231. return
  232. }
  233. if (!this.formItem.tel) {
  234. uni.showToast({
  235. title: '请输入店员手机号码',
  236. icon: 'none'
  237. })
  238. return
  239. }
  240. if (!reg.test(this.formItem.tel)) {
  241. uni.showToast({
  242. title: '请输入正确的手机号',
  243. icon: 'none'
  244. })
  245. return
  246. }
  247. uni.showLoading({
  248. title: '保存中'
  249. })
  250. var dateStr = (new Date()).getTime();
  251. var sign = this.getSign('' + this.storeInfo.storeUserId + dateStr);
  252. this.requst({
  253. url: this.updateUrl,
  254. data: {
  255. timestamp: dateStr,
  256. sign: sign,
  257. storeId: this.storeInfo.storeId,
  258. id: this.storeInfo.storeUserId,
  259. storeUserId: this.formItem.storeUserId,
  260. userName: this.formItem.userName,
  261. tel: this.formItem.tel
  262. },
  263. success: res => {
  264. if (res.data.rtnBean.rtnCode == 0) {
  265. uni.hideLoading()
  266. this.formVisible = false
  267. this.formItem = {
  268. storeUserId: '',
  269. userName: '',
  270. tel: ''
  271. }
  272. this.loadData()
  273. this.modalVisible = false
  274. } else {
  275. uni.hideLoading()
  276. if (res.data.rtnBean.rtnMsg != '') {
  277. this.$api.msg(res.data.rtnBean.rtnMsg);
  278. }
  279. }
  280. },
  281. fail: (e) => {
  282. console.log("接口调用失败:" + JSON.stringify(e));
  283. uni.hideLoading()
  284. }
  285. })
  286. }
  287. },
  288. onLoad() {
  289. this.loadData();
  290. }
  291. }
  292. </script>
  293. <style lang="scss" scoped>
  294. .clerk-page {
  295. width: 100vw;
  296. height: 100vh;
  297. background-color: #fff;
  298. }
  299. .class-list {
  300. height: calc(100vh - 120rpx - env(safe-area-inset-bottom));
  301. height: calc(100vh - 120rpx - constant(safe-area-inset-bottom));
  302. .item {
  303. background-color: #fff;
  304. margin-bottom: 20rpx;
  305. border-radius: 10rpx;
  306. padding: 20rpx;
  307. display: flex;
  308. flex-direction: column;
  309. .row {
  310. @include between;
  311. margin-bottom: 20rpx;
  312. color: $text-color;
  313. }
  314. .name {
  315. font-size: 36rpx;
  316. }
  317. .phone {
  318. font-size: $font-lg;
  319. }
  320. }
  321. }
  322. .add-clerk {
  323. position: fixed;
  324. left: 10vw;
  325. width: 80vw;
  326. height: 80rpx;
  327. border-radius: 40rpx;
  328. @include flexCenter;
  329. color: #fff;
  330. background-color: $light-color;
  331. bottom: calc(20rpx + env(safe-area-inset-bottom));
  332. bottom: calc(20rpx + constant(safe-area-inset-bottom));
  333. }
  334. .container {
  335. .name, .phone {
  336. margin: 40rpx 0;
  337. border: 2rpx solid #ececec;
  338. border-radius: 6rpx;
  339. }
  340. }
  341. </style>