app-commodity.vue 4.8 KB

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