specs.vue 8.5 KB

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