import { memberListPageV2 } from '@/api/masterManagement'
import { required, mobileRequired, mobile, httpUrl, email } from '@/components/template/rules_verify.js'
export default {
  data() {
    return {
      workerList_cz: []
    }
  },
  computed: {
    czpandanxinxi() {
      return [
        {
          name: 'el-input',
          md: 6,
          attributes: {
            placeholder: '请输入',
            disabled: this.formData.status == 'OK'
          },
          formItemAttributes: {
            label: '正激励工单号',
            prop: 'disposeOrderBaseId'
            // rules: [...required],
          }
        },
        {
          name: 'el-select',
          md: 6,
          options: this.orderSmallTypeData,
          attributes: {
            placeholder: '请选择',
            clearable: true,
            filterable: true,
            disabled: this.formData.status == 'OK'
          },
          formItemAttributes: {
            label: '工单类型',
            prop: 'disposeOrderSmallType'
            // rules: [...required],
          },
          events: {
            change: val => {
              if (val) {
                this.formData.disposeOrderSmallTypeText = this.orderSmallTypeData.find(item => item.value == val).label
              } else {
                this.formData.disposeOrderSmallTypeText = ''
              }
            }
          }
        },
        {
          name: 'el-select-add',
          options: this.websitList.map(item => ({ ...item, label: `(${item.value})${item.label}` })),
          md: 6,
          attributes: {
            placeholder: '请选择',
            clearable: true,
            filterable: true,
            disabled: this.formData.status == 'OK'
          },
          formItemAttributes: {
            label: '网点名称',
            prop: 'disposeWebsitId'
            // rules: [...required],
          },
          events: {
            change: val => {
              this.formData.disposeWorkerId = ''
              this.formData.disposeWorkerName = ''
              this.formData.disposeWorkerMobile = ''
              this.getdisposeWebsitIds()
              if (val) {
                this.formData['disposeWebsitName'] = this.websitList.find(item => item.value == val)?.label || val
              } else {
                this.formData['disposeWebsitName'] = ''
              }
            }
          }
        },
        {
          name: 'el-select-add',
          options: this.workerList_cz,
          md: 6,
          attributes: {
            placeholder: '请选择',
            clearable: true,
            filterable: true,
            disabled: this.formData.status == 'OK'
          },
          formItemAttributes: {
            label: '正激励工程师',
            prop: 'disposeWorkerId'
            // rules: [...required],
          },
          events: {
            change: val => {
              if (val) {
                this.formData['disposeWorkerName'] = this.workerList_cz.find(item => item.value == val)?.label || val
                this.formData['disposeWorkerMobile'] =
                  this.workerList_cz.find(item => item.value == val)?.data?.workerMobile || ''
              } else {
                this.formData['disposeWorkerMobile'] = ''
                this.formData['disposeWorkerName'] = ''
              }
            }
          }
        }
      ]
    }
  },
  methods: {
    getdisposeWebsitIds() {
      if (this.formData.disposeWebsitId) {
        memberListPageV2({
          pageNum: 1,
          pageSize: -1,
          params: [
            { param: 'b.examine_status', compare: '=', value: 'OK' },
            { param: 'b.websit_id', compare: '=', value: this.formData.disposeWebsitId }
          ]
        }).then(res => {
          this.workerList_cz = res.data.records.map(item => {
            var { id, userId, ...data } = item
            return {
              value: userId,
              label: data.nickName,
              data: {
                workerId: userId,
                workerName: data.nickName,
                workerIdcard: data.idCard,
                workerMobile: data.mobile,
                ...data
              }
            }
          })
        })
      } else {
        this.workerList_cz = []
      }
    }
  }
}
