adjust.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div class="app-container">
  3. <el-form
  4. :model="queryParams"
  5. ref="queryForm"
  6. :inline="true"
  7. label-width="68px"
  8. >
  9. <el-form-item>
  10. <el-button
  11. type="primary"
  12. icon="el-icon-plus"
  13. size="mini"
  14. @click="handleAdd"
  15. >添加油品</el-button
  16. >
  17. </el-form-item>
  18. </el-form>
  19. <el-table :data="addedOilList" ref="dataTable">
  20. <af-table-column width="55" align="center" />
  21. <af-table-column
  22. label="油品价格id"
  23. v-if="false"
  24. align="center"
  25. prop="oilPriceId"
  26. />
  27. <af-table-column label="油品名称" align="center" prop="oilName" />
  28. <af-table-column label="油品价格" align="center" prop="oilPrice" />
  29. <af-table-column
  30. label="油站id"
  31. v-if="false"
  32. align="center"
  33. prop="stationId"
  34. />
  35. <!--
  36. <af-table-column label="油站名称" align="center" prop="stationNanme" />
  37. -->
  38. <af-table-column label="操作时间" align="center" prop="date" />
  39. <af-table-column
  40. label="操作"
  41. align="center"
  42. class-name="small-padding fixed-width"
  43. >
  44. <template slot-scope="scope">
  45. <el-button
  46. size="mini"
  47. type="text"
  48. icon="el-icon-delete"
  49. @click="handleDelete(scope.row)"
  50. >删除</el-button
  51. >
  52. <el-button
  53. type="text"
  54. icon="el-icon-edit"
  55. size="mini"
  56. @click="handleUpdata(scope.row)"
  57. >调价</el-button
  58. >
  59. </template>
  60. </af-table-column>
  61. </el-table>
  62. <pagination
  63. v-show="total > 0"
  64. :total="total"
  65. :page.sync="queryParams.pageNum"
  66. :limit.sync="queryParams.pageSize"
  67. @pagination="getList"
  68. />
  69. <!-- 添加油品对话框 -->
  70. <el-dialog title="添加油品" :visible.sync="addOpen" width="350px">
  71. <el-form ref="addForm" :model="addForm" :rules="addRules" label-width="90px">
  72. <el-form-item label="油品名称" prop="oilName">
  73. <el-select
  74. v-model="addForm.oilName"
  75. placeholder="油品名称"
  76. clearable
  77. size="small"
  78. @change="onOilNameChang"
  79. >
  80. <el-option
  81. v-for="dict in filterOilList"
  82. :key="dict.dictLabel"
  83. :label="dict.dictLabel"
  84. :value="dict.dictLabel"
  85. />
  86. </el-select>
  87. </el-form-item>
  88. <el-form-item label="油品价格" prop="oilPrice" v-show="showOilPrice" :required="showOilPrice">
  89. <el-input-number
  90. v-model="addForm.oilPrice"
  91. :precision="2"
  92. :min="0"
  93. :step="1"
  94. ></el-input-number>
  95. </el-form-item>
  96. </el-form>
  97. <div slot="footer" class="dialog-footer">
  98. <el-button type="primary" @click="submitAddForm">确 定</el-button>
  99. <el-button @click="cancelAdd">取 消</el-button>
  100. </div>
  101. </el-dialog>
  102. <!-- 调价信息对话框 -->
  103. <el-dialog
  104. title="油品调价"
  105. :visible.sync="updataOpen"
  106. width="400px"
  107. append-to-body
  108. >
  109. <el-form ref="updataForm" :model="updataForm" :rules="updataRules" label-width="80px">
  110. <el-form-item label="油品" prop="oilName" width="80px">
  111. {{updataForm.oilName}}
  112. </el-form-item>
  113. <el-form-item label="调整价格" prop="oilAdjustPrice">
  114. <el-input-number
  115. v-model="updataForm.oilAdjustPrice"
  116. :precision="2"
  117. :min="0"
  118. :step="1"
  119. style="width: 150px"
  120. />元
  121. </el-form-item>
  122. <el-form-item label="生效状态" prop="takeEffectStatus">
  123. <el-radio-group v-model="updataForm.takeEffectStatus">
  124. <el-radio-button label="1">立即生效</el-radio-button>
  125. <el-radio-button label="2">定时生效</el-radio-button>
  126. </el-radio-group>
  127. </el-form-item>
  128. <el-form-item
  129. label="生效时间"
  130. prop="takeEffectDate"
  131. v-show="updataForm.takeEffectStatus==2"
  132. :required="updataForm.takeEffectStatus==2"
  133. >
  134. <el-date-picker
  135. clearable
  136. size="small"
  137. style="width: 200px"
  138. v-model="updataForm.takeEffectDate"
  139. type="datetime"
  140. value-format="yyyy-MM-dd HH:mm:ss"
  141. placeholder="选择生效时间"
  142. >
  143. </el-date-picker>
  144. </el-form-item>
  145. </el-form>
  146. <div slot="footer" class="dialog-footer">
  147. <el-button type="primary" @click="submitUpdataForm">确 定</el-button>
  148. <el-button @click="cancelUpdata">取 消</el-button>
  149. </div>
  150. </el-dialog>
  151. </div>
  152. </template>
  153. <script>
  154. import {
  155. listPrice,
  156. delPrice,
  157. addPrice,
  158. updatePrice,
  159. exportPrice,
  160. } from "@/api/station/price";
  161. import { addAdjust, updateAdjust } from "@/api/station/adjust";
  162. import { getDept } from "@/api/system/dept";
  163. import { stationinfo } from "@/api/station/gun";
  164. import { queryOilType } from "@/utils/oil"
  165. export default {
  166. name: "adjust",
  167. data() {
  168. const validateOilPrice = (rule, value, callback) => {
  169. // 判断是不是非油品
  170. const res = this.allOilList.find((ele)=>{
  171. return ele.dictLabel===this.addForm.oilName
  172. })
  173. if(!res){
  174. callback(new Error("请选择油品后进行价格操作"));
  175. return
  176. }
  177. if(res.dictValue != 3){
  178. if (value == 0){
  179. callback(new Error("请填入价格"));
  180. return
  181. }
  182. }
  183. callback();
  184. };
  185. const validateTakeEffectDate = (rule, value, callback) => {
  186. if(this.updataForm.takeEffectStatus == 2){
  187. if(!value){
  188. callback(new Error("请选择调价时间"));
  189. return
  190. }
  191. }
  192. callback();
  193. };
  194. return {
  195. // 总条数
  196. total: 0,
  197. // 油品价格表格数据
  198. addedOilList: [],
  199. // 是否显示弹出层
  200. addOpen: false,
  201. updataOpen: false,
  202. // 查询参数
  203. queryParams: {
  204. pageNum: 1,
  205. pageSize: 10,
  206. },
  207. stationOptions: [],
  208. // 表单参数
  209. addForm: {},
  210. updataForm: {},
  211. // 表单校验
  212. addRules:{
  213. oilName:[
  214. {
  215. required: true,
  216. trigger: "change",
  217. message: "请选择油品",
  218. }
  219. ],
  220. oilPrice:[
  221. {
  222. validator: validateOilPrice,
  223. trigger: 'blur'
  224. }
  225. ]
  226. },
  227. updataRules: {
  228. oilAdjustPrice:[
  229. {
  230. required: true,
  231. trigger: "blur",
  232. message: "调整价格必须慎重填写",
  233. }
  234. ],
  235. takeEffectStatus: [
  236. {
  237. required: true,
  238. trigger: "blur",
  239. message: "生效状态必须选择",
  240. },
  241. ],
  242. takeEffectDate:[
  243. {
  244. validator: validateTakeEffectDate,
  245. trigger: 'change'
  246. }
  247. ]
  248. },
  249. allOilList: [],
  250. showOilPrice:true
  251. };
  252. },
  253. created() {
  254. this.init();
  255. },
  256. computed: {
  257. filterOilList() {
  258. return this.allOilList.filter((ele) => {
  259. let flag = true;
  260. this.addedOilList.map((item) => {
  261. if (item.oilName === ele.dictLabel) {
  262. flag = false;
  263. }
  264. });
  265. return flag;
  266. });
  267. },
  268. },
  269. methods: {
  270. init(){
  271. this.getList();
  272. this.getDicts("oil_name").then((response) => {
  273. this.allOilList = response.data;
  274. });
  275. },
  276. /** 查询油品价格列表 */
  277. getList() {
  278. this.queryParams.stationId = this.deptId;
  279. listPrice(this.queryParams).then((response) => {
  280. this.addedOilList = response.rows;
  281. this.total = response.total;
  282. });
  283. },
  284. // 取消按钮
  285. cancelAdd() {
  286. this.addOpen = false;
  287. },
  288. /** 搜索按钮操作 */
  289. // handleQuery() {
  290. // this.queryParams.pageNum = 1;
  291. // this.getList();
  292. // },
  293. /** 新增按钮操作 */
  294. handleAdd() {
  295. this.addForm = {
  296. ...this.addForm,
  297. stationId:this.deptId,
  298. oilPrice:0,
  299. oilName:''
  300. }
  301. this.addOpen = true;
  302. },
  303. onOilNameChang(oilName) {
  304. queryOilType(oilName).then((res) => {
  305. if(res == 3){
  306. this.showOilPrice = false
  307. }else{
  308. this.showOilPrice = true
  309. }
  310. })
  311. },
  312. /** 提交按钮 */
  313. submitAddForm() {
  314. this.addForm.stationId = this.deptId;
  315. this.$refs["addForm"].validate((valid) => {
  316. if (valid) {
  317. addPrice(this.addForm).then((response) => {
  318. this.msgSuccess("调价成功");
  319. this.addOpen = false;
  320. this.getList();
  321. });
  322. }
  323. });
  324. },
  325. handleUpdata(row) {
  326. this.updataForm = {
  327. ...this.updataForm,
  328. oilName: row.oilName,
  329. stationId: row.stationId,
  330. oilPriceId: row.oilPriceId,
  331. oilAdjustPrice: row.oilPrice,
  332. takeEffectStatus: 1,
  333. };
  334. this.updataOpen = true;
  335. },
  336. // 取消按钮
  337. cancelUpdata() {
  338. this.updataOpen = false;
  339. },
  340. submitUpdataForm() {
  341. this.$refs["updataForm"].validate((valid) => {
  342. if (valid) {
  343. addAdjust(this.updataForm).then((response) => {
  344. this.msgSuccess("调价成功");
  345. this.updataOpen = false;
  346. this.getList();
  347. });
  348. }
  349. });
  350. },
  351. /** 删除按钮操作 */
  352. handleDelete(row) {
  353. this.$confirm("是否确认删除油品价格", "警告", {
  354. confirmButtonText: "确定",
  355. cancelButtonText: "取消",
  356. type: "warning",
  357. })
  358. .then(function () {
  359. return delPrice(row.oilPriceId);
  360. })
  361. .then(() => {
  362. this.getList();
  363. this.msgSuccess("删除成功");
  364. });
  365. },
  366. /** 导出按钮操作 */
  367. handleExport() {
  368. const queryParams = this.queryParams;
  369. this.$confirm("是否确认导出所有油品价格数据项?", "警告", {
  370. confirmButtonText: "确定",
  371. cancelButtonText: "取消",
  372. type: "warning",
  373. })
  374. .then(function () {
  375. return exportPrice(queryParams);
  376. })
  377. .then((response) => {
  378. this.download(response.msg);
  379. });
  380. },
  381. },
  382. };
  383. </script>