app-commodity.vue 7.1 KB

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