goodList.vue 7.2 KB

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