index.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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="productName">
  5. <el-input
  6. v-model="queryParams.productName"
  7. placeholder="请输入商品名称"
  8. clearable
  9. @keyup.enter.native="handleQuery"
  10. />
  11. </el-form-item>
  12. <el-form-item label="会员情况" prop="memberStatus">
  13. <el-input
  14. v-model="queryParams.memberStatus"
  15. placeholder="请输入会员情况"
  16. clearable
  17. @keyup.enter.native="handleQuery"
  18. />
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  22. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  23. </el-form-item>
  24. </el-form>
  25. <el-row :gutter="10" class="mb8">
  26. <el-col :span="1.5">
  27. <el-button
  28. type="primary"
  29. plain
  30. icon="el-icon-plus"
  31. size="mini"
  32. @click="handleAdd"
  33. v-hasPermi="['saler:productInfo:add']"
  34. >新增</el-button>
  35. </el-col>
  36. <el-col :span="1.5">
  37. <el-button
  38. type="success"
  39. plain
  40. icon="el-icon-edit"
  41. size="mini"
  42. :disabled="single"
  43. @click="handleUpdate"
  44. v-hasPermi="['saler:productInfo:edit']"
  45. >修改</el-button>
  46. </el-col>
  47. <el-col :span="1.5">
  48. <el-button
  49. type="danger"
  50. plain
  51. icon="el-icon-delete"
  52. size="mini"
  53. :disabled="multiple"
  54. @click="handleDelete"
  55. v-hasPermi="['saler:productInfo:remove']"
  56. >删除</el-button>
  57. </el-col>
  58. <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
  59. </el-row>
  60. <el-table v-loading="loading" :data="productInfoList" @selection-change="handleSelectionChange">
  61. <el-table-column type="selection" width="55" align="center" />
  62. <el-table-column label="商品ID" align="center" prop="id" />
  63. <el-table-column label="商品名称" align="center" prop="productName" />
  64. <el-table-column label="购买数量" align="center" prop="purchaseQuantity" />
  65. <el-table-column label="金额" align="center" prop="amount" />
  66. <el-table-column label="预计完成时间" align="center" prop="plannedCompletionDate" width="180">
  67. <template slot-scope="scope">
  68. <span>{{ parseTime(scope.row.plannedCompletionDate, '{y}-{m}-{d}') }}</span>
  69. </template>
  70. </el-table-column>
  71. <el-table-column label="购买次数" align="center" prop="purchaseTimes" />
  72. <el-table-column label="剩余次数" align="center" prop="surplusTimes" />
  73. <el-table-column label="会员情况" align="center" prop="memberStatus" />
  74. <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
  75. <el-table-column label="创建时间" align="center" prop="createTime" width="180">
  76. <template slot-scope="scope">
  77. <span>{{ parseTime(scope.row.createTime) }}</span>
  78. </template>
  79. </el-table-column>
  80. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  81. <template slot-scope="scope">
  82. <el-button
  83. size="mini"
  84. type="text"
  85. icon="el-icon-edit"
  86. @click="handleUpdate(scope.row)"
  87. v-hasPermi="['saler:productInfo:edit']"
  88. >修改</el-button>
  89. <el-button
  90. size="mini"
  91. type="text"
  92. icon="el-icon-delete"
  93. @click="handleDelete(scope.row)"
  94. v-hasPermi="['saler:productInfo:remove']"
  95. >删除</el-button>
  96. </template>
  97. </el-table-column>
  98. </el-table>
  99. <pagination
  100. v-show="total>0"
  101. :total="total"
  102. :page.sync="queryParams.pageNum"
  103. :limit.sync="queryParams.pageSize"
  104. @pagination="getList"
  105. />
  106. <!-- 添加或修改商品对话框 -->
  107. <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
  108. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  109. <el-form-item label="商品名称" prop="productName">
  110. <el-input v-model="form.productName" placeholder="请输入商品名称" />
  111. </el-form-item>
  112. <el-form-item label="购买数量" prop="purchaseQuantity">
  113. <el-input-number v-model="form.purchaseQuantity" :min="0" :max="9999" />
  114. </el-form-item>
  115. <el-form-item label="金额" prop="amount">
  116. <el-input-number v-model="form.amount" :precision="2" :min="0" :step="0.01" />
  117. </el-form-item>
  118. <el-form-item label="预计完成时间" prop="plannedCompletionDate">
  119. <el-date-picker clearable
  120. v-model="form.plannedCompletionDate"
  121. type="date"
  122. value-format="yyyy-MM-dd"
  123. placeholder="请选择预计完成时间">
  124. </el-date-picker>
  125. </el-form-item>
  126. <el-form-item label="购买次数" prop="purchaseTimes">
  127. <el-input-number v-model="form.purchaseTimes" :min="0" :max="9999" />
  128. </el-form-item>
  129. <el-form-item label="剩余次数" prop="surplusTimes">
  130. <el-input-number v-model="form.surplusTimes" :min="0" :max="9999" />
  131. </el-form-item>
  132. <el-form-item label="会员情况" prop="memberStatus">
  133. <el-input v-model="form.memberStatus" placeholder="请输入会员情况" />
  134. </el-form-item>
  135. <el-form-item label="备注" prop="remark">
  136. <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
  137. </el-form-item>
  138. </el-form>
  139. <div slot="footer" class="dialog-footer">
  140. <el-button type="primary" @click="submitForm">确 定</el-button>
  141. <el-button @click="cancel">取 消</el-button>
  142. </div>
  143. </el-dialog>
  144. </div>
  145. </template>
  146. <script>
  147. import { listProductInfo, getProductInfo, addProductInfo, updateProductInfo, delProductInfo } from "@/api/saler/productInfo";
  148. export default {
  149. name: "ProductInfo",
  150. data() {
  151. return {
  152. // 遮罩层
  153. loading: true,
  154. // 选中数组
  155. ids: [],
  156. // 非单个禁用
  157. single: true,
  158. // 非多个禁用
  159. multiple: true,
  160. // 显示搜索条件
  161. showSearch: true,
  162. // 总条数
  163. total: 0,
  164. // 商品表格数据
  165. productInfoList: [],
  166. // 弹出层标题
  167. title: "",
  168. // 是否显示弹出层
  169. open: false,
  170. // 查询参数
  171. queryParams: {
  172. pageNum: 1,
  173. pageSize: 10,
  174. productName: null,
  175. memberStatus: null
  176. },
  177. // 表单参数
  178. form: {},
  179. // 表单校验
  180. rules: {
  181. productName: [
  182. { required: true, message: "商品名称不能为空", trigger: "blur" }
  183. ],
  184. purchaseQuantity: [
  185. { required: true, message: "购买数量不能为空", trigger: "blur" }
  186. ],
  187. amount: [
  188. { required: true, message: "金额不能为空", trigger: "blur" }
  189. ]
  190. }
  191. };
  192. },
  193. created() {
  194. this.getList();
  195. },
  196. methods: {
  197. /** 查询商品列表 */
  198. getList() {
  199. this.loading = true;
  200. listProductInfo(this.queryParams).then(response => {
  201. this.productInfoList = response.data.list;
  202. this.total = response.data.total;
  203. this.loading = false;
  204. });
  205. },
  206. // 取消按钮
  207. cancel() {
  208. this.open = false;
  209. this.reset();
  210. },
  211. // 表单重置
  212. reset() {
  213. this.form = {
  214. id: null,
  215. productName: null,
  216. purchaseQuantity: 0,
  217. amount: 0,
  218. plannedCompletionDate: null,
  219. purchaseTimes: 0,
  220. surplusTimes: 0,
  221. memberStatus: null,
  222. remark: null
  223. };
  224. this.resetForm("form");
  225. },
  226. /** 搜索按钮操作 */
  227. handleQuery() {
  228. this.queryParams.pageNum = 1;
  229. this.getList();
  230. },
  231. /** 重置按钮操作 */
  232. resetQuery() {
  233. this.resetForm("queryForm");
  234. this.handleQuery();
  235. },
  236. // 多选框选中数据
  237. handleSelectionChange(selection) {
  238. this.ids = selection.map(item => item.id)
  239. this.single = selection.length!==1
  240. this.multiple = !selection.length
  241. },
  242. /** 新增按钮操作 */
  243. handleAdd() {
  244. this.reset();
  245. this.open = true;
  246. this.title = "添加商品";
  247. },
  248. /** 修改按钮操作 */
  249. handleUpdate(row) {
  250. this.reset();
  251. const id = row.id || this.ids[0]
  252. getProductInfo(id).then(response => {
  253. this.form = response.data;
  254. this.open = true;
  255. this.title = "修改商品";
  256. });
  257. },
  258. /** 提交按钮 */
  259. submitForm() {
  260. this.$refs["form"].validate(valid => {
  261. if (valid) {
  262. if (this.form.id != null) {
  263. updateProductInfo(this.form).then(response => {
  264. this.$message.success("修改成功");
  265. this.open = false;
  266. this.getList();
  267. });
  268. } else {
  269. addProductInfo(this.form).then(response => {
  270. this.$message.success("新增成功");
  271. this.open = false;
  272. this.getList();
  273. });
  274. }
  275. }
  276. });
  277. },
  278. /** 删除按钮操作 */
  279. handleDelete(row) {
  280. const ids = row.id || this.ids;
  281. this.$confirm('是否确认删除商品编号为"' + ids + '"的数据项?').then(function() {
  282. return delProductInfo(ids);
  283. }).then(() => {
  284. this.getList();
  285. this.$message.success("删除成功");
  286. }).catch(() => {});
  287. }
  288. }
  289. };
  290. </script>