specs.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421
  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" style="width: 40rpx;height: 40rpx"/>
  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.attrValue}}</view>
  21. </view>
  22. <view class="item acea-row row-middle">
  23. <view class="name">成本价</view>
  24. <input type="number" :disabled="administer" v-model="item.cost"
  25. placeholder-class="placeholder" />
  26. </view>
  27. <view class="item acea-row row-middle">
  28. <view class="name">划线价</view>
  29. <input type="number" :disabled="administer" v-model="item.otPrice"
  30. placeholder-class="placeholder" />
  31. </view>
  32. <view class="item acea-row row-middle">
  33. <view class="name">售价</view>
  34. <input type="number" @blur="handleInput(item)" :disabled="administer" min='0' v-model="item.price"
  35. placeholder="请填写售价" placeholder-class="placeholder" />
  36. </view>
  37. <view class="item acea-row row-middle" v-if="isPaidMember">
  38. <view class="name">会员价</view>
  39. <input @blur="handleInput(item)" type="number" :disabled="administer" min='0' v-model="item.vipPrice"
  40. placeholder="请填写会员价" placeholder-class="placeholder" />
  41. </view>
  42. <view class="item acea-row row-middle">
  43. <view class="name">库存</view>
  44. <input type="number" :disabled="administer" v-model="item.stock" placeholder="请填写库存"
  45. placeholder-class="placeholder" />
  46. </view>
  47. </view>
  48. </view>
  49. </checkbox-group>
  50. <view class="footer on acea-row row-between-wrapper" v-if="administer">
  51. <checkbox-group @change="checkboxAllChange" class="flex-y-center ml-22">
  52. <checkbox value="all" :checked="isAllSelect" />
  53. <text class='checkAll ml-12'>全选</text>
  54. </checkbox-group>
  55. <view class="acea-row row-middle">
  56. <view class="bnt acea-row row-center-wrapper" @click="manageTap">取消</view>
  57. <view class="bnt on acea-row row-center-wrapper" @click="batchEdit">批量修改</view>
  58. </view>
  59. </view>
  60. <view class="footer acea-row row-between-wrapper" v-else>
  61. <view class="bnt acea-row row-center-wrapper" @click="manageTap">批量操作</view>
  62. <view class="bnt on acea-row row-center-wrapper" @click="define">保存</view>
  63. </view>
  64. <edit-price :visible='visiblePrice' :isPaidMember="isPaidMember" :goodsInfo='goodsInfo' @closeDrawer='priceCloseDrawer'
  65. @successChange='successChange'></edit-price>
  66. </view>
  67. </template>
  68. <script>
  69. import editPrice from './components/editPrice/index.vue';
  70. import {
  71. employeeProductInfo,
  72. reviewFreeEdit
  73. } from "@/api/work.js";
  74. export default {
  75. components: {
  76. editPrice
  77. },
  78. data() {
  79. return {
  80. attrsList: [],
  81. id: 0,
  82. administer: false,
  83. isAllSelect: false,
  84. visiblePrice: false,
  85. goodsInfo: {
  86. id: 0,
  87. spec_type: 1,
  88. attr_value: {}
  89. },
  90. cateId: '',
  91. isPaidMember:false,
  92. }
  93. },
  94. onShow() {},
  95. onLoad(option) {
  96. this.id = option.id;
  97. this.getAttrsList();
  98. },
  99. methods: {
  100. handleInput(item) {
  101. if (Number(item.vipPrice) > Number(item.price)) {
  102. item.vipPrice = item.price-0.01;
  103. }
  104. if(Number(item.vipPrice)<=0){
  105. item.vipPrice=0.01
  106. }
  107. },
  108. //只能输入两位小数
  109. decimalNum(e,item) {
  110. let that = this
  111. // 通过正则过滤小数点后两位
  112. // valueAsNumber是输入框值经过过滤的数字形式 如001就是1
  113. let value = '';
  114. value = (e.detail.value).toString();
  115. value = (value.match(/^\d*(.?\d{0,2})/g)[0]) || null
  116. that.$set(item,'price', value)
  117. },
  118. //批量获取id集合
  119. getIds() {
  120. let ids = []
  121. this.attrsList.forEach(item => {
  122. if (item.checked) {
  123. ids.push(item.id)
  124. }
  125. })
  126. return ids
  127. },
  128. batchEdit() {
  129. if (!this.getIds().length) {
  130. this.$util.Tips({
  131. title: '请选择商品规格'
  132. });
  133. return
  134. }
  135. this.goodsInfo.id = this.id;
  136. this.goodsInfo.attr_value = {
  137. cost: '',
  138. price: '',
  139. otPrice: '',
  140. stock: '',
  141. vipPrice:''
  142. }
  143. this.visiblePrice = true;
  144. },
  145. define() {
  146. let data = {
  147. attr_value: []
  148. }
  149. this.attrsList.forEach(item => {
  150. data.attr_value.push({
  151. id: item.id,
  152. price: item.price,
  153. stock: item.stock,
  154. cost:item.cost,
  155. otPrice:item.otPrice,
  156. vipPrice:item.vipPrice,
  157. })
  158. })
  159. let requestObj = {
  160. "attrValue": data.attr_value,
  161. "cateId": this.cateId,
  162. "id": this.id
  163. }
  164. reviewFreeEdit(requestObj).then(res => {
  165. if (res.code == 200) {
  166. this.$util.Tips({
  167. title: '操作成功'
  168. });
  169. setTimeout(function() {
  170. uni.navigateBack()
  171. }, 300);
  172. }
  173. })
  174. },
  175. getAttrsList() {
  176. employeeProductInfo(this.id).then(res => {
  177. let data = res.data.attrValueList;
  178. this.isPaidMember=res.data.isPaidMember
  179. this.cateId = res.data.cateId
  180. data.forEach(item => {
  181. item.checked = false;
  182. let str = ''
  183. let obj = JSON.parse(item.attrValue)
  184. for (let key in obj) {
  185. str += `${obj[key]},`
  186. }
  187. str = str.slice(0, str.length - 1)
  188. item.attrValue = str
  189. })
  190. this.attrsList = data;
  191. }).catch(err => {
  192. this.$util.Tips({
  193. title: err
  194. });
  195. })
  196. },
  197. checkboxChange(event) {
  198. let idList = event.detail.value;
  199. this.attrsList.forEach((item) => {
  200. if (idList.indexOf(item.id + '') !== -1) {
  201. item.checked = true;
  202. } else {
  203. item.checked = false;
  204. }
  205. })
  206. if (idList.length == this.attrsList.length) {
  207. this.isAllSelect = true;
  208. } else {
  209. this.isAllSelect = false;
  210. }
  211. },
  212. forGoods(val) {
  213. let that = this;
  214. if (!that.attrsList.length) return
  215. that.attrsList.forEach((item) => {
  216. if (val) {
  217. item.checked = true;
  218. } else {
  219. item.checked = false;
  220. }
  221. })
  222. },
  223. checkboxAllChange(event) {
  224. let value = event.detail.value;
  225. if (value.length) {
  226. this.isAllSelect = true;
  227. this.forGoods(1)
  228. } else {
  229. this.isAllSelect = false;
  230. this.forGoods(0)
  231. }
  232. },
  233. manageTap() {
  234. this.administer = !this.administer;
  235. },
  236. priceCloseDrawer() {
  237. this.visiblePrice = false
  238. },
  239. successChange(e) {
  240. this.visiblePrice = false
  241. let data = e;
  242. this.attrsList.forEach(item => {
  243. if (item.checked) {
  244. if (data.cost) {
  245. item.cost = data.cost
  246. }
  247. if (data.price) {
  248. item.price = data.price
  249. }
  250. if (data.otPrice) {
  251. item.otPrice = data.otPrice
  252. }
  253. if (data.stock) {
  254. item.stock = data.stock
  255. }
  256. if (data.vipPrice&&Number(data.vipPrice)<Number(item.price)) {
  257. item.vipPrice = data.vipPrice
  258. }
  259. if (data.vipPrice&&Number(data.vipPrice)>Number(item.price)) {
  260. item.vipPrice = item.price-0.01
  261. }
  262. if (data.vipPrice&&Number(data.vipPrice)<=0) {
  263. item.vipPrice =0.01
  264. }
  265. if(data.price&&Number(data.price)<Number(item.vipPrice)){
  266. item.vipPrice=data.price-0.01
  267. }
  268. }
  269. })
  270. this.manageTap();
  271. }
  272. }
  273. }
  274. </script>
  275. <style lang="scss" scoped>
  276. ::v-deep .uni-checkbox-input{
  277. margin-right: 0 !important;
  278. width: 40rpx !important;
  279. height: 40rpx !important;
  280. }
  281. ::v-deep checkbox .uni-checkbox-input.uni-checkbox-input-checked {
  282. border: 1px solid #2A7EFB !important;
  283. background-color: #2A7EFB !important;
  284. color: #fff !important;
  285. }
  286. ::v-deep checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  287. border: 1px solid #2A7EFB !important;
  288. background-color: #2A7EFB !important;
  289. color: #fff !important;
  290. }
  291. .specs {
  292. padding: 20rpx 24rpx 112rpx 24rpx;
  293. padding-bottom: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  294. padding-bottom: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  295. .list {
  296. background-color: #fff;
  297. border-radius: 24rpx;
  298. padding: 0 24rpx;
  299. margin-bottom: 20rpx;
  300. .listCon {
  301. flex: 1;
  302. }
  303. &.on {
  304. input {
  305. color: #999999 !important;
  306. }
  307. }
  308. .checkbox {
  309. margin: 32rpx 12rpx 0 0;
  310. }
  311. .item {
  312. min-height: 102rpx;
  313. font-size: 28rpx;
  314. font-family: PingFang SC, PingFang SC;
  315. font-weight: 400;
  316. &~.item {
  317. border-top: 1rpx solid #F1F1F1;
  318. }
  319. .name {
  320. color: #333333;
  321. width: 115rpx;
  322. margin-right: 39rpx;
  323. }
  324. .info {
  325. color: #999999;
  326. flex: 1;
  327. }
  328. input {
  329. font-size: 36rpx;
  330. font-family: 'Regular';
  331. color: #333333;
  332. }
  333. // #ifdef MP
  334. input {
  335. font-size: 30rpx;
  336. }
  337. // #endif
  338. .placeholder {
  339. font-size: 28rpx;
  340. }
  341. .pictrue {
  342. width: 100rpx;
  343. height: 100rpx;
  344. image {
  345. width: 100%;
  346. height: 100%;
  347. border-radius: 16rpx;
  348. }
  349. }
  350. }
  351. }
  352. .footer {
  353. box-sizing: border-box;
  354. padding: 0 20rpx;
  355. width: 100%;
  356. height: 112rpx;
  357. background-color: #fff;
  358. position: fixed;
  359. bottom: 0;
  360. z-index: 30;
  361. height: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  362. height: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  363. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  364. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  365. width: 100%;
  366. left: 0;
  367. &.on {
  368. height: 96rpx;
  369. height: calc(96rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  370. height: calc(96rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  371. .bnt {
  372. width: 160rpx;
  373. height: 64rpx;
  374. font-size: 24rpx;
  375. &.on {
  376. background-color: #2A7EFB;
  377. color: #fff;
  378. margin-left: 16rpx;
  379. }
  380. }
  381. }
  382. .bnt {
  383. width: 346rpx;
  384. height: 72rpx;
  385. border-radius: 200rpx;
  386. border: 1px solid #2A7EFB;
  387. color: #2A7EFB;
  388. font-size: 26rpx;
  389. font-family: PingFang SC, PingFang SC;
  390. font-weight: 500;
  391. &.on {
  392. background-color: #2A7EFB;
  393. color: #fff;
  394. }
  395. }
  396. }
  397. }
  398. </style>