add-goods.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="add-goods-page">
  3. <scroll-view scroll-y class="goods-form">
  4. <view class="item" @click="chooseGoods">
  5. <view class="goodsLabel">{{form.goodsName ? form.goodsName : '选择商品'}}</view>
  6. <view class="value">
  7. <text class="goods-name"></text>
  8. <u-icon v-if="!form.storeSpecialGoodsId" name="arrow-right" size="20" color="#6c6c6c"></u-icon>
  9. </view>
  10. </view>
  11. <view class="item no-border">
  12. <view class="label">缩略图</view>
  13. <view class="value">
  14. <image class="cover" :src="form.pictureUrl" />
  15. </view>
  16. </view>
  17. <view class="item">
  18. <view class="label">原价</view>
  19. <view class="value price">{{moneyConverter(form.costPrice)}}元</view>
  20. </view>
  21. <view class="item">
  22. <view class="label">活动价</view>
  23. <view class="value">
  24. <u-input border="none" inputAlign="right" fontSize="14" v-model="form.activityPrice" placeholder="请填写活动价格"></u-input>
  25. <text class="fixx">元</text>
  26. </view>
  27. </view>
  28. <view class="item">
  29. <view class="label">每单限购</view>
  30. <view class="value">
  31. <u-input border="none" inputAlign="right" type="number" @input="inventoryMaxNum(index,$event)" fontSize="14" v-model="form.maxNum" placeholder="限购数量"></u-input>
  32. <text class="fixx">份</text>
  33. </view>
  34. </view>
  35. <view class="item">
  36. <view class="label">活动库存</view>
  37. <view class="value">
  38. <u-input border="none" inputAlign="right" type="number" @input="inventoryInput(index,$event)" fontSize="14" v-model="form.activityNum" placeholder="999"></u-input>
  39. <text class="fixx">份</text>
  40. </view>
  41. </view>
  42. </scroll-view>
  43. <u-modal
  44. :show="chooseGoodsVisible"
  45. :showConfirmButton="false"
  46. closeOnClickOverlay
  47. @close="chooseGoodsVisible = false">
  48. <view class="modal-container">
  49. <view class="search-wrap">
  50. <view class="input-wrap">
  51. <u-input border="none" fontSize="14" v-model="goodsName" placeholder="商品名称"></u-input>
  52. </view>
  53. <view class="btn" @click="getGoodsList">搜索</view>
  54. </view>
  55. <view class="goods-list">
  56. <view class="item" v-for="item in goodsList" :key="item.goodsId" @click="handItem(item)">
  57. <view class="cover">
  58. <image class="img" :src="item.pictureUrl"/>
  59. </view>
  60. <view class="cont">
  61. <view class="goods-name">
  62. {{item.goodsName}}
  63. </view>
  64. <view class="desc">
  65. 库存: {{item.maxNum}}, 价格: ¥{{moneyConverter(item.costPrice)}}
  66. </view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </u-modal>
  72. <view class="update-events">
  73. <view class="btn" @click="save">保存</view>
  74. </view>
  75. </view>
  76. </template>
  77. <script>
  78. import {mapState} from 'vuex';
  79. export default {
  80. data () {
  81. return {
  82. getStoreSingleGoodsForStoreUrl: '/storeGoodsManageApi/getStoreSingleGoodsForSpecialForStore',
  83. chooseGoodsVisible: false,
  84. goodsName: '',
  85. goodsList: [],
  86. form: {
  87. goodsId: '',
  88. goodsName: '',
  89. costPrice: '',
  90. modelId: '',
  91. pictureUrl: '',
  92. activityPrice: '',
  93. maxNum: '',
  94. activityNum: ''
  95. },
  96. index : '',
  97. idsStr: ''
  98. }
  99. },
  100. computed: {
  101. ...mapState(['storeInfo'])
  102. },
  103. methods: {
  104. handItem(item) {
  105. this.form.goodsId = item.goodsId
  106. this.form.goodsName = item.goodsName;
  107. this.form.costPrice = item.costPrice;
  108. this.form.modelId = item.modelId;
  109. this.form.pictureUrl = item.pictureUrl;
  110. this.chooseGoodsVisible = false
  111. },
  112. inventoryMaxNum(index,e){
  113. // 只能输入数字
  114. const inputType = /[^\d]/g
  115. this.$nextTick(function () {
  116. this.form.maxNum = e.replace(inputType,'');
  117. })
  118. },
  119. inventoryInput(index,e){
  120. // 只能输入数字
  121. const inputType = /[^\d]/g
  122. this.$nextTick(function () {
  123. this.form.activityNum = e.replace(inputType,'');
  124. })
  125. },
  126. chooseGoods() {
  127. if (this.form.storeSpecialGoodsId) {
  128. return;
  129. }
  130. this.goodsName = '';
  131. this.getGoodsList();
  132. this.chooseGoodsVisible = true;
  133. },
  134. getGoodsList() {
  135. uni.showLoading({
  136. title: '加载中'
  137. });
  138. var dateStr = (new Date()).getTime();
  139. var sign = this.getSign('' + this.storeInfo.storeId + dateStr);
  140. this.requst({
  141. url: this.getStoreSingleGoodsForStoreUrl,
  142. data: {
  143. timestamp: dateStr,
  144. sign: sign,
  145. storeId: this.storeInfo.storeId,
  146. goodsName: this.goodsName,
  147. ids: this.idsStr || ''
  148. },
  149. success: res => {
  150. this.goodsList = res.data.list;
  151. uni.hideLoading()
  152. },
  153. fail: (e) => {
  154. console.log("接口调用失败:" + JSON.stringify(e));
  155. uni.hideLoading();
  156. },
  157. })
  158. },
  159. save() {
  160. let regPrice = (/^[0-9]\d*(,\d{3})*(\.\d{1,2})?$|^0\.\d{1,2}$/);
  161. if (!this.form.goodsId) {
  162. this.$api.msg("请选择商品");
  163. return;
  164. }
  165. if (!this.form.activityPrice) {
  166. this.$api.msg("请输入活动价格");
  167. return;
  168. }
  169. if (!regPrice.test(this.form.activityPrice)) {
  170. this.$api.msg("活动价格只能是整数或小数点后两位");
  171. return;
  172. }
  173. if (this.form.activityPrice * 100 >= this.form.costPrice) {
  174. this.$api.msg("活动价必须小于原价");
  175. return;
  176. }
  177. if (!this.form.maxNum) {
  178. this.$api.msg("请输入每单限购");
  179. return;
  180. }
  181. if (Number(this.form.maxNum) === 0) {
  182. this.$api.msg("每单限购要大于0");
  183. return;
  184. }
  185. if (!this.form.activityNum) {
  186. this.$api.msg("请输入活动库存");
  187. return;
  188. }
  189. if (Number(this.form.maxNum) > Number(this.form.activityNum)) {
  190. this.$api.msg("每单限购不能大于活动库存");
  191. return;
  192. }
  193. if (Number(this.form.activityNum) > Number(9999)) {
  194. this.$api.msg("活动库存不能超过9999");
  195. return;
  196. }
  197. let pages = getCurrentPages();
  198. let prevpage = pages[pages.length - 2];
  199. let tempList = prevpage.$vm.goodsList;
  200. for(var i = 0; i < tempList.length; i++) {
  201. if (tempList[i].goodsId == this.form.goodsId && i != this.index){
  202. this.$api.msg("该商品已经选择了,请更换其他商品");
  203. return;
  204. }
  205. }
  206. if (this.index != '') {
  207. prevpage.$vm.goodsList.splice(this.index, 1)
  208. }
  209. this.form.activityPrice = this.form.activityPrice * 100;
  210. prevpage.$vm.goodsList.push(this.form);
  211. uni.navigateBack();
  212. }
  213. },
  214. onShow () {
  215. },
  216. onLoad (options) {
  217. if ('goods' in options) {
  218. this.form = JSON.parse(decodeURIComponent(options.goods));
  219. this.form.activityPrice = this.form.activityPrice / 100;
  220. }
  221. if ('index' in options) {
  222. this.index = options.index
  223. }
  224. if ('idsStr' in options) {
  225. this.idsStr = JSON.parse(decodeURIComponent(options.idsStr));
  226. }
  227. }
  228. }
  229. </script>
  230. <style lang="scss" scoped>
  231. .add-goods-page {
  232. border-top: 2rpx solid #f5f5f5;
  233. min-height: 100vh;
  234. }
  235. .update-events {
  236. width: 100vw;
  237. background-color: #fff;
  238. @include flexCenter;
  239. margin-top: 40rpx;
  240. .btn {
  241. width: 80vw;
  242. height: 80rpx;
  243. border-radius: 40rpx;
  244. background-color: $theme-color;
  245. color: #fff;
  246. @include flexCenter;
  247. }
  248. }
  249. .goods-form {
  250. background-color: #fff;
  251. padding: 0 40rpx;
  252. box-sizing: border-box;
  253. height: calc(100vh - 120rpx - env(safe-area-inset-bottom));
  254. height: calc(100vh - 120rpx - constant(safe-area-inset-bottom));
  255. .item {
  256. @include between;
  257. height: 100rpx;
  258. border-bottom: 2rpx solid #ececec;
  259. font-size: $font-base;
  260. }
  261. .label {
  262. width: 200rpx;
  263. }
  264. .goodsLabel {
  265. width: 380rpx;
  266. overflow: hidden;
  267. text-overflow: ellipsis;
  268. white-space: nowrap;
  269. }
  270. .value {
  271. width: calc(100% - 200rpx);
  272. @include flexEnd;
  273. .cover {
  274. width: 100rpx;
  275. height: 100rpx;
  276. }
  277. }
  278. .no-border {
  279. border-bottom: none;
  280. height: 140rpx;
  281. }
  282. .price {
  283. color: $uni-color-button;
  284. }
  285. .fixx {
  286. margin-left: 20rpx;
  287. }
  288. }
  289. /deep/ .u-modal__content {
  290. padding: 30rpx!important;
  291. box-sizing: border-box;
  292. }
  293. .modal-container {
  294. width: 100%;
  295. .search-wrap {
  296. width: 100%;
  297. @include flexCenter;
  298. border: 2rpx solid $theme-color;
  299. color: $theme-color;
  300. font-size: $font-base;
  301. padding-left: 20rpx;
  302. box-sizing: border-box;
  303. margin-bottom: 20rpx;
  304. .btn {
  305. width: 128rpx;
  306. height: 60rpx;
  307. @include flexCenter;
  308. border-left: 2rpx solid $theme-color;
  309. }
  310. .input-wrap {
  311. flex: 1;
  312. /deep/ .u-input {
  313. width: 100%;
  314. }
  315. }
  316. }
  317. .goods-list {
  318. height: 500rpx;
  319. overflow-y: auto;
  320. overflow-x: hidden;
  321. .item {
  322. margin-bottom: 20rpx;
  323. @include flexStart;
  324. }
  325. .cover {
  326. width: 120rpx;
  327. height: 120rpx;
  328. border-radius: 10rpx;
  329. margin-right: 20rpx;
  330. .img {
  331. width: 120rpx;
  332. height: 120rpx;
  333. }
  334. }
  335. .cont {
  336. font-size: $font-base;
  337. .goods-name {
  338. width: 100%;
  339. text-overflow: -o-ellipsis-lastline;
  340. overflow: hidden;
  341. text-overflow: ellipsis;
  342. display: -webkit-box;
  343. -webkit-line-clamp: 2;
  344. -webkit-box-orient: vertical;
  345. color: $text-color;
  346. }
  347. .desc {
  348. color: $desc-color;
  349. }
  350. }
  351. }
  352. }
  353. </style>