app-commodity.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <template>
  2. <view class="item-cmd_bx">
  3. <view class="img_bx">
  4. <app-img :src="info.cover" alt="商品图" mode="aspectFit" :height="160" />
  5. </view>
  6. <view class="cmd-info_bx">
  7. <view class="tit">{{ info.itemName || "" }}</view>
  8. <view class="kc">库存 {{ info.stock }}</view>
  9. <view class="num-open_bx">
  10. <view class="price">¥{{ showPrice }}</view>
  11. <view class="open-bx" v-if="type == COMMODITY_TYPE.COMMON">
  12. <i
  13. class="iconfont iconjian"
  14. @click="delEvent"
  15. v-if="bigCount > 0 || smallCount > 0"
  16. ></i>
  17. <text class="num" @click="customNum">
  18. <text v-if="bigCount > 0 || smallCount > 0">{{ `${bigCount}` }}</text>
  19. <text v-if="smallCount > 0">/</text>
  20. <text v-if="smallCount > 0">{{ `${smallCount}` }}</text>
  21. </text>
  22. <i class="iconfont iconzeng" @click="addEvent"></i>
  23. </view>
  24. <view class="open-bx" v-else-if="type == COMMODITY_TYPE.CHANGE">
  25. <input class="change-input" v-model="changeAutoPrice" type="digit" placeholder="自动调价" selection-start="0" selection-end="1" />
  26. <i :class="isShowSucceed?'position iconfont iconjihuo':'position'" ></i>
  27. <view class="btn-box" @click="changePriceEvent">确定</view>
  28. </view>
  29. </view>
  30. </view>
  31. </view>
  32. </template>
  33. <script>
  34. import { COMMODITY_TYPE } from "@/utils/declare";
  35. import AppImg from "@/components/app-img";
  36. import { autoPriceByIdApi, changePriceByIdApi } from '@/api/product/index'
  37. import productMins from "@/mixins/productContrapose";
  38. export default {
  39. name: "Commodity",
  40. components: {
  41. AppImg
  42. },
  43. mixins: [productMins],
  44. props: {
  45. info: {
  46. required: true,
  47. type: Object,
  48. default() {
  49. return {};
  50. }
  51. },
  52. type: {
  53. type: String,
  54. default: COMMODITY_TYPE.COMMON
  55. },
  56. bigCount: {
  57. type: Number,
  58. default: 0
  59. },
  60. smallCount: {
  61. type: Number,
  62. default: 0
  63. },
  64. autoPrice: {}
  65. },
  66. data() {
  67. return {
  68. COMMODITY_TYPE,
  69. isShowSucceed:false,
  70. changeAutoPrice:'',
  71. showPrice:0.00,
  72. ifFocus:false
  73. };
  74. },
  75. created() {},
  76. mounted() {
  77. if(this.info.priceLabel == 2){
  78. this.changeAutoPrice = this.info.price
  79. }
  80. this.showPrice = this.info.price
  81. },
  82. methods: {
  83. addEvent() {
  84. this.$emit("add", this.info);
  85. },
  86. delEvent() {
  87. this.$emit("del", this.info);
  88. },
  89. async changePriceEvent(event) {
  90. let self = this
  91. await changePriceByIdApi({
  92. productId: this.info.id,
  93. price: this.changeAutoPrice
  94. }).then(res => {
  95. if(res.code == 1){
  96. this.showPrice = res.data.price
  97. this.isShowSucceed = true
  98. setTimeout(()=>{
  99. this.isShowSucceed = false
  100. },1000)
  101. }else{
  102. self.$msg(res.msg)
  103. }
  104. })
  105. },
  106. customNum() {
  107. this.$emit("customNum", {
  108. ...this.info,
  109. bigCount: this.bigCount,
  110. smallCount: this.smallCount
  111. });
  112. }
  113. }
  114. };
  115. </script>
  116. <style lang="scss" scoped>
  117. .item-cmd_bx {
  118. position: relative;
  119. margin-bottom: 20px;
  120. .img_bx {
  121. height: 160px;
  122. width: 160px;
  123. position: absolute;
  124. left: 0px;
  125. top: 0px;
  126. }
  127. .cmd-info_bx {
  128. padding-left: 177px;
  129. & .tit {
  130. font-size: 28px;
  131. font-weight: 400;
  132. color: #333333;
  133. padding-top: 10px;
  134. }
  135. & .kc {
  136. color: #999999;
  137. font-size: 24px;
  138. padding: 8px 0 24px;
  139. }
  140. & .num-open_bx {
  141. display: flex;
  142. align-items: center;
  143. & .price {
  144. font-size: 28px;
  145. color: #ff2842;
  146. flex: 1;
  147. }
  148. & .open-bx {
  149. display: flex;
  150. align-items: center;
  151. & .iconfont {
  152. //margin-left: 15rpx;
  153. color: #3385ff;
  154. font-size: 42px;
  155. }
  156. .position{
  157. display: block;
  158. width: 70rpx;
  159. text-align: center;
  160. }
  161. .iconcachu {
  162. margin: 0 6px 0 20px;
  163. color: #ccc;
  164. &.edit {
  165. color: #3385ff;
  166. }
  167. }
  168. & > .num {
  169. display: inline-block;
  170. width: 120rpx;
  171. height:45rpx;
  172. text-align:center;
  173. margin: 0 8px;
  174. color: #868686;
  175. border-radius: 22px;
  176. background-color: #f5f5f5;
  177. padding: 3px 0;
  178. font-size: 30rpx;
  179. }
  180. .change-input {
  181. width: 164px;
  182. height: 60px;
  183. line-height: 60px;
  184. text-align: center;
  185. background: #ffffff;
  186. border: 1px solid #dddddd;
  187. border-radius: 4px;
  188. font-size: 25px;
  189. }
  190. .btn-box{
  191. width: 100rpx;
  192. height: 60rpx;
  193. line-height: 60rpx;
  194. color: #ffffff;
  195. background: #3385ff;
  196. text-align: center;
  197. border-radius: 10rpx;
  198. }
  199. }
  200. }
  201. }
  202. }
  203. </style>