productCate.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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" cursorSpacing="100" :placeholder="ciptPlaceholder" />
  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 ciptPlaceholder = ref('请输入规格类型');
  117. const ensureClickHandle = () => {
  118. console.log("ensure")
  119. let flag = true;
  120. if (!attr.value || attr.value.length <= 0) {
  121. return Toast({
  122. title: "规格不能为空"
  123. })
  124. }
  125. attr.value.forEach(item => {
  126. if (!item.attrName) {
  127. flag = false
  128. return Toast({
  129. title: "规格名称不能为空"
  130. })
  131. }
  132. if (item.attrValue && item.attrValue.length > 0) {
  133. item.attrValue.forEach(child => {
  134. if (!child) {
  135. flag = false
  136. return Toast({
  137. title: "规格子集名称不能为空"
  138. })
  139. }
  140. })
  141. } else {
  142. flag = false
  143. return Toast({
  144. title: "规格子集不能为空"
  145. })
  146. }
  147. })
  148. if (!flag) return
  149. appStore.SET_CPATTR(attr.value)
  150. uni.$emit("updateAttr", attr.value)
  151. setTimeout(() => {
  152. uni.navigateBack()
  153. },300)
  154. }
  155. onLoad(() => {
  156. const data = appStore.cProductAttr;
  157. attr.value = data.concat();
  158. })
  159. throttle()
  160. // 添加规格
  161. const addAttr = () => {
  162. ciptPlaceholder.value = '请输入规格类型';
  163. attr.value.push({
  164. attrName: '',
  165. attrValue: []
  166. })
  167. cType.value = 0;
  168. cIndex.value = attr.value.length - 1
  169. cipt.value = '';
  170. showPopUp.value = true;
  171. setTimeout(() => {
  172. iptFocus.value = true
  173. }, 500)
  174. }
  175. // 删除规格
  176. const deleteAttr = (index) => {
  177. attr.value.splice(index, 1)
  178. }
  179. // 删除规格子项值
  180. const deleteSub = (index, idx) => {
  181. attr.value[index].attrValue.splice(idx, 1)
  182. }
  183. // 新增规格子项值
  184. const addSub = (index) => {
  185. ciptPlaceholder.value = '请输入规格项';
  186. cType.value = 1;
  187. cIndex.value = index
  188. cipt.value = '';
  189. showPopUp.value = true;
  190. setTimeout(() => {
  191. iptFocus.value = true
  192. }, 500)
  193. }
  194. const ensureAttrHandle = () => {
  195. if (!cipt.value || !cipt.value.trim()) {
  196. return Toast({
  197. title: "请输入规格值"
  198. });
  199. }
  200. if (cType.value == 0) {
  201. attr.value[cIndex.value].attrName = cipt.value.trim()
  202. } else {
  203. attr.value[cIndex.value].attrValue.push(
  204. cipt.value.trim()
  205. )
  206. }
  207. iptFocus.value = false
  208. console.log(attr.value)
  209. showPopUp.value = false;
  210. }
  211. </script>
  212. <style scoped lang="scss">
  213. page {
  214. background-color: #f9f7f0;
  215. height: 100%;
  216. }
  217. .container {
  218. padding: 16rpx;
  219. background-color: #f9f7f0;
  220. padding-bottom: calc(132rpx + constant(safe-area-inset-bottom));
  221. padding-bottom: calc(132rpx + env(safe-area-inset-bottom));
  222. .main-title {
  223. width: 100%;
  224. height: 48rpx;
  225. display: flex;
  226. justify-content: space-between;
  227. align-items: center;
  228. margin-bottom: 16rpx;
  229. .tit {
  230. font-size: 32rpx;
  231. color: #333;
  232. font-weight: bold;
  233. }
  234. .cate-add {
  235. padding: 16rpx 0 16rpx 16rpx;
  236. font-size: 28rpx;
  237. color: #F8C008;
  238. font-weight: bold;
  239. }
  240. }
  241. }
  242. .cate-list {
  243. .cate-item {
  244. width: 100%;
  245. padding: 20rpx;
  246. background-color: #fff;
  247. border-radius: 16rpx;
  248. margin-bottom: 20rpx;
  249. .cate-header {
  250. width: 100%;
  251. height: 64rpx;
  252. display: flex;
  253. justify-content: space-between;
  254. align-items: center;
  255. border-bottom: 1px solid #F1F3F8;
  256. padding-bottom: 20rpx;
  257. .cate-name {
  258. display: flex;
  259. justify-content: flex-start;
  260. align-items: center;
  261. .pen {
  262. width: 32rpx;
  263. height: 32rpx;
  264. margin-right: 16rpx;
  265. }
  266. .cate-name-ipt {
  267. height: 44rpx;
  268. line-height: 44rpx;
  269. font-size: 28rpx;
  270. color: #333;
  271. }
  272. }
  273. .delete-icon {
  274. padding: 10rpx 0 10rpx 10rpx;
  275. display: flex;
  276. justify-content: center;
  277. align-items: center;
  278. .delete {
  279. width: 32rpx;
  280. height: 32rpx;
  281. }
  282. }
  283. }
  284. .children {
  285. width: 100%;
  286. display: flex;
  287. margin-top: 20rpx;
  288. justify-content: flex-start;
  289. align-items: center;
  290. flex-wrap: wrap;
  291. }
  292. .children-item {
  293. min-width: 120rpx;
  294. padding: 8rpx 16rpx;
  295. border-radius: 8rpx;
  296. margin-right: 20rpx;
  297. margin-bottom: 20rpx;
  298. display: flex;
  299. justify-content: space-between;
  300. align-items: center;
  301. background-color: #F9F7F0;
  302. .cname {
  303. font-size: 28rpx;
  304. color: #333;
  305. margin-right: 16rpx;
  306. line-height: 44rpx;
  307. }
  308. .close {
  309. width: 32rpx;
  310. height: 32rpx;
  311. }
  312. }
  313. .cate-child-add {
  314. padding: 8rpx 16rpx;
  315. width: 220rpx;
  316. background-color: rgba(248, 192, 8, 0.10);
  317. border-radius: 8rpx;
  318. display: flex;
  319. justify-content: flex-start;
  320. align-items: center;
  321. .add {
  322. font-size: 28rpx;
  323. line-height: 44rpx;
  324. color: #F8C008;
  325. }
  326. .plus {
  327. width: 32rpx;
  328. height: 32rpx;
  329. margin-right: 16rpx;
  330. }
  331. }
  332. }
  333. }
  334. .bottom-actions {
  335. position: fixed;
  336. bottom: 0;
  337. left: 0;
  338. right: 0;
  339. width: 100%;
  340. z-index: 8;
  341. background: #FFFFFF;
  342. padding: 22rpx 32rpx calc(22rpx + constant(safe-area-inset-bottom));
  343. padding: 22rpx 32rpx calc(22rpx + env(safe-area-inset-bottom));
  344. }
  345. .action-btn {
  346. font-weight: bold;
  347. line-height: 88rpx;
  348. text-align: center;
  349. border-radius: 16rpx;
  350. font-size: 32rpx;
  351. font-weight: bold;
  352. background: #F8C008;
  353. }
  354. .pop-container {
  355. background-color: #fff;
  356. border-radius: 40rpx 40rpx 0 0;
  357. position: relative;
  358. padding: 22rpx 32rpx calc(22rpx + constant(safe-area-inset-bottom));
  359. padding: 22rpx 32rpx calc(22rpx + env(safe-area-inset-bottom));
  360. .pop-header {
  361. height: 44rpx;
  362. width: 100%;
  363. text-align: center;
  364. line-height: 48rpx;
  365. font-size: 32rpx;
  366. color: #333;
  367. font-weight: bold;
  368. .pop-close {
  369. width: 32rpx;
  370. height: 32rpx;
  371. position: absolute;
  372. right: 32rpx;
  373. top: 32rpx;
  374. }
  375. }
  376. .pop-ipt {
  377. width: 100%;
  378. display: flex;
  379. background-color: #F9F7F0;
  380. border-radius: 16rpx;
  381. margin-top: 32rpx;
  382. margin-bottom: 32rpx;
  383. }
  384. }
  385. .item-textarea {
  386. width: 100rpx;
  387. height: 200rpx;
  388. padding: 16rpx;
  389. flex: 1;
  390. text-align: left;
  391. }
  392. </style>