setting.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. <template>
  2. <view class="content">
  3. <view class="center">
  4. <view class="title">共{{pageList.length}}个型号:{{title}}</view>
  5. <block v-for="(item,index) in pageList" :key="index">
  6. <view class="box">
  7. <view class="box_title cell">{{item.goods_spec}}</view>
  8. <view class="hflex acenter jbetween cell">
  9. <view class="left">价格</view>
  10. <u-input v-model="item.price_selling" border="none" placeholder="请填写商品价格"></u-input>
  11. </view>
  12. <view class="hflex acenter jbetween cell">
  13. <view class="left">库存</view>
  14. <u-input v-model="item.stock_total " border="none" placeholder="请填写商品库存"></u-input>
  15. </view>
  16. <view class="hflex acenter cell">
  17. <view class="left">图片</view>
  18. <view class="img">
  19. <image src="/static/images/common/upload_img2.png" class="upload_img1" @click="uploadImg(index)" v-if="item.sku_image == ''"></image>
  20. <image :src="item.sku_image" class="upload_img1" @click="uploadImg(index)" v-else></image>
  21. <image src="/static/images/common/close.png" class="img_close" v-if="item.sku_image !== ''" @click="closeImg(index)"></image>
  22. </view>
  23. </view>
  24. <view class="hflex acenter jbetween cell">
  25. <view class="left">是否售卖</view>
  26. <u-switch v-model="item.status" activeColor="#81be6a" ></u-switch>
  27. </view>
  28. </view>
  29. </block>
  30. </view>
  31. <view class="bottom">
  32. <view class="btn hflex acenter jcenter" @click="save">
  33. 保存
  34. </view>
  35. </view>
  36. </view>
  37. </template>
  38. <script>
  39. import $api from '@/static/js/api.js'
  40. var that = ''
  41. export default {
  42. data() {
  43. return {
  44. specList: [],
  45. pageList: [],
  46. title: '',
  47. }
  48. },
  49. onLoad(options) {
  50. that = this
  51. that.specList = JSON.parse(options.data)
  52. that.getList()
  53. },
  54. methods: {
  55. getList() {
  56. var list = []
  57. var list2 = []
  58. for(var i=0;i<that.specList.length;i++) {
  59. that.title += that.specList[i].name + '、'
  60. for(var j=0;j<that.specList[i].list.length;j++) {
  61. var data = {
  62. type: i,
  63. name: that.specList[i].list[j].name,
  64. group: that.specList[i].list[j].group,
  65. }
  66. list.push(data)
  67. }
  68. }
  69. that.title = that.title.substr(0,that.title.length - 1)
  70. if(that.specList.length == 2) {
  71. for(var i=0;i<list.length;i++) {
  72. for(var j=i+1;j<list.length;j++) {
  73. if(list[i].type !== list[j].type) {
  74. var data = {
  75. goods_spec: list[i].group + '::' + list[i].name+';;' + list[j].group + '::' + list[j].name,
  76. stock_total : '',
  77. price_selling : '',
  78. sku_image : '',
  79. status : false
  80. }
  81. list2.push(data)
  82. }
  83. }
  84. }
  85. }
  86. if(that.specList.length == 1) {
  87. for(var i=0;i<list.length;i++) {
  88. var data = {
  89. goods_spec: list[i].group+ '::' + list[i].name,
  90. stock_total : '',
  91. price_selling : '',
  92. sku_image : '',
  93. status : false
  94. }
  95. list2.push(data)
  96. }
  97. }
  98. if(that.specList.length == 3) {
  99. console.log(that.specList);
  100. for(var i=0;i<that.specList[0].list.length;i++) {
  101. for(var j=0;j<that.specList[1].list.length;j++) {
  102. for(var k=0;k<that.specList[2].list.length;k++) {
  103. var data = {
  104. goods_spec: that.specList[0].list[i].group+ '::' + that.specList[0].list[i].name+';;'+ that.specList[1].list[j].group+ '::' + that.specList[1].list[j].name + ';;' + that.specList[2].list[k].group+ '::' + that.specList[2].list[k].name,
  105. stock_total : '',
  106. price_selling : '',
  107. sku_image : '',
  108. status : false
  109. }
  110. list2.push(data)
  111. }
  112. }
  113. }
  114. }
  115. that.pageList = list2
  116. },
  117. uploadImg(index) {
  118. uni.chooseImage({
  119. count: 1, //默认9
  120. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  121. sourceType: ['album','camera'], //从相册选择
  122. success: function (res) {
  123. const tempFilePaths = res.tempFilePaths
  124. uni.uploadFile({
  125. url: $api.config.baseUrl + '/data/api.auth.Center/upload',
  126. filePath: tempFilePaths[0],
  127. name: 'file',
  128. header: {
  129. 'token': uni.getStorageSync('token')?uni.getStorageSync('token'):'',
  130. 'api-name': 'iosapp'
  131. },
  132. // formData: {
  133. // 'user': 'test'
  134. // },
  135. success: (res) => {
  136. const data = JSON.parse(res.data)
  137. if (data.code == 1) {
  138. that.pageList[index].sku_image = data.data.url
  139. }
  140. }
  141. });
  142. }
  143. });
  144. },
  145. closeImg(index) {
  146. that.pageList[index].sku_image = ""
  147. },
  148. save() {
  149. for(var i=0;i<that.pageList.length;i++) {
  150. if(that.pageList[i].status) {
  151. that.pageList[i].status = 1
  152. } else {
  153. that.pageList[i].status = 2
  154. }
  155. }
  156. $api.jump('/pages/good/add?data=' + JSON.stringify(that.pageList) + '&spec=' + JSON.stringify(that.specList))
  157. }
  158. },
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .content::v-deep {
  163. .center {
  164. width: 100%;
  165. box-sizing: border-box;
  166. padding: 0 30rpx;
  167. .title {
  168. font-size: 28rpx;
  169. font-weight: 400;
  170. color: #222222;
  171. line-height: 40rpx;
  172. padding: 28rpx 0 0;
  173. }
  174. .box {
  175. background: #F5F5F5;
  176. border-radius: 12px;
  177. margin-top: 24rpx;
  178. padding: 0 20rpx 24rpx;
  179. .box_title {
  180. font-size: 28rpx;
  181. font-weight: 400;
  182. color: #222222;
  183. line-height: 40rpx;
  184. }
  185. .cell {
  186. padding: 24rpx 0 4rpx;
  187. .left {
  188. width: 130rpx;
  189. font-size: 28rpx;
  190. font-weight: 400;
  191. color: #222222;
  192. line-height: 40rpx;
  193. }
  194. .u-input {
  195. width: 500rpx;
  196. height: 64rpx;
  197. background: #FFFFFF;
  198. border-radius: 8rpx;
  199. padding: 0 20rpx !important;
  200. }
  201. .img {
  202. position: relative;
  203. .upload_img1 {
  204. width: 140rpx;
  205. height: 140rpx;
  206. }
  207. .img_close {
  208. position: absolute;
  209. width: 28rpx;
  210. height: 28rpx;
  211. right: 0;
  212. top: 0;
  213. }
  214. }
  215. }
  216. }
  217. .box:nth-last-child(1) {
  218. margin-bottom: 186rpx;
  219. }
  220. }
  221. .bottom {
  222. width: 100%;
  223. height: 166rpx;
  224. background: #FFFFFF;
  225. box-sizing: border-box;
  226. padding: 8rpx 30rpx 0;
  227. position: fixed;
  228. bottom: 0;
  229. z-index: 99;
  230. .btn {
  231. width: 100%;
  232. height: 84rpx;
  233. background: #5471FF;
  234. border-radius: 46rpx;
  235. font-size: 36rpx;
  236. font-weight: 500;
  237. color: #FFFFFF;
  238. line-height: 50rpx;
  239. }
  240. }
  241. }
  242. </style>