goodList.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. // getAllCartType() {
  212. // return this['list' + (this.tabIndex + 1)].filter(site => site.allCheck).length == this['list' + (this.tabIndex + 1)].length
  213. // },
  214. // // 设置所有品全选状态
  215. // checkAllShop() {
  216. // let type = this.getAllCartType()
  217. // this['list' + (this.tabIndex + 1)].forEach(item => {
  218. // item.allCheck = !type
  219. // item.products.forEach(site => {
  220. // site.check = !type
  221. // })
  222. // })
  223. // },
  224. }
  225. }
  226. </script>
  227. <style lang="less" scoped>
  228. page {
  229. width: 100%;
  230. height: 100%;
  231. }
  232. .container {
  233. width: 100%;
  234. height: 100%;
  235. float: left;
  236. position: relative;
  237. background-color: #f7f7f7;
  238. .search-box {
  239. width: 100%;
  240. height: 58px;
  241. box-sizing: border-box;
  242. padding: 2px 12px 1px 12px;
  243. background-color: #FFFFFF;
  244. }
  245. .data-tab {
  246. width: 100%;
  247. height: 45px;
  248. float: left;
  249. }
  250. .data-list {
  251. width: 100%;
  252. height: calc(100% - 154px);
  253. float: left;
  254. }
  255. .good-handle {
  256. width: 100%;
  257. position: absolute;
  258. bottom: 0px;
  259. height: 50px;
  260. background: #ffffff;
  261. .nav-border {
  262. /deep/.uni-tab__cart-button-right {
  263. border-right: 1px solid #74bd60;
  264. }
  265. /deep/.uni-tab__cart-button-right:last-child {
  266. border-right: none;
  267. }
  268. }
  269. }
  270. .good-handle-box {
  271. width: 100%;
  272. float: left;
  273. box-sizing: border-box;
  274. padding: 0 20px 20px 20px;
  275. .handle-button {
  276. width: 100%;
  277. height: 66px;
  278. float: left;
  279. font-size: 15px;
  280. font-family: PingFang SC;
  281. color: #333333;
  282. line-height: 66px;
  283. border: none;
  284. border-top: 1px solid #E0E0E0;
  285. border-radius: 0;
  286. /deep/button {
  287. margin-top: 12px;
  288. }
  289. }
  290. .handle-button:first-child {
  291. border-top: none;
  292. }
  293. .handle-close {
  294. width: 125px;
  295. height: 42px;
  296. float: left;
  297. border-radius: 5px;
  298. font-size: 16px;
  299. font-family: PingFang SC;
  300. line-height: 42px;
  301. position: relative;
  302. left: 50%;
  303. transform: translateX(-50%);
  304. /deep/button {
  305. color: #56a83a !important;
  306. background-color: #F2F2F2 !important;
  307. line-height: 42px;
  308. }
  309. /deep/button::after {
  310. border: none;
  311. }
  312. }
  313. /deep/.u-btn--default {
  314. border: none;
  315. }
  316. }
  317. }
  318. </style>