select_shang.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <template>
  2. <view class="padding">
  3. <view class="text-white padding bg radius">
  4. <view class="bg padding-lr padding-tb-sm flex align-center" style="background-color: white;">
  5. <u-search @change="search" v-model="goodsName" placeholder="请输入商品名称 " bg-color="#F7F7F7"
  6. style="width: 100%;" shape="square" :show-action="false"></u-search>
  7. </view>
  8. <view class="all_circle" v-if="ifallselece" @click="quSelect()" style="background-color:rgba(245, 211, 71, 1);"></view>
  9. <view class="all_circle" v-else @click="allSelect()"></view>
  10. <view class="quanxuan">全选</view>
  11. <view class="all_select" @click="yixuan">已选商品</view>
  12. <!-- 商品列表 -->
  13. <view style="margin-left: -16px;">
  14. <view v-for="(item,index) in shangList" :key="index" class="shang_list">
  15. <view class="shang_circle" v-if="item.shangpin==0" @click="qiehuan(item.goodsId)"></view>
  16. <view class="shang_circle_select" v-if="item.shangpin==1" @click="qiehuan2(item.goodsId,index)"></view>
  17. <image class="shang_image" :src="item.goodsPicture.split(',')[0]"></image>
  18. <view class="shang_name">{{item.goodsName}}</view>
  19. <view class="shang_time">{{item.createTime}}</view>
  20. </view>
  21. </view>
  22. </view>
  23. <u-button @click="submit" class="margin-top" :custom-style="customStyle" shape="square" :hair-line="false">确认
  24. </u-button>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. customStyle: {
  32. backgroundColor: '#FFCC00',
  33. color: '#000000',
  34. border: 0
  35. },
  36. actShopid:'',
  37. page: 1,
  38. limit: 10,
  39. goodsName:'',
  40. shangList:[],
  41. shangIds:[],
  42. ifallselece:false,
  43. }
  44. },
  45. onLoad(option) {
  46. this.actShopid=option.actShopid
  47. //已选择的商品
  48. this.selectShang()
  49. },
  50. onShow() {
  51. //我参与的活动
  52. // this.selectShang()
  53. },
  54. methods: {
  55. //搜索
  56. search() {
  57. this.selectShang()
  58. },
  59. //商品全选
  60. allSelect(){
  61. this.shangList.forEach(item => {
  62. // 'status'为属性名,'非活动'为修改后的内容
  63. item.shangpin = 1
  64. this.shangIds.push(item.goodsId)
  65. })
  66. this.ifallselece=true
  67. },
  68. //取消全选
  69. quSelect(){
  70. this.shangList.forEach(item => {
  71. // 'status'为属性名,'非活动'为修改后的内容
  72. item.shangpin = 0
  73. })
  74. this.shangIds=[]
  75. this.ifallselece=false
  76. },
  77. //变成选中状态
  78. qiehuan(goodsId){
  79. if(this.shangIds.length==this.shangList.length){
  80. if(this.ifallselece){
  81. this.ifallselece=false
  82. }else {
  83. this.ifallselece=true
  84. }
  85. }
  86. this.shangList.forEach(item => {
  87. if (goodsId===item.goodsId) {
  88. // 'status'为属性名,'非活动'为修改后的内容
  89. item.shangpin = 1
  90. }
  91. })
  92. this.shangIds.push(goodsId)
  93. },
  94. //变成不选中
  95. qiehuan2(goodsId,index){
  96. if(this.shangIds.length==this.shangList.length){
  97. if(this.ifallselece){
  98. this.ifallselece=false
  99. }else {
  100. this.ifallselece=true
  101. }
  102. }
  103. this.shangList.forEach(item => {
  104. if (goodsId===item.goodsId) {
  105. // 'status'为属性名,'非活动'为修改后的内容
  106. item.shangpin = 0
  107. }
  108. })
  109. this.shangIds.splice(index, 1);
  110. console.log(this.shangIds,'dddd')
  111. },
  112. //商品加入活动
  113. submit(){
  114. let data = {
  115. "activityShopId": this.actShopid,
  116. "goodsIds": this.shangIds
  117. }
  118. this.$Request.postJson("/admin/activity-goods", data).then(res => {
  119. if(res.code==0){
  120. uni.showToast({
  121. title: '选择成功',
  122. icon: 'success'
  123. })
  124. uni.navigateBack({
  125. delta: 1
  126. })
  127. }else{
  128. uni.showToast({
  129. title: res.msg,
  130. icon: 'none'
  131. })
  132. }
  133. });
  134. },
  135. //已选择的商品
  136. selectShang(){
  137. // var shopId=uni.getStorageSync('shopId')
  138. this.$Request.get(`/admin/activity-goods/${this.actShopid}`).then(res => {
  139. if (res.code == 0) {
  140. let returnData = res.data
  141. //活动列表
  142. this.allShang(returnData)
  143. }else{
  144. uni.showModal({
  145. content:res.msg
  146. })
  147. }
  148. });
  149. },
  150. //店铺所有商品
  151. allShang(returnData){
  152. // /ad?page=1&limit=10&goodsName=&classifyId=&shopId=147&status=0
  153. let data = {
  154. page: this.page,
  155. limit: this.limit,
  156. goodsName: this.goodsName,
  157. shopId: uni.getStorageSync('shopId'),
  158. // status: this.tabIndex == 1 ? 2 : (this.tabIndex == 2 ? 1 : this.tabIndex)
  159. }
  160. this.$Request.getA("/admin/goodsShop/selectGoodsByShopId", data).then(res => {
  161. if (res.code == 0) {
  162. var total = res.data.totalCount
  163. let data2 = {
  164. page: this.page,
  165. limit: total,
  166. goodsName: this.goodsName,
  167. shopId: uni.getStorageSync('shopId'),
  168. // status: this.tabIndex == 1 ? 2 : (this.tabIndex == 2 ? 1 : this.tabIndex)
  169. }
  170. this.$Request.getA("/admin/goodsShop/selectGoodsByShopId", data2).then(res => {
  171. if (res.code == 0) {
  172. uni.hideLoading()
  173. let returnData2 = res.data
  174. const newList =returnData2.list.map(item =>{
  175. return{...item,shangpin:0}
  176. })
  177. var arr = []
  178. if(returnData.length===0){
  179. newList.forEach(item => {
  180. // 'status'为属性名,'非活动'为修改后的内容
  181. item.shangpin = 1
  182. this.shangList.forEach(item => {
  183. this.shangIds.push(item.goodsId)
  184. })
  185. })
  186. this.ifallselece=true
  187. }else{
  188. for(var j in returnData){
  189. newList.forEach(item => {
  190. if (item.goodsId === returnData[j]) {
  191. // 'status'为属性名,'非活动'为修改后的内容
  192. item.shangpin = 1
  193. this.shangIds.push(item.goodsId)
  194. }
  195. })
  196. }
  197. this.ifallselece=true
  198. }
  199. arr=newList
  200. this.shangList = arr
  201. // if (this.page == 1) {
  202. // this.shangList = arr
  203. // } else {
  204. // this.shangList = [...this.shangList, ...arr]
  205. // }
  206. // if(this.page == this.total){
  207. // this.status = 'nomore'
  208. // }else{
  209. // this.status = 'loadmore'
  210. // }
  211. }
  212. })
  213. }
  214. uni.stopPullDownRefresh();
  215. uni.hideLoading()
  216. });
  217. },
  218. //已选商品
  219. yixuan() {
  220. uni.navigateTo({
  221. url:'./yixuan_shang?actShopid='+this.actShopid
  222. })
  223. },
  224. }
  225. }
  226. </script>
  227. <style>
  228. page {
  229. /* background-color: #F5F5F5; */
  230. }
  231. .padding{
  232. padding-top: 0px;
  233. }
  234. .all_circle{
  235. margin-top: 20rpx;
  236. width: 60rpx;
  237. height: 60rpx;
  238. border-radius: 86rpx;
  239. border: 1rpx solid rgba(166, 166, 166, 1);
  240. }
  241. .quanxuan{
  242. margin: -60rpx 0 0 70rpx;
  243. font-size: 28rpx;
  244. font-weight: 400;
  245. line-height: 74rpx;
  246. color: rgba(0, 0, 0, 1);
  247. }
  248. .all_select{
  249. margin: -75rpx 0 0 400rpx;
  250. width: 137rpx;
  251. height: 74rpx;
  252. border-radius: 22rpx;
  253. background: rgba(245, 211, 71, 1);
  254. font-size: 24rpx;
  255. line-height: 74rpx;
  256. color: rgba(0, 0, 0, 1);
  257. text-align: center;
  258. }
  259. /* 商品列表 */
  260. .shang_list{
  261. width: 711rpx;
  262. height: 160rpx;
  263. margin-top: 20rpx;
  264. opacity: 1;
  265. background: rgba(255, 255, 255, 1);
  266. }
  267. .shang_circle{
  268. position: absolute;
  269. margin: 50rpx 0 0 41rpx;
  270. width: 60rpx;
  271. height: 60rpx;
  272. border-radius: 86rpx;
  273. border: 1rpx solid rgba(166, 166, 166, 1);
  274. }
  275. .shang_circle_select{
  276. position: absolute;
  277. margin: 50rpx 0 0 41rpx;
  278. width: 60rpx;
  279. height: 60rpx;
  280. border-radius: 86rpx;
  281. background-color:rgba(245, 211, 71, 1);
  282. }
  283. .shang_image{
  284. position: absolute;
  285. margin: 31rpx 0 0 141rpx;
  286. width: 100rpx;
  287. height: 100rpx;
  288. border-radius: 6rpx;
  289. /* background: url(https://img.js.design/assets/smartFill/img395164da755928.jpeg), rgba(204, 204, 204, 1); */
  290. }
  291. .shang_name{
  292. position: absolute;
  293. margin: 29rpx 0 0 259rpx;
  294. font-size: 32rpx;
  295. color: rgba(0, 0, 0, 1);
  296. }
  297. .shang_time{
  298. position: absolute;
  299. margin: 90rpx 0 0 259rpx;
  300. font-size: 24rpx;
  301. color: rgba(153, 153, 153, 1);
  302. }
  303. </style>