goodList.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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. <uni-goods-nav :fill="true" :options="[]" @buttonClick="goodHandle1" :buttonGroup="buttonGroup1" class="good-handle"
  21. v-if="!manageType" />
  22. <uni-goods-nav :fill="true" :options="[]" @buttonClick="goodHandle2" :buttonGroup="buttonGroup2" class="good-handle"
  23. v-else-if="tabIndex == 0" />
  24. <uni-goods-nav :fill="true" :options="[]" @buttonClick="goodHandle2" :buttonGroup="buttonGroup3" class="good-handle"
  25. v-else-if="tabIndex == 1" />
  26. <uni-goods-nav :fill="true" :options="[]" @buttonClick="goodHandle2" :buttonGroup="buttonGroup4" class="good-handle"
  27. v-else-if="tabIndex == 2" />
  28. <u-popup v-model="popupShow" mode="bottom">
  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. methods: {
  120. // 搜索商品
  121. search(data) {
  122. this.goodName = data.value
  123. this.reasetList()
  124. },
  125. // 切换tab
  126. changeTabs(index) {
  127. this.tabIndex = index;
  128. this.reasetList()
  129. },
  130. // 刷新数据
  131. reasetList() {
  132. this['isOver' + (this.tabIndex + 1)] = false
  133. this['pageIndex' + (this.tabIndex + 1)] = 1
  134. this['list' + (this.tabIndex + 1)] = []
  135. this.getList(this.tabIndex + 1)
  136. },
  137. // 懒加载
  138. handleLoadMore(type) {
  139. if (!this['isOver' + type]) {
  140. this['pageIndex' + type]++
  141. this.getList(type)
  142. }
  143. },
  144. // 获取列表数据
  145. getList(type) {
  146. NET.request(API.getGoodList, {
  147. name: this.goodName,
  148. pageIndex: this['pageIndex' + type],
  149. pageSize: 10,
  150. type: type,
  151. }, 'POST').then(res => {
  152. this['isOver' + type] = res.data.list.length != 10
  153. res.data.list.forEach(site => {
  154. site.check = false
  155. })
  156. this['list' + type] = this['list' + type].concat(res.data.list)
  157. }).catch(error => {
  158. this.$refs.uTips.show({
  159. title: error.data.msg,
  160. type: 'warning',
  161. })
  162. })
  163. },
  164. // 全部分类下查询
  165. goodHandle1(e) {
  166. if (e.index == 0) {
  167. this.manageType = true
  168. } else {
  169. this.popupShow = true
  170. }
  171. },
  172. // 各分类下批量操作
  173. goodHandle2(e) {
  174. if (e.index == 0) {
  175. this.manageType = false
  176. } else {
  177. NET.request(API.setGoodsStatus, {
  178. ids: this['list' + (this.tabIndex + 1)].filter(site => site.check).map(site => {
  179. return site.id
  180. }),
  181. operation: (this.tabIndex == 0 && e.index == 1) ? 1 : ((this.tabIndex == 2 && e.index == 1) ? 2 : 3),
  182. type: this.tabIndex == 0 ? 1 : 2
  183. }, 'POST').then(res => {
  184. this.$refs.uTips.show({
  185. title: '操作成功',
  186. type: 'success',
  187. })
  188. this.reasetList()
  189. }).catch(error => {
  190. this.$refs.uTips.show({
  191. title: error.data.msg,
  192. type: 'warning',
  193. })
  194. })
  195. }
  196. },
  197. // 新增商品
  198. addGood(type) {
  199. this.popupShow = false
  200. uni.navigateTo({
  201. url: '/pagesGood/goodForm?type=add&formType=' + type
  202. });
  203. },
  204. }
  205. }
  206. </script>
  207. <style lang="less" scoped>
  208. page {
  209. width: 100%;
  210. height: 100%;
  211. }
  212. .container {
  213. width: 100%;
  214. height: 100%;
  215. float: left;
  216. background-color: #f7f7f7;
  217. .search-box {
  218. width: 100%;
  219. height: 58px;
  220. box-sizing: border-box;
  221. padding: 2px 12px 1px 12px;
  222. background-color: #FFFFFF;
  223. }
  224. .data-tab {
  225. width: 100%;
  226. height: 45px;
  227. float: left;
  228. }
  229. .data-list {
  230. width: 100%;
  231. height: calc(100% - 154px);
  232. float: left;
  233. }
  234. .good-handle {
  235. width: 100%;
  236. position: fixed;
  237. bottom: 0px;
  238. }
  239. .good-handle-box {
  240. width: 100%;
  241. float: left;
  242. box-sizing: border-box;
  243. padding: 0 20px 20px 20px;
  244. .handle-button {
  245. width: 100%;
  246. height: 66px;
  247. float: left;
  248. font-size: 15px;
  249. font-family: PingFang SC;
  250. color: #333333;
  251. line-height: 66px;
  252. border: none;
  253. border-top: 1px solid #E0E0E0;
  254. border-radius: 0;
  255. }
  256. .handle-button:first-child {
  257. border-top: none;
  258. }
  259. .handle-close {
  260. width: 125px;
  261. height: 42px;
  262. float: left;
  263. background: #F1F1F1;
  264. border-radius: 5px;
  265. font-size: 16px;
  266. font-family: PingFang SC;
  267. color: #51A539;
  268. line-height: 42px;
  269. position: relative;
  270. left: 50%;
  271. transform: translateX(-50%);
  272. }
  273. }
  274. }
  275. </style>