editor.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <view class="padding">
  3. <view class="padding bg radius">
  4. <div style="color:red;">此处修改的规格不会改变已生成的商品,如想更改商品信息请去商品列表更新商品</div>
  5. <view class="">
  6. <view class="text-df text-bold">规格标题</view>
  7. <view>
  8. <u-input v-model="shopName" placeholder="请输入规格标题" />
  9. </view>
  10. </view>
  11. </view>
  12. <view class="bg margin-tb padding-sm radius" v-for="(item,index) in shopList" :key='index'>
  13. <view class="">
  14. <view style="display: flex;width: 100%;">
  15. <view style="width: 70%;" class="text-df text-bold">规格</view>
  16. <view style="width: 30%;text-align: right;" class="text-df text-bold" v-if="index != 0" @tap="delteItem(index)">删除</view>
  17. </view>
  18. <view>
  19. <u-input v-model="item.value" placeholder="请填写" />
  20. </view>
  21. </view>
  22. <view class="">
  23. <view class="text-df text-bold">规格值</view>
  24. <!-- <view>
  25. <u-input v-model="detailName" placeholder="请填写" />
  26. </view> -->
  27. </view>
  28. <view class="flex align-center flex-wrap margin-bottom-sm">
  29. <view v-for="(item1,index1) in item.detail" :key="index1" class="btn flex align-center margin-top"
  30. :class="listIndex1 == index1&&listIndex==index?'active':''" @click="bindqie(index1,item1,index)">
  31. <view>{{item1}}</view>
  32. <view class="margin-left-sm" @tap.stop="bindupdata(index1,item1,index)">x</view>
  33. </view>
  34. <view class="btns margin-top" @click="addtype(1,item1,index)">+添加</view>
  35. </view>
  36. </view>
  37. <u-button class="margin-top addguiges" :custom-style="customStyle" shape="square" :hair-line="false"
  38. @click="addguige()">添加规格
  39. </u-button>
  40. <view class="margin-top">
  41. <u-button @click="submit" class=" addguige" :custom-style="customStyle" shape="square" :hair-line="false">确认
  42. </u-button>
  43. </view>
  44. <!-- 添加规格弹框 -->
  45. <u-popup v-model="show" mode="center" border-radius="14" width="500rpx" height="300rpx">
  46. <view>
  47. <view class="padding">
  48. <view>添加规格类型</view>
  49. <view>
  50. <u-input v-model="typeName" placeholder="请填写" clearable="false" />
  51. </view>
  52. </view>
  53. <view class="addguiges" @click="bindclose(aa)">确定</view>
  54. </view>
  55. </u-popup>
  56. </view>
  57. </template>
  58. <script>
  59. import configdata from '@/common/config.js';
  60. export default {
  61. data() {
  62. return {
  63. shopName: '',
  64. customStyle: {
  65. backgroundColor: '#FFCC00',
  66. color: '#000000',
  67. border: 0
  68. },
  69. shopList: [{
  70. value: '',
  71. detail: [],
  72. }],
  73. listIndex1: 0,
  74. listIndex: 0,
  75. show: false,
  76. typeName: '',
  77. ruleValues: [],
  78. id: '',
  79. guigeLIst: {},
  80. detailName: '',
  81. guigeIndex: 0,
  82. guigezhiIndex: 0,
  83. aa: '',
  84. shopId: '',
  85. }
  86. },
  87. onLoad(option) {
  88. this.id = option.id
  89. this.shopId = this.$queue.getData("shopId")
  90. if (option.id) {
  91. this.guigeLIst = uni.getStorageSync('guige')
  92. this.shopName = this.guigeLIst.ruleName
  93. this.shopList = this.guigeLIst.ruleValue
  94. for (var i = 0; i < this.shopList.length; i++) {
  95. // #ifdef APP
  96. this.shopList[i].detail = this.shopList[i].detail.split(',')
  97. // #endif
  98. // #ifndef APP
  99. this.shopList[i].detail = this.shopList[i].detail.split('/')
  100. // #endif
  101. }
  102. }
  103. },
  104. onShow() {
  105. },
  106. methods: {
  107. delteItem(index){
  108. this.shopList.splice(index, 1)
  109. },
  110. //删除规格
  111. bindupdata(index1, item1, index) {
  112. this.shopList[index].detail.splice(index1, 1)
  113. },
  114. bindqie(index1, item1, index) {
  115. this.listIndex = index
  116. this.listIndex1 = index1
  117. this.shopList[index].detail[index1] = item1
  118. this.typeName = item1
  119. this.aa = index1
  120. this.show = true
  121. },
  122. addtype(index1, item, index) {
  123. this.guigeIndex = index
  124. this.guigezhiIndex = index1
  125. if (index1 == 1) {
  126. this.typeName = ''
  127. this.aa = ''
  128. this.show = true
  129. }
  130. },
  131. bindclose(index) {
  132. if (!this.typeName) {
  133. uni.showToast({
  134. title: '请填写规格',
  135. icon: 'none',
  136. duration: 1000
  137. })
  138. return
  139. }
  140. console.log('aaaaaaa', index)
  141. if (index === '') {
  142. this.show = false
  143. // this.list.push(this.typeName)
  144. this.shopList[this.guigeIndex].detail.push(this.typeName)
  145. } else {
  146. this.show = false
  147. this.shopList[this.guigeIndex].detail[this.aa] = this.typeName
  148. }
  149. },
  150. // 发布
  151. submit() {
  152. if (!this.shopName) {
  153. uni.showToast({
  154. title: '请填写规格标题',
  155. icon: 'none',
  156. duration: 1000
  157. })
  158. return
  159. }
  160. if(this.shopList.length == 0){
  161. uni.showToast({
  162. title: '请选择规格',
  163. icon: 'none',
  164. duration: 1000
  165. })
  166. return
  167. }
  168. var arrLength = this.shopList[this.shopList.length - 1]
  169. if (arrLength.value == '' || arrLength.detail.length == 0) {
  170. uni.showToast({
  171. title: '请填写规格或是规格值',
  172. icon: 'none'
  173. })
  174. return
  175. }
  176. let guigeList = {}
  177. let shopList = JSON.parse(JSON.stringify(this.shopList))
  178. for (var i in shopList) {
  179. shopList[i].detail = shopList[i].detail.toString()
  180. }
  181. console.log(shopList)
  182. guigeList.ruleName = this.shopName
  183. guigeList.ruleValue = shopList
  184. guigeList.shopId = this.shopId
  185. if (this.id) {
  186. guigeList.id = this.id
  187. this.$Request.postJson("/selfGoodsRule/update", guigeList).then(res => {
  188. if (res.code == 0) {
  189. uni.showToast({
  190. title: '修改成功',
  191. icon: 'none'
  192. })
  193. uni.navigateBack()
  194. } else {
  195. uni.showToast({
  196. title: res.msg,
  197. icon: 'none'
  198. })
  199. // this.shopList = this.shopList[this.guigeIndex].detail.split(',')
  200. // console.log(this.shopList,2222)
  201. }
  202. })
  203. } else {
  204. this.$Request.postJson("/selfGoodsRule/save", guigeList).then(res => {
  205. if (res.code == 0) {
  206. uni.navigateBack()
  207. }
  208. })
  209. }
  210. },
  211. // 添加规格
  212. addguige() {
  213. var arrLength = this.shopList[this.shopList.length - 1]
  214. if (arrLength.value == '' || arrLength.detail.length == 0) {
  215. uni.showToast({
  216. title: '请填写规格或是规格值',
  217. icon: 'none'
  218. })
  219. } else {
  220. var data = {
  221. value: '',
  222. detail: [],
  223. }
  224. this.shopList.push(data)
  225. console.log(this.shopList, 11111)
  226. }
  227. }
  228. }
  229. }
  230. </script>
  231. <style>
  232. page {
  233. background-color: #F5F5F5;
  234. }
  235. .bg {
  236. background-color: #FFFFFF;
  237. }
  238. .btn {
  239. border: 1upx solid #CCCCCC;
  240. border-radius: 28px;
  241. padding: 15rpx 30rpx;
  242. margin-right: 25rpx;
  243. }
  244. .btns {
  245. border: 1upx dashed #333333;
  246. border-radius: 28px;
  247. padding: 10rpx 30rpx;
  248. margin-right: 25rpx;
  249. }
  250. .active {
  251. /* background: #FCD202; */
  252. /* border: none; */
  253. }
  254. .addguige {
  255. width: 90%;
  256. margin: 0 auto;
  257. background: #FCD202;
  258. box-shadow: 0px 10upx 20upx 0px #FFD9B3;
  259. border-radius: 16upx;
  260. text-align: center;
  261. height: 88upx;
  262. line-height: 88upx;
  263. /* position: fixed;
  264. bottom: 25upx;
  265. left: 0;
  266. right: 0; */
  267. }
  268. .addguiges {
  269. width: 90%;
  270. margin: 0 auto;
  271. background: #FCD202;
  272. box-shadow: 0px 10upx 20upx 0px #FFD9B3;
  273. border-radius: 16upx;
  274. text-align: center;
  275. height: 88upx;
  276. line-height: 88upx;
  277. /* position: fixed;
  278. bottom: 25upx;
  279. left: 0;
  280. right: 0; */
  281. }
  282. </style>