specs.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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.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">
  52. <checkbox value="all" :checked="isAllSelect" />
  53. <text class='checkAll'>全选</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. /deep/checkbox .uni-checkbox-input.uni-checkbox-input-checked {
  277. border: 1px solid #2A7EFB !important;
  278. background-color: #2A7EFB !important;
  279. color: #fff !important;
  280. }
  281. /deep/checkbox .wx-checkbox-input.wx-checkbox-input-checked {
  282. border: 1px solid #2A7EFB !important;
  283. background-color: #2A7EFB !important;
  284. color: #fff !important;
  285. }
  286. .specs {
  287. padding: 24rpx 20rpx 112rpx 20rpx;
  288. padding-bottom: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  289. padding-bottom: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  290. .list {
  291. background-color: #fff;
  292. border-radius: 24rpx;
  293. padding: 0 24rpx;
  294. margin-bottom: 20rpx;
  295. .listCon {
  296. flex: 1;
  297. }
  298. &.on {
  299. input {
  300. color: #999999 !important;
  301. }
  302. }
  303. .checkbox {
  304. margin: 32rpx 12rpx 0 0;
  305. }
  306. .item {
  307. min-height: 102rpx;
  308. font-size: 28rpx;
  309. font-family: PingFang SC, PingFang SC;
  310. font-weight: 400;
  311. &~.item {
  312. border-top: 1rpx solid #F1F1F1;
  313. }
  314. .name {
  315. color: #333333;
  316. width: 115rpx;
  317. margin-right: 39rpx;
  318. }
  319. .info {
  320. color: #999999;
  321. flex: 1;
  322. }
  323. input {
  324. font-size: 36rpx;
  325. font-family: 'Regular';
  326. color: #333333;
  327. }
  328. // #ifdef MP
  329. input {
  330. font-size: 30rpx;
  331. }
  332. // #endif
  333. .placeholder {
  334. font-size: 28rpx;
  335. }
  336. .pictrue {
  337. width: 100rpx;
  338. height: 100rpx;
  339. image {
  340. width: 100%;
  341. height: 100%;
  342. border-radius: 16rpx;
  343. }
  344. }
  345. }
  346. }
  347. .footer {
  348. box-sizing: border-box;
  349. padding: 0 20rpx;
  350. width: 100%;
  351. height: 112rpx;
  352. background-color: #fff;
  353. position: fixed;
  354. bottom: 0;
  355. z-index: 30;
  356. height: calc(112rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  357. height: calc(112rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  358. padding-bottom: constant(safe-area-inset-bottom); ///兼容 IOS<11.2/
  359. padding-bottom: env(safe-area-inset-bottom); ///兼容 IOS>11.2/
  360. width: 100%;
  361. left: 0;
  362. &.on {
  363. height: 96rpx;
  364. height: calc(96rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  365. height: calc(96rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  366. .bnt {
  367. width: 160rpx;
  368. height: 64rpx;
  369. font-size: 24rpx;
  370. &.on {
  371. background-color: #2A7EFB;
  372. color: #fff;
  373. margin-left: 16rpx;
  374. }
  375. }
  376. }
  377. .bnt {
  378. width: 346rpx;
  379. height: 72rpx;
  380. border-radius: 200rpx;
  381. border: 1px solid #2A7EFB;
  382. color: #2A7EFB;
  383. font-size: 26rpx;
  384. font-family: PingFang SC, PingFang SC;
  385. font-weight: 500;
  386. &.on {
  387. background-color: #2A7EFB;
  388. color: #fff;
  389. }
  390. }
  391. }
  392. }
  393. </style>