inventory.vue 7.9 KB

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