微信

index.vue 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. <template>
  2. <div class="mainPage flex-v">
  3. <div class="top">
  4. <topCaseInfo :data="topCaseInfoData" :userName="userInfo.customer !== undefined ? 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" :ismanger="ismanger" :userGet="item.CustomerCoupon" :isgrey="checkCanDo()" :key="index" :data='item' @share='shareCard'></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" :ismanger="ismanger" :userGet="item.CustomerCard" :isgrey="checkCanDo()" :key="index" :data='item' @share='shareCoupon'></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. ismanger () {
  253. return this.userInfo.UserTypeId == "manager" ? true : false
  254. },
  255. },
  256. components: {
  257. topCaseInfo,
  258. caseTableItem,
  259. myCard,
  260. customerCard,
  261. noMore
  262. },
  263. created () {
  264. if (!this.userInfo.customer.MapUser) {
  265. this.topCaseInfoData.ShowSelect = true
  266. }
  267. if (this.userInfo.customer.MapUser !== '') {
  268. this.getForbidInfo().then((res) => {
  269. this.forbidList = res || []
  270. this.getCustomerList({
  271. ...this.postCustomerData
  272. }).then((res) => {
  273. if (res) {
  274. for (var n = 0; n < res.length; n++) {
  275. if (res[n].RecommendId === this.userInfo.customer.MapUser) {
  276. this.myRecommendUserList.push(res[n])
  277. res[n].showTag = true
  278. } else {
  279. res[n].showTag = false
  280. }
  281. this.data[3].list.push(res[n])
  282. }
  283. } else {
  284. this.data[3].hasPic = true
  285. }
  286. })
  287. this.getMyCouponList({
  288. ...this.postCouponData
  289. }).then((res) => {
  290. res.list = res.list || []
  291. if (res.list.length > 0) {
  292. for (var n = 0; n < res.list.length; n++) {
  293. this.data[2].list.push({
  294. invalid: this.returnInvalid(res.list[n], 'coupon'),
  295. price: parseInt(res.list[n].Price),
  296. title: res.list[n].CouponName,
  297. desc: res.list[n].Share.UseRule,
  298. startDate: this.toolClass.dateFormat(res.list[n].StartDate, 'yyyy年MM月dd日'),
  299. endDate: this.toolClass.dateFormat(res.list[n].EndDate, 'yyyy年MM月dd日'),
  300. totalCount: res.list[n].TotalCount,
  301. SentCount: res.list[n].SentCount,
  302. usedCount: res.list[n].UsedCount,
  303. CardId: res.list[n].CouponId,
  304. })
  305. }
  306. var count = 0
  307. for (var n = 0; n < this.data[2].list.length; n++) {
  308. count += this.data[2].list[n].price * this.data[2].list[n].totalCount - 0
  309. }
  310. this.couponTotalCount = count.toFixed(2)
  311. } else {
  312. this.data[2].hasPic = true
  313. }
  314. })
  315. this.getMyCardList({
  316. ...this.postCardData
  317. }).then((res) => {
  318. res.list = res.list || []
  319. if (res.list.length > 0) {
  320. for (var n = 0; n < res.list.length; n++) {
  321. this.data[1].list.push({
  322. invalid: this.returnInvalid(res.list[n], 'card'),
  323. price: parseInt(res.list[n].Price),
  324. title: res.list[n].CardName,
  325. desc: res.list[n].Share.CardUseRule,
  326. startDate: this.toolClass.dateFormat(res.list[n].StartDate, 'yyyy年MM月dd日'),
  327. endDate: this.toolClass.dateFormat(res.list[n].EndDate, 'yyyy年MM月dd日'),
  328. totalCount: res.list[n].TotalCount,
  329. SentCount: res.list[n].SentCount,
  330. usedCount: res.list[n].UsedCount,
  331. CardId: res.list[n].CardId
  332. })
  333. }
  334. var count = 0
  335. for (var n = 0; n < this.data[1].list.length; n++) {
  336. count += this.data[1].list[n].price * this.data[1].list[n].totalCount - 0
  337. }
  338. this.cardTotalCount = count.toFixed(2)
  339. } else {
  340. this.data[1].hasPic = true
  341. }
  342. })
  343. })
  344. } else {
  345. }
  346. this.getCaseList().then((res) => {
  347. this.locationMapping()
  348. })
  349. },
  350. methods: {
  351. ...mapUserCenterActions([
  352. 'getMyCardList',
  353. 'getMyCouponList',
  354. 'getForbidInfo',
  355. 'getCustomerList',
  356. ]),
  357. ...actions([
  358. 'getCaseList',
  359. ]),
  360. ...caseTableActions([
  361. 'getCaseTableList',
  362. ]),
  363. ...mapCaseActions([
  364. 'getCaseTotal',
  365. 'getCaseConf',
  366. ]),
  367. ...mapCardActions(['getCardList']),
  368. checkCanDo () {
  369. const _that = this
  370. return this.forbidList.filter(x => x.UserId === _that.userInfo.customer.MapUser && x.ForbidType === 'coupon').length > 0
  371. },
  372. returnInvalid (item, type) {
  373. for (var n = 0; n < this.forbidList.length; n++) {
  374. if (this.forbidList[n].UserId === this.userInfo.customer.CustomerId && this.forbidList[n].ForbidType === type) {
  375. return true
  376. }
  377. }
  378. if (item.TotalCount - 0 === item.SentCount - 0 + item.UsedCount - 0 || new Date(item.EndDate).getTime() < Date.now()) {
  379. return true
  380. }
  381. return false
  382. },
  383. toSalesHistory () {
  384. window.location.href = this.getUrl('salesRecord')
  385. },
  386. getUrl (val) {
  387. var url = window.location.pathname
  388. return url.replace('user.html', 'sales.html') + '#/' + val
  389. },
  390. showVanPicker () {
  391. this.showSelect = true
  392. },
  393. selectCase (val) { // 选择案场
  394. this.topCaseInfoData.caseName = val.CaseName
  395. this.topCaseInfoData.caseId = val.CaseId
  396. this.getCaseTableList({
  397. caseid: this.topCaseInfoData.caseId
  398. })
  399. this.showSelect = false
  400. },
  401. cutNav (index) { // 切换nav
  402. this.navActive = index
  403. // this.getList('change')
  404. },
  405. getList (param) {
  406. if (this.navActive === 0) {
  407. return
  408. } else {
  409. if (param === 'change') {
  410. this.data[this.navActive].page = 0
  411. }
  412. if (this.data[this.navActive].hasMore) {
  413. }
  414. }
  415. },
  416. shareCard (item) {
  417. let query = {
  418. id: item.CardId,
  419. type: 'card',
  420. sharetype: 'share',
  421. salesid: this.userInfo.customer.MapUser,
  422. random: this.random()
  423. }
  424. this.$router.push({ name: 'receive', query: query })
  425. },
  426. shareCoupon (item) {
  427. let query = {
  428. id: item.CardId,
  429. type: 'coupon',
  430. sharetype: 'share',
  431. salesid: this.userInfo.customer.MapUser,
  432. random: this.random()
  433. }
  434. this.$router.push({ name: 'receive', query: query })
  435. },
  436. random () {
  437. let rnd = ''
  438. for (let i = 0; i < 5; i++) {
  439. rnd += Math.floor(Math.random() * 10)
  440. }
  441. let timestamp = new Date().valueOf()
  442. return `${rnd}${timestamp}`
  443. },
  444. remark (item) {
  445. // console.log(item)
  446. this.showDialog = true
  447. },
  448. history (item) {
  449. // console.log(item)
  450. window.location.href = this.getUrl('history')
  451. },
  452. record (item) {
  453. // console.log(item)
  454. window.location.href = this.getUrl('getRecord') + '?name=' + item.Name + '&phone=' + item.Phone + '&id=' + item.CustomerId
  455. },
  456. searchMask () {
  457. window.location.href = this.getUrl('customerSearch')
  458. },
  459. locationMapping () {
  460. let that = this
  461. // that.topCaseInfoData.caseName = that.CaseList[0].CaseName
  462. // that.topCaseInfoData.caseId = that.CaseList[0].CaseId
  463. if (this.userInfo.customer.MapUser !== '') {
  464. this.topCaseInfoData.caseId = this.userInfo.customer.BelongCaseId
  465. for (let i = 0; i < this.CaseList.length; i++) {
  466. if (this.CaseList[i].CaseId === this.topCaseInfoData.caseId) {
  467. this.topCaseInfoData.caseName = this.CaseList[i].CaseName
  468. }
  469. }
  470. that.getCaseTableList({
  471. caseid: that.topCaseInfoData.caseId
  472. })
  473. if (this.userInfo.customer.MapUser !== '') {
  474. that.getCaseTotal({
  475. caseid: that.topCaseInfoData.caseId
  476. })
  477. }
  478. } else {
  479. wxsdk({ url: encodeURIComponent(window.location.href.split('#')[0]) }, {
  480. title: '城的空间',
  481. desc: '城的空间',
  482. link: `${window.location.origin}${window.location.pathname}#/mainPage/indexPage`,
  483. thu_image: `${window.location.origin}${window.location.pathname}${logo}`
  484. }).then(() => {
  485. wx.getLocation({
  486. type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  487. success: function (res) {
  488. let latitude1 = res.latitude // 纬度,浮点数,范围为90 ~ -90
  489. let longitude1 = res.longitude // 经度,浮点数,范围为180 ~ -180。
  490. for (let i = 0; i < that.CaseList.length; i++) {
  491. let result = that.CaseList[i].Coordinate.split(",")
  492. let latitude2 = parseFloat(result[0])
  493. let longitude2 = parseFloat(result[1])
  494. if (that.toolClass.getGreatCircleDistance(latitude1, longitude1, latitude2, longitude2) < 500) {
  495. that.topCaseInfoData.caseName = that.CaseList[i].CaseName
  496. that.topCaseInfoData.caseId = that.CaseList[i].CaseId
  497. that.getCaseTableList({
  498. caseid: that.topCaseInfoData.caseId
  499. })
  500. if (this.userInfo.customer.MapUser !== '') {
  501. that.getCaseTotal({
  502. caseid: that.topCaseInfoData.caseId
  503. })
  504. }
  505. }
  506. }
  507. if (!that.topCaseInfoData.caseId || !that.topCaseInfoData.caseName) {
  508. that.topCaseInfoData.caseName = '当前位置无案场'
  509. }
  510. }
  511. })
  512. })
  513. }
  514. },
  515. beforeClose (action, done) {
  516. if (action === 'confirm') {
  517. setTimeout(done, 1000)
  518. } else {
  519. done()
  520. }
  521. },
  522. toOrders (subItem, item) {
  523. const _that = this
  524. this.getCaseConf({ caseid: subItem.CaseId }).then(res => {
  525. if (res.Status === 1) {
  526. 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) } })
  527. } else {
  528. _that.$toast('当前案场已歇业!')
  529. return
  530. }
  531. })
  532. },
  533. }
  534. }
  535. </script>
  536. <!-- Add "scoped" attribute to limit CSS to this component only -->
  537. <style lang="scss" scoped>
  538. @import 'page.scss';
  539. </style>