addComList.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <view class="container">
  3. <u-navbar leftIconColor="#fff" titleStyle="color:#fff;fontSize:36rpx;" :autoBack="true" bgColor="#2C6FF3"
  4. :placeholder="true" title="增加商品"></u-navbar>
  5. <view class="content">
  6. <view class="xy-card" v-for="(item,index) in commList" :key="item.id">
  7. <view class="comm-item">
  8. <view class="image">
  9. <u--image radius="4" width="130rpx" height="130rpx" :src="item.cover" mode="widthFix"
  10. :lazy-load="true">
  11. </u--image>
  12. </view>
  13. <view class="item-content">
  14. <view class="item-top">
  15. <view>
  16. {{item.name}}
  17. </view>
  18. </view>
  19. <view class="item-input-wrap">
  20. <view class="item-input" v-if="type!=1">
  21. <view class="input-label require">
  22. 条形码:
  23. </view>
  24. <view class="input-box">
  25. <text>{{item.barcode}}</text>
  26. </view>
  27. </view>
  28. <view class="item-input" v-if="type!=1">
  29. <view class="input-label require">
  30. 成本价
  31. </view>
  32. <view class="input-box">
  33. <input type="digit" class="input" placeholder="请输入" border="surround" v-model="item.priceCost" />
  34. </view>
  35. </view>
  36. <view class="item-input require">
  37. <view class="input-label">
  38. 零售价
  39. </view>
  40. <view class="input-box">
  41. <input type="digit" class="input" placeholder="请输入" border="surround" v-model="item.price" />
  42. </view>
  43. </view>
  44. <!-- <view class="item-input">
  45. <view class="input-label">
  46. 商品容量
  47. </view>
  48. <view class="input-box">
  49. <input type="number" class="input" placeholder="请输入" border="surround" v-model="item.capacity" />
  50. </view>
  51. </view> -->
  52. <view class="item-input">
  53. <view class="input-label">
  54. 库存预警
  55. </view>
  56. <view class="input-box">
  57. <input type="number" class="input" placeholder="请输入" border="surround" v-model="item.warning" />
  58. </view>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <view class="btn safe-bottom">
  66. <xbutton delay="1500" size="large" @click="sure">完成</xbutton>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import {
  72. bindMerc
  73. } from "@/api/commodity/mercGoods.js"
  74. import {
  75. bindDeviceByGoods
  76. } from "@/api/commodity/goods.js"
  77. export default {
  78. data() {
  79. return {
  80. commList: [],
  81. type: null,
  82. storeName: null,
  83. id: null
  84. }
  85. },
  86. onLoad(o) {
  87. if (o.type == 0) { //公库添加到私库
  88. this.type = 0
  89. } else if (o.type == 1) { //私库添加到设备
  90. this.type = 1;
  91. this.id = o.id;
  92. } else if (o.type == 2) { //公库添加到设备
  93. this.type = 2;
  94. this.id = o.id;
  95. }
  96. this.storeName = o.storeName;
  97. let commStor = JSON.parse(uni.getStorageSync(o.storeName))
  98. this.commList = commStor.map(i => {
  99. i.capacity = 100
  100. i.warning = 5
  101. return i
  102. })
  103. },
  104. methods: {
  105. sure() {
  106. if (this.type == 0) { //添加到私库
  107. let params = this.delParams()
  108. if (!params) return
  109. bindMerc(params).then(res => {
  110. if (res.code == 200) {
  111. this.$modal.msg('添加成功~')
  112. uni.setStorageSync(this.storeName, '') //清空购物车
  113. this.$tab.reLaunch('/pages/globalPages/home?tabName=商品')
  114. }
  115. })
  116. } else { //添加到设备
  117. let params = this.delParams()
  118. if (!params) return
  119. let assignParams = {
  120. deviceIds: [this.id],
  121. goodsList: params,
  122. }
  123. bindDeviceByGoods(assignParams).then(res => {
  124. if (res.code == 200) {
  125. this.$modal.msg('添加成功~')
  126. uni.setStorageSync(this.storeName, '') //清空购物车
  127. setTimeout(() => {
  128. // this.$tab.redirectTo(`/pages/equipment/comManage?id=${this.id}`)
  129. let pageList=getCurrentPages()
  130. let delta=2
  131. pageList.forEach(i=>{
  132. if(i.route=='pages/globalPages/allGoodsSearch'){
  133. delta=3
  134. }
  135. })
  136. uni.navigateBack({
  137. delta: delta
  138. })
  139. }, 1000)
  140. }
  141. })
  142. }
  143. },
  144. delParams() {
  145. let params = [];
  146. for (let i = 0; i < this.commList.length; i++) {
  147. let item = this.commList[i];
  148. let obj = {};
  149. obj.goodsId = this.type == 1 ? item.goodsId : item.id;
  150. if (this.type != 1) { //非私库添加需要输入成本价格
  151. if (item.priceCost != undefined && item.priceCost != null) {
  152. obj.priceCost = item.priceCost * 100;
  153. } else {
  154. this.$modal.msg('请输入成本价!')
  155. return false
  156. }
  157. }
  158. if (item.price != undefined && item.price != null) {
  159. obj.price = item.price * 100;
  160. } else {
  161. this.$modal.msg('请输入零售价格!')
  162. return false
  163. }
  164. if (item.price != undefined && item.price != null && item.priceCost != undefined && item.priceCost !=
  165. null) {
  166. obj.price = item.price * 100;
  167. if (obj.price < obj.priceCost) {
  168. this.$modal.msg('零售价不能低于成本价!')
  169. return false
  170. }
  171. }
  172. if (item.capacity != undefined && item.capacity != null) {
  173. obj.capacity = item.capacity;
  174. } else {
  175. // this.$modal.msg('请输入商品容量!')
  176. // return false
  177. }
  178. if (item.warning != undefined && item.warning != null) {
  179. obj.warning = item.warning;
  180. } else {
  181. // this.$modal.msg('请输入预警值!')
  182. // return false
  183. }
  184. params.push(obj)
  185. }
  186. return params
  187. },
  188. }
  189. }
  190. </script>
  191. <style lang="scss" scoped>
  192. .container {
  193. position: relative;
  194. .content {
  195. padding: 12rpx 24rpx 108rpx;
  196. .xy-card+.xy-card {
  197. margin-top: 18rpx;
  198. }
  199. .tag {
  200. position: absolute;
  201. right: 12rpx;
  202. top: 12rpx;
  203. }
  204. .comm-item {
  205. display: flex;
  206. flex-direction: row;
  207. justify-content: flex-start;
  208. align-items: center;
  209. background-color: #fff;
  210. border-radius: 12rpx;
  211. box-sizing: border-box;
  212. padding: 12rpx;
  213. .image {
  214. width: 130rpx;
  215. }
  216. .item-content {
  217. padding-left: 24rpx;
  218. color: #666;
  219. width: 530rpx;
  220. .item-top {
  221. >view:nth-child(1) {
  222. font-size: 30rpx;
  223. font-weight: bold;
  224. color: #333;
  225. }
  226. >view:nth-child(2) {
  227. font-size: 28rpx;
  228. margin-top: 12rpx;
  229. }
  230. }
  231. .item-input-wrap {
  232. display: flex;
  233. flex-flow: row wrap;
  234. justify-content: space-between;
  235. .item-input {
  236. width: 100%;
  237. display: flex;
  238. flex-flow: row nowrap;
  239. align-items: center;
  240. justify-content: flex-start;
  241. margin-top: 12rpx;
  242. .input-label {
  243. width: 160rpx;
  244. font-size: 30rpx;
  245. line-height: 40rpx;
  246. }
  247. .input-box {
  248. width: 320rpx;
  249. height: 70rpx;
  250. line-height: 70rpx;
  251. .input {
  252. height: 70rpx;
  253. border: 1rpx solid #eee;
  254. box-sizing: border-box;
  255. padding: 0 12rpx;
  256. }
  257. }
  258. }
  259. }
  260. }
  261. }
  262. }
  263. .btn {
  264. position: fixed;
  265. width: 100%;
  266. padding: 24rpx;
  267. left: 0;
  268. bottom: 0;
  269. }
  270. }
  271. </style>