app-commodity.vue 8.0 KB

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