index.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. export default {
  2. data() {
  3. return {
  4. activeStyle: {},
  5. active: 0,
  6. weeks: [],
  7. status: [],
  8. length: 0, //周
  9. //预约记录操作
  10. operation: {
  11. arrived_store: [{
  12. title: '确认完成',
  13. event: 'complet'
  14. }],
  15. wait_confirm: [{
  16. title: '确认预约',
  17. event: 'confirm'
  18. },
  19. {
  20. title: '更改预约',
  21. event: 'update'
  22. },
  23. {
  24. title: '取消预约',
  25. event: 'cancel'
  26. }
  27. ],
  28. wait_to_store: [{
  29. title: '确认到店',
  30. event: 'tostore'
  31. },
  32. {
  33. title: '取消预约',
  34. event: 'cancel'
  35. }
  36. ]
  37. },
  38. yuYueTime: [], //预约时间段
  39. yuYueConfig: {},
  40. yuYueData: {
  41. time: '', //时间
  42. date: '', //日期
  43. member_id: '',
  44. member: {},
  45. // store_id:'',
  46. goods: [],
  47. desc: '',
  48. reserve_id: 0
  49. },
  50. searchMobile: '',
  51. flag: false,
  52. yuYueDetail: null,
  53. weekDate: {
  54. start: '-',
  55. end: '-'
  56. },
  57. week: ['周日', '周一', '周二', '周三', '周四', '周五', '周六'],
  58. current: '',
  59. yuYueDateType: 'week',
  60. goodsList: [],
  61. allServicerList: [], //所有的员工
  62. servicerList: [], //所有的员工
  63. yuyueList: [],
  64. yuyuePage: 1,
  65. yuyueSearchText: '',
  66. reserveId: 0,
  67. yuyueInfo: null,
  68. toDay: '', // 今天日期
  69. };
  70. },
  71. onLoad() {
  72. uni.hideTabBar();
  73. this.init();
  74. },
  75. onReady() {
  76. this.tabActive('tab');
  77. },
  78. methods: {
  79. init() {
  80. this.weeks = [];
  81. this.getYuyueStatus(); // 预约状态
  82. this.getYuyueConfig(); // 预约配置
  83. this.getGoodsList(); // 预约项目列表
  84. this.getServicerList(); // 员工列表
  85. this.getWeekReserve(); // 预约看板/周
  86. this.getYuyueList(); // 预约记录列表
  87. let date = new Date();
  88. var y = date.getFullYear();
  89. var m = date.getMonth() + 1;
  90. var d = date.getDate();
  91. this.toDay = y + '-' + m + '-' + d;
  92. },
  93. tabActive(id) {
  94. const query = uni.createSelectorQuery().in(this);
  95. var tab;
  96. query.select('#' + id).boundingClientRect(data => {
  97. tab = data;
  98. });
  99. query
  100. .select('#' + id + ' .active-bar .text')
  101. .boundingClientRect(data => {
  102. this.activeStyle = {
  103. width: data.width + 'px',
  104. transform: 'translateX(' + (data.left - tab.left) + 'px)'
  105. };
  106. })
  107. .exec();
  108. },
  109. switchTab(value) {
  110. this.active = value;
  111. this.$nextTick(() => {
  112. this.tabActive('tab');
  113. });
  114. },
  115. swiperChange(e) {
  116. this.active = e.detail.current;
  117. this.$nextTick(() => {
  118. this.tabActive('tab');
  119. });
  120. },
  121. // 预约状态
  122. getYuyueStatus() {
  123. this.$api.sendRequest({
  124. url: '/store/storeapi/reserve/status',
  125. success: res => {
  126. if (res.code >= 0) {
  127. this.status = res.data;
  128. }
  129. }
  130. });
  131. },
  132. // 预约配置
  133. getYuyueConfig() {
  134. this.$api.sendRequest({
  135. url: '/store/storeapi/reserve/getConfig',
  136. success: res => {
  137. if (res.code >= 0) {
  138. this.yuYueConfig = res.data;
  139. }
  140. }
  141. });
  142. },
  143. // ******************** 预约看板 ********************
  144. // 查询预约记录(每周)
  145. getWeekReserve() {
  146. if (this.flag) return;
  147. this.flag = true;
  148. this.$api.sendRequest({
  149. url: '/store/storeapi/reserve/getweekday',
  150. data: {
  151. length: this.length
  152. },
  153. success: res => {
  154. if (res.code >= 0) {
  155. this.weeks = res.data;
  156. this.$refs.loading.hide();
  157. this.weekDate.start = this.$util.timeFormat(this.weeks[0].start, 'y-m-d');
  158. this.weekDate.end = this.$util.timeFormat(this.weeks[this.weeks.length - 1].end,
  159. 'y-m-d');
  160. for (let i in this.weeks) {
  161. this.getReserve(i);
  162. if (i == this.weeks.length - 1) {
  163. setTimeout(() => {
  164. this.flag = false;
  165. }, 500);
  166. }
  167. }
  168. }
  169. this.flag = false;
  170. }
  171. });
  172. },
  173. //获取预约分页数据
  174. getReserve(index) {
  175. let currentWeek = this.weeks[index];
  176. if (!currentWeek.page) currentWeek.page = 1;
  177. this.$api.sendRequest({
  178. url: '/store/storeapi/reserve/lists',
  179. data: {
  180. page: currentWeek.page,
  181. start: currentWeek.start,
  182. end: currentWeek.end
  183. },
  184. success: res => {
  185. if (res.code >= 0) {
  186. let data = res.data;
  187. if (currentWeek.page == 1) {
  188. currentWeek.data = {
  189. list: [],
  190. page_count: data.page_count,
  191. count: data.count
  192. };
  193. currentWeek.data['list'] = data.list;
  194. } else {
  195. currentWeek.data['list'] = currentWeek.data['list'].concat(data.list);
  196. }
  197. if (data.page_count >= currentWeek.page) currentWeek.page++;
  198. this.$forceUpdate();
  199. }
  200. }
  201. });
  202. },
  203. //上一周
  204. prevWeek() {
  205. this.$refs.loading.show();
  206. --this.length;
  207. this.getWeekReserve();
  208. },
  209. //下一周
  210. nextWeek() {
  211. this.$refs.loading.show();
  212. ++this.length;
  213. this.getWeekReserve();
  214. },
  215. // ******************** 添加/编辑预约 ********************
  216. // 查询预约项目列表
  217. getGoodsList() {
  218. this.$api.sendRequest({
  219. url: '/store/storeapi/reserve/servicelist',
  220. data: {
  221. page: 1,
  222. page_size: 0
  223. },
  224. success: res => {
  225. if (res.code >= 0) {
  226. this.goodsList = res.data.list;
  227. }
  228. }
  229. });
  230. },
  231. // 查询员工列表
  232. getServicerList() {
  233. this.$api.sendRequest({
  234. url: '/store/storeapi/reserve/servicer',
  235. success: res => {
  236. if (res.code >= 0) {
  237. this.allServicerList = res.data;
  238. }
  239. }
  240. });
  241. },
  242. //添加预约
  243. addYuyue() {
  244. this.yuYueData = {
  245. reserve_id: 0,
  246. member_id: '',
  247. member: {},
  248. time: '', //时间
  249. date: this.toDay, //日期
  250. goods: [{}],
  251. desc: '',
  252. };
  253. this.reserveId = 0;
  254. this.handleYuyueDate();
  255. this.$refs.addYuyuePop.open();
  256. },
  257. closeYuyuePop() {
  258. this.yuYueData = {
  259. time: '', //时间
  260. date: '', //日期
  261. member_id: '',
  262. member: {},
  263. goods: [{}],
  264. desc: '',
  265. reserve_id: 0
  266. };
  267. this.$refs.addYuyuePop.close();
  268. },
  269. // 查询会员信息
  270. searchMember() {
  271. if (this.searchMobile.length == 0) {
  272. this.$util.showToast({
  273. title: '请输入客户手机号'
  274. });
  275. return;
  276. }
  277. if (!this.$util.verifyMobile(this.searchMobile)) {
  278. this.$util.showToast({
  279. title: '手机号格式不正确'
  280. });
  281. return;
  282. }
  283. this.$api.sendRequest({
  284. url: '/cashier/storeapi/member/searchmember',
  285. data: {
  286. search_text: this.searchMobile
  287. },
  288. success: res => {
  289. if (res.data) {
  290. this.yuYueData.member_id = res.data.member_id;
  291. this.yuYueData.member = res.data;
  292. } else {
  293. this.yuYueData.member_id = '';
  294. this.yuYueData.member = {};
  295. this.$util.showToast({
  296. title: '客户未找到'
  297. });
  298. }
  299. }
  300. });
  301. },
  302. //处理预约时间段
  303. handleYuyueDate() {
  304. let time_list = [];
  305. let start = this.yuYueConfig.start / 60;
  306. let end = this.yuYueConfig.end / 60;
  307. let date = new Date();
  308. var y = date.getFullYear();
  309. var m = date.getMonth() + 1;
  310. var d = date.getDate();
  311. let time = date.getHours() * 60 + date.getMinutes();
  312. let yuyue_time_stamp = this.$util.timeTurnTimeStamp(this.yuYueData.date);
  313. let time_stamp = this.$util.timeTurnTimeStamp(y + '-' + m + '-' + d);
  314. // if(time > start) start = time;
  315. for (let i = start; i < end; i++) {
  316. if (i % this.yuYueConfig.interval == 0) {
  317. let data = {
  318. label: (Math.floor(i / 60) < 10 ? '0' + Math.floor(i / 60) : Math.floor(i / 60)) + ':' + (
  319. i % 60 == '0' ? '00' : i % 60),
  320. value: (Math.floor(i / 60) < 10 ? '0' + Math.floor(i / 60) : Math.floor(i / 60)) + ':' + (
  321. i % 60 == '0' ? '00' : i % 60),
  322. disabled: false
  323. };
  324. if (yuyue_time_stamp < time_stamp) data.disabled = true;
  325. if (yuyue_time_stamp == time_stamp && time > i) data.disabled = true;
  326. let week = new Date(this.yuYueData.date).getDay();
  327. let yuyue_week = this.yuYueConfig.week;
  328. let config_week = [];
  329. for (let i in yuyue_week) config_week.push(parseInt(yuyue_week[i]));
  330. if (config_week.indexOf(week) === -1) data.disabled = true;
  331. time_list.push(data);
  332. }
  333. }
  334. this.yuYueTime = time_list;
  335. },
  336. // 监听预约时间
  337. changeYuyueTime(time) {
  338. this.yuYueData.date = time;
  339. this.handleYuyueDate();
  340. },
  341. // 选择预约时间·
  342. selectYuYueTime(index, item) {
  343. if (index >= 0) {
  344. this.yuYueData.time = item.value;
  345. } else {
  346. this.yuYueData.time = '';
  347. }
  348. },
  349. // 设置项目
  350. selectGoods(data, index) {
  351. this.yuYueData.goods[index] = Object.assign(this.yuYueData.goods[index], JSON.parse(JSON.stringify(data)));
  352. this.$forceUpdate();
  353. },
  354. // 加载员工列表
  355. loadServicer(index) {
  356. let goods_id = this.yuYueData.goods[index].goods_id;
  357. this.servicerList = this.allServicerList;
  358. },
  359. // 设置员工
  360. selectServicer(data, index) {
  361. this.yuYueData.goods[index].uid = data.uid;
  362. this.yuYueData.goods[index].username = data.username;
  363. this.$forceUpdate();
  364. },
  365. // 添加项目
  366. addService() {
  367. this.yuYueData.goods.push({});
  368. },
  369. // 删除项目
  370. deleleService(index) {
  371. if (this.yuYueData.goods.length == 1) {
  372. this.$util.showToast({
  373. title: '至少需要有一项项目'
  374. });
  375. } else {
  376. this.yuYueData.goods.splice(index, 1);
  377. }
  378. },
  379. // 预约验证
  380. verify() {
  381. if (!this.yuYueData.member_id) {
  382. this.$util.showToast({
  383. title: '请选择会员'
  384. });
  385. return false;
  386. }
  387. if (!this.yuYueData.date || !this.yuYueData.time) {
  388. this.$util.showToast({
  389. title: '请设置到店时间'
  390. });
  391. return false;
  392. }
  393. if (!this.yuYueData.goods.length) {
  394. this.$util.showToast({
  395. title: '请选择预约项目'
  396. });
  397. return false;
  398. }
  399. for (let i in this.yuYueData.goods) {
  400. if (!this.yuYueData.goods[i]['goods_id']) {
  401. this.$util.showToast({
  402. title: '请选择预约项目'
  403. });
  404. return false;
  405. }
  406. }
  407. return true;
  408. },
  409. // 添加/编辑预约
  410. yuYueSubmit() {
  411. if (this.verify()) {
  412. if (this.flag) return;
  413. this.flag = true;
  414. let data = Object.assign({}, this.yuYueData);
  415. data.goods = JSON.stringify(data.goods);
  416. data.member = JSON.stringify(data.member);
  417. let url = '/store/storeapi/reserve/add';
  418. if (data.reserve_id) url = '/store/storeapi/reserve/update';
  419. this.$api.sendRequest({
  420. url,
  421. data,
  422. success: res => {
  423. this.$util.showToast({
  424. title: res.message
  425. });
  426. this.flag = false;
  427. if (res.code >= 0) {
  428. this.getWeekReserve();
  429. if (this.reserveId) this.getYuyueInfo();
  430. this.closeYuyuePop();
  431. this.yuyuePage = 1;
  432. this.getYuyueList();
  433. }
  434. }
  435. });
  436. }
  437. },
  438. //操作
  439. yuyueEvent(event, data) {
  440. this.reserveId = data.reserve_id;
  441. switch (event) {
  442. case 'info':
  443. this.getYuYueDetail(data.reserve_id);
  444. break;
  445. case 'tostore':
  446. this.tostore(data.reserve_id);
  447. break;
  448. case 'cancel':
  449. this.cancel(data.reserve_id);
  450. break;
  451. case 'confirm':
  452. this.confirm(data.reserve_id);
  453. break;
  454. case 'update': // 修改预约
  455. this.$refs.loading.show();
  456. this.yuYueInfo(data.reserve_id);
  457. break;
  458. case 'complet':
  459. this.complet(data.reserve_id);
  460. break;
  461. }
  462. },
  463. //修改预约
  464. yuYueInfo(reserve_id) {
  465. if (this.flag) return;
  466. this.flag = true;
  467. this.$api.sendRequest({
  468. url: '/store/storeapi/reserve/detail',
  469. data: {
  470. reserve_id
  471. },
  472. success: res => {
  473. if (res.code >= 0) {
  474. this.yuYueData = {
  475. reserve_id: res.data.reserve_id,
  476. member_id: res.data.member_id,
  477. member: res.data.member,
  478. time: this.$util.timeFormat(res.data.reserve_time, 'h:i'),
  479. date: this.$util.timeFormat(res.data.reserve_time, 'y-m-d'),
  480. goods: res.data.item,
  481. desc: res.data.remark
  482. };
  483. this.handleYuyueDate();
  484. this.$refs.addYuyuePop.open();
  485. } else {
  486. this.$util.showToast({
  487. title: res.message
  488. });
  489. }
  490. this.flag = false;
  491. this.$refs.loading.hide();
  492. }
  493. });
  494. },
  495. // 预约详情
  496. getYuYueDetail(reserve_id) {
  497. if (this.flag) return;
  498. this.flag = true;
  499. this.$api.sendRequest({
  500. url: '/store/storeapi/reserve/detail',
  501. data: {
  502. reserve_id
  503. },
  504. success: res => {
  505. if (res.code >= 0) {
  506. this.yuYueDetail = res.data;
  507. this.$refs.yuyuePop.open();
  508. }
  509. this.flag = false;
  510. }
  511. });
  512. },
  513. //确定预约
  514. confirm(reserve_id) {
  515. if (this.flag) return;
  516. this.flag = true;
  517. this.$api.sendRequest({
  518. url: '/store/storeapi/reserve/confirm',
  519. data: {
  520. reserve_id
  521. },
  522. success: res => {
  523. this.flag = false;
  524. if (res.code >= 0) {
  525. this.getWeekReserve();
  526. this.getYuyueInfo();
  527. }
  528. this.$util.showToast({
  529. title: res.message
  530. });
  531. }
  532. });
  533. },
  534. //完成
  535. complet(reserve_id) {
  536. if (this.flag) return;
  537. this.flag = true;
  538. this.$api.sendRequest({
  539. url: '/store/storeapi/reserve/complete',
  540. data: {
  541. reserve_id
  542. },
  543. success: res => {
  544. this.flag = false;
  545. if (res.code >= 0) {
  546. this.getWeekReserve();
  547. this.getYuyueInfo();
  548. }
  549. this.$util.showToast({
  550. title: res.message
  551. });
  552. }
  553. });
  554. },
  555. //取消预约
  556. cancel(reserve_id) {
  557. if (this.flag) return;
  558. this.flag = true;
  559. this.$api.sendRequest({
  560. url: '/store/storeapi/reserve/cancel',
  561. data: {
  562. reserve_id
  563. },
  564. success: res => {
  565. this.flag = false;
  566. if (res.code >= 0) {
  567. this.getWeekReserve();
  568. this.getYuyueInfo();
  569. }
  570. this.$util.showToast({
  571. title: res.message
  572. });
  573. }
  574. });
  575. },
  576. //确认到店
  577. tostore(reserve_id) {
  578. this.$api.sendRequest({
  579. url: '/store/storeapi/reserve/confirmToStore',
  580. data: {
  581. reserve_id
  582. },
  583. success: res => {
  584. this.flag = false;
  585. if (res.code >= 0) {
  586. this.getWeekReserve();
  587. this.getYuyueInfo();
  588. }
  589. this.$util.showToast({
  590. title: res.message
  591. });
  592. }
  593. });
  594. },
  595. // ******************** 预约列表 ********************
  596. // 获取预约分页数据
  597. getYuyueList() {
  598. this.$api.sendRequest({
  599. url: '/store/storeapi/reserve/lists',
  600. data: {
  601. page: this.yuyuePage,
  602. search_text: this.yuyueSearchText
  603. },
  604. success: res => {
  605. if (res.code >= 0) {
  606. if (this.yuyuePage == 1) this.yuyueList = [];
  607. this.yuyueList = this.yuyueList.concat(res.data.list);
  608. if (this.yuyuePage == 1 && this.yuyueList.length > 0) {
  609. this.reserveId = this.yuyueList[0]['reserve_id'];
  610. this.getYuyueInfo();
  611. }
  612. if (res.data.page_count >= this.yuyuePage) this.yuyuePage++;
  613. }
  614. }
  615. });
  616. },
  617. // 搜索预约客户
  618. searchYuyueList() {
  619. this.yuyuePage = 1;
  620. this.getYuyueList();
  621. },
  622. selectYuyue(id) {
  623. this.reserveId = id;
  624. this.getYuyueInfo();
  625. },
  626. getYuyueInfo() {
  627. this.$api.sendRequest({
  628. url: '/store/storeapi/reserve/detail',
  629. data: {
  630. reserve_id: this.reserveId
  631. },
  632. success: res => {
  633. if (res.code >= 0) {
  634. this.yuyueInfo = res.data;
  635. } else {
  636. this.yuyueInfo = null;
  637. }
  638. this.refreshStatus();
  639. this.$forceUpdate();
  640. }
  641. });
  642. },
  643. refreshStatus(){
  644. if(this.yuyueList && this.yuyueInfo){
  645. Object.keys(this.yuyueList).forEach(key => {
  646. let data = this.yuyueList[key];
  647. if(data.reserve_id == this.yuyueInfo['reserve_id']){
  648. this.yuyueList[key]['reserve_state'] = this.yuyueInfo['reserve_state'];
  649. this.yuyueList[key]['reserve_state_name'] = this.yuyueInfo['reserve_state_name'];
  650. }
  651. })
  652. }
  653. }
  654. }
  655. };