goodsList.vue 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <template>
  2. <div class="app-container calendar-list-container">
  3. <!-- 查询和其他操作 -->
  4. <div class="filter-container">
  5. <el-input clearable class="filter-item" style="width: 200px;" placeholder="商品名称"
  6. v-model="listQuery.productName"></el-input>
  7. <el-input clearable class="filter-item" style="width: 200px;" placeholder="商品简称"
  8. v-model="listQuery.productShortForm"></el-input>
  9. <!-- <treeselect class="filter-item" default-expand-all v-model="listQuery.categoryId" :options="categoryOptions"
  10. :normalizer="normalizer" placeholder="商品类别" style="width: 200px" /> -->
  11. <el-cascader
  12. clearable
  13. class="filter-item"
  14. placeholder="商品类别"
  15. style="width: 200px"
  16. v-model="listQuery.categoryId"
  17. :options="categoryOptions"
  18. :props="{
  19. label: 'categoryName',
  20. value: 'id',
  21. emitPath: false,
  22. checkStrictly: true
  23. }"
  24. />
  25. <el-select class="filter-item" style="width: 200px" v-model="listQuery.brandId" filterable placeholder="品牌">
  26. <el-option v-for="item in brandOptions" :key="item.value" :label="item.label" :value="item.value">
  27. </el-option>
  28. </el-select>
  29. <el-select v-model="listQuery.status" clearable placeholder="状态" class="filter-item" style="width: 200px;">
  30. <el-option :key="item.type" v-for="item in goodsStatusList" :label="item.name" :value="item.type">
  31. </el-option>
  32. </el-select>
  33. <el-button class="filter-item" type="primary" v-waves icon="el-icon-search"
  34. @click="handleQuery">查找</el-button>
  35. <el-button class="filter-item" icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  36. <el-button class="filter-item" type="primary" @click="handleAdd" icon="el-icon-plus">添加</el-button>
  37. <el-button class="filter-item" v-waves icon="el-icon-download" @click="handleDownLoad">导出</el-button>
  38. </div>
  39. <!-- 查询结果 -->
  40. <el-table size="small" :data="list" v-loading="listLoading" element-loading-text="正在查询中。。。" border fit
  41. highlight-current-row>
  42. <el-table-column type="index" label="序号" header-align="center" align="center">
  43. </el-table-column>
  44. <el-table-column align="center" min-width="120px" label="商品编号" prop="productCode">
  45. </el-table-column>
  46. <el-table-column align="center" min-width="200px" label="商品名称" prop="productName">
  47. </el-table-column>
  48. <el-table-column align="center" min-width="80px" label="商品简称" prop="productShortForm">
  49. </el-table-column>
  50. <el-table-column align="center" min-width="80px" label="商品类别" prop="categoryName">
  51. </el-table-column>
  52. <el-table-column align="center" min-width="80px" label="品牌" prop="brandName">
  53. </el-table-column>
  54. <el-table-column align="center" min-width="100px" label="主图" prop="imgUrl">
  55. <template slot-scope="scope">
  56. <img class="good-img" :src="scope.row.imgUrl ? scope.row.imgUrl : require('@/assets/avatar.gif')">
  57. </template>
  58. </el-table-column>
  59. <el-table-column align="center" min-width="80px" label="状态">
  60. <template slot-scope="props">
  61. <span v-if="props.row.status == 0" style="color: #67C23A;font-weight: bold;">启用</span>
  62. <span v-if="props.row.status == 1" style="color: #E6A23C;font-weight: bold;">停用</span>
  63. </template>
  64. </el-table-column>
  65. <el-table-column align="center" label="操作" width="240px" class-name="small-padding fixed-width">
  66. <template slot-scope="scope">
  67. <el-button type="primary" size="small" @click="handleUpdate(scope.row)">编辑</el-button>
  68. <el-button type="danger" size="small" @click="handleDelete(scope.row.id)">删除</el-button>
  69. </template>
  70. </el-table-column>
  71. </el-table>
  72. <!-- 分页 -->
  73. <div class="pagination-container">
  74. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
  75. :current-page="listQuery.page" :page-sizes="[10, 20, 30, 50]" :page-size="listQuery.limit"
  76. layout="total, sizes, prev, pager, next, jumper" :total="total">
  77. </el-pagination>
  78. </div>
  79. <!-- 添加或修改对话框 -->
  80. <el-dialog :close-on-click-modal="false" :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible"
  81. width="70%">
  82. <el-form :rules="rules" ref="dataForm" :model="dataForm" status-icon label-position="left"
  83. label-width="100px" style='margin: 0 50px;'>
  84. <el-tabs v-model="activeName" @tab-click="handleClick">
  85. <el-tab-pane label="基本信息" name="first">
  86. <el-form-item label="商品名称" prop="productName">
  87. <el-input v-model="dataForm.productName" placeholder="请输入商品名称"></el-input>
  88. </el-form-item>
  89. <el-form-item label="商品编号" prop="productCode">
  90. <el-input placeholder="请输入商品编号" v-model="dataForm.productCode"></el-input>
  91. </el-form-item>
  92. <el-form-item label="商品简称" prop="productShortForm">
  93. <el-input v-model="dataForm.productShortForm" placeholder="请输入商品简称"></el-input>
  94. </el-form-item>
  95. <el-form-item label="商品类别" prop="categoryId">
  96. <el-cascader
  97. placeholder="请选择商品类别"
  98. style="width: 100%;"
  99. v-model="dataForm.categoryId"
  100. :options="categoryOptions"
  101. :props="{
  102. label: 'categoryName',
  103. value: 'id',
  104. emitPath: false,
  105. checkStrictly: true
  106. }"
  107. />
  108. <!-- <treeselect default-expand-all v-model="dataForm.categoryId" :options="categoryOptions"
  109. :normalizer="normalizer" placeholder="请选择商品类别" /> -->
  110. </el-form-item>
  111. <el-form-item label="品牌" prop="brandId">
  112. <el-select style="width: 100%" v-model="dataForm.brandId" filterable placeholder="请选择品牌">
  113. <el-option v-for="item in brandOptions" :key="item.value" :label="item.label" :value="item.value">
  114. </el-option>
  115. </el-select>
  116. </el-form-item>
  117. <el-form-item label="零售价(元)" prop="price">
  118. <el-input v-model="dataForm.price" placeholder="请输入零售价"></el-input>
  119. </el-form-item>
  120. <el-form-item label="销售价(元)" prop="salePrice">
  121. <el-input v-model="dataForm.salePrice" placeholder="请输入销售价"></el-input>
  122. </el-form-item>
  123. <el-form-item label="成本价(元)" prop="costPrice">
  124. <el-input v-model="dataForm.costPrice" placeholder="请输入成本价"></el-input>
  125. </el-form-item>
  126. <el-form-item label="重量(g)" prop="weight">
  127. <!-- <el-input v-model="dataForm.weight" placeholder="请输入重量" oninput="value=value.replace(/^(0+)|[^\d]+/g,'')"></el-input> -->
  128. <el-input-number v-model="dataForm.weight" :min="1" label="请输入重量"></el-input-number>
  129. </el-form-item>
  130. <el-form-item label="状态" prop="status">
  131. <el-radio-group v-model="dataForm.status">
  132. <el-radio :label="0">启用</el-radio>
  133. <el-radio :label="1">停用</el-radio>
  134. </el-radio-group>
  135. </el-form-item>
  136. <el-form-item style="width: 800px" label="商品图片" prop="imgUrl">
  137. <el-upload :limit="1" :action="fileImgUrl" list-type="picture-card"
  138. :file-list="dataForm.images" :on-success="handleImgSucess" :on-exceed="handleExceed"
  139. :before-upload="beforeUploadImg" :on-remove="handleRemoveImg">
  140. <i class="el-icon-plus"></i>
  141. </el-upload>
  142. </el-form-item>
  143. </el-tab-pane>
  144. <el-tab-pane label="茶叶属性" name="second">
  145. <!-- <el-form-item label="茶叶品牌">
  146. <el-select v-model="dataForm.teaTypeId" filterable placeholder="请选择" style="width: 100%">
  147. <el-option :key="item.dictLabel" v-for="item in tea_type" :label="item.dictLabel"
  148. :value="item.dictLabel">
  149. </el-option>
  150. </el-select>
  151. </el-form-item> -->
  152. <el-form-item label="茶叶级别">
  153. <el-select v-model="dataForm.teaLevel" filterable placeholder="请选择茶叶级别" style="width: 100%">
  154. <el-option :key="item.dictLabel" v-for="item in tea_level" :label="item.dictLabel"
  155. :value="item.dictLabel">
  156. </el-option>
  157. </el-select>
  158. </el-form-item>
  159. <el-form-item label="茶叶系列">
  160. <el-select v-model="dataForm.teaSeries" filterable placeholder="请选择茶叶系列" style="width: 100%">
  161. <el-option :key="item.dictLabel" v-for="item in tea_series" :label="item.dictLabel"
  162. :value="item.dictLabel">
  163. </el-option>
  164. </el-select>
  165. </el-form-item>
  166. <el-form-item label="包装形式">
  167. <el-select v-model="dataForm.teaPackageFormat" multiple filterable placeholder="请选择包装形式"
  168. style="width: 100%">
  169. <el-option :key="item.dictLabel" v-for="item in tea_package_format" :label="item.dictLabel"
  170. :value="item.dictLabel">
  171. </el-option>
  172. </el-select>
  173. </el-form-item>
  174. <el-form-item label="产地">
  175. <el-input v-model="dataForm.teaOrigin" placeholder="请输入产地"></el-input>
  176. </el-form-item>
  177. <el-form-item label="采摘季节">
  178. <el-radio-group v-model="dataForm.teaGetSeason">
  179. <el-radio v-for="item in tea_get_season" :key="item.dictLabel" :label="item.dictLabel"></el-radio>
  180. </el-radio-group>
  181. </el-form-item>
  182. <el-form-item label="保质期">
  183. <el-input placeholder="数值" v-model="dataForm.teaGuaranteeNumber" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" class="input-with-select">
  184. <el-select style="width: 100px;" v-model="dataForm.teaGuaranteeUnit" slot="prepend"
  185. placeholder="请选择">
  186. <el-option label="年" value="年"></el-option>
  187. <el-option label="月" value="月"></el-option>
  188. <el-option label="日" value="日"></el-option>
  189. </el-select>
  190. </el-input>
  191. </el-form-item>
  192. <el-form-item label="生产日期">
  193. <el-date-picker style="width: 100%;" v-model="dataForm.productDate" type="date"
  194. placeholder="选择日期" value-format="yyyy-MM-dd"></el-date-picker>
  195. </el-form-item>
  196. <el-form-item label="年份">
  197. <el-input v-model="dataForm.teaAgingYear" onkeyup="value=value.replace(/^(0+)|[^\d]+/g,'')" placeholder="请输入年份"></el-input>
  198. <span style="color: #F56C6C;">备注:如有机认证、质检报告等</span>
  199. </el-form-item>
  200. <el-form-item label="溯源信息" prop="teaFiles">
  201. <el-upload :limit="1" :action="fileImgUrl" :file-list="dataForm.files" :on-success="handleFileSuccess"
  202. :before-upload="beforeUploadFile" :on-remove="handleRemoveFile">
  203. <el-button size="small" type="primary">点击上传</el-button>
  204. </el-upload>
  205. </el-form-item>
  206. <el-form-item label="存储要求">
  207. <el-checkbox-group v-model="dataForm.teaStorageRequire">
  208. <el-checkbox v-for="item in tea_storage_require" :key="item.dictLabel" :label="item.dictLabel" name="type"></el-checkbox>
  209. </el-checkbox-group>
  210. </el-form-item>
  211. </el-tab-pane>
  212. </el-tabs>
  213. </el-form>
  214. <div slot="footer" class="dialog-footer">
  215. <el-button @click="dialogFormVisible = false">取消</el-button>
  216. <el-button v-if="dialogStatus == 'create'" type="primary" @click="createData">确定</el-button>
  217. <el-button v-else type="primary" @click="updateData">确定</el-button>
  218. </div>
  219. </el-dialog>
  220. </div>
  221. </template>
  222. <script>
  223. import { createItem, updateItem, goodsList, removeItem } from "@/api/goodsManage";
  224. import { listDept } from "@/api/goodsTypeList";
  225. import { listBrand } from '@/api/brand';
  226. import Treeselect from "@riophae/vue-treeselect";
  227. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  228. import { dataTypeList } from "@/api/public";
  229. import waves from "@/directive/waves"; // 水波纹指令
  230. export default {
  231. name: 'goodsList',
  232. components: { Treeselect },
  233. directives: { waves },
  234. data() {
  235. return {
  236. tea_type:[],
  237. tea_level:[],
  238. tea_series:[],
  239. tea_package_format:[],
  240. tea_get_season:[],
  241. tea_storage_require:[],
  242. // 树选项
  243. categoryOptions: [],
  244. activeName: 'first',
  245. brandOptions: [],
  246. goodsStatusList: [
  247. {
  248. type: 0,
  249. name: '启用'
  250. },
  251. {
  252. type: 1,
  253. name: '停用'
  254. },
  255. ],
  256. list: [],
  257. total: 0,
  258. listLoading: false,
  259. listQuery: {
  260. page: 1,
  261. limit: 10,
  262. productName: '',
  263. productShortForm: '',
  264. categoryId: undefined,
  265. brandId: '',
  266. status: '',
  267. },
  268. listBrandQuery: {
  269. limit: 1000,
  270. sort: '+id'
  271. },
  272. dataForm: {
  273. productName: undefined,
  274. productCode: undefined,
  275. productShortForm: undefined,
  276. categoryId: undefined,
  277. brandId: undefined,
  278. price: undefined,
  279. salePrice: undefined,
  280. costPrice: undefined,
  281. weight: 1,
  282. status: 0,
  283. imgUrl: undefined,
  284. teaTypeId: undefined,
  285. teaLevel: undefined,
  286. teaSeries: undefined,
  287. teaPackageFormat: [],
  288. teaOrigin: undefined,
  289. teaGetSeason: undefined,
  290. teaGuaranteeNumber: undefined,
  291. teaGuaranteeUnit: '年',
  292. productDate: undefined,
  293. teaAgingYear: undefined,
  294. teaFiles: undefined,
  295. files: [],
  296. teaStorageRequire: [],
  297. },
  298. dialogFormVisible: false,
  299. dialogStatus: '',
  300. textMap: {
  301. update: "编辑商品",
  302. create: "添加商品",
  303. },
  304. rules: {
  305. productName: [{ required: true, message: "请填写商品名称", trigger: "blur" }],
  306. productCode: [
  307. { required: true, message: "请填写商品编号", trigger: "blur" },
  308. { min: 14, max: 14, message: "商品编号必须为14位", trigger: "blur" },
  309. { pattern: /^(?=.*[A-Za-z])(?=.*\d)[A-Za-z\d]{14,}$/, message: "商品编号必须为14位字母加数字", trigger: "blur" }
  310. ],
  311. categoryId: [{ required: true, message: "请选择商品类别", trigger: "blur" }],
  312. price: [
  313. { required: true, message: "请填写零售价", trigger: "blur" },
  314. {
  315. pattern: /^(([1-9]{1}\d{0,9})|(0{1}))(\.\d{1,2})?$/,
  316. message: "请输入合法的金额数字,最多两位小数",
  317. trigger: "blur"
  318. }
  319. ],
  320. salePrice: [
  321. { required: true, message: "请填写销售价", trigger: "blur" },
  322. {
  323. pattern: /^(([1-9]{1}\d{0,9})|(0{1}))(\.\d{1,2})?$/,
  324. message: "请输入合法的金额数字,最多两位小数",
  325. trigger: "blur"
  326. }
  327. ],
  328. costPrice: [
  329. { required: true, message: "请填写成本价", trigger: "blur" },
  330. {
  331. pattern: /^(([1-9]{1}\d{0,9})|(0{1}))(\.\d{1,2})?$/,
  332. message: "请输入合法的金额数字,最多两位小数",
  333. trigger: "blur"
  334. }
  335. ],
  336. weight: [
  337. { required: true, message: "请填写重量", trigger: "blur" },
  338. ],
  339. status: [{ required: true, message: "请选择状态", trigger: "blur" }],
  340. },
  341. dialogListVisible: false,
  342. fileImgUrl: this.upLoadUrl,
  343. }
  344. },
  345. created() {
  346. this.getListCategory();
  347. this.getBrandList();
  348. this.getDictType();
  349. this.getList();
  350. },
  351. methods: {
  352. handleDownLoad(){
  353. window.location.href = process.env.BASE_API + '/product/export?productName=' + this.listQuery.productName + '&productShortForm=' + this.listQuery.productShortForm;
  354. },
  355. getListCategory() {
  356. listDept().then(response => {
  357. this.categoryOptions = this.handleTree(response.data.data, "id");
  358. });
  359. },
  360. /** 转换证书数据结构 */
  361. normalizer(node) {
  362. if (node.children && !node.children.length) {
  363. delete node.children;
  364. }
  365. return {
  366. id: node.id,
  367. label: node.categoryName,
  368. children: node.children
  369. };
  370. },
  371. handleClick(tab, event) {
  372. console.log(tab, event);
  373. },
  374. getDictType(){
  375. //茶叶品牌tea_type
  376. dataTypeList({ dictType: 'tea_type' }).then(response => {
  377. this.tea_type = response.data.data;
  378. });
  379. //茶叶级别tea_level
  380. dataTypeList({ dictType: 'tea_level' }).then(response => {
  381. this.tea_level = response.data.data;
  382. });
  383. //茶叶系列tea_series
  384. dataTypeList({ dictType: 'tea_series' }).then(response => {
  385. this.tea_series = response.data.data;
  386. });
  387. //包装形式tea_package_format
  388. dataTypeList({ dictType: 'tea_package_format' }).then(response => {
  389. this.tea_package_format = response.data.data;
  390. });
  391. //采摘季节tea_get_season
  392. dataTypeList({ dictType: 'tea_get_season' }).then(response => {
  393. this.tea_get_season = response.data.data;
  394. });
  395. //存储要求tea_storage_require
  396. dataTypeList({ dictType: 'tea_storage_require' }).then(response => {
  397. this.tea_storage_require = response.data.data;
  398. });
  399. },
  400. handleRemoveFile(file, fileList) {
  401. console.log(file, fileList);
  402. let teaFiles = [];
  403. for (let i in fileList) {
  404. let id = fileList[i].response.data.id;
  405. teaFiles.push(id);
  406. }
  407. this.dataForm.teaFiles = teaFiles.join(",");
  408. },
  409. beforeUploadFile(file) {
  410. console.log(file);
  411. const size = file.size / 1024 / 1024;
  412. console.log(size);
  413. if (size > 10) {
  414. this.$message.error("文件大小不能超过10MB!");
  415. return false;
  416. }
  417. },
  418. handleFileSuccess(res, file, fileList) {
  419. console.log(file, fileList);
  420. console.log("------", "==========");
  421. console.log("res = ", res);
  422. let teaFiles = [];
  423. for (let i in fileList) {
  424. let response = fileList[i].response;
  425. if (response.errno && response.errno != "0") {
  426. this.$message.error("该文件上传失败,已被移除,请重新上传!");
  427. // 上传失败移除该 file 对象
  428. fileList.splice(i, 1);
  429. } else {
  430. let id = fileList[i].response.data.id;
  431. teaFiles.push(id);
  432. }
  433. }
  434. this.dataForm.teaFiles = teaFiles.join(",");
  435. },
  436. handleRemoveImg(file, fileList) {
  437. console.log(file, fileList);
  438. let images = [];
  439. for (let i in fileList) {
  440. let response = fileList[i].response;
  441. let url = response.data.url;
  442. images.push(url);
  443. this.dataForm.imgUrl = images.join(",");
  444. }
  445. },
  446. beforeUploadImg(file) {
  447. const isJPGs = file.type === "image/jpeg";
  448. console.log(isJPGs);
  449. },
  450. handleExceed(files, fileList) {
  451. this.$message.warning(
  452. `当前限制选择 1 个文件,本次选择了 ${files.length} 个文件!,共选择了 ${files.length + fileList.length
  453. } 个文件`
  454. );
  455. },
  456. handleImgSucess(res, file, fileList) {
  457. this.dataForm.imgUrl = ""; // 清空画廊图片数组
  458. let images = [];
  459. for (let i in fileList) {
  460. let response = fileList[i].response;
  461. if (response.errno && response.errno != "0") {
  462. this.$message.error("该图片上传失败,已被移除,请重新上传!");
  463. // 上传失败移除该 file 对象
  464. fileList.splice(i, 1);
  465. } else {
  466. let url = response.data.url;
  467. images.push(url);
  468. }
  469. }
  470. this.dataForm.imgUrl = images.join(",");
  471. },
  472. resetForm() {
  473. this.dataForm = {
  474. productName: undefined,
  475. productCode: undefined,
  476. productShortForm: undefined,
  477. categoryId: undefined,
  478. brandId: undefined,
  479. price: undefined,
  480. salePrice: undefined,
  481. costPrice: undefined,
  482. weight: 1,
  483. status: 0,
  484. imgUrl: undefined,
  485. images: [],
  486. teaTypeId: undefined,
  487. teaLevel: undefined,
  488. teaSeries: undefined,
  489. teaPackageFormat: [],
  490. teaOrigin: undefined,
  491. teaGetSeason: undefined,
  492. teaGuaranteeNumber: undefined,
  493. teaGuaranteeUnit: '年',
  494. productDate: undefined,
  495. teaAgingYear: undefined,
  496. teaFiles: undefined,
  497. files: [],
  498. teaStorageRequire: [],
  499. };
  500. },
  501. handleAdd() {
  502. this.activeName = 'first';
  503. this.resetForm();
  504. this.dialogFormVisible = true;
  505. this.dialogStatus = "create";
  506. this.$nextTick(() => {
  507. this.$refs["dataForm"].clearValidate();
  508. });
  509. },
  510. createData() {
  511. this.$refs["dataForm"].validate((valid) => {
  512. if (valid) {
  513. console.log(this.dataForm);
  514. createItem(this.dataForm)
  515. .then((response) => {
  516. this.getList();
  517. this.dialogFormVisible = false;
  518. this.$notify({
  519. title: "成功",
  520. message: "创建成功",
  521. type: "success",
  522. duration: 2000,
  523. });
  524. this.reload();
  525. })
  526. .catch(() => { });
  527. }
  528. });
  529. },
  530. handleUpdate(row) {
  531. this.activeName = 'first';
  532. this.dataForm = Object.assign({}, row);
  533. if (this.dataForm.imgUrl) {
  534. let images = this.dataForm.imgUrl.split(",");
  535. this.dataForm.images = [];
  536. for (let i in images) {
  537. let url = images[i];
  538. let name = "image_" + i;
  539. this.dataForm.images.push({
  540. name: name,
  541. url: url,
  542. response: { error: "0", data: { url: url } },
  543. });
  544. }
  545. }
  546. if (this.dataForm.teaFiles) {
  547. let files = this.dataForm.files;
  548. this.dataForm.files = [];
  549. for (let i in files) {
  550. let url = files[i].url;
  551. let name = files[i].oldName;
  552. let id = files[i].id;
  553. this.dataForm.files.push({
  554. name: name,
  555. url: url,
  556. response: { error: "0", data: { url: url,id:id } },
  557. });
  558. }
  559. }
  560. this.dialogStatus = 'update'
  561. this.dialogFormVisible = true
  562. this.$nextTick(() => {
  563. this.$refs['dataForm'].clearValidate()
  564. })
  565. },
  566. updateData() {
  567. this.$refs['dataForm'].validate((valid) => {
  568. if (valid) {
  569. updateItem(this.dataForm).then(() => {
  570. this.dialogFormVisible = false
  571. this.$notify({
  572. title: '成功',
  573. message: '更新成功',
  574. type: 'success',
  575. duration: 2000
  576. })
  577. this.getList()
  578. })
  579. }
  580. })
  581. },
  582. handleDelete(id) {
  583. this.$confirm('确认删除吗?', '提示', {
  584. confirmButtonText: '确定',
  585. cancelButtonText: '取消',
  586. type: 'warning'
  587. }).then(() => {
  588. removeItem({ id: id }).then(response => {
  589. this.$notify({
  590. title: '成功',
  591. message: '删除成功',
  592. type: 'success',
  593. duration: 2000
  594. })
  595. this.getList();
  596. })
  597. }).catch(() => {
  598. })
  599. },
  600. getBrandList() {
  601. // 获取品牌信息
  602. listBrand(this.listBrandQuery).then(response => {
  603. this.brandOptions = response.data.data.items.map((item) => {
  604. return { value: item.id, label: item.name }
  605. });
  606. }).catch(() => {
  607. this.brandOptions = [];
  608. })
  609. },
  610. getList() {
  611. this.listLoading = true
  612. goodsList(this.listQuery).then(response => {
  613. this.list = response.data.data.items
  614. this.total = response.data.data.total
  615. this.listLoading = false
  616. }).catch(() => { })
  617. },
  618. handleQuery() {
  619. this.listQuery.page = 1
  620. this.getList()
  621. },
  622. /** 重置按钮操作 */
  623. resetQuery() {
  624. this.listQuery = {
  625. page: 1,
  626. limit: 10,
  627. productName: '',
  628. productShortForm: '',
  629. categoryId: '',
  630. brandId: '',
  631. status: '',
  632. };
  633. this.handleQuery();
  634. },
  635. handleSizeChange(val) {
  636. this.listQuery.limit = val
  637. this.getList()
  638. },
  639. handleCurrentChange(val) {
  640. this.listQuery.page = val
  641. this.getList()
  642. },
  643. }
  644. }
  645. </script>
  646. <style>
  647. .good-img {
  648. width: 50px;
  649. height: 50px;
  650. }
  651. .input-with-select .el-input-group__prepend {
  652. background-color: #fff;
  653. }
  654. </style>