app-commodity.vue 7.9 KB

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