add-coupon-goods.vue 8.5 KB

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