value.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="属性项" prop="propertyId">
  5. <el-select v-model="queryParams.propertyId">
  6. <el-option v-for="item in propertyOptions" :key="item.id" :label="item.name" :value="item.id"/>
  7. </el-select>
  8. </el-form-item>
  9. <el-form-item label="名称" prop="name">
  10. <el-input v-model="queryParams.name" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery"/>
  11. </el-form-item>
  12. <el-form-item>
  13. <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
  14. <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
  15. </el-form-item>
  16. </el-form>
  17. <el-row :gutter="10" class="mb8">
  18. <el-col :span="1.5">
  19. <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
  20. v-hasPermi="['system:dict:create']">新增
  21. </el-button>
  22. </el-col>
  23. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  24. </el-row>
  25. <el-table v-loading="loading" :data="dataList">
  26. <el-table-column label="编号" align="center" prop="id"/>
  27. <el-table-column label="名称" align="center" prop="name"/>
  28. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true"/>
  29. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  30. <template v-slot="scope">
  31. <span>{{ parseTime(scope.row.createTime) }}</span>
  32. </template>
  33. </el-table-column>
  34. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  35. <template v-slot="scope">
  36. <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
  37. v-hasPermi="['system:dict:update']">修改
  38. </el-button>
  39. <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
  40. v-hasPermi="['system:dict:delete']">删除
  41. </el-button>
  42. </template>
  43. </el-table-column>
  44. </el-table>
  45. <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
  46. @pagination="getList"/>
  47. <!-- 添加或修改参数配置对话框 -->
  48. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  49. <el-form ref="form" :model="form" :rules="rules" label-width="90px">
  50. <el-form-item label="属性项">
  51. <el-input v-model="form.propertyId" :disabled="true"/>
  52. </el-form-item>
  53. <el-form-item label="名称" prop="name">
  54. <el-input v-model="form.name" placeholder="请输入名称"/>
  55. </el-form-item>
  56. <el-form-item label="备注" prop="remark">
  57. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
  58. </el-form-item>
  59. </el-form>
  60. <div slot="footer" class="dialog-footer">
  61. <el-button type="primary" @click="submitForm">确 定</el-button>
  62. <el-button @click="cancel">取 消</el-button>
  63. </div>
  64. </el-dialog>
  65. </div>
  66. </template>
  67. <script>
  68. import {
  69. createPropertyValue,
  70. deletePropertyValue,
  71. getProperty,
  72. getPropertyList,
  73. getPropertyValue,
  74. getPropertyValuePage,
  75. updatePropertyValue
  76. } from '@/api/mall/product/property'
  77. export default {
  78. name: "PropertyValue",
  79. data() {
  80. return {
  81. // 遮罩层
  82. loading: true,
  83. // 显示搜索条件
  84. showSearch: true,
  85. // 总条数
  86. total: 0,
  87. // 字典表格数据
  88. dataList: [],
  89. // 默认字典类型
  90. defaultPropertyId: "",
  91. // 弹出层标题
  92. title: "",
  93. // 是否显示弹出层
  94. open: false,
  95. // 类型数据字典
  96. propertyOptions: [],
  97. // 查询参数
  98. queryParams: {
  99. pageNo: 1,
  100. pageSize: 10,
  101. propertyId: undefined,
  102. name: undefined,
  103. },
  104. // 表单参数
  105. form: {},
  106. // 表单校验
  107. rules: {
  108. name: [
  109. {required: true, message: "名称不能为空", trigger: "blur"}
  110. ]
  111. },
  112. };
  113. },
  114. created() {
  115. const propertyId = this.$route.params && this.$route.params.propertyId;
  116. this.getProperty(propertyId);
  117. this.getPropertyList();
  118. },
  119. methods: {
  120. /** 查询字典类型详细 */
  121. getProperty(propertyId) {
  122. getProperty(propertyId).then(response => {
  123. this.queryParams.propertyId = response.data.id;
  124. this.defaultPropertyId = response.data.id;
  125. this.getList();
  126. });
  127. },
  128. /** 查询字典类型列表 */
  129. getPropertyList() {
  130. getPropertyList().then(response => {
  131. this.propertyOptions = response.data
  132. });
  133. },
  134. /** 查询字典数据列表 */
  135. getList() {
  136. this.loading = true;
  137. getPropertyValuePage(this.queryParams).then(response => {
  138. this.dataList = response.data.list;
  139. this.total = response.data.total;
  140. this.loading = false;
  141. });
  142. },
  143. // 取消按钮
  144. cancel() {
  145. this.open = false;
  146. this.reset();
  147. },
  148. // 表单重置
  149. reset() {
  150. this.form = {
  151. id: undefined,
  152. propertyId: undefined,
  153. name: undefined,
  154. remark: undefined
  155. };
  156. this.resetForm("form");
  157. },
  158. /** 搜索按钮操作 */
  159. handleQuery() {
  160. this.queryParams.pageNo = 1;
  161. this.getList();
  162. },
  163. /** 重置按钮操作 */
  164. resetQuery() {
  165. this.resetForm("queryForm");
  166. this.queryParams.propertyId = this.defaultPropertyId;
  167. this.handleQuery();
  168. },
  169. /** 新增按钮操作 */
  170. handleAdd() {
  171. this.reset();
  172. this.open = true;
  173. this.title = "添加属性值";
  174. this.form.propertyId = this.queryParams.propertyId;
  175. },
  176. /** 修改按钮操作 */
  177. handleUpdate(row) {
  178. this.reset();
  179. const id = row.id;
  180. getPropertyValue(id).then(response => {
  181. this.form = response.data;
  182. this.open = true;
  183. this.title = "修改属性值";
  184. });
  185. },
  186. /** 提交按钮 */
  187. submitForm: function () {
  188. this.$refs["form"].validate(valid => {
  189. if (valid) {
  190. if (this.form.id !== undefined) {
  191. updatePropertyValue(this.form).then(response => {
  192. this.$modal.msgSuccess("修改成功");
  193. this.open = false;
  194. this.getList();
  195. });
  196. } else {
  197. createPropertyValue(this.form).then(response => {
  198. this.$modal.msgSuccess("新增成功");
  199. this.open = false;
  200. this.getList();
  201. });
  202. }
  203. }
  204. });
  205. },
  206. /** 删除按钮操作 */
  207. handleDelete(row) {
  208. const ids = row.id;
  209. this.$modal.confirm('是否确认删除字典编码为"' + ids + '"的数据项?').then(function () {
  210. return deletePropertyValue(ids);
  211. }).then(() => {
  212. this.getList();
  213. this.$modal.msgSuccess("删除成功");
  214. }).catch(() => {
  215. });
  216. },
  217. /** 导出按钮操作 */
  218. handleExport() {
  219. const queryParams = this.queryParams;
  220. this.$modal.confirm('是否确认导出所有数据项?').then(() => {
  221. this.exportLoading = true;
  222. return exportData(queryParams);
  223. }).then(response => {
  224. this.$download.excel(response, '字典数据.xls');
  225. this.exportLoading = false;
  226. }).catch(() => {
  227. });
  228. }
  229. }
  230. };
  231. </script>