specsStock.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view class="specs">
  3. <checkbox-group @change="checkboxChange">
  4. <view class="list acea-row" :class="administer?'on':''" v-for="(item, index) in attrsList" :key="index">
  5. <!-- #ifndef MP -->
  6. <checkbox class="checkbox" v-if="administer" :value="(item.id).toString()" :checked="item.checked" />
  7. <!-- #endif -->
  8. <!-- #ifdef MP -->
  9. <checkbox class="checkbox" v-if="administer" :value="item.id" :checked="item.checked" />
  10. <!-- #endif -->
  11. <view class="listCon">
  12. <!-- <view class="item acea-row row-middle">
  13. <view class="name">商品图</view>
  14. <view class="pictrue">
  15. <image :src="item.image" mode="aspectFill"></image>
  16. </view>
  17. </view> -->
  18. <view class="item acea-row row-middle">
  19. <view class="name">规格名称</view>
  20. <view class="info">{{item.suk}}</view>
  21. </view>
  22. <view class="item acea-row row-middle">
  23. <view class="name">剩余库存</view>
  24. <view class="stock">{{item.stock}}</view>
  25. </view>
  26. <view class="item acea-row row-middle">
  27. <view>修改库存</view>
  28. <view class="acea-row row-middle">
  29. <view class="itemn acea-row row-middle" :class="item.current == indexn?'on':''" v-for="(itemn, indexn) in navList" :key="indexn" @click="navTap(item,indexn)">
  30. <text class="iconfont" :class="item.current == indexn?'icon-ic_Selected':'icon-ic_unselect'"></text>
  31. <text>{{itemn}}</text>
  32. </view>
  33. </view>
  34. </view>
  35. <view class="item acea-row row-middle">
  36. <view class="name">库存</view>
  37. <input type="number" :disabled="administer" v-model="item.currentStock" placeholder="请填写库存" placeholder-class="placeholder"/>
  38. </view>
  39. </view>
  40. </view>
  41. </checkbox-group>
  42. <view class="footer on acea-row row-between-wrapper" v-if="administer">
  43. <checkbox-group @change="checkboxAllChange">
  44. <checkbox value="all" :checked="isAllSelect" />
  45. <text class='checkAll'>全选</text>
  46. </checkbox-group>
  47. <view class="acea-row row-middle">
  48. <view class="bnt acea-row row-center-wrapper" @click="manageTap">取消</view>
  49. <view class="bnt on acea-row row-center-wrapper" @click="batchEdit">批量修改</view>
  50. </view>
  51. </view>
  52. <view class="footer acea-row row-between-wrapper" v-else>
  53. <view class="bnt acea-row row-center-wrapper" @click="manageTap">批量操作</view>
  54. <view class="bnt on acea-row row-center-wrapper" @click="define">保存</view>
  55. </view>
  56. <edit-stock :visible='visibleStock' :goodsInfo='goodsInfo' :storeNum='storeNum' @closeDrawer='stockCloseDrawer' @successChange='successChange'></edit-stock>
  57. </view>
  58. </template>
  59. <script>
  60. import editStock from './components/editStock/index.vue';
  61. import {
  62. getStoreGetAttrs,
  63. postStoreUpdateAttrs,
  64. } from "@/api/admin";
  65. export default {
  66. components: {
  67. editStock
  68. },
  69. data() {
  70. return {
  71. navList:['入库','出库'],
  72. attrsList:[],
  73. id:0,
  74. administer:false,
  75. isAllSelect: false,
  76. visibleStock: false,
  77. goodsInfo:{
  78. id:0,
  79. spec_type:1,
  80. attr_value:{}
  81. },
  82. storeNum:1
  83. }
  84. },
  85. onShow() {
  86. },
  87. onLoad(option) {
  88. this.id = option.id;
  89. this.storeNum = parseInt(option.storeNum);
  90. this.getAttrsList();
  91. },
  92. methods:{
  93. navTap(item,index){
  94. item.current = index
  95. },
  96. //批量获取id集合
  97. getIds(){
  98. let ids = []
  99. this.attrsList.forEach(item=>{
  100. if(item.checked){
  101. ids.push(item.id)
  102. }
  103. })
  104. return ids
  105. },
  106. batchEdit(){
  107. if(!this.getIds().length){
  108. this.$util.Tips({
  109. title: '请选择商品规格'
  110. });
  111. return
  112. }
  113. this.goodsInfo.id = this.id;
  114. this.visibleStock = true;
  115. },
  116. stockCloseDrawer(){
  117. this.visibleStock = false;
  118. },
  119. define(){
  120. let data = {
  121. attr_value:[]
  122. }
  123. data.type = 'stock';
  124. this.attrsList.forEach(item=>{
  125. let obj = {
  126. unique:item.unique,
  127. stock:item.current? parseInt(item.stock)-parseInt(item.currentStock) : parseInt(item.stock)+parseInt(item.currentStock)
  128. }
  129. data.attr_value.push(obj)
  130. })
  131. postStoreUpdateAttrs(this.id,data).then(res=>{
  132. this.$util.Tips({
  133. title: res.msg
  134. },() => {
  135. uni.navigateTo({
  136. url: '/pages/admin/goods/index'
  137. })
  138. });
  139. }).catch(err=>{
  140. this.$util.Tips({
  141. title: err
  142. });
  143. })
  144. },
  145. getAttrsList(){
  146. getStoreGetAttrs(this.id).then(res=>{
  147. let data = res.data;
  148. data.forEach(item => {
  149. item.checked = false;
  150. item.currentStock = 0;
  151. item.current = 0;
  152. })
  153. this.attrsList = data;
  154. }).catch(err=>{
  155. this.$util.Tips({
  156. title: err
  157. });
  158. })
  159. },
  160. checkboxChange(event) {
  161. let idList = event.detail.value;
  162. this.attrsList.forEach((item) => {
  163. if (idList.indexOf(item.id + '') !== -1) {
  164. item.checked = true;
  165. } else {
  166. item.checked = false;
  167. }
  168. })
  169. if (idList.length == this.attrsList.length) {
  170. this.isAllSelect = true;
  171. } else {
  172. this.isAllSelect = false;
  173. }
  174. },
  175. forGoods(val) {
  176. let that = this;
  177. if (!that.attrsList.length) return
  178. that.attrsList.forEach((item) => {
  179. if (val) {
  180. item.checked = true;
  181. } else {
  182. item.checked = false;
  183. }
  184. })
  185. },
  186. checkboxAllChange(event) {
  187. let value = event.detail.value;
  188. if (value.length) {
  189. this.isAllSelect = true;
  190. this.forGoods(1)
  191. } else {
  192. this.isAllSelect = false;
  193. this.forGoods(0)
  194. }
  195. },
  196. manageTap() {
  197. this.administer = !this.administer;
  198. },
  199. priceCloseDrawer(){
  200. this.visibleStock = false
  201. },
  202. successChange(e){
  203. this.visibleStock = false
  204. this.attrsList.forEach(item=>{
  205. if(item.checked){
  206. item.currentStock = e.currentStock;
  207. item.current = e.current
  208. }
  209. })
  210. this.manageTap();
  211. }
  212. }
  213. }
  214. </script>
  215. <style lang="scss" scoped>
  216. /deep/checkbox .uni-checkbox-input.uni-checkbox-input-checked {
  217. border: 1px solid #2A7EFB !important;
  218. background-color: #2A7EFB !important;
  219. }
  220. /deep/checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  221. border: 1px solid #2A7EFB !important;
  222. background-color: #2A7EFB !important;
  223. }
  224. .specs{
  225. padding: 24rpx 20rpx 112rpx 20rpx;
  226. padding-bottom: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  227. padding-bottom: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  228. .list{
  229. background-color: #fff;
  230. border-radius: 24rpx;
  231. padding: 0 24rpx;
  232. margin-bottom: 20rpx;
  233. .listCon{
  234. flex: 1;
  235. }
  236. &.on {
  237. input{
  238. color: #999999 !important;
  239. }
  240. }
  241. .checkbox{
  242. margin: 32rpx 12rpx 0 0;
  243. }
  244. .item{
  245. min-height: 102rpx;
  246. font-size: 28rpx;
  247. font-family: PingFang SC, PingFang SC;
  248. font-weight: 400;
  249. &~.item{
  250. border-top: 1px solid #F1F1F1;
  251. }
  252. .itemn{
  253. margin-left: 50rpx;
  254. color: #999999;
  255. .iconfont {
  256. margin-top: 4rpx;
  257. color: #CCCCCC;
  258. margin-right: 14rpx;
  259. }
  260. &.on {
  261. color: #333333;
  262. .iconfont {
  263. color: #2A7EFB;
  264. }
  265. }
  266. }
  267. .name{
  268. color: #333333;
  269. width: 115rpx;
  270. margin-right: 39rpx;
  271. }
  272. .info{
  273. color: #999999;
  274. flex: 1;
  275. }
  276. .stock{
  277. font-size: 36rpx;
  278. font-family: 'Regular';
  279. color: #999;
  280. }
  281. input {
  282. font-size: 36rpx;
  283. font-family: 'Regular';
  284. color: #333333;
  285. }
  286. // #ifdef MP
  287. input {
  288. font-size: 30rpx;
  289. }
  290. // #endif
  291. .placeholder{
  292. font-size:28rpx;
  293. }
  294. .pictrue{
  295. width: 100rpx;
  296. height: 100rpx;
  297. image {
  298. width: 100%;
  299. height: 100%;
  300. border-radius: 16rpx;
  301. }
  302. }
  303. }
  304. }
  305. .footer {
  306. box-sizing: border-box;
  307. padding: 0 20rpx;
  308. width: 100%;
  309. height: 112rpx;
  310. background-color: #fff;
  311. position: fixed;
  312. bottom: 0;
  313. z-index: 30;
  314. height: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  315. height: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  316. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  317. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  318. width: 100%;
  319. left: 0;
  320. &.on {
  321. height: 96rpx;
  322. height: calc(96rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  323. height: calc(96rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  324. .bnt{
  325. width: 160rpx;
  326. height: 64rpx;
  327. font-size: 24rpx;
  328. &.on{
  329. background-color: #2A7EFB;
  330. color: #fff;
  331. margin-left: 16rpx;
  332. }
  333. }
  334. }
  335. .bnt {
  336. width: 346rpx;
  337. height: 72rpx;
  338. border-radius: 200rpx;
  339. border: 1px solid #2A7EFB;
  340. color: #2A7EFB;
  341. font-size: 26rpx;
  342. font-family: PingFang SC, PingFang SC;
  343. font-weight: 500;
  344. &.on{
  345. background-color: #2A7EFB;
  346. color: #fff;
  347. }
  348. }
  349. }
  350. }
  351. </style>