goodList.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. <template>
  2. <view class="container">
  3. <view class="search-box">
  4. <uni-search-bar ref="searchBar" radius="5" placeholder="搜索" :defaultText="goodName" clearButton="auto" cancelButton="none"
  5. bgColor="#f7f7f7" @confirm="search" class="search-bar" />
  6. </view>
  7. <view class="data-tab">
  8. <u-tabs :list="tabList" :is-scroll="false" :current="tabIndex" @change="changeTabs" font-size="30" active-color="#52A63A"
  9. inactive-color="#666666" :bold="false" height="90"></u-tabs>
  10. </view>
  11. <scroll-view class="data-list" scroll-y="true" @scrolltolower="handleLoadMore(1)" v-if="tabIndex==0">
  12. <goodItem v-for="(item, index) in list1" :key="index" :goodData="item" :check.sync="item.check" :manageType="manageType"></goodItem>
  13. </scroll-view>
  14. <scroll-view class="data-list" scroll-y="true" @scrolltolower="handleLoadMore(2)" v-else-if="tabIndex==1">
  15. <goodItem v-for="(item, index) in list2" :key="index" :goodData="item" :check.sync="item.check" :manageType="manageType"></goodItem>
  16. </scroll-view>
  17. <scroll-view class="data-list" scroll-y="true" @scrolltolower="handleLoadMore(3)" v-else-if="tabIndex==2">
  18. <goodItem v-for="(item, index) in list3" :key="index" :goodData="item" :check.sync="item.check" :manageType="manageType"></goodItem>
  19. </scroll-view>
  20. <view class="good-handle">
  21. <uni-goods-nav :fill="true" :options="[]" @buttonClick="goodHandle1" :buttonGroup="buttonGroup1" v-if="!manageType" />
  22. <uni-goods-nav :fill="true" :options="[]" @buttonClick="goodHandle2" :buttonGroup="buttonGroup2" class="nav-border"
  23. v-else-if="tabIndex == 0" />
  24. <uni-goods-nav :fill="true" :options="[]" @buttonClick="goodHandle2" :buttonGroup="buttonGroup3" v-else-if="tabIndex == 1" />
  25. <uni-goods-nav :fill="true" :options="[]" @buttonClick="goodHandle2" :buttonGroup="buttonGroup4" class="nav-border"
  26. v-else-if="tabIndex == 2" />
  27. </view>
  28. <u-popup v-model="popupShow" mode="bottom" border-radius="30">
  29. <view class="good-handle-box">
  30. <u-button class="handle-button" :hair-line="false" @click="addGood(1)">普通售卖</u-button>
  31. <u-button class="handle-button" :hair-line="false" @click="addGood(2)">拍卖</u-button>
  32. <u-button class="handle-button" :hair-line="false" @click="addGood(3)">自助采摘</u-button>
  33. <u-button class="handle-close" @click="popupShow = false">取消</u-button>
  34. </view>
  35. </u-popup>
  36. <u-top-tips ref="uTips"></u-top-tips>
  37. </view>
  38. </template>
  39. <script>
  40. const NET = require('@/utils/request')
  41. const API = require('@/config/api')
  42. import goodItem from '@/pagesGood/goodItem.vue'
  43. export default {
  44. components: {
  45. goodItem
  46. },
  47. data() {
  48. return {
  49. goodName: '',
  50. tabIndex: 0,
  51. tabList: [{
  52. name: '出售中'
  53. }, {
  54. name: '已售空'
  55. }, {
  56. name: '已下架'
  57. }],
  58. pageIndex1: 1,
  59. isOver1: false,
  60. list1: [],
  61. pageIndex2: 1,
  62. isOver2: false,
  63. list2: [],
  64. pageIndex3: 1,
  65. isOver3: false,
  66. list3: [],
  67. manageType: false,
  68. popupShow: false,
  69. buttonGroup1: [{
  70. text: '批量管理',
  71. backgroundColor: '#75BD60',
  72. color: '#fff'
  73. }, {
  74. text: '添加商品',
  75. backgroundColor: '#52A63A',
  76. color: '#fff'
  77. }],
  78. buttonGroup2: [{
  79. text: '取消',
  80. backgroundColor: '#52A63A',
  81. color: '#fff'
  82. }, {
  83. text: '下架',
  84. backgroundColor: '#52A63A',
  85. color: '#fff'
  86. }, {
  87. text: '删除',
  88. backgroundColor: '#52A63A',
  89. color: '#fff'
  90. }],
  91. buttonGroup3: [{
  92. text: '取消',
  93. backgroundColor: '#75BD60',
  94. color: '#fff'
  95. }, {
  96. text: '删除',
  97. backgroundColor: '#52A63A',
  98. color: '#fff'
  99. }],
  100. buttonGroup4: [{
  101. text: '取消',
  102. backgroundColor: '#52A63A',
  103. color: '#fff'
  104. }, {
  105. text: '上架',
  106. backgroundColor: '#52A63A',
  107. color: '#fff'
  108. }, {
  109. text: '删除',
  110. backgroundColor: '#52A63A',
  111. color: '#fff'
  112. }],
  113. }
  114. },
  115. onLoad(options) {},
  116. onShow(options) {
  117. this.reasetList()
  118. },
  119. onPullDownRefresh() {
  120. this.reasetList('refresh')
  121. },
  122. methods: {
  123. // 搜索商品
  124. search(data) {
  125. this.goodName = data.value
  126. this.reasetList()
  127. },
  128. // 切换tab
  129. changeTabs(index) {
  130. this.tabIndex = index;
  131. this.reasetList()
  132. },
  133. // 刷新数据
  134. reasetList(refresh) {
  135. this['isOver' + (this.tabIndex + 1)] = false
  136. this['pageIndex' + (this.tabIndex + 1)] = 1
  137. this['list' + (this.tabIndex + 1)] = []
  138. this.getList(this.tabIndex + 1, refresh)
  139. },
  140. // 懒加载
  141. handleLoadMore(type) {
  142. if (!this['isOver' + type]) {
  143. this['pageIndex' + type]++
  144. this.getList(type)
  145. }
  146. },
  147. // 获取列表数据
  148. getList(type, refresh) {
  149. NET.request(API.getGoodList, {
  150. name: this.goodName,
  151. pageIndex: this['pageIndex' + type],
  152. pageSize: 10,
  153. type: type,
  154. }, 'POST').then(res => {
  155. if (refresh == 'refresh') {
  156. uni.stopPullDownRefresh();
  157. }
  158. this['isOver' + type] = res.data.list.length != 10
  159. res.data.list.forEach(site => {
  160. site.check = false
  161. })
  162. this['list' + type] = this['list' + type].concat(res.data.list)
  163. }).catch(error => {
  164. this.$refs.uTips.show({
  165. title: error.data.msg,
  166. type: 'warning',
  167. })
  168. })
  169. },
  170. // 全部分类下查询
  171. goodHandle1(e) {
  172. if (e.index == 0) {
  173. this.manageType = true
  174. } else {
  175. this.popupShow = true
  176. }
  177. },
  178. // 各分类下批量操作
  179. goodHandle2(e) {
  180. if (e.index == 0) {
  181. this.manageType = false
  182. } else {
  183. NET.request(API.setGoodsStatus, {
  184. ids: this['list' + (this.tabIndex + 1)].filter(site => site.check).map(site => {
  185. return site.id
  186. }),
  187. operation: (this.tabIndex == 0 && e.index == 1) ? 1 : ((this.tabIndex == 2 && e.index == 1) ? 2 : 3),
  188. type: this.tabIndex == 0 ? 1 : 2
  189. }, 'POST').then(res => {
  190. this.$refs.uTips.show({
  191. title: '操作成功',
  192. type: 'success',
  193. })
  194. this.reasetList()
  195. }).catch(error => {
  196. this.$refs.uTips.show({
  197. title: error.data.msg,
  198. type: 'warning',
  199. })
  200. })
  201. }
  202. },
  203. // 新增商品
  204. addGood(type) {
  205. this.popupShow = false
  206. uni.navigateTo({
  207. url: '/pagesGood/goodForm?type=add&formType=' + type
  208. });
  209. },
  210. }
  211. }
  212. </script>
  213. <style lang="less" scoped>
  214. page {
  215. width: 100%;
  216. height: 100%;
  217. }
  218. .container {
  219. width: 100%;
  220. height: 100%;
  221. float: left;
  222. position: relative;
  223. background-color: #f7f7f7;
  224. .search-box {
  225. width: 100%;
  226. height: 58px;
  227. box-sizing: border-box;
  228. padding: 2px 12px 1px 12px;
  229. background-color: #FFFFFF;
  230. }
  231. .data-tab {
  232. width: 100%;
  233. height: 45px;
  234. float: left;
  235. }
  236. .data-list {
  237. width: 100%;
  238. height: calc(100% - 154px);
  239. float: left;
  240. }
  241. .good-handle {
  242. width: 100%;
  243. position: absolute;
  244. bottom: 0px;
  245. height: 50px;
  246. background: #ffffff;
  247. .nav-border {
  248. /deep/.uni-tab__cart-button-right {
  249. border-right: 1px solid #74bd60;
  250. }
  251. /deep/.uni-tab__cart-button-right:last-child {
  252. border-right: none;
  253. }
  254. }
  255. }
  256. .good-handle-box {
  257. width: 100%;
  258. float: left;
  259. box-sizing: border-box;
  260. padding: 0 20px 20px 20px;
  261. .handle-button {
  262. width: 100%;
  263. height: 66px;
  264. float: left;
  265. font-size: 15px;
  266. font-family: PingFang SC;
  267. color: #333333;
  268. line-height: 66px;
  269. border: none;
  270. border-top: 1px solid #E0E0E0;
  271. border-radius: 0;
  272. /deep/button {
  273. margin-top: 12px;
  274. }
  275. }
  276. .handle-button:first-child {
  277. border-top: none;
  278. }
  279. .handle-close {
  280. width: 125px;
  281. height: 42px;
  282. float: left;
  283. border-radius: 5px;
  284. font-size: 16px;
  285. font-family: PingFang SC;
  286. line-height: 42px;
  287. position: relative;
  288. left: 50%;
  289. transform: translateX(-50%);
  290. /deep/button {
  291. color: #56a83a !important;
  292. background-color: #F2F2F2 !important;
  293. line-height: 42px;
  294. }
  295. /deep/button::after {
  296. border: none;
  297. }
  298. }
  299. /deep/.u-btn--default {
  300. border: none;
  301. }
  302. }
  303. }
  304. </style>