editGoods.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471
  1. <template>
  2. <view class="container">
  3. <form @submit="onSubmit">
  4. <view class="goods-img-block flex flex-center">
  5. <view class="add-btn" @click="ChooseImage">
  6. <image v-if="thumb" class="logo-img" :src="URL+''+thumb">
  7. </image>
  8. <image v-else src="../static/images/icon_18.png" mode="aspectFit" class="add-img-btn"></image>
  9. <view class="btn-name">添加商品主图</view>
  10. </view>
  11. </view>
  12. <view class="page-block">
  13. <view class="page-title-block">
  14. <view class="title">基本信息</view>
  15. </view>
  16. <view class="content">
  17. <view class="cell flex flex-y-center box-pack-between">
  18. <view class="title-block required">
  19. <text>商品名称</text>
  20. </view>
  21. <view class="desc">
  22. <input type="text" :value="info.name" name="name" class="input-box" placeholder="请输入商品名称"
  23. placeholder-class="desc-placeholder">
  24. </view>
  25. </view>
  26. <view class="cell flex flex-y-center arr-r ">
  27. <view class="title-block required">
  28. <text>商品分类</text>
  29. </view>
  30. <view class="desc">
  31. <picker mode="selector" :range="goodsTypeList" @change="onGoodsTypeChange"
  32. :range-key="'name'">
  33. <view :class="[goodsType?'':'desc-placeholder','input-box']">{{goodsType || '请选择'}}
  34. </view>
  35. </picker>
  36. </view>
  37. </view>
  38. <view class="cell flex flex-y-center">
  39. <view class="title-block required">
  40. <text>商品状态</text>
  41. </view>
  42. <view class="desc">
  43. <view class="desc flex-center">
  44. <view class="checklist-box " @click="choicepay(item.status)"
  45. v-for="(item,index) of goods_list" :key='index'
  46. :class="is_goods==item.status?'actt':''">
  47. <view class="radio__inner" :class="is_goods==item.status?'act_border':''">
  48. <view :class="is_goods==item.status?'is-default-checked':''"
  49. class="radio__inner-icon radio__inner-icon ">
  50. </view>
  51. </view>
  52. <text class="checklist-text">{{item.name}}</text>
  53. </view>
  54. </view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. <!-- -->
  60. <view class="page-block">
  61. <view class="page-title-block">
  62. <view class="title">商品价格</view>
  63. </view>
  64. <view class="content">
  65. <view class="cell flex flex-y-center box-pack-between">
  66. <view class="title-block required">
  67. <text>商品售价</text>
  68. </view>
  69. <view class="desc">
  70. <input type="digit" :value="info.price" name="price" class="input-box" placeholder="请输入商品售价"
  71. placeholder-class="desc-placeholder">
  72. </view>
  73. </view>
  74. <view class="cell flex flex-y-center box-pack-between">
  75. <view class="title-block required">
  76. <text>兑换商品积分</text>
  77. </view>
  78. <view class="desc">
  79. <input type="digit" :value="info.integral" name="integral" class="input-box"
  80. placeholder="兑换商品积分" placeholder-class="desc-placeholder">
  81. </view>
  82. </view>
  83. <view class="cell flex flex-y-center box-pack-between">
  84. <view class="title-block required">
  85. <text>商品库存</text>
  86. </view>
  87. <view class="desc">
  88. <input type="number" :value="info.stock" name="stock" class="input-box"
  89. placeholder="请输入商品库存" placeholder-class="desc-placeholder">
  90. </view>
  91. </view>
  92. <view class="cell flex flex-y-center box-pack-between">
  93. <view class="title-block">
  94. <text>排序</text>
  95. </view>
  96. <view class="desc">
  97. <input type="number" :value="info.sort" name="sort" class="input-box" placeholder="请输入排序"
  98. placeholder-class="desc-placeholder">
  99. </view>
  100. </view>
  101. </view>
  102. </view>
  103. <view class="page-block">
  104. <view class="page-title-block"></view>
  105. <view class="content">
  106. <view class="cell flex flex-y-center box-pack-between">
  107. <view class="title-block">
  108. <text>商品详情</text>
  109. </view>
  110. <view class="flex-center" v-if="id" @click="getEnit">
  111. <text style="color: #007AFF;">{{is_enit?'取消编辑':'编辑'}}</text>
  112. <text class="iconfont icongengduo"></text>
  113. </view>
  114. </view>
  115. </view>
  116. <view class="content">
  117. <view v-if="id">
  118. <block v-if="is_enit">
  119. <textarea style="width: 100%;" :value="info.description" name="description"
  120. placeholder="输入商品详情" />
  121. </block>
  122. <block v-else>
  123. <rich-text :nodes="info.description"></rich-text>
  124. <textarea style="width: 100%;display: none;" :value="info.description" name="description"
  125. placeholder="" />
  126. </block>
  127. </view>
  128. <block v-else>
  129. <textarea style="width: 100%;" :value="info.description" name="description"
  130. placeholder="输入商品详情" />
  131. </block>
  132. </view>
  133. </view>
  134. <!-- -->
  135. <view style="height: 30rpx;"></view>
  136. <!-- -->
  137. <view class="footer-bar">
  138. <view class="content flex flex-center" style="background: none;position: relative;">
  139. <button class="btn" hover-class="none" form-type="submit">
  140. 立即提交
  141. </button>
  142. </view>
  143. </view>
  144. <!-- -->
  145. </form>
  146. </view>
  147. </template>
  148. <script>
  149. export default {
  150. data() {
  151. return {
  152. URL: getApp().globalData.URL,
  153. thumb: "",
  154. store_id: "",
  155. imgid: "",
  156. goods_list: [{
  157. status: 0,
  158. name: "下架",
  159. }, {
  160. status: 1,
  161. name: "上架",
  162. }],
  163. is_goods: 1,
  164. goodsTypeList: [],
  165. goodsType: "",
  166. goodsTypeid: "",
  167. listlabel: [],
  168. labelType: "",
  169. labelTypeid: "",
  170. info: {},
  171. id: "",
  172. is_enit: false,
  173. }
  174. },
  175. onLoad(e) {
  176. this.store_id = uni.getStorageSync("store_id");
  177. this.storeinfo();
  178. if (e.id) {
  179. this.id = e.id;
  180. this.goodsinfo(e.id);
  181. }
  182. },
  183. methods: {
  184. getEnit() {
  185. this.is_enit = !this.is_enit;
  186. },
  187. onGoodsTypeChange(e) {
  188. this.goodsType = this.goodsTypeList[e.detail.value].name;
  189. this.goodsTypeid = this.goodsTypeList[e.detail.value].id;
  190. },
  191. storeinfo() {
  192. this.request({
  193. url: 'Smdcshop/jftype_index',
  194. data: {
  195. admin_id: uni.getStorageSync("admin_id")
  196. }
  197. }).then(res => {
  198. console.log(res)
  199. if (res.code == 200) {
  200. this.goodsTypeList = res.data
  201. }
  202. })
  203. },
  204. goodsinfo(id) {
  205. this.request({
  206. url: 'Smdcshop/jfgoodsinfo',
  207. data: {
  208. id,
  209. }
  210. }).then(res => {
  211. if (res.code == "200") {
  212. this.info = res.data
  213. this.thumb = res.data.thumb;
  214. for (let i of this.goodsTypeList) {
  215. if (i.id == res.data.type_id) {
  216. this.goodsType = i.name
  217. }
  218. }
  219. this.goodsTypeid = res.data.type_id
  220. this.is_goods = res.data.status;
  221. }
  222. })
  223. },
  224. // getData() {
  225. // this.request({
  226. // url: 'Smdcshop/print_tag',
  227. // data: {
  228. // store_id: uni.getStorageSync("store_id")
  229. // }
  230. // }).then(res => {
  231. // if (res.code == "200") {
  232. // this.listlabel = res.data
  233. // }
  234. // })
  235. // },
  236. choicepay(index) {
  237. this.is_goods = index;
  238. },
  239. ChooseImage(e) {
  240. // let type = e.currentTarget.dataset.type;
  241. uni.chooseImage({
  242. count: 1, //默认9
  243. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  244. sourceType: ['album'], //从相册选择
  245. success: (res) => {
  246. console.log(res)
  247. // var tempFilesSize = res.tempFiles[0].size;//获取图片的大小,单位B
  248. res.tempFilePaths.forEach((v, i) => {
  249. // console.log(v)
  250. this.Upload({
  251. url: "Smdcshop/upload",
  252. data: {
  253. url: v,
  254. type: "",
  255. token: "",
  256. admin_id: uni.getStorageSync("admin_id")
  257. }
  258. }).then(res => {
  259. console.log(res, "res")
  260. this.imgid = res.id;
  261. this.thumb = res.src;
  262. }).catch(err => {
  263. uni.showToast({
  264. title: err.message,
  265. icon: 'none'
  266. })
  267. });
  268. })
  269. },
  270. });
  271. },
  272. onSubmit(e) {
  273. let params = {
  274. type_id: this.goodsTypeid,
  275. status: this.is_goods,
  276. admin_id: uni.getStorageSync("admin_id"),
  277. thumb: this.imgid,
  278. },
  279. url;
  280. var data = Object.assign(params, e.detail.value);
  281. console.log(data, "data")
  282. if (this.info.id) {
  283. data.id = this.info.id
  284. url = "Smdcshop/jfgoods_save"
  285. } else {
  286. url = 'Smdcshop/jfgoods_save'
  287. }
  288. if (!data.name || !data.type_id || !data.price || !data.stock || !data.description) {
  289. uni.showToast({
  290. title: "必填项不能为空",
  291. icon: 'none'
  292. })
  293. return false
  294. }
  295. this.request({
  296. url,
  297. data: data
  298. }).then(res => {
  299. if (res.code == 200) {
  300. uni.showToast({
  301. title: res.message,
  302. icon: 'none'
  303. })
  304. setTimeout(() => {
  305. uni.navigateBack()
  306. }, 2000)
  307. }
  308. }).catch((res) => {
  309. uni.showToast({
  310. title: res.message,
  311. icon: 'none'
  312. })
  313. });
  314. },
  315. },
  316. }
  317. </script>
  318. <style>
  319. @import url("../static/css/common.css");
  320. page .page-block .cell .input-box {
  321. text-align: right;
  322. }
  323. page {
  324. background-color: #f4f5f7;
  325. }
  326. .goods-img-block {
  327. width: 100vw;
  328. height: 70vw;
  329. background-color: #F4F6FA;
  330. }
  331. .goods-img-block .add-btn .add-img-btn {
  332. display: block;
  333. width: 64rpx;
  334. height: 64rpx;
  335. margin: 0 auto;
  336. }
  337. .goods-img-block .add-btn .btn-name {
  338. font-size: 32rpx;
  339. color: #999;
  340. line-height: 45rpx;
  341. margin-top: 16rpx;
  342. }
  343. .checklist-box {
  344. display: -webkit-box;
  345. display: -webkit-flex;
  346. display: flex;
  347. -webkit-box-orient: horizontal;
  348. -webkit-box-direction: normal;
  349. -webkit-flex-direction: row;
  350. flex-direction: row;
  351. -webkit-box-align: center;
  352. -webkit-align-items: center;
  353. align-items: center;
  354. margin: 5px 0;
  355. margin-right: 22px;
  356. }
  357. .radio__inner {
  358. -webkit-flex-shrink: 0;
  359. flex-shrink: 0;
  360. display: -webkit-box;
  361. display: -webkit-flex;
  362. display: flex;
  363. -webkit-box-pack: center;
  364. -webkit-justify-content: center;
  365. justify-content: center;
  366. -webkit-box-align: center;
  367. -webkit-align-items: center;
  368. align-items: center;
  369. position: relative;
  370. border: 1px solid #DCDFE6;
  371. border-radius: 2px;
  372. box-sizing: border-box;
  373. width: 16px;
  374. height: 16px;
  375. border-radius: 16px;
  376. background-color: #fff;
  377. z-index: 1;
  378. -webkit-transition: border-color .3s;
  379. transition: border-color .3s;
  380. }
  381. .radio__inner-icon {
  382. width: 8px;
  383. height: 8px;
  384. border-radius: 10px;
  385. opacity: 0;
  386. -webkit-transition: -webkit-transform .3s;
  387. transition: -webkit-transform .3s;
  388. transition: transform .3s;
  389. transition: transform .3s, -webkit-transform .3s;
  390. }
  391. .is-default-checked {
  392. opacity: 1;
  393. background-color: #007aff;
  394. -webkit-transform: rotate(45deg) scaleY(1);
  395. transform: rotate(45deg) scaleY(1);
  396. }
  397. .act_border {
  398. border: 1rpx solid #007AFF;
  399. }
  400. .checklist-text {
  401. font-size: 28rpx;
  402. margin-left: 5px;
  403. -webkit-transition: color 0.2s;
  404. transition: color 0.2s;
  405. color: #000;
  406. }
  407. /* */
  408. </style>