You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

289 lines
9.3 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div>
  3. <el-form :model="form" ref="form" label-width="70px" :rules="rules" style="margin-top: -10px;">
  4. <el-row>
  5. <el-col :span="12">
  6. <el-form-item prop="displayName" label="联系人">
  7. <el-input v-model="form.displayName" size="small"></el-input>
  8. </el-form-item>
  9. </el-col>
  10. <el-col :span="12">
  11. <el-form-item label="职务">
  12. <el-input v-model="form.title" size="small"></el-input>
  13. </el-form-item>
  14. </el-col>
  15. <el-col :span="24">
  16. <el-form-item label="备注">
  17. <el-input type="textarea" v-model="form.remark" size="small" maxlength="50" show-word-limit></el-input>
  18. </el-form-item>
  19. </el-col>
  20. </el-row>
  21. <el-row>
  22. <el-col :span="5">
  23. <el-form-item label="创建者">
  24. <el-input v-model="form.creatorName" disabled size="small"></el-input>
  25. </el-form-item>
  26. </el-col>
  27. <el-col :span="7">
  28. <el-form-item label="创建时间" label-width="80px" style="margin-left:-10px;">
  29. <el-date-picker v-model="form.creationTime" type="datetime" size="small" style="width: 100%" disabled />
  30. </el-form-item>
  31. </el-col>
  32. <el-col :span="5">
  33. <el-form-item label="修改者">
  34. <el-input v-model="form.creatorName" disabled size="small"></el-input>
  35. </el-form-item>
  36. </el-col>
  37. <el-col :span="7">
  38. <el-form-item label="修改时间" label-width="80px" style="margin-left:-10px;">
  39. <el-date-picker v-model="form.lastModificationTime" type="datetime" size="small" style="width: 100%"
  40. disabled />
  41. </el-form-item>
  42. </el-col>
  43. </el-row>
  44. <el-table :data="contactMethodList" border height="300" row-key="id" size="small" highlight-current-row
  45. ref="contactMethod" style="margin-top: 20px;">
  46. <el-table-column prop="contactMethodType" label="类型" width="200">
  47. <template slot-scope="scope">
  48. <el-select v-model="scope.row.contactMethodType" size="small">
  49. <el-option v-for="item in Methodtypes" :key="item.value" :label="item.label" :value="item.value" />
  50. </el-select>
  51. </template>
  52. </el-table-column>
  53. <el-table-column prop="contactMethodValue" label="联系方式">
  54. <template slot-scope="scope">
  55. <el-input v-model="scope.row.contactMethodValue" required size="small" />
  56. </template>
  57. </el-table-column>
  58. <el-table-column fixed="right" label="操作" width="60" align="center">
  59. <template slot-scope="scope">
  60. <i class="el-icon-delete" @click="deleteRow(scope.$index)"
  61. style="font-size: 24px;color: red;cursor:pointer;"></i>
  62. </template>
  63. </el-table-column>
  64. </el-table>
  65. </el-form>
  66. <div style="display: flex;justify-content: space-between;margin-top: 10px;">
  67. <div></div>
  68. <div>
  69. <el-button class="commonbutton" @click="dialogContactPerson = false"> </el-button>
  70. <el-button type="success" class="commonbutton" @click="addMethod">新增联系方式</el-button>
  71. <el-button type="primary" class="commonbutton" @click="submit('form')"> </el-button>
  72. </div>
  73. </div>
  74. </div>
  75. </template>
  76. <script>
  77. import moment from "moment";
  78. import { mapState } from "vuex";
  79. import { getapi, postapi, putapi, deletapi } from "@/api/api";
  80. import { getPagePriv, checkPagePriv, objCopy, deepCopy, arrayExistObj } from "../../utlis/proFunc";
  81. export default {
  82. components: {},
  83. props: ["refFunc"],
  84. data() {
  85. return {
  86. pagePriv: {
  87. routeUrlorPageName: 'customerOrg', //当前页面归属路由或归属页面权限名称
  88. privs: [] // 页面权限
  89. },
  90. form: { //联系人表单信息
  91. id: "",
  92. customerOrgId:'',
  93. creationTime: null,
  94. lastModificationTime: null,
  95. creatorName: "",
  96. lastModifierName: "",
  97. displayName: "",
  98. title: "",
  99. remark: "",
  100. },
  101. formInit:{},
  102. contactMethodList: [], //联系方式(可修改)
  103. Methodtypes: [
  104. //{ value: '',label: '所有订单状态' },
  105. { value: "0", label: "电话" },
  106. { value: "1", label: "邮箱" },
  107. ],
  108. rules: {
  109. displayName: [
  110. { required: true, message: "请输入名称", trigger: "blur" },
  111. ],
  112. },
  113. };
  114. },
  115. created() {
  116. //获取用户当前页面的权限
  117. let userPriv = window.sessionStorage.getItem('userPriv')
  118. if (userPriv) this.pagePriv.privs = deepCopy(getPagePriv(this.pagePriv.routeUrlorPageName))
  119. this.formInit = deepCopy(this.form)
  120. },
  121. //挂载完成
  122. mounted() {
  123. this.getFormData(this.dataTransOpts.tableS.contact_person.id)
  124. },
  125. computed: {
  126. ...mapState(["window", "customerOrg","dialogWin", "dataTransOpts"]),
  127. },
  128. methods: {
  129. moment, checkPagePriv,
  130. // 获取表单数据
  131. getFormData(id){
  132. if(!id){
  133. this.form = deepCopy(this.formInit)
  134. this.form.customerOrgId = this.dataTransOpts.tableS.customer_org.id
  135. this.contactMethodList = []
  136. return
  137. }
  138. getapi(`/api/app/contact-person/${id}`)
  139. .then(res =>{
  140. if(res.code != -1){
  141. this.form = deepCopy(res.data)
  142. this.getContactMethodList(res.data.id)
  143. }
  144. })
  145. },
  146. //获取联系方式列表
  147. //api/app/contact-method/in-contact-person-id?ContactPersonId=3a0c08ad-4304-138b-d9e6-a7338739dfc4' \
  148. getContactMethodList(ContactPersonId) {
  149. if (!ContactPersonId) {
  150. this.contactMethodList = []
  151. return
  152. }
  153. getapi("/api/app/contact-method/in-contact-person-id", {
  154. ContactPersonId,
  155. }).then(res => {
  156. //console.log('res.data',res.data)
  157. if(res.code != -1) this.contactMethodList = res.data;
  158. });
  159. },
  160. //删除联系方式行
  161. deleteRow(index) {
  162. this.$confirm("此操作确定后将永久删除该记录, 是否继续?", "提示", {
  163. confirmButtonText: "是",
  164. cancelButtonText: "否",
  165. type: "warning",
  166. }).then(() => {
  167. this.contactMethodList.splice(index, 1);
  168. //this.submit('form');
  169. }).catch((err) => {
  170. if (err == 'cancel') {
  171. this.$message.info("已取消删除");
  172. }
  173. });
  174. },
  175. //联系人信息提交
  176. submit(formName) {
  177. let body = {
  178. customerOrgId: "",
  179. displayName: "",
  180. title: "",
  181. remark: "",
  182. };
  183. this.$refs[formName].validate((valid, fields) => {
  184. if (!valid) {
  185. this.$message.warning(fields[Object.keys(fields)[0]][0].message);
  186. return false;
  187. }
  188. objCopy(this.form, body);
  189. let contactMethod = {
  190. contactPersonId: this.form.id,
  191. details:this.contactMethodList
  192. }
  193. console.log("body,contactMethod", body,contactMethod);
  194. if (!this.form.id) {
  195. postapi("/api/app/contact-person", body)
  196. .then((res) => {
  197. //console.log('api/app/contact-person')
  198. if (res.code != -1) {
  199. this.form = res.data
  200. this.dataTransOpts.tableS.contact_person.id = res.data.id
  201. this.refFunc(['curChooseRow'],res.data)
  202. contactMethod.contactPersonId = res.data.id
  203. return postapi('/api/app/contactmethod/createmany',contactMethod);
  204. }
  205. })
  206. .then((res) => {
  207. //console.log('api/app/contact-method/many')
  208. if (res && res.code != -1) {
  209. console.log("操作成功!");
  210. this.dialogWin.ContactPersonEdit = false
  211. }
  212. });
  213. } else {
  214. putapi(`/api/app/contact-person/${this.form.id}`, body)
  215. .then((res) => {
  216. if (res.code != -1) {
  217. this.refFunc(['curChooseRow'],this.form)
  218. return postapi('/api/app/contactmethod/createmany',contactMethod);
  219. }
  220. })
  221. .then((res) => {
  222. //console.log('api/app/contact-method/many')
  223. //this.getContactPersonList(this.customerOrgId); //改成局部刷新
  224. if (res && res.code != -1) {
  225. console.log("操作成功!");
  226. this.dialogWin.ContactPersonEdit = false
  227. }
  228. });
  229. }
  230. })
  231. },
  232. //新增联系方式
  233. addMethod() {
  234. this.contactMethodList.push({
  235. contactMethodValue: "",
  236. contactMethodType: "0",
  237. contactPersonId: this.form.id,
  238. });
  239. },
  240. },
  241. watch: {
  242. // 单位id未变时,强制刷新
  243. "dataTransOpts.refresh.contact_person.S": {
  244. // immediate: true,
  245. handler(newVal, oldVal) {
  246. console.log(`watch 联系人 newVal:${newVal} oldVal:${oldVal} customerOrgId: ${this.dataTransOpts.tableS.contact_person.id}`);
  247. this.getFormData(this.dataTransOpts.tableS.contact_person.id)
  248. }
  249. },
  250. // 'customerOrgId' (newVal,oldVal){
  251. // console.log('watch customerOrgId',newVal,oldVal)
  252. // if(newVal != oldVal){
  253. // this.personId = ''
  254. // }
  255. // }
  256. },
  257. };
  258. </script>
  259. <style scoped>
  260. @import '../../assets/css/global_table.css';
  261. @import '../../assets/css/global_input.css';
  262. @import '../../assets/css/global_form.css';
  263. @import '../../assets/css/global_dialog.css';
  264. .btnClass {
  265. width: 110px;
  266. }
  267. </style>