app-commodity.vue 5.9 KB

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