ReportRegister.vue 13 KB

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