select_shang.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  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.showModal({
  129. title: '提示',
  130. content: res.msg,
  131. success: function (res) {
  132. if (res.confirm) {
  133. } else if (res.cancel) {
  134. }
  135. }
  136. });
  137. }
  138. });
  139. },
  140. //已选择的商品
  141. selectShang(){
  142. // var shopId=uni.getStorageSync('shopId')
  143. this.$Request.get(`/admin/activity-goods/${this.actShopid}`).then(res => {
  144. if (res.code == 0) {
  145. let returnData = res.data
  146. //活动列表
  147. this.allShang(returnData)
  148. }else{
  149. uni.showModal({
  150. content:res.msg
  151. })
  152. }
  153. });
  154. },
  155. //店铺所有商品
  156. allShang(returnData){
  157. // /ad?page=1&limit=10&goodsName=&classifyId=&shopId=147&status=0
  158. let data = {
  159. page: this.page,
  160. limit: this.limit,
  161. goodsName: this.goodsName,
  162. shopId: uni.getStorageSync('shopId'),
  163. // status: this.tabIndex == 1 ? 2 : (this.tabIndex == 2 ? 1 : this.tabIndex)
  164. }
  165. this.$Request.getA("/admin/goodsShop/selectGoodsByShopId", data).then(res => {
  166. if (res.code == 0) {
  167. var total = res.data.totalCount
  168. let data2 = {
  169. page: this.page,
  170. limit: total,
  171. goodsName: this.goodsName,
  172. shopId: uni.getStorageSync('shopId'),
  173. // status: this.tabIndex == 1 ? 2 : (this.tabIndex == 2 ? 1 : this.tabIndex)
  174. }
  175. this.$Request.getA("/admin/goodsShop/selectGoodsByShopId", data2).then(res => {
  176. if (res.code == 0) {
  177. uni.hideLoading()
  178. let returnData2 = res.data
  179. const newList =returnData2.list.map(item =>{
  180. return{...item,shangpin:0}
  181. })
  182. var arr = []
  183. if(returnData.length===0){
  184. newList.forEach(item => {
  185. // 'status'为属性名,'非活动'为修改后的内容
  186. item.shangpin = 1
  187. this.shangList.forEach(item => {
  188. this.shangIds.push(item.goodsId)
  189. })
  190. })
  191. this.ifallselece=true
  192. }else{
  193. for(var j in returnData){
  194. newList.forEach(item => {
  195. if (item.goodsId === returnData[j]) {
  196. // 'status'为属性名,'非活动'为修改后的内容
  197. item.shangpin = 1
  198. this.shangIds.push(item.goodsId)
  199. }
  200. })
  201. }
  202. this.ifallselece=true
  203. }
  204. arr=newList
  205. this.shangList = arr
  206. // if (this.page == 1) {
  207. // this.shangList = arr
  208. // } else {
  209. // this.shangList = [...this.shangList, ...arr]
  210. // }
  211. // if(this.page == this.total){
  212. // this.status = 'nomore'
  213. // }else{
  214. // this.status = 'loadmore'
  215. // }
  216. }
  217. })
  218. }
  219. uni.stopPullDownRefresh();
  220. uni.hideLoading()
  221. });
  222. },
  223. //已选商品
  224. yixuan() {
  225. uni.navigateTo({
  226. url:'./yixuan_shang?actShopid='+this.actShopid
  227. })
  228. },
  229. }
  230. }
  231. </script>
  232. <style>
  233. page {
  234. /* background-color: #F5F5F5; */
  235. }
  236. .padding{
  237. padding-top: 0px;
  238. }
  239. .all_circle{
  240. margin-top: 20rpx;
  241. width: 60rpx;
  242. height: 60rpx;
  243. border-radius: 86rpx;
  244. border: 1rpx solid rgba(166, 166, 166, 1);
  245. }
  246. .quanxuan{
  247. margin: -60rpx 0 0 70rpx;
  248. font-size: 28rpx;
  249. font-weight: 400;
  250. line-height: 74rpx;
  251. color: rgba(0, 0, 0, 1);
  252. }
  253. .all_select{
  254. margin: -75rpx 0 0 400rpx;
  255. width: 137rpx;
  256. height: 74rpx;
  257. border-radius: 22rpx;
  258. background: rgba(245, 211, 71, 1);
  259. font-size: 24rpx;
  260. line-height: 74rpx;
  261. color: rgba(0, 0, 0, 1);
  262. text-align: center;
  263. }
  264. /* 商品列表 */
  265. .shang_list{
  266. width: 711rpx;
  267. height: 160rpx;
  268. margin-top: 20rpx;
  269. opacity: 1;
  270. background: rgba(255, 255, 255, 1);
  271. }
  272. .shang_circle{
  273. position: absolute;
  274. margin: 50rpx 0 0 41rpx;
  275. width: 60rpx;
  276. height: 60rpx;
  277. border-radius: 86rpx;
  278. border: 1rpx solid rgba(166, 166, 166, 1);
  279. }
  280. .shang_circle_select{
  281. position: absolute;
  282. margin: 50rpx 0 0 41rpx;
  283. width: 60rpx;
  284. height: 60rpx;
  285. border-radius: 86rpx;
  286. background-color:rgba(245, 211, 71, 1);
  287. }
  288. .shang_image{
  289. position: absolute;
  290. margin: 31rpx 0 0 141rpx;
  291. width: 100rpx;
  292. height: 100rpx;
  293. border-radius: 6rpx;
  294. /* background: url(https://img.js.design/assets/smartFill/img395164da755928.jpeg), rgba(204, 204, 204, 1); */
  295. }
  296. .shang_name{
  297. position: absolute;
  298. margin: 29rpx 0 0 259rpx;
  299. font-size: 32rpx;
  300. color: rgba(0, 0, 0, 1);
  301. }
  302. .shang_time{
  303. position: absolute;
  304. margin: 90rpx 0 0 259rpx;
  305. font-size: 24rpx;
  306. color: rgba(153, 153, 153, 1);
  307. }
  308. </style>