goods.vue 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373
  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%" mode="aspectFill"></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%" mode="aspectFill"></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%" mode="aspectFill"></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. let token = uni.getStorageSync('shopToken')
  862. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, that, (resPath) => {
  863. // uni.showLoading({
  864. // title: '上传中'
  865. // })
  866. uni.uploadFile({
  867. url: that.config('APIHOST1') + '/admin/new-file/upload',
  868. filePath: resPath,
  869. header: {
  870. token: token
  871. },
  872. name: 'file',
  873. success: (uploadFileRes) => {
  874. console.log(uploadFileRes, 'l')
  875. if (e == 1) {
  876. if (that.goodsPicture.length < 6) {
  877. that.goodsPicture.push(JSON.parse(uploadFileRes.data).data)
  878. }
  879. } else if (e == 2) {
  880. if (that.goodsParticularsPicture.length < 6) {
  881. that.goodsParticularsPicture.push(JSON.parse(uploadFileRes.data).data)
  882. }
  883. console.log(that.goodsParticularsPicture)
  884. }
  885. uni.hideLoading()
  886. },
  887. fail: () => {
  888. uni.showToast({
  889. title: '上传失败',
  890. icon: 'error'
  891. })
  892. }
  893. })
  894. })
  895. }
  896. }
  897. })
  898. },
  899. // 图片上传
  900. addImage(e) {
  901. let that = this
  902. uni.chooseImage({
  903. count: 1,
  904. sourceType: ['album', 'camera'],
  905. success: (res) => {
  906. for (let i = 0; i < res.tempFiles.length; i++) {
  907. //这里的id和页面中写的html代码的canvas的id要一致
  908. let canvasId = 'zipCanvas'
  909. //原图的路径
  910. let imagePath = res.tempFiles[i].path
  911. //大小限制
  912. let limitSize = 1024 * 2
  913. //初始绘画区域是画布自身的宽度也就是屏幕宽度
  914. let drawWidth = uni.getSystemInfoSync().windowWidth
  915. let that = this
  916. let token = uni.getStorageSync('shopToken')
  917. getLessLimitSizeImage(canvasId, imagePath, limitSize, drawWidth, that, (resPath) => {
  918. // uni.showLoading({
  919. // title: '上传中'
  920. // })
  921. uni.uploadFile({
  922. url: that.config('APIHOST1') + '/admin/new-file/upload',
  923. filePath: resPath,
  924. header: {
  925. token: token
  926. },
  927. name: 'file',
  928. success: (uploadFileRes) => {
  929. console.log(uploadFileRes, 'l')
  930. if (e == 1) {
  931. that.shop.goodsCover = JSON.parse(uploadFileRes.data).data
  932. }
  933. uni.hideLoading()
  934. },
  935. fail: () => {
  936. uni.showToast({
  937. title: '上传失败',
  938. icon: 'error'
  939. })
  940. }
  941. })
  942. })
  943. }
  944. }
  945. })
  946. },
  947. config: function (name) {
  948. var info = null
  949. if (name) {
  950. var name2 = name.split('.') //字符分割
  951. if (name2.length > 1) {
  952. info = configdata[name2[0]][name2[1]] || null
  953. } else {
  954. info = configdata[name] || null
  955. }
  956. if (info == null) {
  957. let web_config = cache.get('web_config')
  958. if (web_config) {
  959. if (name2.length > 1) {
  960. info = web_config[name2[0]][name2[1]] || null
  961. } else {
  962. info = web_config[name] || null
  963. }
  964. }
  965. }
  966. }
  967. return info
  968. },
  969. // 发布
  970. submit() {
  971. this.shop.goodsPicture = this.goodsPicture
  972. this.shop.goodsPicture = this.goodsPicture.toString()
  973. this.shop.goodsParticularsPicture = this.goodsParticularsPicture.toString()
  974. this.shop.goodsLabel = this.goodsLabel.toString()
  975. if (!this.shop.goodsName) {
  976. uni.showToast({
  977. title: '请填写商品标题',
  978. icon: 'none',
  979. duration: 1000
  980. })
  981. return
  982. }
  983. if (!this.shop.classifyName) {
  984. uni.showToast({
  985. title: '请选择商品分类',
  986. icon: 'none',
  987. duration: 1000
  988. })
  989. return
  990. }
  991. if (!this.shop.goodsLabel) {
  992. uni.showToast({
  993. title: '请填写商品标签',
  994. icon: 'none',
  995. duration: 1000
  996. })
  997. return
  998. }
  999. if (!this.shop.originalMoney) {
  1000. this.shop.originalMoney = this.shop.goodsMoney
  1001. // uni.showToast({
  1002. // title: '请填写商品原价',
  1003. // icon: 'none',
  1004. // duration: 1000
  1005. // })
  1006. // return
  1007. }
  1008. // console.log(this.shop.packMoney,'------------')
  1009. // if (this.shop.packMoney*1 != '') {
  1010. // uni.showToast({
  1011. // title: '请填写商品打包费',
  1012. // icon: 'none',
  1013. // duration: 1000
  1014. // })
  1015. // return
  1016. // }
  1017. if (!this.shop.goodsMoney) {
  1018. uni.showToast({
  1019. title: '请填写商品售价',
  1020. icon: 'none',
  1021. duration: 1000
  1022. })
  1023. return
  1024. }
  1025. if (!this.shop.goodsDescribe) {
  1026. this.shop.goodsDescribe = '无'
  1027. // uni.showToast({
  1028. // title: '请填写商品描述',
  1029. // icon: 'none',
  1030. // duration: 1000
  1031. // })
  1032. // return
  1033. }
  1034. if (!this.shop.goodsCover) {
  1035. uni.showToast({
  1036. title: '请上传商品封面图',
  1037. icon: 'none',
  1038. duration: 1000
  1039. })
  1040. return
  1041. }
  1042. if (!this.shop.goodsPicture) {
  1043. uni.showToast({
  1044. title: '请上传商品轮播图',
  1045. icon: 'none',
  1046. duration: 1000
  1047. })
  1048. return
  1049. }
  1050. if (!this.shop.goodsParticularsPicture) {
  1051. this.goodsParticularsPicture = [this.Tupian('/xiangqing/12ecc56005731327e02f42f0d851848.png')]
  1052. // uni.showToast({
  1053. // title: '请上传商品详情图',
  1054. // icon: 'none',
  1055. // duration: 1000
  1056. // })
  1057. // return
  1058. }
  1059. if (this.attrsid == 2) {
  1060. if (this.shop.attr.length == 0) {
  1061. uni.showToast({
  1062. title: '请选择商品规格',
  1063. icon: 'none',
  1064. duration: 1000
  1065. })
  1066. return
  1067. }
  1068. }
  1069. let shops = this.shop
  1070. for (var i = 0; i < shops.attr.length; i++) {
  1071. let attrValues = shops.attr[i].attrValue
  1072. for (var j = 0; j < attrValues.length; j++) {
  1073. let details = attrValues[j].detail
  1074. let detailss = ''
  1075. for (var z = 0; z < details.length; z++) {
  1076. detailss = detailss + details[z]
  1077. }
  1078. shops.attr[i].attrValue[j].detail = detailss
  1079. }
  1080. }
  1081. if (this.update == 0) {
  1082. var url = '/admin/goods/insertGoods'
  1083. }
  1084. if (this.update == 1) {
  1085. var url = '/admin/goods/update'
  1086. }
  1087. this.$Request.postJsonA(url, shops).then((res) => {
  1088. if (res.code == 0) {
  1089. uni.showToast({
  1090. title: '操作成功',
  1091. icon: 'none'
  1092. })
  1093. setTimeout(function () {
  1094. uni.navigateBack()
  1095. }, 1000)
  1096. } else {
  1097. uni.showToast({
  1098. title: res.msg,
  1099. icon: 'none'
  1100. })
  1101. }
  1102. })
  1103. },
  1104. //删除规格
  1105. bindupdata(index) {
  1106. console.log('this.shop.goodsLabel', typeof this.goodsLabel)
  1107. this.goodsLabel.splice(index, 1)
  1108. },
  1109. addtype1() {
  1110. this.typeName = ''
  1111. this.show2 = true
  1112. },
  1113. bindclose1() {
  1114. if (!this.typeName) {
  1115. uni.showToast({
  1116. title: '请填写规格',
  1117. icon: 'none',
  1118. duration: 1000
  1119. })
  1120. return
  1121. }
  1122. this.goodsLabel.push(this.typeName)
  1123. this.show2 = false
  1124. },
  1125. // 获取商铺详情
  1126. goodsDet(goodsId) {
  1127. let data = {
  1128. goodsId: goodsId
  1129. }
  1130. this.$Request.getA('/admin/goods/selectGoodsById', data).then((res) => {
  1131. if (res.code == 0) {
  1132. this.dataCentre = res.data
  1133. this.shop = res.data
  1134. this.getClassifyList()
  1135. if (this.shop.goodsLabel) {
  1136. this.goodsLabel = this.shop.goodsLabel.split(',')
  1137. }
  1138. if (this.shop.goodsPicture) {
  1139. this.goodsPicture = this.shop.goodsPicture.split(',')
  1140. }
  1141. if (this.shop.goodsParticularsPicture) {
  1142. this.goodsParticularsPicture = this.shop.goodsParticularsPicture.split(',')
  1143. }
  1144. if (res.data.attr.length == 0) {
  1145. this.attrsid = 1
  1146. this.attrsType = '单规格'
  1147. } else {
  1148. this.attrsid = 2
  1149. this.attrsType = '多规格'
  1150. }
  1151. this.getguige()
  1152. }
  1153. })
  1154. }
  1155. }
  1156. }
  1157. </script>
  1158. <style>
  1159. page {
  1160. background-color: #f5f5f5;
  1161. }
  1162. .bg {
  1163. background-color: #ffffff;
  1164. }
  1165. .btn {
  1166. border: 1upx solid #cccccc;
  1167. border-radius: 10px;
  1168. padding: 0rpx 30rpx;
  1169. margin-right: 25rpx;
  1170. height: 30px;
  1171. line-height: 30px;
  1172. }
  1173. .boxH {
  1174. background: #fcd202;
  1175. border: none;
  1176. }
  1177. .btns {
  1178. border: 1upx dashed #333333;
  1179. border-radius: 28px;
  1180. padding: 0rpx 35rpx;
  1181. margin-right: 25rpx;
  1182. height: 30px;
  1183. line-height: 30px;
  1184. }
  1185. .active {
  1186. background: #fcd202;
  1187. border: none;
  1188. }
  1189. .actives {
  1190. background: #fcd202;
  1191. border: none;
  1192. }
  1193. .addguige {
  1194. width: 90%;
  1195. margin: 0 auto 25rpx;
  1196. background: #fcd202;
  1197. box-shadow: 0px 10upx 20upx 0px #ffd9b3;
  1198. border-radius: 16upx;
  1199. text-align: center;
  1200. height: 88upx;
  1201. line-height: 88upx;
  1202. /* position: fixed;
  1203. bottom: 25upx;
  1204. left: 0;
  1205. right: 0; */
  1206. }
  1207. .addguiges {
  1208. width: 90%;
  1209. margin: 0 auto;
  1210. background: #fcd202;
  1211. box-shadow: 0px 10upx 20upx 0px #ffd9b3;
  1212. border-radius: 16upx;
  1213. text-align: center;
  1214. height: 88upx;
  1215. line-height: 88upx;
  1216. /* position: fixed;
  1217. bottom: 25upx;
  1218. left: 0;
  1219. right: 0; */
  1220. }
  1221. .u-input__textarea {
  1222. background-color: #f5f5f5 !important;
  1223. padding: 10rpx !important;
  1224. }
  1225. .btn_search {
  1226. display: flex;
  1227. align-items: center;
  1228. justify-content: center;
  1229. margin-top: 20rpx;
  1230. width: 200rpx;
  1231. height: 80rpx;
  1232. color: #fff;
  1233. border-radius: 10rpx;
  1234. background-color: #3e8ef7;
  1235. }
  1236. .tupianPop {
  1237. width: 672rpx;
  1238. height: 95vh;
  1239. overflow-y: auto;
  1240. }
  1241. .pop_header {
  1242. display: flex;
  1243. align-items: center;
  1244. justify-content: space-between;
  1245. padding: 0 20rpx;
  1246. height: 70rpx;
  1247. font-size: 32rpx;
  1248. font-weight: bold;
  1249. background-color: #f5f9ff;
  1250. }
  1251. .pop_box {
  1252. padding: 0 20rpx;
  1253. height: 20vh;
  1254. }
  1255. .box_header {
  1256. padding: 0 20rpx;
  1257. height: 70rpx;
  1258. line-height: 70rpx;
  1259. font-size: 28rpx;
  1260. font-weight: bold;
  1261. }
  1262. .header_text {
  1263. margin-left: 18rpx;
  1264. color: #666666;
  1265. }
  1266. .box_body {
  1267. display: flex;
  1268. flex-wrap: wrap;
  1269. height: 20vh;
  1270. }
  1271. .img_box {
  1272. position: relative;
  1273. margin-right: 55rpx;
  1274. margin-top: 35rpx;
  1275. width: 150rpx;
  1276. height: 187rpx;
  1277. border-radius: 8rpx;
  1278. }
  1279. .images {
  1280. width: 100%;
  1281. height: 100%;
  1282. border-radius: 8rpx;
  1283. }
  1284. .box_check {
  1285. position: absolute;
  1286. top: -25rpx;
  1287. right: -25rpx;
  1288. width: 50rpx;
  1289. height: 50rpx;
  1290. border-radius: 50%;
  1291. border: 2rpx solid #808080;
  1292. background-color: #fff;
  1293. }
  1294. .box_check_active {
  1295. position: absolute;
  1296. top: -25rpx;
  1297. right: -25rpx;
  1298. display: flex;
  1299. align-items: center;
  1300. justify-content: center;
  1301. width: 50rpx;
  1302. height: 50rpx;
  1303. border-radius: 50%;
  1304. background-color: #ff8d1a;
  1305. }
  1306. .btn_pop {
  1307. display: flex;
  1308. align-items: center;
  1309. justify-content: center;
  1310. margin: 20rpx auto;
  1311. width: 626rpx;
  1312. height: 90rpx;
  1313. font-size: 32rpx;
  1314. color: #fff;
  1315. border-radius: 115rpx;
  1316. background-color: #f18731;
  1317. }
  1318. </style>