editor.vue 7.1 KB

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