updCodeW.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. <template>
  2. <div class="updCodeWBox" v-loading="loading" :element-loading-text="loadingStr">
  3. <!-- <div class="updCodeWBox-title">
  4. <p>弱歸戶</p>
  5. </div>
  6. <el-divider border-style="dashed" /> -->
  7. <div style="line-height: 1px;height: 100%;overflow: auto;">
  8. <div style="margin-bottom: 10px;">
  9. <h3>區域</h3>
  10. <el-radio-group class="radioSty" v-model="countryId" @change="cIdChange">
  11. <el-radio label="CN" size="large" border>大陆地区</el-radio>
  12. <el-radio label="TW" size="large" border>臺灣地區</el-radio>
  13. </el-radio-group>
  14. </div>
  15. <div style="margin-bottom: 10px;" v-if="provinceIdData != null">
  16. <h3>省/直轄市</h3>
  17. <el-radio-group class="radioSty" v-model="provinceId" @change="pIdChange">
  18. <el-radio size="large" :label="p.provinceId" border v-for="p in provinceIdData">{{ p.provinceName }}</el-radio>
  19. </el-radio-group>
  20. </div>
  21. <div style="margin-bottom: 10px;" v-if="cityIdData != null">
  22. <h3>市/界</h3>
  23. <el-radio-group class="radioSty" v-model="cityId">
  24. <el-radio size="large" :label="c.cityId" border v-for="c in cityIdData" @click="searchSchool(c.cityId)">{{ c.cityName }}</el-radio>
  25. </el-radio-group>
  26. </div>
  27. <div style="margin-bottom: 10px;margin-top: 70px;">
  28. <div style="display: flex;justify-content: center;align-items: center;">
  29. <span style="font-weight: bold;font-size: 23px;margin-right: 5px;">搜尋</span>
  30. <el-input v-model="wordFilter" placeholder="請填入簡碼或學校名稱" style="width: 500px;"/>
  31. </div>
  32. <el-table :data="showData" stripe style="width: 100%" >
  33. <el-table-column prop="code" label="代碼" />
  34. <el-table-column prop="shortCode" label="簡碼" />
  35. <el-table-column prop="name" label="學校名稱" />
  36. <el-table-column label="">
  37. <template #default="scope">
  38. <el-button type="primary" size="small" @click="handleUpdSchoolW(scope.row.id, scope.row.name, scope.row.shortCode)">歸戶</el-button>
  39. </template>
  40. </el-table-column>
  41. </el-table>
  42. </div>
  43. </div>
  44. </div>
  45. </template>
  46. <script setup>
  47. import country from '@/static/country.json'
  48. import { h, reactive, ref, computed, getCurrentInstance, markRaw } from 'vue'
  49. import { SuccessFilled, Warning } from '@element-plus/icons'
  50. import { ElMessageBox, ElMessage, ElInput, ElForm, ElFormItem } from 'element-plus'
  51. let { proxy } = getCurrentInstance()
  52. const loading = ref(false)
  53. const countryId = ref(null)
  54. const provinceId = ref(null)
  55. const provinceIdData = ref(null)
  56. const cityId = ref(null)
  57. const cityIdData = ref(null)
  58. const tableData = ref([])
  59. const wordFilter = ref('')
  60. const loadingStr = ref('')
  61. const cIdChange = (cId) => {
  62. cityId.value = null
  63. provinceId.value = null
  64. provinceIdData.value = null
  65. cityIdData.value = null
  66. switch(cId){
  67. case 'TW':
  68. cityIdData.value = country.filter(function(c){
  69. return c.countryId == cId && c.lang == 'zh-tw' && c.areaType == 'y'
  70. })
  71. break;
  72. case 'CN':
  73. provinceIdData.value = country.filter(function(c){
  74. return c.countryId == cId && c.lang == 'zh-cn' && c.areaType == 'p'
  75. })
  76. break;
  77. }
  78. }
  79. const pIdChange = (provinceId) =>{
  80. cityId.value = null
  81. cityIdData.value = null
  82. let lang = ''
  83. switch(countryId.value){
  84. case 'TW':
  85. lang = 'zh-tw'
  86. break;
  87. case 'CN':
  88. lang = 'zh-cn'
  89. break;
  90. }
  91. cityIdData.value = country.filter(function(c){
  92. return c.provinceId == provinceId && c.lang == lang && c.areaType == 'y'
  93. })
  94. }
  95. const searchSchool = async (cityId) =>{
  96. let data = {
  97. countryId: countryId.value,
  98. cityId: cityId,
  99. fullData: true
  100. }
  101. if(provinceId.value != null) {
  102. data.provinceId = provinceId.value
  103. }
  104. wordFilter.value = ''
  105. loadingStr.value = '搜索學校中...'
  106. loading.value = true
  107. await proxy.$api.getSchooBasicInfo(data).then((res) => {
  108. tableData.value = res
  109. }).catch(e=>{
  110. ElMessage.error('搜尋失敗')
  111. }).finally(() => {
  112. loading.value = false
  113. })
  114. }
  115. const showData = computed({
  116. get(){
  117. if(wordFilter.value != ''){
  118. let result = []
  119. console.log(wordFilter.value, 'wordFilter.value')
  120. tableData.value.forEach((f)=>{
  121. if(f.name.indexOf(wordFilter.value) >= 0){
  122. result.push(f)
  123. } else if(f.shortCode && f.shortCode.indexOf(wordFilter.value) >= 0){
  124. result.push(f)
  125. }
  126. })
  127. return result
  128. } else {
  129. return tableData.value
  130. }
  131. }
  132. })
  133. const handleUpdSchoolW = async (schDocId, schName, shortCode) =>{
  134. const iDsCount = ref(0)
  135. // 檢查array 內容是否重複
  136. function isArrayRep(array){
  137. var result = new Set();
  138. var repeat = new Set();
  139. array.forEach(item => {
  140. result.has(item) ? repeat.add(item) : result.add(item);
  141. })
  142. // console.log(result); // {1, 2, "a", 3, "b"}
  143. // console.log(repeat); // {1, "a"}
  144. // console.log(repeat.size)
  145. if(repeat.size != 0){
  146. return true
  147. } else {
  148. return false
  149. }
  150. }
  151. // 規則檢查: iDs
  152. const checkIds = (value) => {
  153. let isErr = false
  154. if(!value) {
  155. isErr = true
  156. return "請填入要歸戶的醍摩豆ID"
  157. } else if(value && !/^[0-9\n]+$/.test(value)){
  158. isErr = true
  159. return "只能輸入醍摩豆ID與換行"
  160. } else if(value && isArrayRep(value.split('\n'))){
  161. isErr = true
  162. return "醍摩豆ID有重複"
  163. } else if(value){
  164. let errIds = []
  165. let tmp = value.split('\n')
  166. tmp.forEach(e=> {
  167. if(e.length != 10) {
  168. errIds.push(e)
  169. } else {
  170. let now = Math.floor(new Date().getTime() / 1000)
  171. let orgId = parseInt(e)
  172. if(parseInt(e.substring(0, 1)) >= 6){
  173. orgId -= 5000000000
  174. }
  175. if(orgId > now){
  176. errIds.push(e)
  177. }
  178. }
  179. })
  180. if(errIds.length > 0){
  181. // console.log(errIds, 'errIds')
  182. isErr = true
  183. return "請檢查醍摩豆ID是否符合格式或有空格"
  184. }
  185. }
  186. if(!isErr && value != ''){
  187. let tArray = value.split('\n')
  188. iDsCount.value = tArray.length
  189. } else {
  190. iDsCount.value = 0
  191. }
  192. return true
  193. }
  194. if(!shortCode){
  195. ElMessageBox.alert('此學校目前沒有簡碼', `***${schName}***`,
  196. {
  197. type: 'warning',
  198. icon: markRaw(Warning),
  199. }
  200. )
  201. // 中斷
  202. return
  203. }
  204. ElMessageBox.prompt(
  205. '請填入要歸戶的醍摩豆ID', `歸戶至 ${schName} - ${shortCode}`, {
  206. confirmButtonText: '歸戶',
  207. cancelButtonText: '取消',
  208. inputType: 'textarea',
  209. inputValidator: checkIds,
  210. customClass: 'prompClass',
  211. roundButton: true,
  212. closeOnClickModal: false
  213. }
  214. ).then(({value})=>{
  215. let showStr = value.replaceAll('\n', ', ')
  216. ElMessageBox.confirm(
  217. `確認要歸戶以下的醍摩豆ID嗎?\n${showStr} \n\n 總共 ${iDsCount.value} 位`,
  218. `歸戶至 ${schName} - ${shortCode}`,
  219. {
  220. confirmButtonText: '確認',
  221. cancelButtonText: '先不要',
  222. type: 'info',
  223. customClass: 'confirmClass'
  224. }
  225. ).then(async ()=>{
  226. let reqData = {
  227. schoolDocId: schDocId,
  228. ids: value.split('\n')
  229. }
  230. loadingStr.value = '弱歸戶...'
  231. loading.value = true
  232. await proxy.$api.updUserSchoolW(reqData).then((res) => {
  233. ElMessageBox.alert('成功', '弱歸戶成功',
  234. {
  235. type: 'info',
  236. icon: markRaw(SuccessFilled),
  237. }
  238. )
  239. }).catch(e=>{
  240. ElMessage.error('搜尋失敗')
  241. }).finally(() => {
  242. loading.value = false
  243. })
  244. })
  245. })
  246. }
  247. </script>
  248. <style>
  249. .prompClass textarea{
  250. min-height: 220px!important;
  251. }
  252. .confirmClass p{
  253. white-space: pre-line;
  254. }
  255. .radioSty .el-radio__input{
  256. display: none;
  257. }
  258. .radioSty .el-radio__label{
  259. font-weight: bold;
  260. font-size: 15px!important;
  261. }
  262. .radioSty .el-radio{
  263. margin-right: 10px;
  264. }
  265. </style>
  266. <style scoped>
  267. .updCodeWBox{
  268. width: 100%;
  269. height: 82vh;
  270. background-color: #fff;
  271. z-index:999;
  272. box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.3);
  273. border-radius: 10px;
  274. padding: 1%;
  275. text-align: left;
  276. }
  277. .updCodeWBox-title{
  278. line-height: 40px;
  279. font-size:24px;
  280. font-weight: bold;
  281. color:#7b84a9;
  282. text-align: center;
  283. }
  284. </style>