editor.vue 7.3 KB

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