productCate.vue 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view class="container">
  3. <view class="main-title">
  4. <view class="tit">
  5. 规格类型
  6. </view>
  7. <view class="cate-add" @click="addAttr">
  8. 新增规格
  9. </view>
  10. </view>
  11. <view class="cate-list">
  12. <view class="cate-item" v-for="(item,index) in attr" :key="index">
  13. <view class="cate-header">
  14. <view class="cate-name">
  15. <image class="pen" src="@/static/images/edit-pen.png"></image>
  16. <up-input class="cate-name-ipt" v-model="item.attrName" placeholder="请输入规格类型" inputAlign="left"
  17. border="none" type="text">
  18. </up-input>
  19. </view>
  20. <view class="delete-icon" @click="deleteAttr(index)">
  21. <image class="delete" src="/static/images/delete.png"></image>
  22. </view>
  23. </view>
  24. <view class="cate-child">
  25. <view class="children">
  26. <view class="children-item" v-for="(child,idx) in item.attrValue" :key="'c'+idx">
  27. <view class="cname">
  28. {{child}}
  29. </view>
  30. <image class="close" @click="deleteSub(index,idx)" src="@/static/images/close-icon.png"
  31. mode=""></image>
  32. </view>
  33. </view>
  34. <view class="cate-child-add" @click="addSub(index)">
  35. <image class="plus" src="@/static/images/plus-icon.png" mode=""></image>
  36. <view class="add">
  37. 添加规格项
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. </view>
  43. <view class="bottom-actions">
  44. <view class="action-btn" @click="throttle(ensureClickHandle,500)"> 确定 </view>
  45. </view>
  46. <up-popup :show="showPopUp" :round="20" :duration="150" mode="bottom" @close="showPopUp=false"
  47. @open="showPopUp=true">
  48. <view class="pop-container">
  49. <view class="pop-header">
  50. 规格类型
  51. <image class="pop-close" src="/static/images/close-icon.png" mode="" @click="showPopUp=false">
  52. </image>
  53. </view>
  54. <view class="pop-ipt">
  55. <textarea class="item-textarea" @confirm="ensureAttrHandle" maxlength="100" :focus="iptFocus"
  56. v-model="cipt" placeholder="请输入规格类型" />
  57. </view>
  58. <view class="action-btn" @click="ensureAttrHandle"> 确定 </view>
  59. </view>
  60. </up-popup>
  61. </view>
  62. </template>
  63. <script setup>
  64. import {
  65. ref,
  66. computed,
  67. watch,
  68. nextTick
  69. } from 'vue';
  70. import {
  71. onShow,
  72. onLoad,
  73. onBackPress
  74. } from "@dcloudio/uni-app";
  75. import {
  76. productCategory,
  77. productSave,
  78. productUpdate,
  79. templatesList,
  80. productInfo
  81. } from "@/api/merchant";
  82. import CategorySelector from '@/components/CategorySelector';
  83. import {
  84. useAppStore
  85. } from "@/stores/app";
  86. import {
  87. useImageUpload
  88. } from "@/hooks/useImageUpload";
  89. import {
  90. useToast
  91. } from "@/hooks/useToast";
  92. import {
  93. debounce,
  94. throttle
  95. } from '../../../uni_modules/uview-plus';
  96. const {
  97. Toast
  98. } = useToast();
  99. const appStore = useAppStore();
  100. const cateDemo = {
  101. "id": 1586,
  102. "productId": 729,
  103. "attrName": "圈号",
  104. "attrValues": "56mm,68mm,78mm",
  105. "type": 0,
  106. "isDel": false
  107. }
  108. const attr = ref([])
  109. const showPopUp = ref(false)
  110. const cipt = ref('')
  111. const cIndex = ref();
  112. const cSubIndex = ref()
  113. const iptFocus = ref(false)
  114. // 当前变更类型,0代表规格值,1代表规格子值
  115. const cType = ref(0)
  116. const ensureClickHandle = () => {
  117. console.log("ensure")
  118. let flag = true;
  119. if (!attr.value || attr.value.length <= 0) {
  120. return Toast({
  121. title: "规格不能为空"
  122. })
  123. }
  124. attr.value.forEach(item => {
  125. if (!item.attrName) {
  126. flag = false
  127. return Toast({
  128. title: "规格名称不能为空"
  129. })
  130. }
  131. if (item.attrValue && item.attrValue.length > 0) {
  132. item.attrValue.forEach(child => {
  133. if (!child) {
  134. flag = false
  135. return Toast({
  136. title: "规格子集名称不能为空"
  137. })
  138. }
  139. })
  140. } else {
  141. flag = false
  142. return Toast({
  143. title: "规格子集不能为空"
  144. })
  145. }
  146. })
  147. if (!flag) return
  148. appStore.SET_CPATTR(attr.value)
  149. uni.$emit("updateAttr", attr.value)
  150. setTimeout(() => {
  151. uni.navigateBack()
  152. },300)
  153. }
  154. onLoad(() => {
  155. const data = appStore.cProductAttr;
  156. attr.value = data.concat();
  157. })
  158. throttle()
  159. // 添加规格
  160. const addAttr = () => {
  161. attr.value.push({
  162. attrName: '',
  163. attrValue: []
  164. })
  165. cType.value = 0;
  166. cIndex.value = attr.value.length - 1
  167. cipt.value = '';
  168. showPopUp.value = true;
  169. setTimeout(() => {
  170. iptFocus.value = true
  171. }, 500)
  172. }
  173. // 删除规格
  174. const deleteAttr = (index) => {
  175. attr.value.splice(index, 1)
  176. }
  177. // 删除规格子项值
  178. const deleteSub = (index, idx) => {
  179. attr.value[index].attrValue.splice(idx, 1)
  180. }
  181. // 新增规格子项值
  182. const addSub = (index) => {
  183. cType.value = 1;
  184. cIndex.value = index
  185. cipt.value = '';
  186. showPopUp.value = true;
  187. setTimeout(() => {
  188. iptFocus.value = true
  189. }, 500)
  190. }
  191. const ensureAttrHandle = () => {
  192. if (!cipt.value || !cipt.value.trim()) {
  193. return Toast({
  194. title: "请输入规格值"
  195. });
  196. }
  197. if (cType.value == 0) {
  198. attr.value[cIndex.value].attrName = cipt.value.trim()
  199. } else {
  200. attr.value[cIndex.value].attrValue.push(
  201. cipt.value.trim()
  202. )
  203. }
  204. iptFocus.value = false
  205. console.log(attr.value)
  206. showPopUp.value = false;
  207. }
  208. </script>
  209. <style scoped lang="scss">
  210. page {
  211. background-color: #f9f7f0;
  212. height: 100%;
  213. }
  214. .container {
  215. padding: 16rpx;
  216. background-color: #f9f7f0;
  217. padding-bottom: calc(132rpx + constant(safe-area-inset-bottom));
  218. padding-bottom: calc(132rpx + env(safe-area-inset-bottom));
  219. .main-title {
  220. width: 100%;
  221. height: 48rpx;
  222. display: flex;
  223. justify-content: space-between;
  224. align-items: center;
  225. margin-bottom: 16rpx;
  226. .tit {
  227. font-size: 32rpx;
  228. color: #333;
  229. font-weight: bold;
  230. }
  231. .cate-add {
  232. padding: 16rpx 0 16rpx 16rpx;
  233. font-size: 28rpx;
  234. color: #F8C008;
  235. font-weight: bold;
  236. }
  237. }
  238. }
  239. .cate-list {
  240. .cate-item {
  241. width: 100%;
  242. padding: 20rpx;
  243. background-color: #fff;
  244. border-radius: 16rpx;
  245. margin-bottom: 20rpx;
  246. .cate-header {
  247. width: 100%;
  248. height: 64rpx;
  249. display: flex;
  250. justify-content: space-between;
  251. align-items: center;
  252. border-bottom: 1px solid #F1F3F8;
  253. padding-bottom: 20rpx;
  254. .cate-name {
  255. display: flex;
  256. justify-content: flex-start;
  257. align-items: center;
  258. .pen {
  259. width: 32rpx;
  260. height: 32rpx;
  261. margin-right: 16rpx;
  262. }
  263. .cate-name-ipt {
  264. height: 44rpx;
  265. line-height: 44rpx;
  266. font-size: 28rpx;
  267. color: #333;
  268. }
  269. }
  270. .delete-icon {
  271. padding: 10rpx 0 10rpx 10rpx;
  272. display: flex;
  273. justify-content: center;
  274. align-items: center;
  275. .delete {
  276. width: 32rpx;
  277. height: 32rpx;
  278. }
  279. }
  280. }
  281. .children {
  282. width: 100%;
  283. display: flex;
  284. margin-top: 20rpx;
  285. justify-content: flex-start;
  286. align-items: center;
  287. flex-wrap: wrap;
  288. }
  289. .children-item {
  290. min-width: 120rpx;
  291. padding: 8rpx 16rpx;
  292. border-radius: 8rpx;
  293. margin-right: 20rpx;
  294. margin-bottom: 20rpx;
  295. display: flex;
  296. justify-content: space-between;
  297. align-items: center;
  298. background-color: #F9F7F0;
  299. .cname {
  300. font-size: 28rpx;
  301. color: #333;
  302. margin-right: 16rpx;
  303. line-height: 44rpx;
  304. }
  305. .close {
  306. width: 32rpx;
  307. height: 32rpx;
  308. }
  309. }
  310. .cate-child-add {
  311. padding: 8rpx 16rpx;
  312. width: 220rpx;
  313. background-color: rgba(248, 192, 8, 0.10);
  314. border-radius: 8rpx;
  315. display: flex;
  316. justify-content: flex-start;
  317. align-items: center;
  318. .add {
  319. font-size: 28rpx;
  320. line-height: 44rpx;
  321. color: #F8C008;
  322. }
  323. .plus {
  324. width: 32rpx;
  325. height: 32rpx;
  326. margin-right: 16rpx;
  327. }
  328. }
  329. }
  330. }
  331. .bottom-actions {
  332. position: fixed;
  333. bottom: 0;
  334. left: 0;
  335. right: 0;
  336. width: 100%;
  337. z-index: 8;
  338. background: #FFFFFF;
  339. padding: 22rpx 32rpx calc(22rpx + constant(safe-area-inset-bottom));
  340. padding: 22rpx 32rpx calc(22rpx + env(safe-area-inset-bottom));
  341. }
  342. .action-btn {
  343. font-weight: bold;
  344. line-height: 88rpx;
  345. text-align: center;
  346. border-radius: 16rpx;
  347. font-size: 32rpx;
  348. font-weight: bold;
  349. background: #F8C008;
  350. }
  351. .pop-container {
  352. background-color: #fff;
  353. border-radius: 40rpx 40rpx 0 0;
  354. position: relative;
  355. padding: 22rpx 32rpx calc(22rpx + constant(safe-area-inset-bottom));
  356. padding: 22rpx 32rpx calc(22rpx + env(safe-area-inset-bottom));
  357. .pop-header {
  358. height: 44rpx;
  359. width: 100%;
  360. text-align: center;
  361. line-height: 48rpx;
  362. font-size: 32rpx;
  363. color: #333;
  364. font-weight: bold;
  365. .pop-close {
  366. width: 32rpx;
  367. height: 32rpx;
  368. position: absolute;
  369. right: 32rpx;
  370. top: 32rpx;
  371. }
  372. }
  373. .pop-ipt {
  374. width: 100%;
  375. display: flex;
  376. background-color: #F9F7F0;
  377. border-radius: 16rpx;
  378. margin-top: 32rpx;
  379. margin-bottom: 32rpx;
  380. }
  381. }
  382. .item-textarea {
  383. width: 100rpx;
  384. height: 200rpx;
  385. padding: 16rpx;
  386. flex: 1;
  387. text-align: left;
  388. }
  389. </style>