index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  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-row>
  241. </el-form-item>
  242. <el-form-item label="属性">
  243. <el-row :span="24">
  244. <el-col :span="10">
  245. <el-input
  246. type="textarea"
  247. :rows="2"
  248. v-model="dynamicValidateForm.property"
  249. placeholder="热,冰,少冰,去冰;标准糖,半糖; 含咖啡"
  250. ></el-input>
  251. </el-col>
  252. <el-col :span="10" :offset="1">
  253. <span> 不同类的属性用分号隔开,同类属性用逗号隔开</span>
  254. </el-col>
  255. </el-row>
  256. </el-form-item>
  257. <!-- --------------------------------------------- -->
  258. </el-form>
  259. <span slot="footer" class="dialog-footer">
  260. <el-button @click="cancel('dynamicValidateForm')">取 消</el-button>
  261. <el-button type="primary" @click="submitForm('dynamicValidateForm')"
  262. >确 定</el-button
  263. >
  264. </span>
  265. <div>
  266. <el-link
  267. href="https://help.aliyun.com/document_detail/195868.html?spm=a2c4g.11186623.6.620.74d062e7wbqjEy"
  268. target="_blank"
  269. type="success"
  270. >图片上传工具下载</el-link
  271. >
  272. </div>
  273. <div>商品小图限制 80k 以内</div>
  274. <div>商品大图限制 150k 以内</div>
  275. </el-dialog>
  276. </div>
  277. </template>
  278. <script>
  279. import { getGoodsList } from "@/api/order";
  280. import { createSku } from "@/api/shop";
  281. const recommendationList = [
  282. {
  283. name: "新品推荐",
  284. value: "有颜有料,樱你而美"
  285. },
  286. {
  287. name: "活力早餐",
  288. value: "超低脂高饱腹感,马上预约"
  289. },
  290. {
  291. name: "限时折扣",
  292. value: "限定版口感,马上品鉴"
  293. },
  294. {
  295. name: "Nowwa特调",
  296. value: "限定版口感,马上品鉴!"
  297. },
  298. {
  299. name: "经典家族",
  300. value: "四大产区精品咖啡豆"
  301. },
  302. {
  303. name: "风味鉴赏",
  304. value: "咖啡里的缤纷艺术"
  305. },
  306. {
  307. name: "奶茶果茶",
  308. value: "一起喝茶吧!"
  309. },
  310. {
  311. name: "多杯组合",
  312. value: "一起分享,加倍快乐"
  313. },
  314. {
  315. name: "烘培零食",
  316. value: "早餐/下午茶好搭档(必须和饮品一起下单 )"
  317. },
  318. {
  319. name: "面包配咖啡",
  320. value: "早餐/下午茶好搭档"
  321. },
  322. {
  323. name: "Nowwa礼品",
  324. value: "送给你的美好心意"
  325. }
  326. ];
  327. export default {
  328. data() {
  329. return {
  330. tableData: [],
  331. listLoading: true,
  332. dialogVisible: false,
  333. recommendationList,
  334. // form
  335. inputVisible: false,
  336. inputValue: "",
  337. dynamicValidateForm: {
  338. id: "",
  339. name: "",
  340. nameeng: "",
  341. pricenow: "",
  342. priceorigin: "",
  343. image: "",
  344. slides: [],
  345. category: "",
  346. recommendation: "",
  347. description: "",
  348. property: ""
  349. },
  350. rules: {
  351. id: [{ required: true, message: " ", trigger: "blur" }],
  352. name: [{ required: true, message: " ", trigger: "blur" }],
  353. nameeng: [{ required: true, message: " ", trigger: "blur" }],
  354. pricenow: [{ required: true, message: " ", trigger: "blur" }],
  355. priceorigin: [{ required: true, message: " ", trigger: "blur" }],
  356. image: [{ required: true, message: " ", trigger: "blur" }],
  357. category: [{ required: true, message: " ", trigger: "blur" }],
  358. recommendation: [{ required: true, message: " ", trigger: "change" }],
  359. description: [{ required: true, message: " ", trigger: "blur" }]
  360. }
  361. };
  362. },
  363. created() {
  364. this.getList();
  365. },
  366. methods: {
  367. getList() {
  368. this.listLoading = true;
  369. getGoodsList().then(res => {
  370. console.log(res);
  371. this.tableData = res;
  372. this.listLoading = false;
  373. });
  374. },
  375. // form
  376. submitForm(formName) {
  377. this.$refs[formName].validate(valid => {
  378. if (valid) {
  379. let params = Object.assign({}, this.dynamicValidateForm, {
  380. id: this.dynamicValidateForm.id - 0,
  381. slides: this.dynamicValidateForm.slides.join(";"),
  382. pricenow: this.dynamicValidateForm.pricenow - 0,
  383. priceorigin: this.dynamicValidateForm.priceorigin - 0
  384. });
  385. createSku(params)
  386. .then(res => {
  387. console.log(res);
  388. if (res === "OK") {
  389. this.cancel("dynamicValidateForm");
  390. this.$message.success("sku创建成功!");
  391. }
  392. })
  393. .catch(err => {
  394. console.log(err);
  395. });
  396. console.log(params);
  397. } else {
  398. console.log("error submit!!");
  399. return false;
  400. }
  401. });
  402. },
  403. resetForm(formName) {
  404. this.$refs[formName].resetFields();
  405. },
  406. cancel(formName) {
  407. this.dialogVisible = false;
  408. this.$refs[formName].resetFields();
  409. },
  410. // tag
  411. handleClose(tag) {
  412. this.dynamicValidateForm.slides.splice(
  413. this.dynamicValidateForm.slides.indexOf(tag),
  414. 1
  415. );
  416. },
  417. showInput() {
  418. this.inputVisible = true;
  419. this.$nextTick(_ => {
  420. this.$refs.saveTagInput.$refs.input.focus();
  421. });
  422. },
  423. handleInputConfirm() {
  424. let inputValue = this.inputValue;
  425. if (inputValue) {
  426. this.dynamicValidateForm.slides.push(inputValue);
  427. }
  428. this.inputVisible = false;
  429. this.inputValue = "";
  430. }
  431. }
  432. };
  433. </script>
  434. <style lang="scss">
  435. .container {
  436. padding: 20px;
  437. }
  438. .filter-container {
  439. padding: 20px;
  440. // text-align: right;
  441. }
  442. .el-tag + .el-tag {
  443. margin-left: 10px;
  444. }
  445. .button-new-tag {
  446. margin-left: 10px;
  447. height: 32px;
  448. line-height: 30px;
  449. padding-top: 0;
  450. padding-bottom: 0;
  451. }
  452. .input-new-tag {
  453. width: 90px;
  454. margin-left: 10px;
  455. vertical-align: bottom;
  456. }
  457. </style>