index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  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 prop="slides" 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-col>
  217. <el-col :span="10" :offset="1">
  218. <span> 推荐语,同一类别的咖啡共用一个推荐语</span>
  219. </el-col>
  220. </el-row>
  221. </el-form-item>
  222. <el-form-item prop="description" label="商品描述">
  223. <el-row :span="24">
  224. <el-col :span="10">
  225. <el-input
  226. type="textarea"
  227. :rows="2"
  228. v-model="dynamicValidateForm.description"
  229. placeholder="限量赠网红樱花饼干。优选宇治抹茶,精细石 磨研磨,搭配进口樱花粉,碰撞绝妙层次感。"
  230. ></el-input>
  231. </el-col>
  232. </el-row>
  233. </el-form-item>
  234. <el-form-item prop="property" label="属性">
  235. <el-row :span="24">
  236. <el-col :span="10">
  237. <el-input
  238. type="textarea"
  239. :rows="2"
  240. v-model="dynamicValidateForm.property"
  241. placeholder="热,冰,少冰,去冰;标准糖,半糖; 含咖啡"
  242. ></el-input>
  243. </el-col>
  244. <el-col :span="10" :offset="1">
  245. <span> 不同类的属性用分号隔开,同类属性用逗号隔开</span>
  246. </el-col>
  247. </el-row>
  248. </el-form-item>
  249. <!-- --------------------------------------------- -->
  250. </el-form>
  251. <span slot="footer" class="dialog-footer">
  252. <el-button @click="cancel('dynamicValidateForm')">取 消</el-button>
  253. <el-button type="primary" @click="submitForm('dynamicValidateForm')"
  254. >确 定</el-button
  255. >
  256. </span>
  257. <div>
  258. <el-link
  259. href="https://help.aliyun.com/document_detail/195868.html?spm=a2c4g.11186623.6.620.74d062e7wbqjEy"
  260. target="_blank"
  261. type="success"
  262. >图片上传工具下载</el-link
  263. >
  264. </div>
  265. </el-dialog>
  266. </div>
  267. </template>
  268. <script>
  269. import { getGoodsList } from "@/api/order";
  270. import { createSku } from "@/api/shop";
  271. export default {
  272. data() {
  273. return {
  274. tableData: [],
  275. listLoading: true,
  276. dialogVisible: false,
  277. // form
  278. inputVisible: false,
  279. inputValue: "",
  280. dynamicValidateForm: {
  281. id: "",
  282. name: "",
  283. nameeng: "",
  284. pricenow: "",
  285. priceorigin: "",
  286. image: "",
  287. slides: [],
  288. category: "",
  289. recommendation: "",
  290. description: "",
  291. property: ""
  292. },
  293. rules: {
  294. id: [{ required: true, message: " ", trigger: "blur" }],
  295. name: [{ required: true, message: " ", trigger: "blur" }],
  296. nameeng: [{ required: true, message: " ", trigger: "blur" }],
  297. pricenow: [{ required: true, message: " ", trigger: "blur" }],
  298. priceorigin: [{ required: true, message: " ", trigger: "blur" }],
  299. image: [{ required: true, message: " ", trigger: "blur" }],
  300. slides: [{ required: true, message: " ", trigger: "change" }],
  301. category: [{ required: true, message: " ", trigger: "blur" }],
  302. recommendation: [{ required: true, message: " ", trigger: "blur" }],
  303. description: [{ required: true, message: " ", trigger: "blur" }],
  304. property: [{ required: true, message: " ", trigger: "blur" }]
  305. }
  306. };
  307. },
  308. created() {
  309. this.getList();
  310. },
  311. methods: {
  312. getList() {
  313. this.listLoading = true;
  314. getGoodsList().then(res => {
  315. console.log(res);
  316. this.tableData = res;
  317. this.listLoading = false;
  318. });
  319. },
  320. // form
  321. submitForm(formName) {
  322. this.$refs[formName].validate(valid => {
  323. if (valid) {
  324. let params = Object.assign({}, this.dynamicValidateForm, {
  325. id: this.dynamicValidateForm.id - 0,
  326. slides: this.dynamicValidateForm.slides.join(";"),
  327. pricenow: this.dynamicValidateForm.pricenow - 0,
  328. priceorigin: this.dynamicValidateForm.priceorigin - 0
  329. });
  330. createSku(params)
  331. .then(res => {
  332. console.log(res);
  333. if (res === "OK") {
  334. this.cancel("dynamicValidateForm");
  335. this.$message.success("sku创建成功!");
  336. }
  337. })
  338. .catch(err => {
  339. console.log(err);
  340. });
  341. console.log(params);
  342. } else {
  343. console.log("error submit!!");
  344. return false;
  345. }
  346. });
  347. },
  348. resetForm(formName) {
  349. this.$refs[formName].resetFields();
  350. },
  351. cancel(formName) {
  352. this.dialogVisible = false;
  353. this.$refs[formName].resetFields();
  354. },
  355. // tag
  356. handleClose(tag) {
  357. this.dynamicValidateForm.slides.splice(
  358. this.dynamicValidateForm.slides.indexOf(tag),
  359. 1
  360. );
  361. },
  362. showInput() {
  363. this.inputVisible = true;
  364. this.$nextTick(_ => {
  365. this.$refs.saveTagInput.$refs.input.focus();
  366. });
  367. },
  368. handleInputConfirm() {
  369. let inputValue = this.inputValue;
  370. if (inputValue) {
  371. this.dynamicValidateForm.slides.push(inputValue);
  372. }
  373. this.inputVisible = false;
  374. this.inputValue = "";
  375. }
  376. }
  377. };
  378. </script>
  379. <style lang="scss">
  380. .container {
  381. padding: 20px;
  382. }
  383. .filter-container {
  384. padding: 20px;
  385. // text-align: right;
  386. }
  387. .el-tag + .el-tag {
  388. margin-left: 10px;
  389. }
  390. .button-new-tag {
  391. margin-left: 10px;
  392. height: 32px;
  393. line-height: 30px;
  394. padding-top: 0;
  395. padding-bottom: 0;
  396. }
  397. .input-new-tag {
  398. width: 90px;
  399. margin-left: 10px;
  400. vertical-align: bottom;
  401. }
  402. </style>