PriceRegister.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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="title">
  20. <el-input
  21. v-model="ruleForm.title"
  22. class="inputCom"
  23. placeholder="请输入标题"
  24. ></el-input>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  28. <el-form-item label="价格" prop="price">
  29. <el-input-number
  30. v-model="ruleForm.price"
  31. class="inputCom"
  32. placeholder="请输入价格"
  33. ></el-input-number>
  34. </el-form-item>
  35. </el-col>
  36. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  37. <el-form-item label="次数起始(包含)" prop="beginNum">
  38. <el-input-number
  39. v-model="ruleForm.beginNum"
  40. class="inputCom"
  41. placeholder="请输入次数起始"
  42. ></el-input-number>
  43. </el-form-item>
  44. </el-col>
  45. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  46. <el-form-item label="次数结束(包含)" prop="endNum">
  47. <el-input-number
  48. v-model="ruleForm.endNum"
  49. class="inputCom"
  50. placeholder="请输入次数结束"
  51. ></el-input-number>
  52. </el-form-item>
  53. </el-col>
  54. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  55. <el-form-item label="状态" prop="status">
  56. <el-select v-model="ruleForm.status" placeholder="请选择状态">
  57. <el-option
  58. :label="item.name"
  59. :value="item.state"
  60. v-for="item in stateList"
  61. :key="item.state"
  62. ></el-option>
  63. </el-select>
  64. </el-form-item>
  65. </el-col>
  66. <el-col :xs="24" :sm="24" :md="12" :lg="12" :xl="12">
  67. <el-form-item label="渠道级别" prop="channelLevel ">
  68. <el-select v-model="ruleForm.channelLevel" placeholder="请选择渠道级别">
  69. <el-option
  70. :label="item.name"
  71. :value="item.level"
  72. v-for="item in channelLevelList"
  73. :key="item.level"
  74. ></el-option>
  75. </el-select>
  76. </el-form-item>
  77. </el-col>
  78. </el-row>
  79. </el-form>
  80. <span slot="footer" class="dialog-footer">
  81. <el-button @click="cancle" round>取 消</el-button>
  82. <el-button
  83. v-show="isView"
  84. type="primary"
  85. round
  86. :disabled="disableFlag"
  87. @click="submitCom"
  88. >确 定</el-button
  89. >
  90. <el-button
  91. v-show="!isView"
  92. type="primary"
  93. round
  94. :disabled="disableFlag"
  95. @click="submitCom"
  96. >修 改</el-button
  97. >
  98. </span>
  99. </el-dialog>
  100. </div>
  101. </template>
  102. <script>
  103. // import { oSessionStorage } from "../../utils/utils";
  104. import { oSessionStorage } from "../utils/utils";
  105. import { basePath } from "../utils/http";
  106. import md5 from "md5";
  107. export default {
  108. data() {
  109. var validatePass = (rule, value, callback) => {
  110. if (value === "") {
  111. callback(new Error("请输入密码"));
  112. } else if (value.length < 6) {
  113. callback(new Error("密码至少6位"));
  114. } else {
  115. callback();
  116. }
  117. };
  118. var validatePhone = (rule, value, callback) => {
  119. let myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
  120. if (value === "") {
  121. callback(new Error("请输入手机号"));
  122. } else if (!myreg.test(value)) {
  123. callback(new Error("请输入正确格式"));
  124. } else {
  125. callback();
  126. }
  127. };
  128. return {
  129. action: "",
  130. disableFlag: false,
  131. phoneFlag: false,
  132. flag: 3,
  133. dialogVisible: false,
  134. //渠道列表
  135. stateList: [
  136. { name: "生效中", state: "1" },
  137. { name: "已停用", state: "0" },
  138. ],
  139. //渠道级别
  140. channelLevelList: [
  141. { name: "级别1", level: "1" },
  142. { name: "级别2", level: "2" },
  143. ],
  144. ruleForm: {
  145. id: "",
  146. //标题
  147. title: "",
  148. //价格
  149. price: "",
  150. //起始次数
  151. beginNum: "",
  152. //结束次数
  153. endNum: "",
  154. //状态
  155. status: "",
  156. //渠道级别
  157. channelLevel: "",
  158. },
  159. isView: true,
  160. rules: {
  161. title: [{ required: true, message: "请输入标题", trigger: "blur" }],
  162. price: [{ required: true, message: "请输入价格", trigger: "blur" }],
  163. beginNum: [{ required: true, message: "请输入起始次数", trigger: "blur" }],
  164. endNum: [{ required: true, message: "请输入结束次数", trigger: "blur" }],
  165. status: [{ required: true, message: "请选择状态", trigger: "change" }],
  166. },
  167. };
  168. },
  169. mounted() {
  170. let userInfo = JSON.parse(oSessionStorage.getItem("userInfo"));
  171. this.ruleForm.parentCode = userInfo.invitationCode;
  172. this.action = basePath + "/file/customUpload";
  173. //获取到router 传输过来的信息
  174. this.ruleForm.channelId = this.$route.query.channelId;
  175. //获取渠道信息
  176. // this.ruleForm.type = "3";
  177. },
  178. methods: {
  179. disableFlagStatus() {
  180. setTimeout(() => {
  181. this.disableFlag = false;
  182. }, 1500);
  183. },
  184. beforeAvatarUpload(file) {
  185. const fileName = file.name;
  186. const fileType = fileName.substring(fileName.lastIndexOf("."));
  187. if (fileType !== ".jpg" && fileType !== ".jpeg" && fileType !== ".png") {
  188. // alert("请上传jpg、jpge或png的图片!");
  189. this.$message.error("请上传jpg、jpge或png的图片!");
  190. return false;
  191. }
  192. return true;
  193. },
  194. //handleAvatarSuccess
  195. //上传成功后的回调
  196. handleAvatarSuccess(data) {
  197. if (data.code == 200) {
  198. this.ruleForm.avatar = basePath + "/file/show?filePath=" + data.data;
  199. console.log(basePath + "/file/show?filePath=" + data.data);
  200. } else {
  201. //失败
  202. }
  203. },
  204. phoneCheck() {
  205. //判断是否重复
  206. this.$http.get(`v1/system/checkPhone/${this.ruleForm.phone}`, {}, (res) => {
  207. // this.$toast.success({message:'成功'});
  208. if (res && res.code == 200) {
  209. if (res.data) {
  210. this.phoneFlag = true;
  211. } else {
  212. this.phoneFlag = false;
  213. // this.$toast.success({ message: "手机号重复" });
  214. this.$message.warning("手机号重复");
  215. }
  216. } else {
  217. // this.$toast.fail({ message: res.msg });
  218. this.$message.error(res.msg);
  219. }
  220. });
  221. },
  222. timeChange(val) {
  223. if (val !== null) {
  224. //根据时间得到格式化的数据
  225. this.ruleForm.birthDate = this.formatterTime(val);
  226. }
  227. },
  228. formatterTime(val) {
  229. let date = new Date(val);
  230. let year = date.getFullYear();
  231. let month = date.getMonth() + 1;
  232. month = this.formatterMon(month);
  233. let day = date.getDate();
  234. day = this.formatterMon(day);
  235. return year + "-" + month + "-" + day;
  236. },
  237. formatterMon(val) {
  238. if (val < 10) {
  239. return "0" + val;
  240. } else {
  241. return val;
  242. }
  243. },
  244. open(val) {
  245. this.cancle();
  246. this.dialogVisible = true;
  247. this.isView = val;
  248. this.$nextTick(() => {
  249. this.$refs["ruleForm"].clearValidate();
  250. });
  251. },
  252. edit(val) {
  253. this.dialogVisible = true;
  254. this.isView = false;
  255. this.ruleForm.id = val.id;
  256. this.ruleForm.title = val.title;
  257. this.ruleForm.price = val.price;
  258. this.ruleForm.beginNum = val.beginNum;
  259. this.ruleForm.endNum = val.endNum;
  260. this.ruleForm.status = val.status;
  261. this.ruleForm.channelLevel = val.channelLevel;
  262. console.log(val.channelLevel)
  263. },
  264. cancle() {
  265. //清空表单
  266. this.ruleForm.id = "";
  267. this.ruleForm.title = "";
  268. this.ruleForm.price = "";
  269. this.ruleForm.beginNum = "";
  270. this.ruleForm.endNum = "";
  271. this.ruleForm.status = "";
  272. this.ruleForm.channelLevel = "";
  273. this.$refs["ruleForm"].clearValidate();
  274. this.dialogVisible = false;
  275. },
  276. submitCom() {
  277. if (this.disableFlag) {
  278. return;
  279. }
  280. this.disableFlag = true;
  281. this.$refs["ruleForm"].validate((valid) => {
  282. if (valid) {
  283. this.disableFlag=true;
  284. //判断是编辑还是新增
  285. if (this.isView) {
  286. this.register();
  287. } else {
  288. this.editUserFun();
  289. }
  290. //都校验通过后可以触发注册接口了
  291. //调用方法进行入参
  292. }else{
  293. this.disableFlagStatus()
  294. }
  295. });
  296. },
  297. register() {
  298. let that = this;
  299. this.$http.post(
  300. `/price/save`,
  301. {
  302. title: this.ruleForm.title,
  303. price: this.ruleForm.price,
  304. beginNum: this.ruleForm.beginNum,
  305. endNum: this.ruleForm.endNum,
  306. status : this.ruleForm.status ,
  307. channelLevel: this.ruleForm.channelLevel,
  308. // ...this.ruleForm, //解构对象
  309. },
  310. (res) => {
  311. this.disableFlagStatus()
  312. if (res && res.code == 200) {
  313. this.dialogVisible = false;
  314. this.$message.success(res.msg);
  315. // this.$toast.success({ message: "成功" });
  316. //调用父组件的查询方法
  317. that.$emit("search");
  318. } else {
  319. // this.$toast.fail({ message: res.msg });
  320. this.$message.error(res.msg);
  321. }
  322. //清空缓存
  323. this.cancle();
  324. }
  325. );
  326. },
  327. editUserFun() {
  328. let that = this;
  329. this.$http.post(
  330. `/price/update`,
  331. {
  332. ...this.ruleForm,
  333. // ...this.ruleForm, //解构对象
  334. },
  335. (res) => {
  336. this.disableFlagStatus()
  337. if (res && res.code == 200) {
  338. this.dialogVisible = false;
  339. // this.$toast.success({ message: "成功" });
  340. //调用父组件的查询方法
  341. that.$emit("search");
  342. this.$message.success("修改成功");
  343. } else {
  344. // this.$toast.fail({ message: res.msg });
  345. this.$message.error(res.msg);
  346. }
  347. //清空缓存
  348. }
  349. );
  350. },
  351. },
  352. };
  353. </script>
  354. <style scoped>
  355. .inputCom {
  356. width: 200px;
  357. }
  358. .avatar-uploader .el-upload {
  359. border: 1px dashed #d9d9d9;
  360. border-radius: 6px;
  361. cursor: pointer;
  362. position: relative;
  363. overflow: hidden;
  364. }
  365. .avatar-uploader .el-upload:hover {
  366. border-color: #409eff;
  367. }
  368. .avatar-uploader-icon {
  369. font-size: 28px;
  370. color: #8c939d;
  371. width: 178px;
  372. height: 178px;
  373. line-height: 178px;
  374. text-align: center;
  375. border: 1px solid;
  376. }
  377. .avatar {
  378. width: 178px;
  379. height: 178px;
  380. display: block;
  381. }
  382. </style>