config.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <view class="goods">
  3. <view class="order-setuo">
  4. <view class="order-title">商品设置</view>
  5. <view class="order-list">
  6. <view class="list-left">排序方式:</view>
  7. <view class="list-right">
  8. <view class="uni-list-cell-db">
  9. <picker @change="bindPickerChange" :value="index" :range="array" style="display: inline-block;">
  10. <view class="uni-input">{{array[index]}}</view>
  11. </picker>
  12. </view>
  13. <text class="iconfont iconright"></text>
  14. </view>
  15. </view>
  16. <view class="order-list">
  17. <view class="list-left">默认排序值:</view>
  18. <view class="list-right"><input type="number" v-model="goodsCoinfig.goods_sort_confog.default_value" placeholder="0" /></view>
  19. </view>
  20. <view class="order-list">
  21. <view class="list-left">默认搜索关键词:</view>
  22. <view class="list-right"><input type="text" v-model="goodsCoinfig.default_words.words" placeholder="0" /></view>
  23. </view>
  24. <view class="order-list">
  25. <view class="list-left">热门搜索:</view>
  26. </view>
  27. <view class="more-spec" :class="{ 'safe-area': isIphonex }">
  28. <view class="spec-item" v-for="(item, index) in words_array" :key="index">
  29. <view class="spec-name">
  30. <text class="action iconfont iconjian" @click="deleteSpec(index)"></text>
  31. <text class="label">关键字:</text>
  32. <input class="uni-input" v-model="words_array[index]" placeholder="请输入关键字" />
  33. </view>
  34. </view>
  35. <view @click="Add()" class="color-base-text add-spec">+添加</view>
  36. </view>
  37. </view>
  38. <view class="footer-wrap" :class="{ 'safe-area': isIphonex }">
  39. <button type="primary" @click="save()">保存</button>
  40. </view>
  41. </view>
  42. </template>
  43. <script>
  44. export default {
  45. data() {
  46. return {
  47. title: 'picker',
  48. array: ['正序排列', '倒序排列'],
  49. index: 0,
  50. words_array: [],
  51. default_value: '',
  52. words: '',
  53. goodsCoinfig : {
  54. default_words: {
  55. words:''
  56. },
  57. goods_sort_confog:{
  58. default_value:'',
  59. type:''
  60. },
  61. hot_words:{
  62. words:'',
  63. words_array:[]
  64. }
  65. },
  66. isIphonex: false,
  67. goodsSpecMax: 4,
  68. // 规格值最大数量
  69. goodsSpecValueMax: 10,
  70. goodsSpecFormat: []
  71. }
  72. },
  73. onLoad(option) {
  74. this.isIphonex = this.$util.uniappIsIPhoneX();
  75. this.goodsSpecFormat = uni.getStorageSync('editGoodsSpecFormat') ? JSON.parse(uni.getStorageSync('editGoodsSpecFormat')) : [];
  76. },
  77. onShow() {
  78. this.goodsSet();
  79. },
  80. methods: {
  81. bindPickerChange: function(e) {
  82. this.index = e.target.value
  83. // console.log(this.index,'0')
  84. },
  85. // 添加关键字
  86. Add() {
  87. this.words_array.push('');
  88. },
  89. //删除关键字
  90. deleteSpec(index) {
  91. uni.showModal({
  92. title: '操作提示',
  93. content: '确定要删除吗?',
  94. success: res => {
  95. if (res.confirm) this.words_array.splice(index, 1);
  96. }
  97. });
  98. },
  99. goodsSet() {
  100. this.$api.sendRequest({
  101. url: '/shopapi/goods/config',
  102. success: res => {
  103. if (res.code >= 0 && res.data) {
  104. this.goodsCoinfig = res.data,
  105. console.log(this.goodsCoinfig,'123')
  106. this.words_array = res.data.hot_words.words_array;
  107. if(res.data.goods_sort_confog.type == 'asc'){
  108. this.index = 0
  109. }else{
  110. this.index = 1
  111. }
  112. // this.default_value = res.data.goods_sort_confog.default_value;
  113. // this.words = res.data.default_words.words;
  114. }
  115. }
  116. });
  117. },
  118. // 保存
  119. save() {
  120. if(this.goodsCoinfig.hot_words.words_array.length <= 0 ||this.goodsCoinfig.default_words.words ==''){
  121. this.$util.showToast({
  122. title:'修改失败'
  123. });
  124. return false
  125. }
  126. this.$api.sendRequest({
  127. url: '/shopapi/goods/setconfig',
  128. data:{
  129. hot_words:this.goodsCoinfig.hot_words.words_array,
  130. default_words:JSON.parse(JSON.stringify(this.goodsCoinfig.default_words.words)),
  131. sort_type:this.index == 0 ? 'asc' : 'desc',
  132. sort_value:this.goodsCoinfig.goods_sort_confog.default_value,
  133. },
  134. success: res => {
  135. let msg = res.message
  136. if(res.code == 0 ) {
  137. this.$util.showToast({
  138. title: msg
  139. });
  140. setTimeout(() => {
  141. this.$util.redirectTo('/pages/index/all_menu')
  142. }, 500);
  143. }
  144. }
  145. });
  146. // if (!this.verify()) return;
  147. // this.goodsSpecFormat.forEach(item => {
  148. // item.value.forEach(citem => {
  149. // if (citem.spec_name == '') {
  150. // citem.spec_name = item.spec_name;
  151. // }
  152. // });
  153. // });
  154. // uni.setStorageSync('editGoodsSpecFormat', JSON.stringify(this.goodsSpecFormat));
  155. // uni.navigateBack({
  156. // delta: 1
  157. // });
  158. }
  159. }
  160. }
  161. </script>
  162. <style lang="scss">
  163. .goods{
  164. .order-setuo {
  165. margin:20rpx 30rpx;
  166. background: #fff;
  167. padding:15rpx 30rpx;
  168. border-radius: 10rpx;
  169. .order-list {
  170. display: flex;
  171. flex-direction: row;
  172. justify-content: space-between;
  173. align-items: center;
  174. border-bottom:1px solid #eee;
  175. padding:20rpx 0;
  176. .list-right {
  177. display: flex;
  178. flex-direction: row;
  179. align-items: center;
  180. font-size: 28rpx;
  181. font-family: PingFang SC;
  182. font-weight: 500;
  183. color: #303133;
  184. input {
  185. font-size: 28rpx;
  186. font-family: PingFang SC;
  187. font-weight: 500;
  188. color: #909399;
  189. text-align: right;
  190. margin-right:20rpx;
  191. max-width: 280rpx;
  192. }
  193. .order-content {
  194. font-size: 28rpx;
  195. font-family: PingFang SC;
  196. font-weight: 500;
  197. color: #909399;
  198. text-align: right;
  199. margin-right:20rpx;
  200. }
  201. switch, .uni-switch-wrapper, .uni-switch-input {
  202. width: 80rpx;
  203. height: 42rpx;
  204. }
  205. .iconfont {
  206. font-size: 30rpx;
  207. color: #909399;
  208. }
  209. }
  210. .list-left {
  211. font-size: 28rpx;
  212. font-family: PingFang SC;
  213. font-weight: 500;
  214. color: #303133;
  215. }
  216. }
  217. .order-list:last-child {
  218. border:none;
  219. }
  220. .order-title {
  221. font-size: 32rpx;
  222. font-family: PingFang SC;
  223. font-weight: bold;
  224. color: #303133;
  225. margin-bottom: 10rpx;
  226. }
  227. }
  228. .footer-wrap {
  229. margin-top:80rpx;
  230. padding: 0 0 100rpx;
  231. }
  232. }
  233. .footer-wrap {
  234. padding-bottom: 40rpx;
  235. padding-bottom: 40rpx;
  236. position: fixed;
  237. width: 100%;
  238. bottom: 0;
  239. padding: 20px 0;
  240. z-index: 10;
  241. background-color: #fff;
  242. }
  243. .safe-area {
  244. /* #ifndef MP */
  245. padding-bottom: calc(constant(safe-area-inset-bottom) + 100rpx);
  246. padding-bottom: calc(env(safe-area-inset-bottom) + 100rpx);
  247. /* #endif */
  248. }
  249. .more-spec {
  250. margin: $margin-updown 0 80rpx 0;
  251. &.safe-area {
  252. margin-bottom: 200rpx;
  253. }
  254. .spec-item {
  255. background-color: #fff;
  256. border-radius: $border-radius;
  257. margin-bottom: $margin-updown;
  258. .action {
  259. background-color: $color-disabled;
  260. border-radius: 50%;
  261. color: #fff;
  262. width: 36rpx;
  263. height: 36rpx;
  264. line-height: 36rpx;
  265. display: inline-block;
  266. text-align: center;
  267. font-weight: bold;
  268. margin-right: 20rpx;
  269. }
  270. .label {
  271. vertical-align: middle;
  272. margin-right: $margin-both;
  273. }
  274. input {
  275. vertical-align: middle;
  276. display: inline-block;
  277. flex: 1;
  278. text-align: right;
  279. }
  280. .spec-name,
  281. .spec-value {
  282. display: flex;
  283. align-items: center;
  284. height: 100rpx;
  285. line-height: 100rpx;
  286. padding: 0 30rpx;
  287. border-bottom: 1px solid $color-line;
  288. }
  289. .spec-value {
  290. margin-left: 60rpx;
  291. padding-left: 0;
  292. }
  293. .add-spec-value {
  294. height: 100rpx;
  295. line-height: 100rpx;
  296. margin-left: 60rpx;
  297. }
  298. }
  299. .add-spec {
  300. text-align: center;
  301. background-color: #fff;
  302. height: 100rpx;
  303. line-height: 100rpx;
  304. border-radius: $border-radius;
  305. }
  306. .tip {
  307. text-align: center;
  308. color: $color-tip;
  309. font-size: $font-size-tag;
  310. padding: $padding;
  311. }
  312. }
  313. button {
  314. color: #FFFFFF;
  315. background-color: #FF6A00;
  316. margin-top: 20rpx;
  317. }
  318. </style>