goods.vue 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. <template>
  2. <view class="padding">
  3. <view class="text-white padding bg radius">
  4. <div style="color: red">新增商品默认库存为1000件,需要修改可点击操作批量修改库存</div>
  5. <u-form :model="shop" label-position="top">
  6. <u-form-item label="商品标题">
  7. <u-input v-model="shop.goodsName" placeholder="请填写商品标题" />
  8. <view class="btn_search" @click="handleSearch">查询</view>
  9. </u-form-item>
  10. <u-form-item label="商品分类">
  11. <u-input v-model="shop.classifyName" placeholder="请选择" :disabled="true" @click="getflshow()" />
  12. </u-form-item>
  13. <u-form-item label="商品标签">
  14. <!-- <u-input v-model="" placeholder="请填写" /> -->
  15. <view class="flex align-center flex-wrap margin-bottom-sm">
  16. <view v-for="(item, index) in goodsLabel" :key="index" class="btn flex align-center margin-top">
  17. <view>{{ item }}</view>
  18. <view class="margin-left-sm" @tap.stop="bindupdata(index)">x</view>
  19. </view>
  20. <view class="btns margin-top" @click="addtype1()">+添加</view>
  21. </view>
  22. </u-form-item>
  23. <u-form-item label="商品原价(选填)">
  24. <u-input v-model="shop.originalMoney" @input="ZheKouInput" placeholder="请填写" />
  25. </u-form-item>
  26. <u-form-item label="打包费(选填)">
  27. <u-input v-model="shop.packMoney" placeholder="请填写" />
  28. </u-form-item>
  29. <u-form-item label="商品售价">
  30. <u-input v-model="shop.goodsMoney" @input="ZheKouInput" placeholder="请填写" />
  31. </u-form-item>
  32. <view class="padding bg radius margin-tb" style="padding: 10px 0">
  33. <view>
  34. <view class="text-lg" style="color: #333">商品描述(选填)</view>
  35. <view class="margin-tb-sm">
  36. <u-input
  37. v-model="shop.goodsDescribe"
  38. type="textarea"
  39. height="200"
  40. placeholde="请描述一下您的特长"
  41. maxlengt="200"
  42. :clearable="false"
  43. style="background: #f5f5f5"
  44. />
  45. </view>
  46. </view>
  47. <view>
  48. <view class="text-lg margin-top-sm text-black">商品封面图</view>
  49. <view class="flex" style="overflow: hidden; flex-wrap: wrap">
  50. <view v-if="shop.goodsCover.length">
  51. <view class="margin-top flex margin-right-sm flex-wrap">
  52. <view class="flex" style="width: 200rpx; height: 200rpx; margin-right: 2rpx; position: relative">
  53. <image :src="shop.goodsCover" style="width: 100%; height: 100%"></image>
  54. <view style="z-index: 9; position: absolute; top: -15rpx; right: -15rpx" @click="removeImgs()">
  55. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="margin-top" @click="addImage(1)" v-if="shop.goodsCover.length <= 0">
  61. <view style="width: 200rpx; height: 200rpx; background: #f4f5f6" class="flex justify-center align-center">
  62. <view>
  63. <view class="text-center">
  64. <image src="../static/addimg.png" style="width: 65rpx; height: 55rpx"></image>
  65. </view>
  66. <view class="text-center text-black">添加图片</view>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. <view>
  73. <view class="text-lg margin-top-sm text-black">商品轮播图(可多张)</view>
  74. <view class="flex" style="overflow: hidden; flex-wrap: wrap">
  75. <view v-if="goodsPicture.length">
  76. <view class="margin-top flex margin-right-sm flex-wrap">
  77. <view
  78. class="flex"
  79. style="width: 200rpx; height: 200rpx; margin-right: 2rpx; position: relative"
  80. v-for="(image, index) in goodsPicture"
  81. :key="index"
  82. >
  83. <image :src="image" style="width: 100%; height: 100%"></image>
  84. <view style="z-index: 9; position: absolute; top: -15rpx; right: -15rpx" @click="removeImg(index, 'lb')">
  85. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. <view class="margin-top" @click="addImages(1)" v-if="goodsPicture.length < maxCount">
  91. <view style="width: 200rpx; height: 200rpx; background: #f4f5f6" class="flex justify-center align-center">
  92. <view>
  93. <view class="text-center">
  94. <image src="../static/addimg.png" style="width: 65rpx; height: 55rpx"></image>
  95. </view>
  96. <view class="text-center text-black">添加图片</view>
  97. </view>
  98. </view>
  99. </view>
  100. </view>
  101. </view>
  102. <view>
  103. <view class="text-lg margin-top-sm text-black">商品详情图(可多张)(选填)</view>
  104. <view class="flex" style="overflow: hidden; flex-wrap: wrap">
  105. <view v-if="goodsParticularsPicture.length">
  106. <view class="margin-top flex margin-right-sm flex-wrap">
  107. <view
  108. class="flex"
  109. style="width: 200rpx; height: 200rpx; margin-right: 2rpx; position: relative"
  110. v-for="(image, index) in goodsParticularsPicture"
  111. :key="index"
  112. >
  113. <image :src="image" style="width: 100%; height: 100%"></image>
  114. <view style="z-index: 9; position: absolute; top: -15rpx; right: -15rpx" @click="removeImg(index, 'sq')">
  115. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  116. </view>
  117. </view>
  118. </view>
  119. </view>
  120. <view class="margin-top" @click="addImages(2)" v-if="goodsParticularsPicture.length < maxCount">
  121. <view style="width: 200rpx; height: 200rpx; background: #f4f5f6" class="flex justify-center align-center">
  122. <view>
  123. <view class="text-center">
  124. <image src="../static/addimg.png" style="width: 65rpx; height: 55rpx"></image>
  125. </view>
  126. <view class="text-center text-black">添加图片</view>
  127. </view>
  128. </view>
  129. </view>
  130. </view>
  131. </view>
  132. <!-- <view>
  133. <view class="text-lg margin-top-sm text-black">商品详情图(可多张)</view>
  134. <editor id="editor"
  135. style="height:350rpx;color: #000000;font-size: 28rpx;width: 100%;border: 2rpx solid #F0F0F0;padding: 16rpx;"
  136. placeholder="请输入商品详情" @ready="onEditorReady" @input="getText"></editor>
  137. </view>
  138. <view>
  139. <view class="margin-top" @click="addImages(2)" v-if="goodsParticularsPicture.length<=1">
  140. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  141. class="flex justify-center align-center">
  142. <view>
  143. <view class="text-center">
  144. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  145. </image>
  146. </view>
  147. <view class="text-center text-black">添加图片</view>
  148. </view>
  149. </view>
  150. </view>
  151. </view> -->
  152. </view>
  153. <u-form-item label="规格类型">
  154. <u-input v-model="attrsType" placeholder="请选择" :disabled="true" @click="ggShow()" />
  155. </u-form-item>
  156. <u-form-item label="商品规格" v-if="attrsid == 2">
  157. <view style="width: 100%">
  158. <view style="display: flex; width: 100%">
  159. <u-input style="width: 80%" v-model="attrs" placeholder="请选择" :disabled="true" @click="openguige()" />
  160. <view style="width: 20%; text-align: right; color: #ff4701" v-if="attrs" @click="goGuiGeItem()">修改价格</view>
  161. </view>
  162. <view style="color: #ff4701; font-size: 24upx">*修改商品、商品售价后,商品规格将重置,请谨慎操作!</view>
  163. </view>
  164. </u-form-item>
  165. </u-form>
  166. </view>
  167. <u-button @click="submit" class="margin-top" :custom-style="customStyle" shape="square" :hair-line="false">提交</u-button>
  168. <!-- 规格弹框 -->
  169. <u-popup v-model="Guigeshow" mode="bottom" border-radius="14" :closeable="closeable">
  170. <view>
  171. <scroll-view scroll-y="true" style="max-height: calc(100vh - 120rpx)">
  172. <view class="padding">
  173. <view>规格类型</view>
  174. <view class="flex align-center margin-top-sm flex-wrap">
  175. <view class="" v-for="(item, indexs) in list" :key="indexs">
  176. <view class="btn margin-top-sm flex align-center flex-wrap" :class="listIndex == indexs ? 'boxH' : ''" @click="bindguige(indexs, 1, item.ruleName)">
  177. {{ item.ruleName }}
  178. </view>
  179. <!-- <view class="btns margin-top-sm" @click="addtype(1)">+添加</view> -->
  180. </view>
  181. </view>
  182. <view v-for="(name, index) in attrList.ruleValue" :key="index">
  183. <view class="margin-top-sm">{{ name.value }}</view>
  184. <view class="flex align-center flex-wrap margin-top-sm">
  185. <!-- :class="typeIndex1 == index&&typeIndex == ind?'active':''" -->
  186. <view class="btn margin-top-sm" v-for="(ite, ind) in name.detail1" :key="ind" @click="bindguige(ind, 2, name.detail, index)" v-if="name.detail1">
  187. {{ ite }}
  188. </view>
  189. <!-- <view class="btns margin-top-sm">+添加</view> -->
  190. </view>
  191. </view>
  192. </view>
  193. </scroll-view>
  194. <view class="addguige" @click="bindget()">确定</view>
  195. </view>
  196. </u-popup>
  197. <u-select v-model="flshow" :list="ClassifyList" valueName="classifyId" labelName="classifyName" @confirm="confirm"></u-select>
  198. <!-- 规格类型 -->
  199. <u-select v-model="ggshow" :list="attrList1" valueName="id" labelName="name" @confirm="ggconfirm"></u-select>
  200. <!-- 添加规格弹框 -->
  201. <u-popup v-model="show2" mode="center" border-radius="14" width="500rpx" height="300rpx" :closeable="closeable">
  202. <view>
  203. <view class="padding">
  204. <view>添加标签</view>
  205. <view>
  206. <u-input v-model="typeName" placeholder="请填写" />
  207. </view>
  208. </view>
  209. <view class="addguiges" @click="bindclose1()">确定</view>
  210. </view>
  211. </u-popup>
  212. <!-- 选择图片弹窗 -->
  213. <u-popup v-model="tupianShow" mode="center" border-radius="4">
  214. <view class="tupianPop">
  215. <view class="pop_header">
  216. 选择图片
  217. <u-icon name="close" color="#000" size="28" @click="handleClose"></u-icon>
  218. </view>
  219. <!-- 封面图区域 -->
  220. <view class="box_header">
  221. 封面图
  222. <text class="header_text">/ 共{{ totalCountFengmian }}条</text>
  223. </view>
  224. <view class="pop_box">
  225. <scroll-view class="box_body" enable-flex scroll-y @scrolltolower="scrolltolowerFengmian">
  226. <view class="img_box" v-for="item in fengmianList" :key="item.id" @click="clickItemFengmian(item)">
  227. <image class="images" :src="item.goodsCover" mode="aspectFill"></image>
  228. <view class="box_check" v-if="!item.isCheck"></view>
  229. <view v-else class="box_check_active">
  230. <u-icon name="checkmark" color="#fff" size="28"></u-icon>
  231. </view>
  232. </view>
  233. <view v-if="!fengmianList.length" class="">暂无数据</view>
  234. </scroll-view>
  235. </view>
  236. <!-- 轮播图区域 -->
  237. <view class="box_header">
  238. 轮播图
  239. <text class="header_text">/ 共{{ totalCountLunbo }}条</text>
  240. </view>
  241. <view class="pop_box">
  242. <scroll-view class="box_body" enable-flex scroll-y @scrolltolower="scrolltolowerLunbo">
  243. <view class="img_box" v-for="item in lunboList" :key="item.id" @click="clickItemLunbo(item)">
  244. <image class="images" :src="item.goodsPicture" mode="aspectFill"></image>
  245. <view class="box_check" v-if="!item.isCheck"></view>
  246. <view v-else class="box_check_active">
  247. <u-icon name="checkmark" color="#fff" size="28"></u-icon>
  248. </view>
  249. </view>
  250. <view v-if="!lunboList.length" class="">暂无数据</view>
  251. </scroll-view>
  252. </view>
  253. <!-- 详情图区域 -->
  254. <view class="box_header">
  255. 详情图
  256. <text class="header_text">/ 共{{ totalCountXiangqing }}条</text>
  257. </view>
  258. <view class="pop_box">
  259. <scroll-view class="box_body" enable-flex scroll-y @scrolltolower="scrolltolowerXiangqing">
  260. <view class="img_box" v-for="item in xiangqingList" :key="item.id" @click="clickItemXiangqing(item)">
  261. <image class="images" :src="item.goodsParticularsPicture" mode="aspectFill"></image>
  262. <view class="box_check" v-if="!item.isCheck"></view>
  263. <view v-else class="box_check_active">
  264. <u-icon name="checkmark" color="#fff" size="28"></u-icon>
  265. </view>
  266. </view>
  267. <view v-if="!xiangqingList.length" class="">暂无数据</view>
  268. </scroll-view>
  269. </view>
  270. <!-- 确认按钮区域 -->
  271. <view class="btn_pop" @click="handleConfrim">确认</view>
  272. </view>
  273. </u-popup>
  274. <!-- 用于图片压缩的canvas画布 -->
  275. <canvas
  276. :style="{
  277. width: cw + 'px',
  278. height: cw + 'px',
  279. position: 'absolute',
  280. zIndex: -1,
  281. left: '-10000rpx',
  282. top: '-10000rpx'
  283. }"
  284. canvas-id="zipCanvas"
  285. ></canvas>
  286. <!--画布结束-->
  287. </view>
  288. </template>
  289. <script>
  290. import configdata from '@/common/config.js'
  291. import getLessLimitSizeImage from '@/utils/imageCompress.js'
  292. export default {
  293. data() {
  294. return {
  295. shop: {
  296. goodsName: '',
  297. classifyId: '',
  298. classifyName: '',
  299. goodsLabel: [],
  300. attr: [],
  301. sku: [],
  302. originalMoney: '',
  303. packMoney: 0,
  304. goodsMoney: '',
  305. goodsDescribe: '',
  306. //详情图
  307. goodsCover: '',
  308. goodsPicture: [],
  309. goodsParticularsPicture: [],
  310. shopId: uni.getStorageSync('shopId')
  311. },
  312. shops: {
  313. goodsName: '',
  314. classifyId: '',
  315. classifyName: '',
  316. goodsLabel: [],
  317. attr: [],
  318. sku: [],
  319. originalMoney: '',
  320. packMoney: 0,
  321. goodsMoney: '',
  322. goodsDescribe: '',
  323. //详情图
  324. goodsCover: '',
  325. goodsPicture: [],
  326. goodsParticularsPicture: [],
  327. shopId: uni.getStorageSync('shopId')
  328. },
  329. attrs: '',
  330. goodsLabel: [],
  331. goodsPicture: [],
  332. goodsParticularsPicture: [],
  333. customStyle: {
  334. backgroundColor: '#FFCC00',
  335. color: '#000000',
  336. border: 0
  337. },
  338. status: 1,
  339. customStyle1: {
  340. color: '#000000',
  341. position: 'fixed',
  342. bottom: '15rpx',
  343. left: '0rpx',
  344. right: '0rpx',
  345. margin: '0rpx 50rpx',
  346. backgroundColor: '#FFCC00'
  347. },
  348. Guigeshow: false,
  349. //详情图
  350. goodsCover: [],
  351. shopId: '',
  352. page: 1,
  353. limit: 100,
  354. list: [],
  355. listIndex: 0,
  356. typeIndex: 0,
  357. typeIndex1: 0,
  358. wdIndex: 0,
  359. show: false,
  360. typeName: '',
  361. shows: false,
  362. typeperature: '',
  363. flshow: false,
  364. ggshow: false,
  365. ClassifyList: [],
  366. attrList: {},
  367. attrLists: [],
  368. shopId: '',
  369. show2: false,
  370. update: 0,
  371. maxCount: 4,
  372. editorCtx: '',
  373. htmlMessage: '',
  374. closeable: true,
  375. attrsType: '多规格',
  376. attrsid: 2,
  377. attrList1: [
  378. {
  379. name: '单规格',
  380. id: 1
  381. },
  382. {
  383. name: '多规格',
  384. id: 2
  385. }
  386. ],
  387. //画板边长默认是屏幕宽度,正方形画布
  388. cw: uni.getSystemInfoSync().windowWidth,
  389. tupianShow: false,
  390. fengmianList: [],
  391. currPageFengmian: 1,
  392. totalCountFengmian: 0,
  393. lunboList: [],
  394. currPageLunbo: 1,
  395. totalCountLunbo: 0,
  396. xiangqingList: [],
  397. currPageXiangqing: 1,
  398. totalCountXiangqing: 0
  399. }
  400. },
  401. onLoad(option) {
  402. console.log('option', option)
  403. if (option.goodsId) {
  404. this.update = 1
  405. uni.setNavigationBarTitle({
  406. title: '修改商品'
  407. })
  408. this.goodsDet(option.goodsId)
  409. } else {
  410. this.update = 0
  411. }
  412. // console.log(option, '店铺id')
  413. // this.shopId = option.shopId
  414. this.shopId = this.$queue.getData('shopId')
  415. this.getguige()
  416. // this.onEditorReady();
  417. },
  418. onShow() {
  419. let list = this.$queue.getData('guigeSelectItemList')
  420. if (list) {
  421. this.shop.sku = list
  422. this.$queue.remove('guigeSelectItemList')
  423. }
  424. this.getClassifyList()
  425. },
  426. methods: {
  427. handleConfrim() {
  428. let fmList = this.fengmianList.filter((ele) => ele.isCheck)
  429. let lbList = []
  430. this.lunboList.forEach((ele) => {
  431. if (ele.isCheck) {
  432. lbList.push(ele.goodsPicture)
  433. }
  434. })
  435. let xqList = []
  436. this.xiangqingList.forEach((ele) => {
  437. if (ele.isCheck) {
  438. xqList.push(ele.goodsParticularsPicture)
  439. }
  440. })
  441. console.log(fmList)
  442. console.log(lbList)
  443. console.log(xqList)
  444. this.tupianShow = false
  445. if (fmList.length) {
  446. this.shop.goodsCover = fmList[0].goodsCover
  447. }
  448. if (lbList.length) {
  449. this.goodsPicture = [...this.goodsPicture, ...lbList]
  450. }
  451. if (xqList.length) {
  452. this.goodsParticularsPicture = [...this.goodsParticularsPicture, ...xqList]
  453. }
  454. },
  455. clickItemFengmian(item) {
  456. if (item.isCheck) {
  457. item.isCheck = false
  458. } else {
  459. this.fengmianList.forEach((ele) => (ele.isCheck = false))
  460. item.isCheck = true
  461. }
  462. },
  463. clickItemLunbo(item) {
  464. let count = 0
  465. this.lunboList.forEach((ele) => {
  466. if (ele.isCheck) {
  467. count++
  468. }
  469. })
  470. if (item.isCheck) {
  471. item.isCheck = false
  472. } else {
  473. if (count >= this.maxCount - this.goodsPicture.length) {
  474. uni.showToast({
  475. title: '最多上传4张',
  476. icon: 'none'
  477. })
  478. } else {
  479. item.isCheck = true
  480. }
  481. }
  482. },
  483. clickItemXiangqing(item) {
  484. let count = 0
  485. this.xiangqingList.forEach((ele) => {
  486. if (ele.isCheck) {
  487. count++
  488. }
  489. })
  490. if (item.isCheck) {
  491. item.isCheck = false
  492. } else {
  493. if (count >= this.maxCount - this.goodsParticularsPicture.length) {
  494. uni.showToast({
  495. title: '最多上传4张',
  496. icon: 'none'
  497. })
  498. } else {
  499. item.isCheck = true
  500. }
  501. }
  502. },
  503. scrolltolowerFengmian() {
  504. if (this.totalCountFengmian > this.fengmianList.length) {
  505. this.currPageFengmian++
  506. this.getFengMian()
  507. } else {
  508. uni.showToast({
  509. title: '没有更多数据了',
  510. icon: 'none'
  511. })
  512. }
  513. },
  514. scrolltolowerLunbo() {
  515. if (this.totalCountLunbo > this.lunboList.length) {
  516. this.currPageLunbo++
  517. this.getLunBo()
  518. } else {
  519. uni.showToast({
  520. title: '没有更多数据了',
  521. icon: 'none'
  522. })
  523. }
  524. },
  525. scrolltolowerXiangqing() {
  526. if (this.totalCountXiangqing > this.xiangqingList.length) {
  527. this.currPageXiangqing++
  528. this.getXiangQing()
  529. } else {
  530. uni.showToast({
  531. title: '没有更多数据了',
  532. icon: 'none'
  533. })
  534. }
  535. },
  536. handleSearch() {
  537. if (!this.shop.goodsName) {
  538. uni.showToast({
  539. title: '请输入商户标题',
  540. icon: 'none'
  541. })
  542. return
  543. }
  544. this.fengmianList = []
  545. this.currPageFengmian = 1
  546. this.lunboList = []
  547. this.currPageLunbo = 1
  548. this.xiangqingList = []
  549. this.currPageXiangqing = 1
  550. this.tupianShow = true
  551. this.getFengMian()
  552. this.getLunBo()
  553. this.getXiangQing()
  554. },
  555. async getFengMian() {
  556. let data = {
  557. page: this.currPageFengmian,
  558. limit: 6,
  559. name: this.shop.goodsName
  560. }
  561. let res = await this.$Request.getA('/app/goods/goodsCoverList', data)
  562. // console.log(res)
  563. if (res.code == 0) {
  564. res.data.list.forEach((item) => {
  565. item.isCheck = false
  566. })
  567. this.fengmianList = [...this.fengmianList, ...res.data.list]
  568. this.totalCountFengmian = res.data.totalCount
  569. }
  570. },
  571. async getLunBo() {
  572. let data = {
  573. page: this.currPageLunbo,
  574. limit: 6,
  575. name: this.shop.goodsName
  576. }
  577. let res = await this.$Request.getA('/app/goods/goodsPictureList', data)
  578. // console.log(res)
  579. if (res.code == 0) {
  580. res.data.list.forEach((item) => {
  581. item.isCheck = false
  582. })
  583. this.lunboList = [...this.lunboList, ...res.data.list]
  584. this.totalCountLunbo = res.data.totalCount
  585. }
  586. },
  587. async getXiangQing() {
  588. let data = {
  589. page: this.currPageXiangqing,
  590. limit: 6,
  591. name: this.shop.goodsName
  592. }
  593. let res = await this.$Request.getA('/app/goods/goodsParticularsPictureList', data)
  594. // console.log(res)
  595. if (res.code == 0) {
  596. res.data.list.forEach((item) => {
  597. item.isCheck = false
  598. })
  599. this.xiangqingList = [...this.xiangqingList, ...res.data.list]
  600. this.totalCountXiangqing = res.data.totalCount
  601. }
  602. },
  603. handleClose() {
  604. this.tupianShow = false
  605. },
  606. ZheKouInput(e) {
  607. console.log(e)
  608. this.attrs = ''
  609. this.shop.attr = []
  610. if (this.attrsid == 1) {
  611. this.guigeclect()
  612. } else {
  613. this.getgoodslist()
  614. }
  615. },
  616. goGuiGeItem() {
  617. this.$queue.setData('guigeSelectItemList', this.shop.sku)
  618. uni.navigateTo({
  619. url: '/my/publish/guigeitem'
  620. })
  621. },
  622. //获取分类
  623. getflshow() {
  624. console.log(this.ClassifyList.length)
  625. if (this.ClassifyList.length == 0) {
  626. uni.navigateTo({
  627. url: '/my/store/fenlei'
  628. })
  629. } else {
  630. this.flshow = true
  631. }
  632. },
  633. // 规格类型
  634. ggShow() {
  635. this.ggshow = true
  636. },
  637. //获取商品规格列表
  638. getgoodslist() {
  639. let ruleValues = this.attrList.ruleValue
  640. for (var j = 0; j < ruleValues.length; j++) {
  641. let details = ruleValues[j].detail
  642. ruleValues[j].detail = ruleValues[j].detail.toString()
  643. }
  644. let data = {
  645. attrName: this.attrList.ruleName,
  646. attrValue: ruleValues,
  647. ruleId: this.attrList.id
  648. }
  649. this.$Request
  650. .postJsonBB(
  651. '/admin/goods/isFormatAttr',
  652. {
  653. coverImg: this.shop.goodsCover,
  654. originalPrice: this.shop.originalMoney,
  655. price: this.shop.goodsMoney
  656. },
  657. data
  658. )
  659. .then((res) => {
  660. if (res.code == 0) {
  661. // this.shop.sku.push(res.data.value)
  662. this.shop.sku = res.data.value
  663. console.log(res.data.value, '111', this.shop.sku)
  664. }
  665. })
  666. },
  667. //获取规格
  668. bindget() {
  669. this.getgoodslist()
  670. this.attrs = this.attrList.ruleName
  671. var obj = {}
  672. obj.attrName = this.attrList.ruleName
  673. obj.attrValue = this.attrList.ruleValue
  674. obj.ruleId = this.attrList.id
  675. this.shop.attr.push(obj)
  676. this.Guigeshow = false
  677. },
  678. //商品分类
  679. confirm(e) {
  680. // console.log(e)
  681. this.shop.classifyName = e[0].label
  682. this.shop.classifyId = e[0].value
  683. },
  684. //规格分类
  685. ggconfirm(e) {
  686. // console.log(e)
  687. this.attrsType = e[0].label
  688. this.attrsid = e[0].value
  689. if (e[0].value == 1) {
  690. this.shop.attr = []
  691. this.guigeclect()
  692. }
  693. },
  694. // 单规格
  695. guigeclect() {
  696. let data = {
  697. coverImg: this.shop.goodsCover,
  698. originalPrice: this.shop.originalMoney,
  699. price: this.shop.goodsMoney
  700. }
  701. this.$Request.getA('/admin/goods/onlyFormatAttr', data).then((res) => {
  702. if (res.code == 0) {
  703. // this.shop.sku.push(res.data.value)
  704. this.shop.sku = res.data.value
  705. console.log(res.data.value, '111', this.shop.sku)
  706. }
  707. })
  708. },
  709. addtype(index) {
  710. if (index == 1) {
  711. this.show = true
  712. } else if (index == 2) {
  713. this.shows = true
  714. }
  715. },
  716. bindclose() {
  717. if (index == 1) {
  718. this.show = false
  719. } else if (index == 2) {
  720. this.shows = false
  721. }
  722. },
  723. //弹框规格切换
  724. bindguige(index, e, name, index1) {
  725. // console.log(index, e, name)
  726. if (e == 1) {
  727. this.listIndex = index
  728. this.attrList = this.list[index]
  729. } else if (e == 2) {
  730. this.typeIndex = index
  731. this.typeIndex1 = index1
  732. } else if (e == 3) {
  733. this.wdIndex = index
  734. }
  735. },
  736. //规格弹框
  737. openguige() {
  738. if (!this.attrList.ruleValue) {
  739. uni.showToast({
  740. title: '暂无规格',
  741. icon: 'none',
  742. duration: 1000
  743. })
  744. return
  745. }
  746. // 打开规格选项弹框
  747. this.Guigeshow = true
  748. },
  749. //获取商品规格
  750. getguige() {
  751. let data = {
  752. // page: this.page,
  753. // limit: this.limit,
  754. shopId: this.shopId
  755. }
  756. this.$Request.getA('/selfGoodsRule/list', data).then((res) => {
  757. if (res.code == 0) {
  758. // this.shop.sku = res.data
  759. if (res.data.length > 0) {
  760. this.list = res.data
  761. this.list.forEach((res) => {
  762. res.ruleValue.forEach((ret) => {
  763. ret.detail = ret.detail.split(',')
  764. ret.detail1 = ret.detail
  765. })
  766. })
  767. console.log('this.attrList', this.list)
  768. this.attrList = this.list[0]
  769. if (this.shop.attr && this.shop.attr.length > 0) {
  770. for (var i in res.data) {
  771. if (this.shop.attr[0].ruleId == res.data[i].id) {
  772. this.attrs = res.data[i].ruleName
  773. }
  774. }
  775. }
  776. }
  777. }
  778. })
  779. },
  780. // 商品类型
  781. getClassifyList() {
  782. let data = {
  783. shopId: this.shopId
  784. }
  785. this.$Request.getA('/admin/goods/selectAllClassify', data).then((res) => {
  786. if (res.code == 0) {
  787. this.ClassifyList = res.data
  788. this.counts = this.ClassifyList[0].classifyId
  789. if (this.shop.classifyId != '') {
  790. for (var i in res.data) {
  791. if (this.shop.classifyId == res.data[i].classifyId) {
  792. this.shop.classifyName = res.data[i].classifyName
  793. }
  794. }
  795. }
  796. }
  797. })
  798. },
  799. getStarttime(e) {
  800. console.log(e)
  801. console.log(this.shop)
  802. this.shop.openTime = e.hour + ':' + e.minute
  803. },
  804. getEndtime(e) {
  805. console.log(e)
  806. this.shop.closeTime = e.hour + ':' + e.minute
  807. },
  808. // 详情图删除
  809. removeImg(index, texts) {
  810. if (texts == 'lb') {
  811. this.goodsPicture.splice(index, 1)
  812. } else if (texts == 'sq') {
  813. this.goodsParticularsPicture.splice(index, 1)
  814. }
  815. },
  816. // 身份证 资格证删除
  817. removeImgs() {
  818. // if (index == 1) {
  819. this.shop.goodsCover = ''
  820. // }
  821. },
  822. bindOpen(e) {
  823. console.log(e)
  824. let that = this
  825. uni.chooseLocation({
  826. success: function (res) {
  827. console.log('位置名称:' + res.name)
  828. console.log('详细地址:' + res.address)
  829. console.log('纬度:' + res.latitude)
  830. console.log('经度:' + res.longitude)
  831. that.shop.detailedAddress = res.address
  832. that.shop.shopLat = res.latitude
  833. that.shop.shopLng = res.longitude
  834. }
  835. })
  836. },
  837. // 图片上传
  838. addImages(e) {
  839. let num = 0
  840. if (e == 1) {
  841. num = this.maxCount - this.goodsPicture.length
  842. }
  843. if (e == 2) {
  844. num = this.maxCount - this.goodsParticularsPicture.length
  845. }
  846. let that = this
  847. uni.chooseImage({
  848. count: num,
  849. sourceType: ['album', 'camera'],
  850. success: (res) => {
  851. for (let i = 0; i < res.tempFiles.length; i++) {
  852. //这里的id和页面中写的html代码的canvas的id要一致
  853. let canvasId = 'zipCanvas'
  854. //原图的路径
  855. let imagePath = res.tempFiles[i].path
  856. //大小限制
  857. let limitSize = 1024 * 2
  858. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  859. let drawWidth = uni.getSystemInfoSync().windowWidth
  860. let that = this
  861. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, that, (resPath) => {
  862. uni.showLoading({
  863. title: '上传中'
  864. })
  865. uni.uploadFile({
  866. url: that.config('APIHOST1') + '/alioss/upload',
  867. filePath: resPath,
  868. name: 'file',
  869. success: (uploadFileRes) => {
  870. if (e == 1) {
  871. if (that.goodsPicture.length < 6) {
  872. that.goodsPicture.push(JSON.parse(uploadFileRes.data).data)
  873. }
  874. } else if (e == 2) {
  875. if (that.goodsParticularsPicture.length < 6) {
  876. that.goodsParticularsPicture.push(JSON.parse(uploadFileRes.data).data)
  877. }
  878. console.log(that.goodsParticularsPicture)
  879. }
  880. uni.hideLoading()
  881. },
  882. fail: () => {
  883. uni.showToast({
  884. title: '上传失败',
  885. icon: 'error'
  886. })
  887. }
  888. })
  889. })
  890. }
  891. }
  892. })
  893. },
  894. // 图片上传
  895. addImage(e) {
  896. let that = this
  897. uni.chooseImage({
  898. count: 1,
  899. sourceType: ['album', 'camera'],
  900. success: (res) => {
  901. for (let i = 0; i < res.tempFiles.length; i++) {
  902. //这里的id和页面中写的html代码的canvas的id要一致
  903. let canvasId = 'zipCanvas'
  904. //原图的路径
  905. let imagePath = res.tempFiles[i].path
  906. //大小限制
  907. let limitSize = 1024 * 2
  908. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  909. let drawWidth = uni.getSystemInfoSync().windowWidth
  910. let that = this
  911. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, that, (resPath) => {
  912. uni.showLoading({
  913. title: '上传中'
  914. })
  915. uni.uploadFile({
  916. url: that.config('APIHOST1') + '/alioss/upload',
  917. filePath: resPath,
  918. name: 'file',
  919. success: (uploadFileRes) => {
  920. if (e == 1) {
  921. that.shop.goodsCover = JSON.parse(uploadFileRes.data).data
  922. }
  923. uni.hideLoading()
  924. },
  925. fail: () => {
  926. uni.showToast({
  927. title: '上传失败',
  928. icon: 'error'
  929. })
  930. }
  931. })
  932. })
  933. }
  934. }
  935. })
  936. },
  937. config: function (name) {
  938. var info = null
  939. if (name) {
  940. var name2 = name.split('.') //字符分割
  941. if (name2.length > 1) {
  942. info = configdata[name2[0]][name2[1]] || null
  943. } else {
  944. info = configdata[name] || null
  945. }
  946. if (info == null) {
  947. let web_config = cache.get('web_config')
  948. if (web_config) {
  949. if (name2.length > 1) {
  950. info = web_config[name2[0]][name2[1]] || null
  951. } else {
  952. info = web_config[name] || null
  953. }
  954. }
  955. }
  956. }
  957. return info
  958. },
  959. // 发布
  960. submit() {
  961. this.shop.goodsPicture = this.goodsPicture
  962. this.shop.goodsPicture = this.goodsPicture.toString()
  963. this.shop.goodsParticularsPicture = this.goodsParticularsPicture.toString()
  964. this.shop.goodsLabel = this.goodsLabel.toString()
  965. if (!this.shop.goodsName) {
  966. uni.showToast({
  967. title: '请填写商品标题',
  968. icon: 'none',
  969. duration: 1000
  970. })
  971. return
  972. }
  973. if (!this.shop.classifyName) {
  974. uni.showToast({
  975. title: '请选择商品分类',
  976. icon: 'none',
  977. duration: 1000
  978. })
  979. return
  980. }
  981. if (!this.shop.goodsLabel) {
  982. uni.showToast({
  983. title: '请填写商品标签',
  984. icon: 'none',
  985. duration: 1000
  986. })
  987. return
  988. }
  989. if (!this.shop.originalMoney) {
  990. this.shop.originalMoney = this.shop.goodsMoney
  991. // uni.showToast({
  992. // title: '请填写商品原价',
  993. // icon: 'none',
  994. // duration: 1000
  995. // })
  996. // return
  997. }
  998. // console.log(this.shop.packMoney,'------------')
  999. // if (this.shop.packMoney*1 != '') {
  1000. // uni.showToast({
  1001. // title: '请填写商品打包费',
  1002. // icon: 'none',
  1003. // duration: 1000
  1004. // })
  1005. // return
  1006. // }
  1007. if (!this.shop.goodsMoney) {
  1008. uni.showToast({
  1009. title: '请填写商品售价',
  1010. icon: 'none',
  1011. duration: 1000
  1012. })
  1013. return
  1014. }
  1015. if (!this.shop.goodsDescribe) {
  1016. this.shop.goodsDescribe = '无'
  1017. // uni.showToast({
  1018. // title: '请填写商品描述',
  1019. // icon: 'none',
  1020. // duration: 1000
  1021. // })
  1022. // return
  1023. }
  1024. if (!this.shop.goodsCover) {
  1025. uni.showToast({
  1026. title: '请上传商品封面图',
  1027. icon: 'none',
  1028. duration: 1000
  1029. })
  1030. return
  1031. }
  1032. if (!this.shop.goodsPicture) {
  1033. uni.showToast({
  1034. title: '请上传商品轮播图',
  1035. icon: 'none',
  1036. duration: 1000
  1037. })
  1038. return
  1039. }
  1040. if (!this.shop.goodsParticularsPicture) {
  1041. this.goodsParticularsPicture = [this.Tupian('/xiangqing/12ecc56005731327e02f42f0d851848.png')]
  1042. // uni.showToast({
  1043. // title: '请上传商品详情图',
  1044. // icon: 'none',
  1045. // duration: 1000
  1046. // })
  1047. // return
  1048. }
  1049. if (this.attrsid == 2) {
  1050. if (this.shop.attr.length == 0) {
  1051. uni.showToast({
  1052. title: '请选择商品规格',
  1053. icon: 'none',
  1054. duration: 1000
  1055. })
  1056. return
  1057. }
  1058. }
  1059. let shops = this.shop
  1060. for (var i = 0; i < shops.attr.length; i++) {
  1061. let attrValues = shops.attr[i].attrValue
  1062. for (var j = 0; j < attrValues.length; j++) {
  1063. let details = attrValues[j].detail
  1064. let detailss = ''
  1065. for (var z = 0; z < details.length; z++) {
  1066. detailss = detailss + details[z]
  1067. }
  1068. shops.attr[i].attrValue[j].detail = detailss
  1069. }
  1070. }
  1071. if (this.update == 0) {
  1072. var url = '/admin/goods/insertGoods'
  1073. }
  1074. if (this.update == 1) {
  1075. var url = '/admin/goods/update'
  1076. }
  1077. this.$Request.postJsonA(url, shops).then((res) => {
  1078. if (res.code == 0) {
  1079. uni.showToast({
  1080. title: '操作成功',
  1081. icon: 'none'
  1082. })
  1083. setTimeout(function () {
  1084. uni.navigateBack()
  1085. }, 1000)
  1086. } else {
  1087. uni.showToast({
  1088. title: res.msg,
  1089. icon: 'none'
  1090. })
  1091. }
  1092. })
  1093. },
  1094. //删除规格
  1095. bindupdata(index) {
  1096. console.log('this.shop.goodsLabel', typeof this.goodsLabel)
  1097. this.goodsLabel.splice(index, 1)
  1098. },
  1099. addtype1() {
  1100. this.typeName = ''
  1101. this.show2 = true
  1102. },
  1103. bindclose1() {
  1104. if (!this.typeName) {
  1105. uni.showToast({
  1106. title: '请填写规格',
  1107. icon: 'none',
  1108. duration: 1000
  1109. })
  1110. return
  1111. }
  1112. this.goodsLabel.push(this.typeName)
  1113. this.show2 = false
  1114. },
  1115. // 获取商铺详情
  1116. goodsDet(goodsId) {
  1117. let data = {
  1118. goodsId: goodsId
  1119. }
  1120. this.$Request.getA('/admin/goods/selectGoodsById', data).then((res) => {
  1121. if (res.code == 0) {
  1122. this.dataCentre = res.data
  1123. this.shop = res.data
  1124. this.getClassifyList()
  1125. if (this.shop.goodsLabel) {
  1126. this.goodsLabel = this.shop.goodsLabel.split(',')
  1127. }
  1128. if (this.shop.goodsPicture) {
  1129. this.goodsPicture = this.shop.goodsPicture.split(',')
  1130. }
  1131. if (this.shop.goodsParticularsPicture) {
  1132. this.goodsParticularsPicture = this.shop.goodsParticularsPicture.split(',')
  1133. }
  1134. if (res.data.attr.length == 0) {
  1135. this.attrsid = 1
  1136. this.attrsType = '单规格'
  1137. } else {
  1138. this.attrsid = 2
  1139. this.attrsType = '多规格'
  1140. }
  1141. this.getguige()
  1142. }
  1143. })
  1144. }
  1145. }
  1146. }
  1147. </script>
  1148. <style>
  1149. page {
  1150. background-color: #f5f5f5;
  1151. }
  1152. .bg {
  1153. background-color: #ffffff;
  1154. }
  1155. .btn {
  1156. border: 1upx solid #cccccc;
  1157. border-radius: 10px;
  1158. padding: 0rpx 30rpx;
  1159. margin-right: 25rpx;
  1160. height: 30px;
  1161. line-height: 30px;
  1162. }
  1163. .boxH {
  1164. background: #fcd202;
  1165. border: none;
  1166. }
  1167. .btns {
  1168. border: 1upx dashed #333333;
  1169. border-radius: 28px;
  1170. padding: 0rpx 35rpx;
  1171. margin-right: 25rpx;
  1172. height: 30px;
  1173. line-height: 30px;
  1174. }
  1175. .active {
  1176. background: #fcd202;
  1177. border: none;
  1178. }
  1179. .actives {
  1180. background: #fcd202;
  1181. border: none;
  1182. }
  1183. .addguige {
  1184. width: 90%;
  1185. margin: 0 auto 25rpx;
  1186. background: #fcd202;
  1187. box-shadow: 0px 10upx 20upx 0px #ffd9b3;
  1188. border-radius: 16upx;
  1189. text-align: center;
  1190. height: 88upx;
  1191. line-height: 88upx;
  1192. /* position: fixed;
  1193. bottom: 25upx;
  1194. left: 0;
  1195. right: 0; */
  1196. }
  1197. .addguiges {
  1198. width: 90%;
  1199. margin: 0 auto;
  1200. background: #fcd202;
  1201. box-shadow: 0px 10upx 20upx 0px #ffd9b3;
  1202. border-radius: 16upx;
  1203. text-align: center;
  1204. height: 88upx;
  1205. line-height: 88upx;
  1206. /* position: fixed;
  1207. bottom: 25upx;
  1208. left: 0;
  1209. right: 0; */
  1210. }
  1211. .u-input__textarea {
  1212. background-color: #f5f5f5 !important;
  1213. padding: 10rpx !important;
  1214. }
  1215. .btn_search {
  1216. display: flex;
  1217. align-items: center;
  1218. justify-content: center;
  1219. margin-top: 20rpx;
  1220. width: 200rpx;
  1221. height: 80rpx;
  1222. color: #fff;
  1223. border-radius: 10rpx;
  1224. background-color: #3e8ef7;
  1225. }
  1226. .tupianPop {
  1227. width: 672rpx;
  1228. height: 95vh;
  1229. overflow-y: auto;
  1230. }
  1231. .pop_header {
  1232. display: flex;
  1233. align-items: center;
  1234. justify-content: space-between;
  1235. padding: 0 20rpx;
  1236. height: 70rpx;
  1237. font-size: 32rpx;
  1238. font-weight: bold;
  1239. background-color: #f5f9ff;
  1240. }
  1241. .pop_box {
  1242. padding: 0 20rpx;
  1243. height: 20vh;
  1244. }
  1245. .box_header {
  1246. padding: 0 20rpx;
  1247. height: 70rpx;
  1248. line-height: 70rpx;
  1249. font-size: 28rpx;
  1250. font-weight: bold;
  1251. }
  1252. .header_text {
  1253. margin-left: 18rpx;
  1254. color: #666666;
  1255. }
  1256. .box_body {
  1257. display: flex;
  1258. flex-wrap: wrap;
  1259. height: 20vh;
  1260. }
  1261. .img_box {
  1262. position: relative;
  1263. margin-right: 55rpx;
  1264. margin-top: 35rpx;
  1265. width: 150rpx;
  1266. height: 187rpx;
  1267. border-radius: 8rpx;
  1268. }
  1269. .images {
  1270. width: 100%;
  1271. height: 100%;
  1272. border-radius: 8rpx;
  1273. }
  1274. .box_check {
  1275. position: absolute;
  1276. top: -25rpx;
  1277. right: -25rpx;
  1278. width: 50rpx;
  1279. height: 50rpx;
  1280. border-radius: 50%;
  1281. border: 2rpx solid #808080;
  1282. background-color: #fff;
  1283. }
  1284. .box_check_active {
  1285. position: absolute;
  1286. top: -25rpx;
  1287. right: -25rpx;
  1288. display: flex;
  1289. align-items: center;
  1290. justify-content: center;
  1291. width: 50rpx;
  1292. height: 50rpx;
  1293. border-radius: 50%;
  1294. background-color: #ff8d1a;
  1295. }
  1296. .btn_pop {
  1297. display: flex;
  1298. align-items: center;
  1299. justify-content: center;
  1300. margin: 20rpx auto;
  1301. width: 626rpx;
  1302. height: 90rpx;
  1303. font-size: 32rpx;
  1304. color: #fff;
  1305. border-radius: 115rpx;
  1306. background-color: #f18731;
  1307. }
  1308. </style>