app-commodity.vue 5.8 KB

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