FiccServiceTable.vue 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. <script setup>
  2. import { ref,watch } from "vue";
  3. const props = defineProps({
  4. serviceData: {
  5. type:Array,
  6. default:()=>[]
  7. },
  8. hasSercive: {
  9. type:Array,
  10. default:()=>[]
  11. },
  12. canEdit: false,
  13. editValue: {},
  14. contractType:null,
  15. isEdit:false // 是新增合同还是修改合同
  16. });
  17. const emits=defineEmits(['handleShowService'])
  18. const tableData=ref([])
  19. watch(()=>props.editValue,(nval, oval)=>{
  20. if (nval.ServiceTemplateId) {
  21. tableData.value.forEach((item) => {
  22. if (item.ServiceTemplateId === nval.ServiceTemplateId) {
  23. item.Value = nval.Value;
  24. // item 表格数据 nval 更新的数据
  25. // 更新表头 item.Detail[0]
  26. console.log([nval.tableHeadData,...nval.tableData]);
  27. let arr=[nval.tableHeadData,...nval.tableData].map((item2,index2)=>{
  28. let obj={}
  29. item2.forEach((item3,index3)=>{
  30. let key=`Col${index3+1}`
  31. obj={...obj,[key]:JSON.stringify(item3)}
  32. })
  33. return obj
  34. })
  35. console.log(arr);
  36. item.Detail=arr
  37. }
  38. });
  39. }
  40. })
  41. // 初始化数据
  42. const initTableData=()=>{
  43. if (props.serviceData.length === 0) return;
  44. let arr = props.serviceData.map((item, index) => {
  45. return {
  46. ...item,
  47. selected: false,
  48. disable: false,
  49. text1: item.Detail ? "选择品种" : "查看报价单",
  50. text2: "下载报价单",
  51. };
  52. });
  53. // 合同详情或者是需要编辑情况下
  54. if (props.hasSercive.length !== 0) {
  55. arr.forEach((item) => {
  56. props.hasSercive.forEach((e) => {
  57. if (e.ServiceTemplateId === item.ServiceTemplateId) {
  58. item.Value = e.Value;
  59. item.Detail = e.DetailList || e.Detail;
  60. item.selected = true;
  61. item.disable = false;
  62. }
  63. if (item.SelectType === "radio" && e.ServiceTemplateId !== item.ServiceTemplateId) {
  64. if (!item.selected) {
  65. item.disable = false;
  66. }
  67. }
  68. });
  69. });
  70. // 合同详情 全部禁用
  71. if (!props.canEdit) {
  72. arr.forEach((item) => {
  73. item.disable = true;
  74. // 如果是小套餐类型 即存在Detail 则将选择品种改为查看报价单
  75. if (item.Detail) {
  76. item.text1 = "查看报价单";
  77. }
  78. });
  79. }
  80. // this.tableData = arr;
  81. } else {
  82. // 新增 默认选择第一个
  83. // arr.forEach((item, index) => {
  84. // if (index === 0) {
  85. // item.selected = true;
  86. // }
  87. // });
  88. //如果第一个是单选的 则将其他的禁用
  89. // if (arr[0] && arr[0].SelectType === "radio") {
  90. // arr.forEach((item) => {
  91. // if (item.ServiceTemplateId !== arr[0].ServiceTemplateId && item.SelectName === arr[0].SelectName) {
  92. // item.disable = true;
  93. // item.selected = false;
  94. // }
  95. // });
  96. // }
  97. }
  98. if(props.contractType==='补充协议'){
  99. arr.forEach(item=>{
  100. //大套餐 禁用
  101. if(item.ServiceTemplateId===1){
  102. item.disable=true
  103. item.selected=false
  104. }else{
  105. item.disable=false
  106. }
  107. })
  108. }
  109. tableData.value = arr;
  110. }
  111. // 一开始进来 serviceData数据为空数组
  112. watch(()=>props.serviceData,()=>{
  113. initTableData();
  114. },
  115. {immediate:true,deep:true})
  116. watch(()=>props.contractType,(nval)=>{
  117. initTableData();
  118. if(nval==='补充协议'){
  119. tableData.value.forEach(item=>{
  120. //大套餐 禁用
  121. if(item.ServiceTemplateId===1){
  122. item.disable=true
  123. item.selected=false
  124. }else{
  125. item.disable=false
  126. }
  127. // 需求更改,新增合同类型为"补充协议的时候",不默认勾选宏观经济
  128. // 将默认的勾选的宏观经济去除
  129. if(item.ServiceTemplateId===2 && !props.isEdit){
  130. for (let i = 0; i < item.Detail.slice(3,6).length; i++) {
  131. let temp = JSON.parse(item.Detail.slice(3,6)[i].Col2)
  132. temp.ValueId.length=0
  133. temp.Value=""
  134. item.Detail.slice(3,6)[i].Col2 = JSON.stringify(temp)
  135. }
  136. }
  137. })
  138. }else{
  139. // 如果一个都没选中过 则重置都为非禁用
  140. let flag=0
  141. tableData.value.forEach(item=>{
  142. if(item.selected){
  143. flag++
  144. }
  145. // "补充协议"切换会其他合同类型时,恢复默认,即勾选宏观经济的状态
  146. if(item.ServiceTemplateId===2 && !props.isEdit){
  147. for (let i = 0; i < item.Detail.slice(3,6).length; i++) {
  148. let temp = JSON.parse(item.Detail.slice(3,6)[i].Col2)
  149. if(temp.ValueId.length===0){
  150. temp.ValueId[0]=1
  151. temp.Value="宏观经济"
  152. item.Detail.slice(3,6)[i].Col2 = JSON.stringify(temp)
  153. }
  154. }
  155. }
  156. })
  157. if(flag==0){
  158. tableData.value.forEach(item=>{
  159. item.disable=false
  160. })
  161. }
  162. }
  163. })
  164. // 选项切换
  165. const handleChange=(e)=>{
  166. if (e.SelectType === "radio") {
  167. if (e.selected) {
  168. tableData.value.forEach((item) => {
  169. if (item.ServiceTemplateId !== e.ServiceTemplateId && item.SelectName === e.SelectName) {
  170. item.disable = true;
  171. item.selected = false;
  172. }
  173. });
  174. // 如果是小套餐则 主动展示弹窗
  175. if(e.Detail&&e.Detail.length){
  176. handleShow(e)
  177. }
  178. } else {
  179. tableData.value.forEach((item) => {
  180. if (item.ServiceTemplateId !== e.ServiceTemplateId && item.SelectName === e.SelectName) {
  181. // 如果选择了补充协议 则大套餐仍然不可选
  182. if(props.contractType==='补充协议'&&item.ServiceTemplateId===1){
  183. item.disable=true
  184. item.selected=false
  185. }else{
  186. item.disable = false;
  187. item.selected = false;
  188. }
  189. }
  190. });
  191. }
  192. }
  193. }
  194. //下载报价单
  195. const handleDownloadImg=(e)=>{
  196. let link = document.createElement("a");
  197. //判断e.Value是否以 http开头
  198. if (e.Value.startsWith("http")) {
  199. link.href = e.Value + "?response-content-type=application/octet-stream"; //下载链接
  200. } else {
  201. link.href = e.Value;
  202. }
  203. link.setAttribute("download", e.Title);
  204. link.style.display = "none"; //a标签隐藏
  205. document.body.appendChild(link);
  206. link.click();
  207. }
  208. const handleShow=(e)=>{
  209. emits("handleShowService", e);
  210. }
  211. defineExpose({
  212. tableData
  213. })
  214. </script>
  215. <template>
  216. <el-table border :data="tableData" style="width: 601px">
  217. <el-table-column label="套餐类型" width="200" align="center">
  218. <template #default="scope">
  219. <el-checkbox
  220. @change="handleChange(scope.row)"
  221. :label="scope.row.Title"
  222. v-model="scope.row.selected"
  223. :disabled="scope.row.disable"
  224. style="width: 100%; text-align: left; padding-left: 50px"
  225. ></el-checkbox>
  226. </template>
  227. </el-table-column>
  228. <el-table-column width="200">
  229. <template #default="scope">
  230. <span style="cursor: pointer; color: #409eff; padding-left: 50px" v-if="scope.row.selected" @click="handleShow(scope.row)">{{ scope.row.text1 }}</span>
  231. </template>
  232. </el-table-column>
  233. <el-table-column width="200" align="center">
  234. <template #default="scope">
  235. <span style="cursor: pointer; color: #409eff" v-if="scope.row.selected && scope.row.Value" @click="handleDownloadImg(scope.row)">{{ scope.row.text2 }}</span>
  236. </template>
  237. </el-table-column>
  238. </el-table>
  239. </template>
  240. <style></style>