chooseBundle.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="page-wrap">
  3. <!-- 搜索 -->
  4. <view class="page-header" id="bundle-item-header">
  5. <u-row gutter="16" justify="space-between">
  6. <u-col :span="isGobleSearch ? 9 : 12">
  7. <u-search placeholder="请输入关键字" v-model="queryWord" @focus="isGobleSearch=true" @custom="searchData" @search="searchData" :action-style="{'color': '#fff', 'font-size': '24rpx', 'background-color': '#ff4546', 'border-radius': '6rpx', 'padding': '6rpx 15rpx'}"></u-search>
  8. </u-col>
  9. <u-col span="3" v-show="isGobleSearch">
  10. <view class="close-con">
  11. <text class="close-search" @click="isGobleSearch=false">关闭搜索</text>
  12. </view>
  13. </u-col>
  14. </u-row>
  15. </view>
  16. <view class="category-nav-wrap">
  17. <scroll-view class="nav-left" scroll-y :style="'height:'+screenHeight+'px'" v-show="!isGobleSearch">
  18. <view :class="['nav-left-item', nowInd == index ? 'active' : '' ] " v-for="(item, index) in typeList" :name="item.code" :key="item.id" @click="changeNav(item,index)">
  19. <text class="nav-left-item-name">{{item.dispName}}</text>
  20. </view>
  21. </scroll-view>
  22. <scroll-view class="nav-right" scroll-y :style="{'height': (screenHeight - 20)+'px', 'width': isGobleSearch ? '100%': '70%'}">
  23. <view class="nav-right-item" v-for="(item, index) in packageListData" :key="index" v-if="packageListData.length>0" >
  24. <text class="item-name">{{item.name}}</text>
  25. <view class="item-f-con">
  26. <text style="color: red;">¥{{item.price}}</text>
  27. <view class="handle-btns">
  28. <u-button class="item-btn" shape="circle" size="mini" @click="intoDetail(item.id)">查详情</u-button>
  29. <u-button class="item-btn buy-btn" type="primary" shape="circle" size="mini" hover-class="none" :custom-style="customBtnStyle" @click="buyBundle(item)">下 单</u-button>
  30. </view>
  31. </view>
  32. </view>
  33. <u-empty v-if="packageListData.length==0" style="height: auto;padding-top: 10vh;" :text="noDataText" mode="data"></u-empty>
  34. </scroll-view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import { getLookUpDatas } from '@/api/data'
  40. import { getBundleList } from '@/api/customerBundle'
  41. export default{
  42. name: 'chooseBundle',
  43. data(){
  44. return{
  45. noDataText: '数据加载中,请稍后...',
  46. typeList: [],
  47. screenHeight: '', // 屏幕可见高度
  48. packageListData: [], // 二级 数据
  49. nowInd: 0, // 当前选中导航下标
  50. queryWord: '',
  51. isGobleSearch: false, // 是否全局搜索
  52. clsId: '',
  53. customBtnStyle: { // 自定义按钮样式
  54. borderColor: '#ff4546',
  55. backgroundColor: '#ff4546',
  56. color: '#fff'
  57. },
  58. }
  59. },
  60. methods: {
  61. // 获取套餐分类
  62. getBundleType(){
  63. getLookUpDatas({type:'BUNDLE_TYPE'}).then(res=>{
  64. if (res.status == 200) {
  65. this.typeList = res.data
  66. this.typeList.unshift({dispName:'全部',code: '',id: 0})
  67. }else{
  68. this.typeList = []
  69. }
  70. })
  71. },
  72. // 初始化数据
  73. initData (){
  74. const _this = this
  75. uni.showLoading({ title: '加载中...' })
  76. getBundleList({
  77. queryWord: this.queryWord,
  78. clsId: this.clsId
  79. }).then(res => {
  80. uni.hideLoading()
  81. if (res.status == 200) {
  82. _this.packageListData = res.data
  83. _this.noDataText = '暂无数据'
  84. } else {
  85. _this.packageListData = []
  86. _this.noDataText = res.message ? res.message : '网络似乎出错了,请稍后再试'
  87. }
  88. })
  89. },
  90. // 对比已选择项目
  91. hasChecked (row){
  92. let b = this.packageListData
  93. let has = b.findIndex(item => {
  94. if (item.customerBundleId){
  95. return false
  96. }
  97. return item.itemId && item.itemId == row.id
  98. })
  99. return has >= 0
  100. },
  101. // 切换一级菜单更改二级菜单数据
  102. changeNav(item,ind){
  103. this.nowInd = ind
  104. this.clsId = item.code
  105. this.initData()
  106. },
  107. // 下单
  108. buyBundle(item){
  109. uni.navigateTo({
  110. url: '/pages/workOrder/sellOrder/buyBundle?bundleId='+item.id+'&totalAmount='+item.price
  111. })
  112. },
  113. // 搜索,默认当前分类下得全部
  114. searchData (){
  115. if(this.isGobleSearch && this.queryWord == ''){
  116. this.packageListData = []
  117. return
  118. }
  119. this.clsId = ''
  120. this.nowInd = 0
  121. this.initData()
  122. // 隐藏键盘
  123. uni.hideKeyboard()
  124. },
  125. // 进入套餐详情
  126. intoDetail (id){
  127. uni.navigateTo({
  128. url: `/pages/workOrder/sellOrder/bundleDetail?id=${id}`
  129. })
  130. },
  131. // 设置滚动区域高度
  132. setScreenHeight() {
  133. const _this = this;
  134. setTimeout(() => {
  135. uni.getSystemInfo({
  136. success: res => {
  137. console.log(res)
  138. const query = uni.createSelectorQuery().in(this);
  139. query.select('#bundle-item-header').boundingClientRect(data => {
  140. console.log(data)
  141. // 设置滚动区域高度
  142. // app中无法获取windowTop,故用80替代
  143. _this.screenHeight = res.screenHeight - 70 - data.height - 45;
  144. }).exec();
  145. }
  146. });
  147. }, 100);
  148. }
  149. },
  150. mounted() {
  151. this.setScreenHeight()
  152. },
  153. onLoad() {
  154. this.getBundleType()
  155. this.initData()
  156. },
  157. watch: {
  158. // 全局搜索
  159. isGobleSearch(val) {
  160. if (val) {
  161. this.packageListData = [];
  162. } else {
  163. this.queryWord = '';
  164. this.initData();
  165. }
  166. }
  167. }
  168. }
  169. </script>
  170. <style scoped lang="scss">
  171. .page-wrap{
  172. width: 100%;
  173. height: 100vh;
  174. .page-header{
  175. padding: 20upx 30upx;
  176. border-bottom: 1upx solid #f2f2f2;
  177. background: #FFFFFF;
  178. .close-con{
  179. text-align: right;
  180. .close-search{
  181. display: inline-block;
  182. color: #515a6e;
  183. border: 2upx dashed #dcdee2;
  184. border-radius: 6upx;
  185. padding: 12upx 15upx;
  186. font-size: 24upx;
  187. }
  188. }
  189. }
  190. .category-nav-wrap{
  191. display: flex;
  192. justify-content: space-between;
  193. width: 100%;
  194. .nav-left{
  195. width: 30%;
  196. height: 100vh;
  197. border-right: 1upx solid #f2f2f2;
  198. background-color: #fff;
  199. .nav-left-item{
  200. color: #303133;
  201. border-right: 2upx solid #fff;
  202. padding: 24upx 20upx;
  203. background-color: #fff;
  204. position: relative;
  205. }
  206. .nav-left-item.active{
  207. color: #ff9900;
  208. background: #fdf6ec;
  209. }
  210. .nav-left-item.active:after{
  211. content: '';
  212. display: block;
  213. width: 2px;
  214. position: absolute;
  215. top: 0;
  216. bottom: 0;
  217. right: 0;
  218. background: #fcbd71;
  219. }
  220. }
  221. .nav-right{
  222. height: 100vh;
  223. padding: 20upx;
  224. box-sizing: border-box;
  225. .nav-right-item{
  226. padding: 20upx 30upx;
  227. border: 1upx solid #f2f2f2;
  228. background: #FFFFFF;
  229. margin: 6px 0;
  230. border-radius: 10px;
  231. display: flex;
  232. flex-direction: column;
  233. justify-content: space-between;
  234. .item-name{
  235. font-size: 28upx;
  236. margin-bottom: 20upx;
  237. }
  238. .item-f-con{
  239. display: flex;
  240. align-items: center;
  241. justify-content: space-between;
  242. }
  243. .item-btn{
  244. display: inline-block;
  245. margin-left: 20upx;
  246. width: 112upx;
  247. }
  248. .item-btn.btn-unselected{
  249. background-color: #2db7f5!important;;
  250. border-color: #2db7f5!important;;
  251. }
  252. .item-btn.btn-selected{
  253. background-color: #19be6b!important;;
  254. border-color: #19be6b!important;
  255. }
  256. }
  257. }
  258. }
  259. }
  260. </style>