index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <div class="app-container">
  3. <el-form :model="queryParams" ref="queryRef" :inline="true" v-show="showSearch" label-width="68px">
  4. <el-form-item label="时间" prop="xhTime">
  5. <el-date-picker clearable
  6. v-model="queryParams.xhTime"
  7. type="date"
  8. value-format="YYYY-MM-DD"
  9. placeholder="请选择时间">
  10. </el-date-picker>
  11. </el-form-item>
  12. <el-form-item label="规格" prop="xhType">
  13. <el-select
  14. v-model="queryParams.xhType"
  15. placeholder="请选择规格"
  16. clearable
  17. @change="handleSpecChange" style="width: 150px;">
  18. <el-option
  19. v-for="item in specOptions"
  20. :key="item.value"
  21. :label="item.label"
  22. :value="item.value">
  23. </el-option>
  24. </el-select>
  25. </el-form-item>
  26. <el-form-item label="供方" prop="xhClass">
  27. <el-select
  28. v-model="queryParams.xhClass"
  29. placeholder="请选择供方"
  30. clearable
  31. :disabled="!queryParams.xhType" style="width: 150px;">
  32. <el-option
  33. v-for="item in supplierOptions"
  34. :key="item"
  35. :label="item"
  36. :value="item">
  37. </el-option>
  38. </el-select>
  39. </el-form-item>
  40. <el-form-item label="价格" prop="price">
  41. <el-input
  42. v-model="queryParams.price"
  43. placeholder="请输入价格"
  44. clearable
  45. @keyup.enter="handleQuery"
  46. />
  47. </el-form-item>
  48. <el-form-item>
  49. <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
  50. <el-button icon="Refresh" @click="resetQuery">重置</el-button>
  51. </el-form-item>
  52. </el-form>
  53. <el-row :gutter="10" class="mb8">
  54. <el-col :span="1.5">
  55. <el-button
  56. type="primary"
  57. plain
  58. icon="Plus"
  59. @click="handleAdd"
  60. >新增</el-button>
  61. </el-col>
  62. <el-col :span="1.5">
  63. <el-button
  64. type="success"
  65. plain
  66. icon="Edit"
  67. :disabled="single"
  68. @click="handleUpdate"
  69. >修改</el-button>
  70. </el-col>
  71. <el-col :span="1.5">
  72. <el-button
  73. type="danger"
  74. plain
  75. icon="Delete"
  76. :disabled="multiple"
  77. @click="handleDelete"
  78. >删除</el-button>
  79. </el-col>
  80. <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
  81. </el-row>
  82. <el-table v-loading="loading" :data="xhList" @selection-change="handleSelectionChange">
  83. <el-table-column type="selection" width="55" align="center" />
  84. <!-- <el-table-column label="ID" align="center" prop="xhId" />-->
  85. <el-table-column label="时间" align="center" prop="xhTime" width="180">
  86. <template #default="scope">
  87. <span>{{ parseTime(scope.row.xhTime, '{y}-{m}-{d}') }}</span>
  88. </template>
  89. </el-table-column>
  90. <el-table-column label="规格" align="center" prop="xhType" />
  91. <el-table-column label="供方" align="center" prop="xhClass" />
  92. <el-table-column label="价格" align="center" prop="price" />
  93. <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
  94. <template #default="scope">
  95. <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)">修改</el-button>
  96. <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
  97. </template>
  98. </el-table-column>
  99. </el-table>
  100. <pagination
  101. v-show="total>0"
  102. :total="total"
  103. v-model:page="queryParams.pageNum"
  104. v-model:limit="queryParams.pageSize"
  105. @pagination="getList"
  106. />
  107. <!-- 添加或修改现货价格对话框 -->
  108. <el-dialog :title="title" v-model="open" width="500px" append-to-body>
  109. <el-form ref="xhRef" :model="form" :rules="rules" label-width="80px">
  110. <el-form-item label="时间" prop="xhTime">
  111. <el-date-picker clearable
  112. v-model="form.xhTime"
  113. type="date"
  114. value-format="YYYY-MM-DD"
  115. placeholder="请选择时间">
  116. </el-date-picker>
  117. </el-form-item>
  118. <el-form-item label="规格" prop="xhType">
  119. <el-select
  120. v-model="form.xhType"
  121. placeholder="请选择规格"
  122. @change="handleFormSpecChange">
  123. <el-option
  124. v-for="item in specOptions"
  125. :key="item.value"
  126. :label="item.label"
  127. :value="item.value">
  128. </el-option>
  129. </el-select>
  130. </el-form-item>
  131. <el-form-item label="供方" prop="xhClass">
  132. <el-select
  133. v-model="form.xhClass"
  134. placeholder="请选择供方"
  135. :disabled="!form.xhType">
  136. <el-option
  137. v-for="item in formSupplierOptions"
  138. :key="item"
  139. :label="item"
  140. :value="item">
  141. </el-option>
  142. </el-select>
  143. </el-form-item>
  144. <el-form-item label="价格" prop="price">
  145. <el-input v-model="form.price" placeholder="请输入价格" />
  146. </el-form-item>
  147. </el-form>
  148. <template #footer>
  149. <div class="dialog-footer">
  150. <el-button type="primary" @click="submitForm">确 定</el-button>
  151. <el-button @click="cancel">取 消</el-button>
  152. </div>
  153. </template>
  154. </el-dialog>
  155. </div>
  156. </template>
  157. <script setup name="Xh">
  158. import { listXh, getXh, delXh, addXh, updateXh } from "@/api/lean/xh";
  159. const { proxy } = getCurrentInstance();
  160. const xhList = ref([]);
  161. const open = ref(false);
  162. const loading = ref(true);
  163. const showSearch = ref(true);
  164. const ids = ref([]);
  165. const single = ref(true);
  166. const multiple = ref(true);
  167. const total = ref(0);
  168. const title = ref("");
  169. // 规格选项
  170. const specOptions = ref([
  171. { value: '120D/120f', label: '120D/120f' },
  172. { value: '150D/096f', label: '150D/096f' },
  173. { value: '150D/120f', label: '150D/120f' },
  174. { value: '150D/144f', label: '150D/144f' },
  175. { value: '200D/096f', label: '200D/096f' },
  176. { value: '200D/144f', label: '200D/144f' },
  177. { value: '250D/120f', label: '250D/120f' },
  178. { value: '300D/144f', label: '300D/144f' },
  179. { value: '450D/192f', label: '450D/192f' }
  180. ]);
  181. // 供方选项(根据规格动态变化)
  182. const supplierOptions = ref([]);
  183. const formSupplierOptions = ref([]);
  184. // 规格与供方的映射关系
  185. const specSupplierMap = {
  186. '120D/120f': ['盛虹202dtex/120f', '盛元220dtex/120f'],
  187. '150D/096f': ['恒通298dtex/096f', '盛虹263dtex/096f', '盛元275dtex/096f'],
  188. '150D/120f': ['盛虹268dtex/120f', '盛元275dtex/120f'],
  189. '150D/144f': ['恒通272dtex/144f', '盛虹265dtex/144f', '盛元272dtex/144f'],
  190. '200D/096f': ['恒通378dtex/096f', '恒逸378dtex/096f', '盛虹368dtex/096f', '盛元365dtex/096f'],
  191. '200D/144f': ['恒通378dtex/144f', '盛虹363dtex/144f', '盛元365dtex/144f'],
  192. '250D/120f': ['恒通478dtex/122f', '恒逸478dtex/120f', '盛虹465dtex/120f'],
  193. '300D/144f': ['恒通545dtex/144f', '恒逸560dtex/144f', '盛虹575dtex/144f'],
  194. '450D/192f': ['恒通758dtex/192f']
  195. };
  196. const data = reactive({
  197. form: {},
  198. queryParams: {
  199. pageNum: 1,
  200. pageSize: 10,
  201. xhTime: null,
  202. xhType: null,
  203. xhClass: null,
  204. price: null,
  205. orderByColumn: "xh_time",
  206. isAsc: "descending"
  207. },
  208. rules: {
  209. }
  210. });
  211. const { queryParams, form, rules } = toRefs(data);
  212. /** 处理规格变化 */
  213. function handleSpecChange(spec) {
  214. if (spec && specSupplierMap[spec]) {
  215. supplierOptions.value = specSupplierMap[spec];
  216. // 如果当前选择的供方不在新选项中,则清空供方选择
  217. if (queryParams.value.xhClass && !supplierOptions.value.includes(queryParams.value.xhClass)) {
  218. queryParams.value.xhClass = null;
  219. }
  220. } else {
  221. supplierOptions.value = [];
  222. queryParams.value.xhClass = null;
  223. }
  224. }
  225. /** 处理表单中规格变化 */
  226. function handleFormSpecChange(spec) {
  227. if (spec && specSupplierMap[spec]) {
  228. formSupplierOptions.value = specSupplierMap[spec];
  229. // 如果当前选择的供方不在新选项中,则清空供方选择
  230. if (form.value.xhClass && !formSupplierOptions.value.includes(form.value.xhClass)) {
  231. form.value.xhClass = null;
  232. }
  233. } else {
  234. formSupplierOptions.value = [];
  235. form.value.xhClass = null;
  236. }
  237. }
  238. /** 查询现货价格列表 */
  239. function getList() {
  240. loading.value = true;
  241. listXh(queryParams.value).then(response => {
  242. xhList.value = response.rows;
  243. total.value = response.total;
  244. loading.value = false;
  245. });
  246. }
  247. // 取消按钮
  248. function cancel() {
  249. open.value = false;
  250. reset();
  251. }
  252. // 表单重置
  253. function reset() {
  254. form.value = {
  255. xhId: null,
  256. xhTime: null,
  257. xhType: null,
  258. xhClass: null,
  259. price: null
  260. };
  261. formSupplierOptions.value = [];
  262. proxy.resetForm("xhRef");
  263. }
  264. /** 搜索按钮操作 */
  265. function handleQuery() {
  266. queryParams.value.pageNum = 1;
  267. getList();
  268. }
  269. /** 重置按钮操作 */
  270. function resetQuery() {
  271. proxy.resetForm("queryRef");
  272. supplierOptions.value = [];
  273. handleQuery();
  274. }
  275. // 多选框选中数据
  276. function handleSelectionChange(selection) {
  277. ids.value = selection.map(item => item.xhId);
  278. single.value = selection.length != 1;
  279. multiple.value = !selection.length;
  280. }
  281. /** 新增按钮操作 */
  282. function handleAdd() {
  283. reset();
  284. open.value = true;
  285. title.value = "添加现货价格";
  286. }
  287. /** 修改按钮操作 */
  288. function handleUpdate(row) {
  289. reset();
  290. const _xhId = row.xhId || ids.value
  291. getXh(_xhId).then(response => {
  292. form.value = response.data;
  293. // 初始化供方选项
  294. if (form.value.xhType && specSupplierMap[form.value.xhType]) {
  295. formSupplierOptions.value = specSupplierMap[form.value.xhType];
  296. }
  297. open.value = true;
  298. title.value = "修改现货价格";
  299. });
  300. }
  301. /** 提交按钮 */
  302. function submitForm() {
  303. proxy.$refs["xhRef"].validate(valid => {
  304. if (valid) {
  305. if (form.value.xhId != null) {
  306. updateXh(form.value).then(response => {
  307. proxy.$modal.msgSuccess("修改成功");
  308. open.value = false;
  309. getList();
  310. });
  311. } else {
  312. addXh(form.value).then(response => {
  313. proxy.$modal.msgSuccess("新增成功");
  314. open.value = false;
  315. getList();
  316. });
  317. }
  318. }
  319. });
  320. }
  321. /** 删除按钮操作 */
  322. function handleDelete(row) {
  323. const _xhIds = row.xhId || ids.value;
  324. proxy.$modal.confirm('是否确认删除现货价格编号为"' + _xhIds + '"的数据项?').then(function() {
  325. return delXh(_xhIds);
  326. }).then(() => {
  327. getList();
  328. proxy.$modal.msgSuccess("删除成功");
  329. }).catch(() => {});
  330. }
  331. /** 导出按钮操作 */
  332. function handleExport() {
  333. proxy.download('lean/xh/export', {
  334. ...queryParams.value
  335. }, `xh_${new Date().getTime()}.xlsx`)
  336. }
  337. getList();
  338. </script>