chooseBundle.vue 7.3 KB

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