index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <div class="app-container">
  3. <el-form ref="form" :model="form" :rules="rules" label-width="120px">
  4. <el-form-item label="油站名称" prop="stationId" >
  5. <el-select
  6. v-model="form.stationId"
  7. placeholder="请选择油站"
  8. clearable
  9. size="small"
  10. @change="onInstitutionChang"
  11. >
  12. <el-option
  13. v-for="item in stationOptions"
  14. :key="item.deptId"
  15. :label="item.deptName"
  16. :value="item.deptId"
  17. ></el-option>
  18. </el-select>
  19. </el-form-item>
  20. <el-form-item v-show="false" label="油站名称" prop="stationName">
  21. <el-input v-model="form.stationName" placeholder="请输入油站名称" />
  22. </el-form-item>
  23. <el-form-item label="油品积分规则" ></el-form-item>
  24. <div>
  25. <el-row v-for="(item, index) in form.itemsDetail" :key="index" style="margin-left: 80px;">
  26. <el-form
  27. :inline="true"
  28. :model="form.itemsDetail[index]"
  29. :rules="rules"
  30. ref="ruleForms"
  31. class="demo-form-inline"
  32. size="small"
  33. >
  34. <el-form-item>
  35. <span>规则类型</span>
  36. <el-select v-model="item.ruleType" placeholder="请选择油品" clearable size="small" >
  37. <el-option
  38. v-for="item in ruleTypeOptions"
  39. :key="item.dictValue"
  40. :label="item.dictLabel"
  41. :value="item.dictValue"
  42. ></el-option>
  43. </el-select>
  44. <span>满</span>
  45. <el-input-number v-model="item.ruleTerms" :min="0" size="small" />
  46. <span v-if="item.ruleType=='1'">L</span>
  47. <span v-else>元</span>
  48. <span>起累计 </span>
  49. <el-select v-model="item.oilName" placeholder="请选择油品" clearable size="small" @change="oilNameChang(index)" >
  50. <el-option
  51. v-for="item in oilNameOptions"
  52. :key="item.oilName"
  53. :label="item.oilName"
  54. :value="item.oilName"
  55. ></el-option>
  56. </el-select>
  57. <el-select
  58. v-model="item.gread"
  59. placeholder="请选择等级"
  60. clearable
  61. size="small"
  62. >
  63. <el-option
  64. v-for="item in gradeOptions"
  65. :key="item.grade"
  66. :label="item.grade"
  67. :value="item.grade"
  68. ></el-option>
  69. </el-select>
  70. <span>每消费</span>
  71. <el-input-number v-model="item.saleAmt" size="small" :min="0"/>
  72. <span>元</span>
  73. <el-input-number v-model="item.integral" size="small" :min="0"/>
  74. <span>积分</span>
  75. </el-form-item>
  76. <el-form-item>
  77. <el-button
  78. type="danger"
  79. @click="del(index)"
  80. size="small"
  81. >删除</el-button>
  82. <el-button
  83. type="success"
  84. @click="addItem"
  85. size="small"
  86. >新增</el-button>
  87. </el-form-item>
  88. </el-form>
  89. </el-row>
  90. </div>
  91. <el-form-item label="非油品积分规则" ></el-form-item>
  92. <div>
  93. <el-row v-for="(item, index) in form.notOilList" :key="index" style="margin-left: 80px;">
  94. <el-form
  95. :inline="true"
  96. :model="form.notOilList[index]"
  97. :rules="rules"
  98. ref="ruleForms"
  99. class="demo-form-inline"
  100. size="small"
  101. >
  102. <el-form-item>
  103. <span>满</span>
  104. <el-input-number v-model="item.ruleTerms" :min="0" size="small" />
  105. <span></span>
  106. <span>元 起累计 </span>
  107. <span>每消费</span>
  108. <el-input-number v-model="item.saleAmt" size="small" :min="0"/>
  109. <span>元</span>
  110. <el-input-number v-model="item.integral" size="small" :min="0"/>
  111. <span>积分</span>
  112. </el-form-item>
  113. </el-form>
  114. </el-row>
  115. </div>
  116. <el-form-item label="有效期设置" prop="termDateManage">
  117. <el-radio-group v-model="form.termDateManage">
  118. <el-radio
  119. v-for="dict in termDateManageOptions"
  120. :key="dict.dictValue"
  121. :label="dict.dictValue"
  122. >{{dict.dictLabel}}</el-radio>
  123. </el-radio-group>
  124. <el-date-picker clearable size="small" style="width: 200px;margin-left: 10px;"
  125. v-model="form.emptyDate"
  126. type="date"
  127. value-format="yyyy-MM-dd"
  128. placeholder="选择清空积分时间">
  129. </el-date-picker>
  130. <span>清空积分</span>
  131. </el-form-item>
  132. <el-form-item label= "到期提醒设置" prop="expirationReminder">
  133. <el-radio-group v-model="form.expirationReminder">
  134. <el-radio
  135. v-for="dict in expirationOptions"
  136. :key="dict.dictValue"
  137. :label="dict.dictValue"
  138. >{{dict.dictLabel}}</el-radio>
  139. </el-radio-group>
  140. <el-date-picker clearable size="small" style="margin-left: 10px;width: 200px"
  141. v-model="form.remindDate"
  142. type="date"
  143. value-format="yyyy-MM-dd"
  144. placeholder="选择提醒时间设置">
  145. </el-date-picker>
  146. </el-form-item>
  147. <el-form-item label="积分活动设置" ></el-form-item>
  148. <el-form-item >
  149. <el-radio-group v-model="form.integralActivity">
  150. <el-radio
  151. v-for="dict in integralActivityOptions"
  152. :key="dict.dictValue"
  153. :label="dict.dictValue"
  154. >{{dict.dictLabel}}</el-radio>
  155. </el-radio-group>
  156. </el-form-item>
  157. <el-row>
  158. <el-col :span="8" style="margin-left: 80px;">
  159. <el-form-item label="日期选择" prop="datePicker">
  160. <el-date-picker clearable size="small" style="margin-left: 10px;width: 200px"
  161. v-model="form.datePicker"
  162. type="dates"
  163. value-format="yyyy-MM-dd"
  164. placeholder="选择提醒时间设置">
  165. </el-date-picker>
  166. </el-form-item>
  167. </el-col>
  168. <el-col :span="8">
  169. <el-form-item label="积分比例" prop="integralProportion">
  170. <el-input-number v-model="form.integralProportion" :min="1" placeholder="请输入加倍比例" />
  171. </el-form-item>
  172. </el-col>
  173. </el-row>
  174. <el-form-item label="抵扣油品规则" prop="integralDeductionOil">
  175. <el-radio-group v-model="form.integralDeductionOil">
  176. <el-radio
  177. v-for="dict in integralDeductionOilOptions"
  178. :key="dict.dictValue"
  179. :label="dict.dictValue"
  180. >{{dict.dictLabel}}</el-radio>
  181. </el-radio-group>
  182. </el-form-item>
  183. <el-form-item label="积分轮播图">
  184. <el-upload
  185. class="avatar-uploader"
  186. :action="addressUrl"
  187. :headers="headers"
  188. multiple
  189. list-type="picture-card"
  190. :limit='5'
  191. :file-list="form.imgFileList"
  192. accept="image/gif,image/jpeg,image/png,image/jpg,image/bmp"
  193. :before-upload="beforeAvatarUpload"
  194. :on-remove="handleRemove"
  195. :on-success="handlepaymentSuccess">
  196. <i class="el-icon-plus"></i>
  197. <div class="el-upload__tip" slot="tip">只能上传jpg/png文件,最多上传5张且单张图片不超过1M</div>
  198. </el-upload>
  199. <el-dialog :visible.sync="dialogVisible" append-to-body>
  200. <img width="100%" :src="dialogImageUrl" alt="" />
  201. </el-dialog>
  202. </el-form-item>
  203. </el-form>
  204. <div slot="footer" class="dialog-footer">
  205. <el-button type="primary" @click="submitForm">确 定</el-button>
  206. <el-button @click="cancel">取 消</el-button>
  207. </div>
  208. </div>
  209. </template>
  210. <script>
  211. import { getToken } from "@/utils/auth";
  212. import {getGun, stationinfo} from "@/api/station/gun";
  213. import { addRule, updateRule,oilNameList,gradeList,getRule } from "@/api/integral/rule";
  214. export default {
  215. name: "ruleDetail",
  216. data() {
  217. return {
  218. // 遮罩层
  219. loading: true,
  220. // 选中数组
  221. ids: [],
  222. // 非单个禁用
  223. single: true,
  224. // 弹出层标题
  225. title: "",
  226. uploadUrl:"",
  227. stationOptions:[],
  228. oilNameOptions:[],
  229. ruleTypeOptions:[],
  230. termDateManageOptions:[],
  231. expirationOptions:[],
  232. integralDeductionOilOptions:[],
  233. integralActivityOptions:[],
  234. gradeOptions:[],
  235. imgInfoList: [], //包含图片的id,name,size的集合
  236. imgNameList: [], //后端返回的上传图片的name集合,传到后端
  237. imgSize: [], //后端返回的上传图片的imgSize集合,传到后端
  238. deleteImgFileList: [], //存已被删除了的图片的id
  239. dialogImageUrl: '',
  240. dialogVisible: false,
  241. // 是否显示弹出层
  242. open: false,
  243. // 查询参数
  244. queryParams: {
  245. pageNum: 1,
  246. pageSize: 10,
  247. stationId: null,
  248. stationName: null,
  249. ruleType: null,
  250. oilName: null
  251. },
  252. // 表单参数
  253. form: {
  254. itemsDetail: [{}],
  255. notOilList: [{}],
  256. imgFileList:[]
  257. },
  258. // 表单校验
  259. rules: {
  260. },
  261. headers: { Authorization: "Bearer " + getToken() },
  262. addressUrl: location.protocol+"//"+location.host+ process.env.VUE_APP_BASE_API+"/common/upload"
  263. };
  264. },
  265. created() {
  266. //判断是否是做修改
  267. if(this.$route.query.stationId!=null && this.$route.query.stationId!="" && this.$route.query.parentId !=null &&this.$route.query.parentId !=""){
  268. this.queryParams.stationId=this.$route.query.stationId;
  269. let id=this.$route.query.parentId;
  270. if(id!=null && id != ""){
  271. getRule(id).then(response => {
  272. this.form = response.data;
  273. if(this.form.notOilList.length==0 ){
  274. this.form.notOilList=[{}];
  275. }
  276. if(this.form.itemsDetail.length==0 ){
  277. this.form.itemsDetail=[{}];
  278. }
  279. });
  280. oilNameList(this.queryParams).then(response => {
  281. this.oilNameOptions = response.rows;
  282. });
  283. }
  284. }
  285. stationinfo().then(response => {
  286. this.stationOptions = response.rows;
  287. });
  288. this.getDicts("rule_type").then(response => {
  289. this.ruleTypeOptions = response.data;
  290. });
  291. this.getDicts("term_date").then(response => {
  292. this.termDateManageOptions = response.data;
  293. });
  294. this.getDicts("expiration").then(response => {
  295. this.expirationOptions = response.data;
  296. });
  297. this.getDicts("integral_deduction_oil").then(response => {
  298. this.integralDeductionOilOptions = response.data;
  299. });
  300. this.getDicts("integral_manage").then(response => {
  301. this.integralActivityOptions = response.data;
  302. });
  303. },
  304. methods: {
  305. //添加行
  306. addItem() {
  307. this.form.itemsDetail.push({
  308. ruleTerms: '',
  309. oilName: '',
  310. gread: '',
  311. saleAmt: '' ,
  312. integral: '',
  313. ruleType: ''
  314. });
  315. },
  316. // 删除行
  317. del(index) {
  318. this.form.itemsDetail.splice(index, 1);
  319. },
  320. queryreset() {
  321. this.queryParams={
  322. stationId: null,
  323. stationName: null,
  324. oilName: null
  325. }
  326. },
  327. changeGread(e){
  328. //获取等级名称和id
  329. console.log(e);
  330. },
  331. onInstitutionChang(){
  332. let obj = {};
  333. obj = this.stationOptions.find((item)=>{//这里的userList就是上面遍历的数据源
  334. return item.deptId === this.form.stationId;//筛选出匹配数据
  335. })
  336. this.queryreset();
  337. this.form.stationName=obj.deptName;
  338. this.queryParams.stationId=obj.deptId;
  339. oilNameList(this.queryParams).then(response => {
  340. this.oilNameOptions = response.rows;
  341. });
  342. },
  343. oilNameChang(e){
  344. let obj = {};
  345. console.log("oilNameOptions:",this.oilNameOptions);
  346. console.log("e:",this.form.itemsDetail[e].oilName);
  347. obj = this.oilNameOptions.find((item)=>{//这里的userList就是上面遍历的数据源
  348. return item.oilName === this.form.itemsDetail[e].oilName;//筛选出匹配数据
  349. })
  350. this.queryreset();
  351. //获取油站名称
  352. this.queryParams.stationId = this.form.stationId;
  353. this.queryParams.oilName=obj.oilName;
  354. console.log("stationId", this.form.stationId);
  355. console.log("oilname",obj.oilName);
  356. gradeList(this.queryParams).then(response => {
  357. this.gradeOptions = response.rows;
  358. console.log("gradeOptions", this.gradeOptions );
  359. });
  360. },
  361. handlePictureCardPreview(file) {
  362. console.log("file",file);
  363. this.dialogImageUrl = file.url;
  364. this.dialogVisible = true;
  365. },
  366. handleRemove(file, fileList) {
  367. if(fileList!=null && fileList.length>0){
  368. this.form.imgFileList=[];
  369. for (let i = 0; i < fileList.length; i++) {
  370. let fileName = fileList[i].name;
  371. let imgurl = fileList[i].url;
  372. this.form.imgFileList.push({name:fileName,url:imgurl});
  373. }
  374. }else{
  375. this.form.imgFileList = fileList;
  376. }
  377. },
  378. beforeAvatarUpload(file) {
  379. const isType = file.type === 'image/jpeg' || 'image/png';
  380. const isLt5M = file.size / 1024 / 1024 < 1;
  381. if (!isType) {
  382. this.$message.error('上传头像图片只能是 JPG 或 PNG格式!');
  383. }
  384. if (!isLt5M) {
  385. this.$message.error('上传头像图片大小不能超过 1MB!');
  386. }
  387. return isType && isLt5M;
  388. },
  389. //上传成功
  390. handlepaymentSuccess(response,file, fileList){
  391. let imgurl=location.protocol+"//"+location.host+process.env.VUE_APP_BASE_API+response.fileName;
  392. this.form.imgFileList.push({name:file.name,url:imgurl});
  393. },
  394. /** 提交按钮 */
  395. submitForm() {
  396. this.$refs["form"].validate(valid => {
  397. if (valid) {
  398. if (this.form.id != null) {
  399. if(this.form.datePicker != null){
  400. this.form.datePicker =this.form.datePicker.toString();
  401. }
  402. if(this.form.notOilList!=null&&this.form.notOilList.length>0||this.form.notOilList[0].hasOwnProperty(saleAmt)){
  403. if(this.form.notOilList[0].saleAmt==""||this.form.notOilList[0].saleAmt=="0" ||this.form.notOilList[0].saleAmt=="undefined"){
  404. this.form.notOilList=[];
  405. }
  406. }
  407. updateRule(this.form).then(response => {
  408. this.msgSuccess("修改成功");
  409. });
  410. } else {
  411. if(this.form.datePicker != null){
  412. this.form.datePicker =this.form.datePicker.toString();
  413. }
  414. if(this.form.notOilList!=null&&this.form.notOilList.length>0||this.form.notOilList[0].hasOwnProperty(saleAmt)){
  415. if(this.form.notOilList[0].saleAmt==""||this.form.notOilList[0].saleAmt=="0" ||this.form.notOilList[0].saleAmt=="undefined"){
  416. this.form.notOilList=[];
  417. }
  418. }
  419. addRule(this.form).then(response => {
  420. this.msgSuccess("新增成功");
  421. });
  422. }
  423. }
  424. });
  425. },
  426. // 取消按钮
  427. cancel() {
  428. this.queryreset();
  429. }
  430. },
  431. }
  432. </script>