ContractChannelRegister.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. <template>
  2. <div>
  3. <el-dialog
  4. :title="isView ? '签约新增' : '签约编辑'"
  5. :visible.sync="dialogVisible"
  6. :before-close="cancle"
  7. width="60%"
  8. >
  9. <el-form
  10. :inline="true"
  11. :model="ruleForm"
  12. :rules="rules"
  13. ref="ruleForm"
  14. label-width="120px"
  15. class="demo-ruleForm"
  16. >
  17. <el-row>
  18. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  19. <el-form-item label="剩余次数" prop="unuse">
  20. <el-input-number
  21. v-model="ruleForm.unuse"
  22. class="inputCom"
  23. :min="0"
  24. placeholder="请输入剩余次数"
  25. ></el-input-number>
  26. </el-form-item>
  27. </el-col>
  28. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  29. <el-form-item label="充值使用次数" prop="rechargeUsed">
  30. <el-input-number
  31. v-model="ruleForm.rechargeUsed"
  32. class="inputCom"
  33. :min="0"
  34. placeholder="请输入充值使用次数"
  35. ></el-input-number>
  36. </el-form-item>
  37. </el-col>
  38. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  39. <el-form-item label="累计充值次数" prop="rechargeCount">
  40. <el-input-number
  41. v-model="ruleForm.rechargeCount"
  42. class="inputCom"
  43. :min="0"
  44. placeholder="请输入累计充值次数"
  45. ></el-input-number>
  46. </el-form-item>
  47. </el-col>
  48. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  49. <el-form-item label="签约单次金额" prop="signAmount">
  50. <el-input-number
  51. :min="0"
  52. v-model="ruleForm.signAmount"
  53. class="inputCom"
  54. placeholder="请输入签约单次金额"
  55. ></el-input-number>
  56. </el-form-item>
  57. </el-col>
  58. </el-row>
  59. <el-row>
  60. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  61. <el-form-item label="海报背景图" prop="background">
  62. <el-upload
  63. accept=".png, .jpg, .jpeg"
  64. class="avatar-uploader"
  65. name="file"
  66. :action="action"
  67. :show-file-list="false"
  68. :on-success="handleAvatarSuccess"
  69. :before-upload="beforeAvatarUpload"
  70. >
  71. <img v-if="ruleForm.background" :src="ruleForm.background" class="avatar" />
  72. <i v-else class="el-icon-plus avatar-uploader-icon"></i>
  73. <div class="el-upload__tip" slot="tip">
  74. 海报背景图建议上传720*1280分辨率图片
  75. </div>
  76. </el-upload>
  77. </el-form-item>
  78. </el-col>
  79. </el-row>
  80. </el-form>
  81. <span slot="footer" class="dialog-footer">
  82. <el-button type="info" round @click="cancle">取 消</el-button>
  83. <el-button
  84. v-show="isView"
  85. type="primary"
  86. round
  87. :disabled="disableFlag"
  88. @click="submitCom"
  89. >确 定</el-button
  90. >
  91. <el-button
  92. v-show="!isView"
  93. type="primary"
  94. round
  95. :disabled="disableFlag"
  96. @click="submitCom"
  97. >修 改</el-button
  98. >
  99. </span>
  100. </el-dialog>
  101. </div>
  102. </template>
  103. <script>
  104. // import { oSessionStorage } from "../../utils/utils";
  105. import { oSessionStorage } from "../utils/utils";
  106. import { basePath } from "../utils/http";
  107. import md5 from "md5";
  108. export default {
  109. data() {
  110. var validatePass = (rule, value, callback) => {
  111. if (value === "") {
  112. callback(new Error("请输入密码"));
  113. } else if (value.length < 6) {
  114. callback(new Error("密码至少6位"));
  115. } else {
  116. callback();
  117. }
  118. };
  119. return {
  120. channelList: [],
  121. action: "",
  122. disableFlag: false,
  123. phoneFlag: false,
  124. flag: 3,
  125. dialogVisible: false,
  126. //渠道列表
  127. statusList: [
  128. { name: "签约", status: "1" },
  129. { name: "解约", status: "0" },
  130. ],
  131. selfPageList:[
  132. { name: "是", status: "1" },
  133. { name: "否", status: "0" },
  134. ],
  135. ruleForm: {
  136. id: "",
  137. //渠道id
  138. channelId: "",
  139. //渠道名字
  140. channelName:'',
  141. //已使用次数
  142. used:'',
  143. //单次价格
  144. singlePrice:'',
  145. //充值使用次数
  146. rechargeUsed:'',
  147. //剩余次数
  148. unuse:'',
  149. //累计充值次数
  150. rechargeCount:'',
  151. //签约单次金额
  152. signAmount:'',
  153. //有效时间起
  154. effectiveDate:'',
  155. //有效时间止
  156. expirationDate:'',
  157. //签约状态
  158. status:'',
  159. //自定义收尾页
  160. selfPage:'',
  161. //备注
  162. remarks:'',
  163. //背景图地址
  164. background:'',
  165. //海报
  166. poster:'',
  167. isDelete:'0'
  168. },
  169. isView: true,
  170. rules: {
  171. singlePrice: [{ required: true, message: "请输入单次价格", trigger: "blur" }],
  172. used: [{ required: true, message: "请输入已使用次数", trigger: "blur" }],
  173. rechargeUsed: [{ required: true, message: "请输入充值使用次数", trigger: "blur" }],
  174. unuse: [{ required: true, message: "请输入剩余次数", trigger: "blur" }],
  175. rechargeCount: [{ required: true, message: "请输入累计充值次数", trigger: "blur" }],
  176. signAmount: [{ required: true, message: "请输入签约单次金额", trigger: "blur" }],
  177. status: [{ required: true, message: "请输选择状态", trigger: "change" }],
  178. },
  179. };
  180. },
  181. mounted() {
  182. let userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  183. this.ruleForm.parentCode = userInfo.invitationCode;
  184. this.action = basePath + "/file/customUpload";
  185. //获取渠道信息
  186. this.getChannel();
  187. // this.ruleForm.type = "3";
  188. this.getChannel();
  189. },
  190. methods: {
  191. disableFlagStatus() {
  192. setTimeout(() => {
  193. this.disableFlag = false;
  194. }, 1500);
  195. },
  196. getChannel() {
  197. this.$http.get(`/channel/findAll`, {}, (res) => {
  198. // this.$toast.success({message:'成功'});
  199. if (res && res.code == 200) {
  200. //将值赋值给list
  201. this.channelList = res.data;
  202. } else {
  203. this.$message.error(res.msg);
  204. }
  205. });
  206. },
  207. beforeAvatarUpload(file) {
  208. const fileName = file.name;
  209. const fileType = fileName.substring(fileName.lastIndexOf("."));
  210. if (fileType !== ".jpg" && fileType !== ".jpeg" && fileType !== ".png") {
  211. // alert("请上传jpg、jpge或png的图片!");
  212. this.$message.error("请上传jpg、jpge或png的图片!");
  213. return false;
  214. }
  215. return true;
  216. },
  217. //handleAvatarSuccess
  218. //上传成功后的回调
  219. handleAvatarSuccess(data) {
  220. if (data.code == 200) {
  221. this.ruleForm.background = basePath + "/file/show?filePath=" + data.data;
  222. } else {
  223. //失败
  224. }
  225. },
  226. phoneCheck() {
  227. //判断是否重复
  228. this.$http.get(`v1/system/checkPhone/${this.ruleForm.phone}`, {}, (res) => {
  229. // this.$toast.success({message:'成功'});
  230. if (res && res.code == 200) {
  231. if (res.data) {
  232. this.phoneFlag = true;
  233. } else {
  234. this.phoneFlag = false;
  235. // this.$toast.success({ message: "手机号重复" });
  236. this.$message.warning("手机号重复");
  237. }
  238. } else {
  239. // this.$toast.fail({ message: res.msg });
  240. this.$message.error(res.msg);
  241. }
  242. });
  243. },
  244. timeChange(val) {
  245. if (val !== null) {
  246. //根据时间得到格式化的数据
  247. this.ruleForm.birthDate = this.formatterTime(val);
  248. }
  249. },
  250. formatterTime(val) {
  251. let date = new Date(val);
  252. let year = date.getFullYear();
  253. let month = date.getMonth() + 1;
  254. month = this.formatterMon(month);
  255. let day = date.getDate();
  256. day = this.formatterMon(day);
  257. return year + "-" + month + "-" + day;
  258. },
  259. formatterMon(val) {
  260. if (val < 10) {
  261. return "0" + val;
  262. } else {
  263. return val;
  264. }
  265. },
  266. open(val) {
  267. this.cancle();
  268. this.dialogVisible = true;
  269. this.isView = val;
  270. this.$nextTick(() => {
  271. this.$refs["ruleForm"].clearValidate();
  272. });
  273. },
  274. edit(val) {
  275. this.dialogVisible = true;
  276. this.isView = false;
  277. this.ruleForm.id=val.id;
  278. this.ruleForm.channelId=val.channelId;
  279. this.ruleForm.channelName=val.channelName;
  280. this.ruleForm.used=val.used;
  281. this.ruleForm.singlePrice=val.singlePrice;
  282. this.ruleForm.rechargeUsed=val.rechargeUsed;
  283. this.ruleForm.unuse=val.unuse;
  284. this.ruleForm.rechargeCount=val.rechargeCount;
  285. this.ruleForm.signAmount=val.signAmount;
  286. this.ruleForm.effectiveDate=val.effectiveDate;
  287. this.ruleForm.expirationDate=val.expirationDate;
  288. this.ruleForm.status=val.status;
  289. this.ruleForm.selfPage=val.selfPage;
  290. this.ruleForm.remarks=val.remarks;
  291. this.ruleForm.background=val.background;
  292. this.ruleForm.poster=val.poster;
  293. },
  294. cancle() {
  295. //清空表单
  296. this.ruleForm.id=''
  297. this.ruleForm.channelId=''
  298. this.ruleForm.channelName=''
  299. this.ruleForm.used=''
  300. this.ruleForm.singlePrice=''
  301. this.ruleForm.rechargeUsed=''
  302. this.ruleForm.unuse=''
  303. this.ruleForm.rechargeCount=''
  304. this.ruleForm.signAmount=''
  305. this.ruleForm.effectiveDate=''
  306. this.ruleForm.expirationDate=''
  307. this.ruleForm.status=''
  308. this.ruleForm.selfPage=''
  309. this.ruleForm.remarks=''
  310. this.ruleForm.background=''
  311. this.ruleForm.poster=''
  312. this.$refs["ruleForm"].clearValidate();
  313. this.dialogVisible = false;
  314. },
  315. submitCom() {
  316. if (this.disableFlag) {
  317. return;
  318. }
  319. this.disableFlag = true;
  320. this.$refs["ruleForm"].validate((valid) => {
  321. if (valid) {
  322. //判断是编辑还是新增
  323. if (this.isView) {
  324. this.register();
  325. } else {
  326. this.editUserFun();
  327. }
  328. //都校验通过后可以触发注册接口了
  329. //调用方法进行入参
  330. }else{
  331. this.disableFlagStatus()
  332. }
  333. });
  334. },
  335. getChannelName(){
  336. if(this.ruleForm.channelId==''){
  337. this.ruleForm.channelName=''
  338. }else{
  339. for(let i=0;i<this.channelList.length;i++){
  340. if(this.ruleForm.channelId==this.channelList[i].id){
  341. this.ruleForm.channelName=this.channelList[i].name;
  342. }
  343. }
  344. }
  345. },
  346. register() {
  347. this.getChannelName();
  348. let that = this;
  349. this.$http.post(
  350. `/sign/save`,
  351. {
  352. channelId: this.ruleForm.channelId,
  353. channelName: this.ruleForm.channelName,
  354. singlePrice: this.ruleForm.singlePrice,
  355. used:this.ruleForm.singlePrice,
  356. unuse:this.ruleForm.unuse,
  357. rechargeUsed:this.ruleForm.rechargeUsed,
  358. rechargeCount:this.ruleForm.rechargeCount,
  359. signAmount:this.ruleForm.signAmount,
  360. effectiveDate:this.ruleForm.effectiveDate,
  361. expirationDate:this.ruleForm.expirationDate,
  362. status:this.ruleForm.status,
  363. selfPage:this.ruleForm.selfPage,
  364. remarks:this.ruleForm.remarks,
  365. background:this.ruleForm.background,
  366. poster:this.ruleForm.poster,
  367. // ...this.ruleForm, //解构对象
  368. },
  369. (res) => {
  370. this.disableFlagStatus()
  371. if (res && res.code == 200) {
  372. this.dialogVisible = false;
  373. this.$message.success(res.msg);
  374. // this.$toast.success({ message: "成功" });
  375. //调用父组件的查询方法
  376. that.$emit("search");
  377. } else {
  378. // this.$toast.fail({ message: res.msg });
  379. this.$message.error(res.msg);
  380. }
  381. //清空缓存
  382. this.cancle();
  383. }
  384. );
  385. },
  386. editUserFun() {
  387. this.getChannelName();
  388. let that = this;
  389. this.$http.post(
  390. `/sign/save`,
  391. {
  392. ...this.ruleForm,
  393. // ...this.ruleForm, //解构对象
  394. },
  395. (res) => {
  396. this.disableFlagStatus()
  397. if (res && res.code == 200) {
  398. this.dialogVisible = false;
  399. // this.$toast.success({ message: "成功" });
  400. //调用父组件的查询方法
  401. that.$emit("search");
  402. this.$message.success("修改成功");
  403. } else {
  404. // this.$toast.fail({ message: res.msg });
  405. this.$message.error(res.msg);
  406. }
  407. //清空缓存
  408. }
  409. );
  410. },
  411. },
  412. };
  413. </script>
  414. <style>
  415. .el-date-picker__editor-wrap>>> .el-input{
  416. width:auto !important
  417. }
  418. .el-date-picker__editor-wrap>>> .el-input__inner{
  419. width:auto !important
  420. }
  421. </style>
  422. <style scoped>
  423. .inputCom {
  424. width: 200px;
  425. }
  426. .avatar-uploader .el-upload {
  427. border: 1px dashed #d9d9d9;
  428. border-radius: 6px;
  429. cursor: pointer;
  430. position: relative;
  431. overflow: hidden;
  432. }
  433. .avatar-uploader .el-upload:hover {
  434. border-color: #409eff;
  435. }
  436. .avatar-uploader-icon {
  437. font-size: 28px;
  438. color: #8c939d;
  439. width: 178px;
  440. height: 178px;
  441. line-height: 178px;
  442. text-align: center;
  443. border: 1px solid;
  444. }
  445. .avatar {
  446. width: 178px;
  447. height: 178px;
  448. display: block;
  449. }
  450. </style>