goods.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. <template>
  2. <view class="padding">
  3. <view class="text-white padding bg radius">
  4. <u-form :model="shop" label-position="top">
  5. <u-form-item label="商品标题">
  6. <u-input v-model="shop.goodsName" placeholder="请填写商品标题" />
  7. </u-form-item>
  8. <u-form-item label="商品分类">
  9. <u-input v-model="shop.classifyName" placeholder="请选择" :disabled="true" @click="getflshow()" />
  10. </u-form-item>
  11. <u-form-item label="商品标签">
  12. <!-- <u-input v-model="" placeholder="请填写" /> -->
  13. <view class="flex align-center flex-wrap margin-bottom-sm">
  14. <view v-for="(item,index) in goodsLabel" :key="index" class="btn flex align-center margin-top">
  15. <view>{{item}}</view>
  16. <view class="margin-left-sm" @tap.stop="bindupdata(index)">x</view>
  17. </view>
  18. <view class="btns margin-top" @click="addtype1()">+添加</view>
  19. </view>
  20. </u-form-item>
  21. <u-form-item label="商品原价">
  22. <u-input v-model="shop.originalMoney" @input="ZheKouInput" placeholder="请填写" />
  23. </u-form-item>
  24. <u-form-item label="打包费">
  25. <u-input v-model="shop.packMoney" placeholder="请填写" />
  26. </u-form-item>
  27. <u-form-item label="商品售价">
  28. <u-input v-model="shop.goodsMoney" @input="ZheKouInput" placeholder="请填写" />
  29. </u-form-item>
  30. <view class="padding bg radius margin-tb" style="padding: 10px 0;">
  31. <view>
  32. <view class="text-lg" style="color: #333;">商品描述</view>
  33. <view class="margin-tb-sm">
  34. <u-input v-model="shop.goodsDescribe" type="textarea" height="200" placeholde="请描述一下您的特长"
  35. maxlengt="200" :clearable="false" style="background:#F5F5F5;" />
  36. </view>
  37. </view>
  38. <view>
  39. <view class="text-lg margin-top-sm text-black">商品封面图</view>
  40. <view class="flex" style="overflow: hidden;flex-wrap: wrap;">
  41. <view v-if="shop.goodsCover.length">
  42. <view class="margin-top flex margin-right-sm flex-wrap">
  43. <view class="flex"
  44. style="width: 200rpx;height: 200rpx;margin-right: 2rpx;position: relative;">
  45. <image :src="shop.goodsCover" style="width: 100%;height: 100%;"></image>
  46. <view style="z-index: 9;position: absolute;top: -15rpx;right: -15rpx;"
  47. @click="removeImgs()">
  48. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. <view class="margin-top" @click="addImage(1)" v-if="shop.goodsCover.length<=0">
  54. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  55. class="flex justify-center align-center">
  56. <view>
  57. <view class="text-center">
  58. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  59. </image>
  60. </view>
  61. <view class="text-center text-black">添加图片</view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. <view>
  68. <view class="text-lg margin-top-sm text-black">商品轮播图(可多张)</view>
  69. <view class="flex" style="overflow: hidden;flex-wrap: wrap;">
  70. <view v-if="goodsPicture.length">
  71. <view class="margin-top flex margin-right-sm flex-wrap">
  72. <view class="flex"
  73. style="width: 200rpx;height: 200rpx;margin-right: 2rpx;position: relative;"
  74. v-for="(image,index) in goodsPicture" :key="index">
  75. <image :src="image" style="width: 100%;height: 100%;"></image>
  76. <view style="z-index: 9;position: absolute;top: -15rpx;right: -15rpx;"
  77. @click="removeImg(index,'lb')">
  78. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  79. </view>
  80. </view>
  81. </view>
  82. </view>
  83. <view class="margin-top" @click="addImages(1)" v-if="goodsPicture.length<=5">
  84. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  85. class="flex justify-center align-center">
  86. <view>
  87. <view class="text-center">
  88. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  89. </image>
  90. </view>
  91. <view class="text-center text-black">添加图片</view>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. <view>
  98. <view class="text-lg margin-top-sm text-black">商品详情图(可多张)</view>
  99. <view class="flex" style="overflow: hidden;flex-wrap: wrap;">
  100. <view v-if="goodsParticularsPicture.length">
  101. <view class="margin-top flex margin-right-sm flex-wrap">
  102. <view class="flex"
  103. style="width: 200rpx;height: 200rpx;margin-right: 2rpx;position: relative;"
  104. v-for="(image,index) in goodsParticularsPicture" :key="index">
  105. <image :src="image" style="width: 100%;height: 100%;"></image>
  106. <view style="z-index: 9;position: absolute;top: -15rpx;right: -15rpx;"
  107. @click="removeImg(index,'sq')">
  108. <u-icon name="close-circle-fill" color="#FCD202" size="50rpx"></u-icon>
  109. </view>
  110. </view>
  111. </view>
  112. </view>
  113. <view class="margin-top" @click="addImages(2)" v-if="goodsParticularsPicture.length<=5">
  114. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  115. class="flex justify-center align-center">
  116. <view>
  117. <view class="text-center">
  118. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  119. </image>
  120. </view>
  121. <view class="text-center text-black">添加图片</view>
  122. </view>
  123. </view>
  124. </view>
  125. </view>
  126. </view>
  127. <!-- <view>
  128. <view class="text-lg margin-top-sm text-black">商品详情图(可多张)</view>
  129. <editor id="editor"
  130. style="height:350rpx;color: #000000;font-size: 28rpx;width: 100%;border: 2rpx solid #F0F0F0;padding: 16rpx;"
  131. placeholder="请输入商品详情" @ready="onEditorReady" @input="getText"></editor>
  132. </view>
  133. <view>
  134. <view class="margin-top" @click="addImages(2)" v-if="goodsParticularsPicture.length<=1">
  135. <view style="width: 200rpx;height: 200rpx;background: #f4f5f6;"
  136. class="flex justify-center align-center">
  137. <view>
  138. <view class="text-center">
  139. <image src="../static/addimg.png" style="width: 65rpx;height: 55rpx;">
  140. </image>
  141. </view>
  142. <view class="text-center text-black">添加图片</view>
  143. </view>
  144. </view>
  145. </view>
  146. </view> -->
  147. </view>
  148. <u-form-item label="规格类型">
  149. <u-input v-model="attrsType" placeholder="请选择" :disabled="true" @click="ggShow()" />
  150. </u-form-item>
  151. <u-form-item label="商品规格" v-if="attrsid==2">
  152. <view style="width: 100%;">
  153. <view style="display: flex;width: 100%;">
  154. <u-input style="width: 80%;" v-model="attrs" placeholder="请选择" :disabled="true"
  155. @click="openguige()" />
  156. <view style="width: 20%;text-align: right;color: #FF4701;" v-if="attrs"
  157. @click="goGuiGeItem()">
  158. 修改价格</view>
  159. </view>
  160. <view style="color: #FF4701;font-size: 24upx;">*修改商品、商品售价后,商品规格将重置,请谨慎操作!</view>
  161. </view>
  162. </u-form-item>
  163. </u-form>
  164. </view>
  165. <u-button @click="submit" class="margin-top" :custom-style="customStyle" shape="square" :hair-line="false">提交
  166. </u-button>
  167. <!-- 规格弹框 -->
  168. <u-popup v-model="Guigeshow" mode="bottom" border-radius="14" :closeable="closeable">
  169. <view>
  170. <scroll-view scroll-y="true">
  171. <view class="padding" style="margin-bottom: 70px;">
  172. <view>规格类型</view>
  173. <view class="flex align-center margin-top-sm flex-wrap">
  174. <view class="" v-for="(item,indexs) in list" :key="indexs">
  175. <view class="btn margin-top-sm flex align-center flex-wrap"
  176. :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'
  187. @click="bindguige(ind,2,name.detail,index)" v-if="name.detail1">
  188. {{ite}}
  189. </view>
  190. <!-- <view class="btns margin-top-sm">+添加</view> -->
  191. </view>
  192. </view>
  193. </view>
  194. </scroll-view>
  195. <view class="addguige" @click="bindget()">确定</view>
  196. </view>
  197. </u-popup>
  198. <u-select v-model="flshow" :list="ClassifyList" valueName='classifyId' labelName="classifyName"
  199. @confirm="confirm">
  200. </u-select>
  201. <!-- 规格类型 -->
  202. <u-select v-model="ggshow" :list="attrList1" valueName='id' labelName="name" @confirm="ggconfirm">
  203. </u-select>
  204. <!-- 添加规格弹框 -->
  205. <u-popup v-model="show2" mode="center" border-radius="14" width="500rpx" height="300rpx" :closeable="closeable">
  206. <view>
  207. <view class="padding">
  208. <view>添加标签</view>
  209. <view>
  210. <u-input v-model="typeName" placeholder="请填写" />
  211. </view>
  212. </view>
  213. <view class="addguiges" @click="bindclose1()">确定</view>
  214. </view>
  215. </u-popup>
  216. </view>
  217. </template>
  218. <script>
  219. import configdata from '@/common/config.js';
  220. export default {
  221. data() {
  222. return {
  223. shop: {
  224. goodsName: '',
  225. classifyId: '',
  226. classifyName: '',
  227. goodsLabel: [],
  228. attr: [],
  229. sku: [],
  230. originalMoney: '',
  231. packMoney: 0,
  232. goodsMoney: '',
  233. goodsDescribe: '',
  234. //详情图
  235. goodsCover: '',
  236. goodsPicture: [],
  237. goodsParticularsPicture: [],
  238. shopId: uni.getStorageSync('shopId')
  239. },
  240. shops: {
  241. goodsName: '',
  242. classifyId: '',
  243. classifyName: '',
  244. goodsLabel: [],
  245. attr: [],
  246. sku: [],
  247. originalMoney: '',
  248. packMoney: 0,
  249. goodsMoney: '',
  250. goodsDescribe: '',
  251. //详情图
  252. goodsCover: '',
  253. goodsPicture: [],
  254. goodsParticularsPicture: [],
  255. shopId: uni.getStorageSync('shopId')
  256. },
  257. attrs: '',
  258. goodsLabel: [],
  259. goodsPicture: [],
  260. goodsParticularsPicture: [],
  261. customStyle: {
  262. backgroundColor: '#FFCC00',
  263. color: '#000000',
  264. border: 0
  265. },
  266. status: 1,
  267. customStyle1: {
  268. color: '#000000',
  269. position: "fixed",
  270. bottom: "15rpx",
  271. left: "0rpx",
  272. right: "0rpx",
  273. margin: "0rpx 50rpx",
  274. backgroundColor: '#FFCC00',
  275. },
  276. Guigeshow: false,
  277. //详情图
  278. goodsCover: [],
  279. shopId: '',
  280. page: 1,
  281. limit: 100,
  282. list: [],
  283. listIndex: 0,
  284. typeIndex: 0,
  285. typeIndex1: 0,
  286. wdIndex: 0,
  287. show: false,
  288. typeName: '',
  289. shows: false,
  290. typeperature: '',
  291. flshow: false,
  292. ggshow: false,
  293. ClassifyList: [],
  294. attrList: {},
  295. attrLists: [],
  296. shopId: '',
  297. show2: false,
  298. update: 0,
  299. count: 6,
  300. editorCtx: '',
  301. htmlMessage: '',
  302. closeable: true,
  303. attrsType: '多规格',
  304. attrsid: 2,
  305. attrList1: [{
  306. 'name': '单规格',
  307. 'id': 1
  308. },
  309. {
  310. 'name': '多规格',
  311. 'id': 2
  312. }
  313. ],
  314. }
  315. },
  316. onLoad(option) {
  317. console.log('option', option)
  318. if (option.goodsId) {
  319. this.update = 1
  320. uni.setNavigationBarTitle({
  321. title: '修改商品'
  322. })
  323. this.goodsDet(option.goodsId)
  324. } else {
  325. this.update = 0
  326. }
  327. // console.log(option, '店铺id')
  328. // this.shopId = option.shopId
  329. this.shopId = this.$queue.getData("shopId")
  330. this.getguige()
  331. // this.onEditorReady();
  332. },
  333. onShow() {
  334. let list = this.$queue.getData('guigeSelectItemList');
  335. if (list) {
  336. this.shop.sku = list;
  337. this.$queue.remove('guigeSelectItemList');
  338. }
  339. this.getClassifyList()
  340. },
  341. methods: {
  342. ZheKouInput(e) {
  343. console.log(e)
  344. this.attrs = '';
  345. this.shop.attr = []
  346. if (this.attrsid == 1) {
  347. this.guigeclect()
  348. } else {
  349. this.getgoodslist()
  350. }
  351. },
  352. goGuiGeItem() {
  353. this.$queue.setData('guigeSelectItemList', this.shop.sku)
  354. uni.navigateTo({
  355. url: '/my/publish/guigeitem'
  356. });
  357. },
  358. //获取分类
  359. getflshow() {
  360. console.log(this.ClassifyList.length)
  361. if (this.ClassifyList.length == 0) {
  362. uni.navigateTo({
  363. url: '/my/store/fenlei'
  364. })
  365. } else {
  366. this.flshow = true
  367. }
  368. },
  369. // 规格类型
  370. ggShow() {
  371. this.ggshow = true
  372. },
  373. //获取商品规格列表
  374. getgoodslist() {
  375. let ruleValues = this.attrList.ruleValue
  376. for (var j = 0; j < ruleValues.length; j++) {
  377. let details = ruleValues[j].detail;
  378. ruleValues[j].detail = ruleValues[j].detail.toString();
  379. }
  380. let data = {
  381. attrName: this.attrList.ruleName,
  382. attrValue: ruleValues,
  383. ruleId: this.attrList.id,
  384. }
  385. this.$Request.postJsonA("/admin/goods/isFormatAttr?coverImg=" + this.shop.goodsCover + '&originalPrice=' +
  386. this.shop.originalMoney + '&price=' + this.shop.goodsMoney, data).then(res => {
  387. if (res.code == 0) {
  388. // this.shop.sku.push(res.data.value)
  389. this.shop.sku = res.data.value
  390. console.log(res.data.value, '111', this.shop.sku)
  391. }
  392. });
  393. },
  394. //获取规格
  395. bindget() {
  396. this.getgoodslist()
  397. this.attrs = this.attrList.ruleName
  398. var obj = {}
  399. obj.attrName = this.attrList.ruleName
  400. obj.attrValue = this.attrList.ruleValue
  401. obj.ruleId = this.attrList.id
  402. this.shop.attr.push(obj)
  403. this.Guigeshow = false
  404. },
  405. //商品分类
  406. confirm(e) {
  407. // console.log(e)
  408. this.shop.classifyName = e[0].label
  409. this.shop.classifyId = e[0].value
  410. },
  411. //规格分类
  412. ggconfirm(e) {
  413. // console.log(e)
  414. this.attrsType = e[0].label
  415. this.attrsid = e[0].value
  416. if (e[0].value == 1) {
  417. this.shop.attr = []
  418. this.guigeclect()
  419. }
  420. },
  421. // 单规格
  422. guigeclect() {
  423. this.$Request.getA("/admin/goods/onlyFormatAttr?coverImg=" + this.shop.goodsCover + '&originalPrice=' +
  424. this.shop.originalMoney + '&price=' + this.shop.goodsMoney).then(res => {
  425. if (res.code == 0) {
  426. // this.shop.sku.push(res.data.value)
  427. this.shop.sku = res.data.value
  428. console.log(res.data.value, '111', this.shop.sku)
  429. }
  430. });
  431. },
  432. addtype(index) {
  433. if (index == 1) {
  434. this.show = true
  435. } else if (index == 2) {
  436. this.shows = true
  437. }
  438. },
  439. bindclose() {
  440. if (index == 1) {
  441. this.show = false
  442. } else if (index == 2) {
  443. this.shows = false
  444. }
  445. },
  446. //弹框规格切换
  447. bindguige(index, e, name, index1) {
  448. // console.log(index, e, name)
  449. if (e == 1) {
  450. this.listIndex = index
  451. this.attrList = this.list[index]
  452. } else if (e == 2) {
  453. this.typeIndex = index
  454. this.typeIndex1 = index1
  455. } else if (e == 3) {
  456. this.wdIndex = index
  457. }
  458. },
  459. //规格弹框
  460. openguige() {
  461. if (!this.attrList.ruleValue) {
  462. uni.showToast({
  463. title: '暂无规格',
  464. icon: 'none',
  465. duration: 1000
  466. })
  467. return
  468. }
  469. // 打开规格选项弹框
  470. this.Guigeshow = true
  471. },
  472. //获取商品规格
  473. getguige() {
  474. let data = {
  475. // page: this.page,
  476. // limit: this.limit,
  477. shopId: this.shopId,
  478. }
  479. this.$Request.getA("/selfGoodsRule/list", data).then(res => {
  480. if (res.code == 0) {
  481. // this.shop.sku = res.data
  482. if (res.data.length > 0) {
  483. this.list = res.data
  484. this.list.forEach(res => {
  485. res.ruleValue.forEach(ret => {
  486. ret.detail = ret.detail.split(',')
  487. ret.detail1 = ret.detail
  488. })
  489. })
  490. console.log('this.attrList', this.list)
  491. this.attrList = this.list[0]
  492. if (this.shop.attr && this.shop.attr.length > 0) {
  493. for (var i in res.data) {
  494. if (this.shop.attr[0].ruleId == res.data[i].id) {
  495. this.attrs = res.data[i].ruleName
  496. }
  497. }
  498. }
  499. }
  500. }
  501. });
  502. },
  503. // 商品类型
  504. getClassifyList() {
  505. this.$Request.getA("/admin/goods/selectAllClassify?shopId=" + this.shopId).then(res => {
  506. if (res.code == 0) {
  507. this.ClassifyList = res.data
  508. this.counts = this.ClassifyList[0].classifyId
  509. if (this.shop.classifyId != '') {
  510. for (var i in res.data) {
  511. if (this.shop.classifyId == res.data[i].classifyId) {
  512. this.shop.classifyName = res.data[i].classifyName
  513. }
  514. }
  515. }
  516. }
  517. });
  518. },
  519. getStarttime(e) {
  520. console.log(e)
  521. console.log(this.shop)
  522. this.shop.openTime = e.hour + ':' + e.minute
  523. },
  524. getEndtime(e) {
  525. console.log(e)
  526. this.shop.closeTime = e.hour + ':' + e.minute
  527. },
  528. // 详情图删除
  529. removeImg(index, texts) {
  530. if (texts == 'lb') {
  531. this.goodsPicture.splice(index, 1)
  532. } else if (texts == 'sq') {
  533. this.goodsParticularsPicture.splice(index, 1)
  534. }
  535. },
  536. // 身份证 资格证删除
  537. removeImgs() {
  538. // if (index == 1) {
  539. this.shop.goodsCover = ''
  540. // }
  541. },
  542. bindOpen(e) {
  543. console.log(e)
  544. let that = this
  545. uni.chooseLocation({
  546. success: function(res) {
  547. console.log('位置名称:' + res.name);
  548. console.log('详细地址:' + res.address);
  549. console.log('纬度:' + res.latitude);
  550. console.log('经度:' + res.longitude);
  551. that.shop.detailedAddress = res.address
  552. that.shop.shopLat = res.latitude
  553. that.shop.shopLng = res.longitude
  554. }
  555. });
  556. },
  557. // 图片上传
  558. addImages(e) {
  559. if (e == 1) {
  560. var num = this.goodsPicture.length
  561. this.count = 6 - num
  562. }
  563. if (e == 2) {
  564. var num = this.goodsParticularsPicture.length
  565. this.count = 6 - num
  566. }
  567. let that = this
  568. uni.chooseImage({
  569. count: this.count,
  570. sourceType: ['album', 'camera'],
  571. success: res => {
  572. for (let i = 0; i < res.tempFilePaths.length; i++) {
  573. that.$queue.showLoading("上传中...");
  574. uni.uploadFile({ // 上传接口
  575. url: that.config("APIHOST1") + '/alioss/upload', //真实的接口地址
  576. // url: 'https://mxys.chuanghai-tech.com/sqx_fast/alioss/upload',
  577. filePath: res.tempFilePaths[i],
  578. name: 'file',
  579. success: (uploadFileRes) => {
  580. if (e == 1) {
  581. if (that.goodsPicture.length < 6) {
  582. that.goodsPicture.push(JSON.parse(uploadFileRes.data)
  583. .data)
  584. }
  585. } else if (e == 2) {
  586. if (that.goodsParticularsPicture.length < 6) {
  587. that.goodsParticularsPicture.push(JSON.parse(
  588. uploadFileRes.data).data)
  589. }
  590. console.log(that.goodsParticularsPicture)
  591. }
  592. uni.hideLoading();
  593. }
  594. });
  595. }
  596. }
  597. })
  598. },
  599. // 图片上传
  600. addImage(e) {
  601. let that = this
  602. uni.chooseImage({
  603. count: 1,
  604. sourceType: ['album', 'camera'],
  605. success: res => {
  606. for (let i = 0; i < res.tempFilePaths.length; i++) {
  607. that.$queue.showLoading("上传中...");
  608. uni.uploadFile({ // 上传接口
  609. // url: that.config("APIHOST1") + '/alioss/upload', //真实的接口地址
  610. url: 'https://mxys.chuanghai-tech.com/sqx_fast/alioss/upload',
  611. filePath: res.tempFilePaths[i],
  612. name: 'file',
  613. success: (uploadFileRes) => {
  614. if (e == 1) {
  615. that.shop.goodsCover = JSON.parse(uploadFileRes.data).data
  616. }
  617. uni.hideLoading();
  618. }
  619. });
  620. }
  621. }
  622. })
  623. },
  624. config: function(name) {
  625. var info = null;
  626. if (name) {
  627. var name2 = name.split("."); //字符分割
  628. if (name2.length > 1) {
  629. info = configdata[name2[0]][name2[1]] || null;
  630. } else {
  631. info = configdata[name] || null;
  632. }
  633. if (info == null) {
  634. let web_config = cache.get("web_config");
  635. if (web_config) {
  636. if (name2.length > 1) {
  637. info = web_config[name2[0]][name2[1]] || null;
  638. } else {
  639. info = web_config[name] || null;
  640. }
  641. }
  642. }
  643. }
  644. return info;
  645. },
  646. // 发布
  647. submit() {
  648. this.shop.goodsPicture = this.goodsPicture
  649. this.shop.goodsPicture = this.goodsPicture.toString();
  650. this.shop.goodsParticularsPicture = this.goodsParticularsPicture.toString();
  651. this.shop.goodsLabel = this.goodsLabel.toString();
  652. if (!this.shop.goodsName) {
  653. uni.showToast({
  654. title: '请填写商品标题',
  655. icon: 'none',
  656. duration: 1000
  657. })
  658. return
  659. }
  660. if (!this.shop.classifyName) {
  661. uni.showToast({
  662. title: '请选择商品分类',
  663. icon: 'none',
  664. duration: 1000
  665. })
  666. return
  667. }
  668. if (!this.shop.goodsLabel) {
  669. uni.showToast({
  670. title: '请填写商品标签',
  671. icon: 'none',
  672. duration: 1000
  673. })
  674. return
  675. }
  676. if (!this.shop.originalMoney) {
  677. uni.showToast({
  678. title: '请填写商品原价',
  679. icon: 'none',
  680. duration: 1000
  681. })
  682. return
  683. }
  684. // console.log(this.shop.packMoney,'------------')
  685. // if (this.shop.packMoney*1 != '') {
  686. // uni.showToast({
  687. // title: '请填写商品打包费',
  688. // icon: 'none',
  689. // duration: 1000
  690. // })
  691. // return
  692. // }
  693. if (!this.shop.goodsMoney) {
  694. uni.showToast({
  695. title: '请填写商品售价',
  696. icon: 'none',
  697. duration: 1000
  698. })
  699. return
  700. }
  701. if (!this.shop.goodsDescribe) {
  702. uni.showToast({
  703. title: '请填写商品描述',
  704. icon: 'none',
  705. duration: 1000
  706. })
  707. return
  708. }
  709. if (!this.shop.goodsCover) {
  710. uni.showToast({
  711. title: '请上传商品封面图',
  712. icon: 'none',
  713. duration: 1000
  714. })
  715. return
  716. }
  717. if (!this.shop.goodsPicture) {
  718. uni.showToast({
  719. title: '请上传商品轮播图',
  720. icon: 'none',
  721. duration: 1000
  722. })
  723. return
  724. }
  725. if (!this.shop.goodsParticularsPicture) {
  726. uni.showToast({
  727. title: '请上传商品详情图',
  728. icon: 'none',
  729. duration: 1000
  730. })
  731. return
  732. }
  733. if (this.attrsid == 2) {
  734. if (this.shop.attr.length == 0) {
  735. uni.showToast({
  736. title: '请选择商品规格',
  737. icon: 'none',
  738. duration: 1000
  739. })
  740. return
  741. }
  742. }
  743. let shops = this.shop;
  744. for (var i = 0; i < shops.attr.length; i++) {
  745. let attrValues = shops.attr[i].attrValue;
  746. for (var j = 0; j < attrValues.length; j++) {
  747. let details = attrValues[j].detail;
  748. let detailss = '';
  749. for (var z = 0; z < details.length; z++) {
  750. detailss = detailss + details[z];
  751. }
  752. shops.attr[i].attrValue[j].detail = detailss
  753. }
  754. }
  755. if (this.update == 0) {
  756. var url = '/admin/goods/insertGoods'
  757. }
  758. if (this.update == 1) {
  759. var url = '/admin/goods/update'
  760. }
  761. this.$Request.postJsonA(url, shops).then(res => {
  762. if (res.code == 0) {
  763. uni.showToast({
  764. title: '操作成功',
  765. icon: 'none'
  766. })
  767. setTimeout(function() {
  768. uni.navigateBack()
  769. }, 1000)
  770. } else {
  771. uni.showToast({
  772. title: res.msg,
  773. icon: 'none'
  774. })
  775. }
  776. });
  777. },
  778. //删除规格
  779. bindupdata(index) {
  780. console.log('this.shop.goodsLabel', typeof this.goodsLabel)
  781. this.goodsLabel.splice(index, 1)
  782. },
  783. addtype1() {
  784. this.typeName = ''
  785. this.show2 = true
  786. },
  787. bindclose1() {
  788. if (!this.typeName) {
  789. uni.showToast({
  790. title: '请填写规格',
  791. icon: 'none',
  792. duration: 1000
  793. })
  794. return
  795. }
  796. this.goodsLabel.push(this.typeName)
  797. this.show2 = false
  798. },
  799. // 获取商铺详情
  800. goodsDet(goodsId) {
  801. this.$Request.getA("/admin/goods/selectGoodsById?goodsId=" + goodsId).then(res => {
  802. if (res.code == 0) {
  803. this.dataCentre = res.data;
  804. this.shop = res.data;
  805. this.getClassifyList()
  806. if (this.shop.goodsLabel) {
  807. this.goodsLabel = this.shop.goodsLabel.split(',')
  808. }
  809. if (this.shop.goodsPicture) {
  810. this.goodsPicture = this.shop.goodsPicture.split(',')
  811. }
  812. if (this.shop.goodsParticularsPicture) {
  813. this.goodsParticularsPicture = this.shop.goodsParticularsPicture.split(',')
  814. }
  815. if (res.data.attr.length == 0) {
  816. this.attrsid = 1
  817. this.attrsType = '单规格'
  818. } else {
  819. this.attrsid = 2
  820. this.attrsType = '多规格'
  821. }
  822. this.getguige()
  823. }
  824. });
  825. }
  826. }
  827. }
  828. </script>
  829. <style>
  830. page {
  831. background-color: #F5F5F5;
  832. }
  833. .bg {
  834. background-color: #FFFFFF;
  835. }
  836. .btn {
  837. border: 1upx solid #CCCCCC;
  838. border-radius: 10px;
  839. padding: 0rpx 30rpx;
  840. margin-right: 25rpx;
  841. height: 30px;
  842. line-height: 30px;
  843. }
  844. .boxH {
  845. background: #FCD202;
  846. border: none;
  847. }
  848. .btns {
  849. border: 1upx dashed #333333;
  850. border-radius: 28px;
  851. padding: 0rpx 35rpx;
  852. margin-right: 25rpx;
  853. height: 30px;
  854. line-height: 30px;
  855. }
  856. .active {
  857. background: #FCD202;
  858. border: none;
  859. }
  860. .actives {
  861. background: #FCD202;
  862. border: none;
  863. }
  864. .addguige {
  865. width: 90%;
  866. margin: 0 auto;
  867. background: #FCD202;
  868. box-shadow: 0px 10upx 20upx 0px #FFD9B3;
  869. border-radius: 16upx;
  870. text-align: center;
  871. height: 88upx;
  872. line-height: 88upx;
  873. position: fixed;
  874. bottom: 25upx;
  875. left: 0;
  876. right: 0;
  877. }
  878. .addguiges {
  879. width: 90%;
  880. margin: 0 auto;
  881. background: #FCD202;
  882. box-shadow: 0px 10upx 20upx 0px #FFD9B3;
  883. border-radius: 16upx;
  884. text-align: center;
  885. height: 88upx;
  886. line-height: 88upx;
  887. /* position: fixed;
  888. bottom: 25upx;
  889. left: 0;
  890. right: 0; */
  891. }
  892. .u-input__textarea {
  893. background-color: #f5f5f5 !important;
  894. padding: 10rpx !important;
  895. }
  896. </style>