微信

index.vue 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. <template>
  2. <div class="mainPage flex-v">
  3. <div class="top">
  4. <topCaseInfo :data="topCaseInfoData" :userName="userInfo.customer.RealName ? userInfo.customer.RealName : userInfo.customer.Name" @selectCase="showVanPicker"></topCaseInfo>
  5. </div>
  6. <nav class="flex-h" v-if="userInfo.customer.MapUser !== ''">
  7. <a class="flex-item" v-for="(item,index) in cutNavList" :key="index" v-if="userInfo.customer.UserTypeId !== 'manager' || item.id !== '4'" :class="{'active': navActive === index}" @click="cutNav(index)">{{item.value}}</a>
  8. </nav>
  9. <div class="content">
  10. <div>
  11. <ul>
  12. <li :hidden="navActive !== 0 && userInfo.customer.MapUser !== ''" class="placeOrder">
  13. <div class="topInfo flex-h" v-if="userInfo.customer.MapUser !== ''">
  14. <div class="flex-item">
  15. <div>
  16. <span>共计已使用:{{caseTotal.total}}杯</span>
  17. </div>
  18. </div>
  19. <div class="flex-item">
  20. <div>
  21. <span>本月已用:{{caseTotal.monthtotal}}杯</span>
  22. </div>
  23. </div>
  24. <router-link :to="{name: 'orderList'}">点单记录</router-link>
  25. </div>
  26. <div class="areaListParent flex-h">
  27. <div class="flex-item">
  28. <div>
  29. <ul class="areaList">
  30. <li v-for="(item,index) in CaseTableList" :key="index">
  31. <div class="title">
  32. <!-- <i class="iconfont icon-yinchenglogo"></i> -->
  33. <img :src="item.AreaIcon" class="iconfont icon-yinchenglogo">
  34. <span>{{item.AreaName}}</span>
  35. </div>
  36. <ul class="subAreaList flex-h">
  37. <!-- <router-link tag="li" class="flex-item flex-h" v-for="(subItem,subIndex) in item.Tables" :key="subIndex" :to="{name: 'placeOrder', query: { tableid: encodeURI(subItem.TableId), tableno: encodeURI(subItem.TableNo), caseid: encodeURI(subItem.CaseId), casename: encodeURI(topCaseInfoData.caseName), areaid: encodeURI(subItem.AreaId), areaname: encodeURI(item.AreaName)}}">
  38. <caseTableItem :icon="item.AreaIcon" :item="subItem" :index="subIndex"></caseTableItem>
  39. </router-link> -->
  40. <li class="flex-item flex-h" v-for="(subItem,subIndex) in item.Tables" :key="subIndex" @click="toOrders(subItem, item)">
  41. <caseTableItem :icon="item.AreaIcon" :item="subItem" :index="subIndex"></caseTableItem>
  42. </li>
  43. <li class="flex-item noData" v-if="(item.Tables || []).length % 2 != 0"></li>
  44. </ul>
  45. </li>
  46. </ul>
  47. </div>
  48. </div>
  49. </div>
  50. </li>
  51. <li :hidden="navActive !== 1" class="my-card">
  52. <div class="list-box">
  53. <div class="cardAndCouponInfo flex-h">
  54. <div class="flex-item">
  55. <div>
  56. <span>卡券货值总额:</span>
  57. <span>¥{{cardTotalCount}}</span>
  58. </div>
  59. </div>
  60. <a @click="toSalesHistory" v-if="userInfo.customer.UserTypeId == 'manager'">销售记录</a>
  61. </div>
  62. <myCard v-for="(item,index) in data[1].list" :ismanager="userInfo.customer.UserTypeId == 'manager'" :isgrey="checkCanDo()" :key="index" :data='item' @share='shareCard' @detail='toCardNumDetail'></myCard>
  63. <noMore v-if="data[1].hasPic"></noMore>
  64. </div>
  65. </li>
  66. <li :hidden="navActive !== 2" class="my-card">
  67. <div class="list-box">
  68. <div class="cardAndCouponInfo flex-h">
  69. <div class="flex-item">
  70. <div>
  71. <span>卡券货值总额:</span>
  72. <span>¥{{couponTotalCount}}</span>
  73. </div>
  74. </div>
  75. <a @click="toSalesHistory" v-if="userInfo.customer.UserTypeId == 'manager'">销售记录</a>
  76. </div>
  77. <myCard v-for="(item,index) in data[2].list" :ismanager="userInfo.customer.UserTypeId == 'manager'" :isgrey="checkCanDo()" :key="index" :data='item' @share='shareCoupon' @detail='toCouponNumDetail'></myCard>
  78. <noMore v-if="data[2].hasPic"></noMore>
  79. </div>
  80. </li>
  81. <li :hidden="navActive !== 3" class="customer-card">
  82. <div class="list-box">
  83. <div class="search-bar flex-h">
  84. <span>共{{this.data[3].list.length}}位客户</span>
  85. <van-checkbox v-model="postCustomerData.isrecommend">
  86. 我推荐的客户({{myRecommendUserList.length}}人)
  87. <img
  88. slot="icon"
  89. slot-scope="props"
  90. :src="postCustomerData.isrecommend ? icon.active : icon.normal"
  91. style="width:.2rem;height:.2rem;bottom: .02rem;position: relative;"
  92. >
  93. </van-checkbox>
  94. <i class="iconfont icon-sousuo search-icon" @click="searchMask"></i>
  95. </div>
  96. <customerCard v-for="(item,index) in postCustomerData.isrecommend ? myRecommendUserList : data[3].list" :key="index" :data='item' @record='record'></customerCard>
  97. <noMore v-if="data[3].hasPic"></noMore>
  98. </div>
  99. </li>
  100. </ul>
  101. </div>
  102. </div>
  103. <div class="selectCase" :hidden="!showSelect"></div>
  104. <van-picker :hidden="!showSelect"
  105. show-toolbar
  106. title="选择案场"
  107. :columns="CaseList"
  108. @cancel="showSelect = false"
  109. @confirm="selectCase"
  110. value-key="CaseName"
  111. />
  112. <van-dialog
  113. v-model="showDialog"
  114. show-cancel-button
  115. title='添加备注'
  116. :before-close="beforeClose">
  117. <van-field
  118. v-model="message"
  119. type="textarea"
  120. placeholder="请输入备注"
  121. rows="3"
  122. autosize/>
  123. </van-dialog>
  124. </div>
  125. </template>
  126. <script>
  127. import caseTableItem from '../../../../components/caseTableItem/index'
  128. import topCaseInfo from '../../../../components/topCaseInfo/index'
  129. import myCard from '../../../../components/myCard/myCard'
  130. import customerCard from '../../../../components/customerCard/customerCard'
  131. import active from '../../../../common/icon/check-box-checked.png'
  132. import normal from '../../../../common/icon/check-box-empty.png'
  133. import logo from '../../../../common/icon/indexlogo.jpg'
  134. import wxsdk from '../../../../util/share'
  135. import noMore from '../../../../components/noMore/noMore'
  136. import { mapState, createNamespacedHelpers } from 'vuex'
  137. const { mapActions: actions } = createNamespacedHelpers('app')
  138. const { mapActions: caseTableActions } = createNamespacedHelpers('placeOrderForCoffee')
  139. const { mapState: mapCaseState, mapActions: mapCaseActions } = createNamespacedHelpers('case')
  140. const { mapState: mapCardState, mapActions: mapCardActions } = createNamespacedHelpers('myCard')
  141. const { mapActions: mapUserCenterActions } = createNamespacedHelpers('userCenter')
  142. const wx = require('weixin-js-sdk')
  143. export default {
  144. name: '',
  145. data () {
  146. return {
  147. myRecommendUserList: [],
  148. forbidList: [],
  149. postCustomerData: {
  150. page: 1,
  151. pagesize: 10000,
  152. isrecommend: false,
  153. },
  154. couponTotalCount: 0,
  155. cardTotalCount: 0,
  156. postCouponData: {
  157. page: 1,
  158. pagesize: 10000
  159. },
  160. postCardData: {
  161. page: 1,
  162. pagesize: 10000
  163. },
  164. pullUpLoad: true,
  165. pullUpLoadThreshold: 40,
  166. startY: 0,
  167. isloading: true,
  168. icon: {
  169. active: active,
  170. normal: normal
  171. },
  172. active,
  173. normal,
  174. navActive: 0,
  175. showDialog: false,
  176. message: '',
  177. logo,
  178. cutNavList: [{
  179. value: '城咖啡',
  180. id: '1',
  181. }, {
  182. value: '我的卡',
  183. id: '2',
  184. }, {
  185. value: '我的券',
  186. id: '3',
  187. }, {
  188. value: '我的客户',
  189. id: '4',
  190. }],
  191. topCaseInfoData: {
  192. caseName: '',
  193. caseId: '',
  194. ShowSelect: false,
  195. },
  196. caseInfo: {
  197. value: '',
  198. id: ''
  199. },
  200. showSelect: false,
  201. list: [{
  202. name: '案场名称1',
  203. list: [{}, {}, {}, {}, {}],
  204. }, {
  205. name: '案场名称2',
  206. list: [{}, {}, {}, {}, {}],
  207. }],
  208. data: [
  209. {
  210. hasPic: false,
  211. hasMore: true,
  212. page: 1,
  213. pagesize: 1,
  214. list: []
  215. },
  216. {
  217. hasPic: false,
  218. hasMore: true,
  219. page: 1,
  220. pagesize: 1,
  221. list: []
  222. },
  223. {
  224. hasPic: false,
  225. hasMore: true,
  226. page: 1,
  227. pagesize: 1,
  228. list: []
  229. },
  230. {
  231. hasPic: false,
  232. hasMore: true,
  233. page: 1,
  234. pagesize: 1,
  235. list: []
  236. }
  237. ]
  238. }
  239. },
  240. computed: {
  241. ...mapState({
  242. userInfo: x => x.userCenter.userInfo,
  243. CaseList: x => x.app.CaseList,
  244. CaseTableList: x => x.placeOrderForCoffee.CaseTableList,
  245. }),
  246. ...mapCaseState({
  247. caseTotal: x => x.caseTotal,
  248. }),
  249. ...mapCardState({
  250. cardList: x => x.cardList
  251. }),
  252. },
  253. components: {
  254. topCaseInfo,
  255. caseTableItem,
  256. myCard,
  257. customerCard,
  258. noMore
  259. },
  260. created () {
  261. if (!this.userInfo.customer.MapUser) {
  262. this.topCaseInfoData.ShowSelect = true
  263. }
  264. if (this.userInfo.customer.MapUser !== '') {
  265. this.getForbidInfo().then((res) => {
  266. this.forbidList = res || []
  267. this.getCustomerList({
  268. ...this.postCustomerData
  269. }).then((res) => {
  270. if (res) {
  271. for (var n = 0; n < res.length; n++) {
  272. if (res[n].RecommendId === this.userInfo.customer.MapUser) {
  273. this.myRecommendUserList.push(res[n])
  274. res[n].showTag = true
  275. } else {
  276. res[n].showTag = false
  277. }
  278. this.data[3].list.push(res[n])
  279. }
  280. } else {
  281. this.data[3].hasPic = true
  282. }
  283. })
  284. this.getMyCouponList({
  285. ...this.postCouponData
  286. }).then((res) => {
  287. res.list = res.list || []
  288. if (res.list.length > 0) {
  289. for (var n = 0; n < res.list.length; n++) {
  290. this.data[2].list.push({
  291. invalid: this.returnInvalid(res.list[n], 'coupon'),
  292. price: parseInt(res.list[n].Price),
  293. title: res.list[n].CouponName,
  294. desc: res.list[n].Share.UseRule,
  295. startDate: this.toolClass.dateFormat(res.list[n].StartDate, 'yyyy年MM月dd日'),
  296. endDate: this.toolClass.dateFormat(res.list[n].EndDate, 'yyyy年MM月dd日'),
  297. totalCount: res.list[n].TotalCount,
  298. SentCount: res.list[n].SentCount,
  299. usedCount: res.list[n].UsedCount,
  300. CardId: res.list[n].CouponId,
  301. CustomerList: res.list[n].CustomerCoupon || []
  302. })
  303. }
  304. var count = 0
  305. for (var n = 0; n < this.data[2].list.length; n++) {
  306. count += this.data[2].list[n].price * this.data[2].list[n].totalCount - 0
  307. }
  308. this.couponTotalCount = count.toFixed(2)
  309. } else {
  310. this.data[2].hasPic = true
  311. }
  312. })
  313. this.getMyCardList({
  314. ...this.postCardData
  315. }).then((res) => {
  316. res.list = res.list || []
  317. if (res.list.length > 0) {
  318. for (var n = 0; n < res.list.length; n++) {
  319. this.data[1].list.push({
  320. invalid: this.returnInvalid(res.list[n], 'card'),
  321. price: parseInt(res.list[n].Price),
  322. title: res.list[n].CardName,
  323. desc: res.list[n].Share.CardUseRule,
  324. startDate: this.toolClass.dateFormat(res.list[n].StartDate, 'yyyy年MM月dd日'),
  325. endDate: this.toolClass.dateFormat(res.list[n].EndDate, 'yyyy年MM月dd日'),
  326. totalCount: res.list[n].TotalCount,
  327. SentCount: res.list[n].SentCount,
  328. usedCount: res.list[n].UsedCount,
  329. CardId: res.list[n].CardId,
  330. CustomerList: res.list[n].CustomerCard || []
  331. })
  332. }
  333. var count = 0
  334. for (var n = 0; n < this.data[1].list.length; n++) {
  335. count += this.data[1].list[n].price * this.data[1].list[n].totalCount - 0
  336. }
  337. this.cardTotalCount = count.toFixed(2)
  338. } else {
  339. this.data[1].hasPic = true
  340. }
  341. })
  342. })
  343. } else {
  344. }
  345. this.getCaseList().then((res) => {
  346. this.locationMapping()
  347. })
  348. },
  349. methods: {
  350. ...mapUserCenterActions([
  351. 'getMyCardList',
  352. 'getMyCouponList',
  353. 'getForbidInfo',
  354. 'getCustomerList',
  355. ]),
  356. ...actions([
  357. 'getCaseList',
  358. ]),
  359. ...caseTableActions([
  360. 'getCaseTableList',
  361. ]),
  362. ...mapCaseActions([
  363. 'getCaseTotal',
  364. 'getCaseConf',
  365. ]),
  366. ...mapCardActions(['getCardList']),
  367. checkCanDo () {
  368. const _that = this
  369. return this.forbidList.filter(x => x.UserId === _that.userInfo.customer.MapUser && x.ForbidType === 'coupon').length > 0
  370. },
  371. checkCanOrder () {
  372. const _that = this
  373. return this.forbidList.filter(x => x.UserId === _that.userInfo.customer.MapUser && x.ForbidType === 'goods').length > 0
  374. },
  375. toCardNumDetail (item) {
  376. if (this.userInfo.customer.UserTypeId === 'manager') {
  377. window.location.href = `${this.getUrl('cardAndCouponNum')}?id=${item.CardId}&type=card`
  378. }
  379. },
  380. toCouponNumDetail (item) {
  381. if (this.userInfo.customer.UserTypeId === 'manager') {
  382. window.location.href = `${this.getUrl('cardAndCouponNum')}?id=${item.CardId}&type=coupon`
  383. }
  384. },
  385. returnInvalid (item, type) {
  386. for (var n = 0; n < this.forbidList.length; n++) {
  387. if (this.forbidList[n].UserId === this.userInfo.customer.CustomerId && this.forbidList[n].ForbidType === type) {
  388. return true
  389. }
  390. }
  391. if (item.TotalCount - 0 === item.SentCount - 0 + item.UsedCount - 0 || new Date(item.EndDate).getTime() < Date.now()) {
  392. return true
  393. }
  394. return false
  395. },
  396. toSalesHistory () {
  397. window.location.href = this.getUrl('salesRecord')
  398. },
  399. getUrl (val) {
  400. var url = window.location.pathname
  401. return url.replace('user.html', 'sales.html') + '#/' + val
  402. },
  403. showVanPicker () {
  404. this.showSelect = true
  405. },
  406. selectCase (val) { // 选择案场
  407. this.topCaseInfoData.caseName = val.CaseName
  408. this.topCaseInfoData.caseId = val.CaseId
  409. this.getCaseTableList({
  410. caseid: this.topCaseInfoData.caseId
  411. })
  412. this.showSelect = false
  413. },
  414. cutNav (index) { // 切换nav
  415. this.navActive = index
  416. // this.getList('change')
  417. },
  418. getList (param) {
  419. if (this.navActive === 0) {
  420. return
  421. } else {
  422. if (param === 'change') {
  423. this.data[this.navActive].page = 0
  424. }
  425. if (this.data[this.navActive].hasMore) {
  426. }
  427. }
  428. },
  429. shareCard (item) {
  430. let query = {
  431. id: item.CardId,
  432. type: 'card',
  433. sharetype: 'share',
  434. salesid: this.userInfo.customer.MapUser,
  435. random: this.random()
  436. }
  437. this.$router.push({ name: 'receive', query: query })
  438. },
  439. shareCoupon (item) {
  440. let query = {
  441. id: item.CardId,
  442. type: 'coupon',
  443. sharetype: 'share',
  444. salesid: this.userInfo.customer.MapUser,
  445. random: this.random()
  446. }
  447. this.$router.push({ name: 'receive', query: query })
  448. },
  449. random () {
  450. let rnd = ''
  451. for (let i = 0; i < 5; i++) {
  452. rnd += Math.floor(Math.random() * 10)
  453. }
  454. let timestamp = new Date().valueOf()
  455. return `${rnd}${timestamp}`
  456. },
  457. remark (item) {
  458. // console.log(item)
  459. this.showDialog = true
  460. },
  461. history (item) {
  462. // console.log(item)
  463. window.location.href = this.getUrl('history')
  464. },
  465. record (item) {
  466. // console.log(item)
  467. window.location.href = this.getUrl('getRecord') + '?name=' + item.Name + '&phone=' + item.Phone + '&id=' + item.CustomerId
  468. },
  469. searchMask () {
  470. window.location.href = this.getUrl('customerSearch')
  471. },
  472. locationMapping () {
  473. let that = this
  474. // that.topCaseInfoData.caseName = that.CaseList[0].CaseName
  475. // that.topCaseInfoData.caseId = that.CaseList[0].CaseId
  476. if (this.userInfo.customer.MapUser !== '') {
  477. this.topCaseInfoData.caseId = this.userInfo.customer.BelongCaseId
  478. for (let i = 0; i < this.CaseList.length; i++) {
  479. if (this.CaseList[i].CaseId === this.topCaseInfoData.caseId) {
  480. this.topCaseInfoData.caseName = this.CaseList[i].CaseName
  481. }
  482. }
  483. that.getCaseTableList({
  484. caseid: that.topCaseInfoData.caseId
  485. })
  486. if (this.userInfo.customer.MapUser !== '') {
  487. that.getCaseTotal({
  488. caseid: that.topCaseInfoData.caseId
  489. })
  490. }
  491. } else {
  492. wxsdk({ url: encodeURIComponent(window.location.href.split('#')[0]) }, {
  493. title: '城的空间',
  494. desc: '城的空间',
  495. link: `${window.location.origin}${window.location.pathname}#/mainPage/indexPage`,
  496. thu_image: `https://spaceofcheng.oss-cn-beijing.aliyuncs.com/indexlogo.jpg?x-oss-process=style/wxicon`
  497. }).then(() => {
  498. wx.getLocation({
  499. type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  500. success: function (res) {
  501. let latitude1 = res.latitude // 纬度,浮点数,范围为90 ~ -90
  502. let longitude1 = res.longitude // 经度,浮点数,范围为180 ~ -180。
  503. for (let i = 0; i < that.CaseList.length; i++) {
  504. let result = that.CaseList[i].Coordinate.split(",")
  505. let latitude2 = parseFloat(result[0])
  506. let longitude2 = parseFloat(result[1])
  507. if (that.toolClass.getGreatCircleDistance(latitude1, longitude1, latitude2, longitude2) < 500) {
  508. that.topCaseInfoData.caseName = that.CaseList[i].CaseName
  509. that.topCaseInfoData.caseId = that.CaseList[i].CaseId
  510. that.getCaseTableList({
  511. caseid: that.topCaseInfoData.caseId
  512. })
  513. if (this.userInfo.customer.MapUser !== '') {
  514. that.getCaseTotal({
  515. caseid: that.topCaseInfoData.caseId
  516. })
  517. }
  518. }
  519. }
  520. if (!that.topCaseInfoData.caseId || !that.topCaseInfoData.caseName) {
  521. that.topCaseInfoData.caseName = '当前位置无案场'
  522. }
  523. }
  524. })
  525. })
  526. }
  527. },
  528. beforeClose (action, done) {
  529. if (action === 'confirm') {
  530. setTimeout(done, 1000)
  531. } else {
  532. done()
  533. }
  534. },
  535. toOrders (subItem, item) {
  536. const _that = this
  537. this.getCaseConf({ caseid: subItem.CaseId }).then(res => {
  538. if (this.checkCanOrder()){
  539. _that.$toast('您的点单功能已被关闭!')
  540. return
  541. }
  542. if (res.Status === 1) {
  543. this.$router.push({ name: 'placeOrder', query: { tableid: encodeURI(subItem.TableId), tableno: encodeURI(subItem.TableNo), caseid: encodeURI(subItem.CaseId), casename: encodeURI(_that.topCaseInfoData.caseName), areaid: encodeURI(subItem.AreaId), areaname: encodeURI(item.AreaName) } })
  544. } else {
  545. _that.$toast('当前案场已歇业!')
  546. return
  547. }
  548. })
  549. },
  550. }
  551. }
  552. </script>
  553. <!-- Add "scoped" attribute to limit CSS to this component only -->
  554. <style lang="scss" scoped>
  555. @import 'page.scss';
  556. </style>