goodList.vue 7.3 KB

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