index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <template>
  2. <div class="container">
  3. <el-card class="box-card">
  4. <div class="filter-container">
  5. <el-button type="primary" @click="dialogVisible = true"
  6. >新建sku</el-button
  7. >
  8. </div>
  9. <el-table
  10. :data="tableData"
  11. style="width: 100%; fontsize: 12px"
  12. v-loading="listLoading"
  13. :cell-style="{ padding: '6px 0' }"
  14. >
  15. <el-table-column prop="id" label="ID" width="50px"></el-table-column>
  16. <el-table-column
  17. prop="category"
  18. label="category"
  19. width="100"
  20. ></el-table-column>
  21. <el-table-column
  22. prop="description"
  23. label="description"
  24. show-overflow-tooltip
  25. ></el-table-column>
  26. <el-table-column
  27. prop="image"
  28. show-overflow-tooltip
  29. label="image"
  30. ></el-table-column>
  31. <el-table-column
  32. prop="name"
  33. label="name"
  34. show-overflow-tooltip
  35. ></el-table-column>
  36. <el-table-column
  37. prop="nameeng"
  38. label="nameeng"
  39. show-overflow-tooltip
  40. ></el-table-column>
  41. <el-table-column
  42. prop="pricenow"
  43. label="pricenow"
  44. width="100"
  45. ></el-table-column>
  46. <el-table-column
  47. prop="priceorigin"
  48. label="priceorigin"
  49. width="100"
  50. ></el-table-column>
  51. <el-table-column
  52. prop="property"
  53. label="property"
  54. show-overflow-tooltip
  55. ></el-table-column>
  56. <el-table-column
  57. prop="recommendation"
  58. label="recommendation"
  59. show-overflow-tooltip
  60. ></el-table-column>
  61. <el-table-column
  62. prop="rule"
  63. show-overflow-tooltip
  64. label="rule"
  65. width="120"
  66. ></el-table-column>
  67. <!--
  68. <el-table-column prop="isbuild" label="状态">
  69. <template slot-scope="{row}">
  70. <span :style="{color:row.isbuild == 1?'#409EFF':'red'}">{{ row.isbuild | filterBuild }}</span>
  71. </template>
  72. </el-table-column>-->
  73. </el-table>
  74. </el-card>
  75. <!-- 弹窗 -->
  76. <el-dialog title="新增" :visible.sync="dialogVisible">
  77. <!-- 新增sku -->
  78. <el-form
  79. :model="dynamicValidateForm"
  80. ref="dynamicValidateForm"
  81. label-width="100px"
  82. class="demo-dynamic"
  83. :rules="rules"
  84. >
  85. <el-form-item prop="id" label="菜单id">
  86. <el-row :span="24">
  87. <el-col :span="10">
  88. <el-input
  89. type="number"
  90. v-model="dynamicValidateForm.id"
  91. placeholder="菜单id,尽量把同一类别的放一块"
  92. ></el-input>
  93. </el-col>
  94. <el-col :span="10" :offset="1"
  95. >菜单id,尽量把同一类别的放一块</el-col
  96. >
  97. </el-row>
  98. </el-form-item>
  99. <el-form-item prop="name" label="名称">
  100. <el-row :span="24">
  101. <el-col :span="10">
  102. <el-input
  103. v-model="dynamicValidateForm.name"
  104. placeholder="神奇咖啡"
  105. ></el-input>
  106. </el-col>
  107. </el-row>
  108. </el-form-item>
  109. <el-form-item prop="nameeng" label="英文名">
  110. <el-row :span="24">
  111. <el-col :span="10">
  112. <el-input
  113. v-model="dynamicValidateForm.nameeng"
  114. placeholder="legend coffee"
  115. ></el-input>
  116. </el-col>
  117. </el-row>
  118. </el-form-item>
  119. <el-form-item prop="pricenow" label="现价">
  120. <el-row :span="24">
  121. <el-col :span="10">
  122. <el-input
  123. type="number"
  124. v-model="dynamicValidateForm.pricenow"
  125. placeholder="现价"
  126. ></el-input>
  127. </el-col>
  128. <el-col :span="10" :offset="1">
  129. <span>现价,2.0/3.0门店有统一折扣,则此字段没什么用</span>
  130. </el-col>
  131. </el-row>
  132. </el-form-item>
  133. <el-form-item prop="priceorigin" label="原价">
  134. <el-row :span="24">
  135. <el-col :span="10">
  136. <el-input
  137. type="number"
  138. v-model="dynamicValidateForm.priceorigin"
  139. placeholder="原价"
  140. ></el-input>
  141. </el-col>
  142. </el-row>
  143. </el-form-item>
  144. <el-form-item prop="image" label="产品图片">
  145. <el-row :span="24">
  146. <el-col :span="10">
  147. <el-input
  148. v-model="dynamicValidateForm.image"
  149. placeholder="元气樱樱抹茶拿铁.jpg"
  150. ></el-input>
  151. </el-col>
  152. <el-col :span="10" :offset="1">
  153. <span>
  154. 请先把该名字命名的大图和小图分别传到mpmedium和mpthumb目录下</span
  155. >
  156. </el-col>
  157. </el-row>
  158. </el-form-item>
  159. <el-form-item label="大图轮播">
  160. <el-row :span="24">
  161. <el-col :span="10">
  162. <el-tag
  163. :key="tag"
  164. v-for="tag in dynamicValidateForm.slides"
  165. closable
  166. :disable-transitions="false"
  167. @close="handleClose(tag)"
  168. >
  169. {{ tag }}
  170. </el-tag>
  171. <el-input
  172. class="input-new-tag"
  173. v-if="inputVisible"
  174. v-model="inputValue"
  175. ref="saveTagInput"
  176. size="small"
  177. @keyup.enter.native="handleInputConfirm"
  178. @blur="handleInputConfirm"
  179. >
  180. </el-input>
  181. <el-button
  182. v-else
  183. class="button-new-tag"
  184. size="small"
  185. @click="showInput"
  186. >+</el-button
  187. >
  188. </el-col>
  189. <el-col :span="10" :offset="1">
  190. <span> 元气樱樱抹茶拿铁.jpg</span>
  191. </el-col>
  192. </el-row>
  193. </el-form-item>
  194. <el-form-item prop="category" label="类目">
  195. <el-row :span="24">
  196. <el-col :span="10">
  197. <el-input
  198. v-model="dynamicValidateForm.category"
  199. placeholder="新品推荐"
  200. ></el-input>
  201. </el-col>
  202. <el-col :span="10" :offset="1">
  203. <span> 同一类别的咖啡会归一起</span>
  204. </el-col>
  205. </el-row>
  206. </el-form-item>
  207. <el-form-item prop="recommendation" label="推荐语">
  208. <el-row :span="24">
  209. <el-col :span="10">
  210. <!-- <el-input
  211. type="textarea"
  212. :rows="2"
  213. v-model="dynamicValidateForm.recommendation"
  214. placeholder="有颜有料,樱你而美"
  215. ></el-input> -->
  216. <el-select v-model="dynamicValidateForm.recommendation">
  217. <el-option
  218. v-for="(item, index) in recommendationList"
  219. :key="index"
  220. :label="item.name"
  221. :value="item.value"
  222. ></el-option>
  223. </el-select>
  224. </el-col>
  225. <el-col :span="10" :offset="1">
  226. <span> 推荐语,同一类别的咖啡共用一个推荐语</span>
  227. </el-col>
  228. </el-row>
  229. </el-form-item>
  230. <el-form-item prop="description" label="商品描述">
  231. <el-row :span="24">
  232. <el-col :span="10">
  233. <el-input
  234. type="textarea"
  235. :rows="2"
  236. v-model="dynamicValidateForm.description"
  237. placeholder="限量赠网红樱花饼干。优选宇治抹茶,精细石 磨研磨,搭配进口樱花粉,碰撞绝妙层次感。"
  238. ></el-input>
  239. </el-col>
  240. <el-col :span="10" :offset="1">
  241. <span> \n 为换行符</span>
  242. </el-col>
  243. </el-row>
  244. </el-form-item>
  245. <el-form-item label="属性">
  246. <el-row :span="24">
  247. <el-col :span="10">
  248. <el-input
  249. type="textarea"
  250. :rows="2"
  251. v-model="dynamicValidateForm.property"
  252. placeholder="热,冰,少冰,去冰;标准糖,半糖; 含咖啡"
  253. ></el-input>
  254. </el-col>
  255. <el-col :span="10" :offset="1">
  256. <span> 不同类的属性用分号隔开,同类属性用逗号隔开</span>
  257. </el-col>
  258. </el-row>
  259. </el-form-item>
  260. <!-- --------------------------------------------- -->
  261. </el-form>
  262. <span slot="footer" class="dialog-footer">
  263. <el-button @click="cancel('dynamicValidateForm')">取 消</el-button>
  264. <el-button type="primary" @click="submitForm('dynamicValidateForm')"
  265. >确 定</el-button
  266. >
  267. </span>
  268. <div>
  269. <el-link
  270. href="https://help.aliyun.com/document_detail/195868.html?spm=a2c4g.11186623.6.620.74d062e7wbqjEy"
  271. target="_blank"
  272. type="success"
  273. >图片上传工具下载</el-link
  274. >
  275. </div>
  276. <div>商品小图限制 80k 以内</div>
  277. <div>商品大图限制 150k 以内</div>
  278. </el-dialog>
  279. </div>
  280. </template>
  281. <script>
  282. import { getGoodsList } from "@/api/order";
  283. import { createSku } from "@/api/shop";
  284. const recommendationList = [
  285. {
  286. name: "新品推荐",
  287. value: "有颜有料,樱你而美"
  288. },
  289. {
  290. name: "活力早餐",
  291. value: "超低脂高饱腹感,马上预约"
  292. },
  293. {
  294. name: "限时折扣",
  295. value: "限定版口感,马上品鉴"
  296. },
  297. {
  298. name: "Nowwa特调",
  299. value: "限定版口感,马上品鉴!"
  300. },
  301. {
  302. name: "经典家族",
  303. value: "四大产区精品咖啡豆"
  304. },
  305. {
  306. name: "风味鉴赏",
  307. value: "咖啡里的缤纷艺术"
  308. },
  309. {
  310. name: "奶茶果茶",
  311. value: "一起喝茶吧!"
  312. },
  313. {
  314. name: "多杯组合",
  315. value: "一起分享,加倍快乐"
  316. },
  317. {
  318. name: "烘培零食",
  319. value: "早餐/下午茶好搭档(必须和饮品一起下单 )"
  320. },
  321. {
  322. name: "面包配咖啡",
  323. value: "早餐/下午茶好搭档"
  324. },
  325. {
  326. name: "Nowwa礼品",
  327. value: "送给你的美好心意"
  328. }
  329. ];
  330. export default {
  331. data() {
  332. return {
  333. tableData: [],
  334. listLoading: true,
  335. dialogVisible: false,
  336. recommendationList,
  337. // form
  338. inputVisible: false,
  339. inputValue: "",
  340. dynamicValidateForm: {
  341. id: "",
  342. name: "",
  343. nameeng: "",
  344. pricenow: "",
  345. priceorigin: "",
  346. image: "",
  347. slides: [],
  348. category: "",
  349. recommendation: "",
  350. description: "",
  351. property: ""
  352. },
  353. rules: {
  354. id: [{ required: true, message: " ", trigger: "blur" }],
  355. name: [{ required: true, message: " ", trigger: "blur" }],
  356. nameeng: [{ required: true, message: " ", trigger: "blur" }],
  357. pricenow: [{ required: true, message: " ", trigger: "blur" }],
  358. priceorigin: [{ required: true, message: " ", trigger: "blur" }],
  359. image: [{ required: true, message: " ", trigger: "blur" }],
  360. category: [{ required: true, message: " ", trigger: "blur" }],
  361. recommendation: [{ required: true, message: " ", trigger: "change" }],
  362. description: [{ required: true, message: " ", trigger: "blur" }]
  363. }
  364. };
  365. },
  366. created() {
  367. this.getList();
  368. },
  369. methods: {
  370. getList() {
  371. this.listLoading = true;
  372. getGoodsList().then(res => {
  373. console.log(res);
  374. this.tableData = res;
  375. this.listLoading = false;
  376. });
  377. },
  378. // form
  379. submitForm(formName) {
  380. this.$refs[formName].validate(valid => {
  381. if (valid) {
  382. let params = Object.assign({}, this.dynamicValidateForm, {
  383. id: this.dynamicValidateForm.id - 0,
  384. slides: this.dynamicValidateForm.slides.join(";"),
  385. pricenow: this.dynamicValidateForm.pricenow - 0,
  386. priceorigin: this.dynamicValidateForm.priceorigin - 0
  387. });
  388. createSku(params)
  389. .then(res => {
  390. console.log(res);
  391. if (res === "OK") {
  392. this.cancel("dynamicValidateForm");
  393. this.$message.success("sku创建成功!");
  394. }
  395. })
  396. .catch(err => {
  397. console.log(err);
  398. });
  399. console.log(params);
  400. } else {
  401. console.log("error submit!!");
  402. return false;
  403. }
  404. });
  405. },
  406. resetForm(formName) {
  407. this.$refs[formName].resetFields();
  408. },
  409. cancel(formName) {
  410. this.dialogVisible = false;
  411. this.$refs[formName].resetFields();
  412. },
  413. // tag
  414. handleClose(tag) {
  415. this.dynamicValidateForm.slides.splice(
  416. this.dynamicValidateForm.slides.indexOf(tag),
  417. 1
  418. );
  419. },
  420. showInput() {
  421. this.inputVisible = true;
  422. this.$nextTick(_ => {
  423. this.$refs.saveTagInput.$refs.input.focus();
  424. });
  425. },
  426. handleInputConfirm() {
  427. let inputValue = this.inputValue;
  428. if (inputValue) {
  429. this.dynamicValidateForm.slides.push(inputValue);
  430. }
  431. this.inputVisible = false;
  432. this.inputValue = "";
  433. }
  434. }
  435. };
  436. </script>
  437. <style lang="scss">
  438. .container {
  439. padding: 20px;
  440. }
  441. .filter-container {
  442. padding: 20px;
  443. // text-align: right;
  444. }
  445. .el-tag + .el-tag {
  446. margin-left: 10px;
  447. }
  448. .button-new-tag {
  449. margin-left: 10px;
  450. height: 32px;
  451. line-height: 30px;
  452. padding-top: 0;
  453. padding-bottom: 0;
  454. }
  455. .input-new-tag {
  456. width: 90px;
  457. margin-left: 10px;
  458. vertical-align: bottom;
  459. }
  460. </style>