app-commodity.vue 8.0 KB

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