app-commodity.vue 7.6 KB

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