<template>
	<view>

		<cu-custom bgColor="bg-gradual-pink" :isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">检测委托申请</block>
		</cu-custom>

		<form>
			<uni-group mode="card">
				<view class="cu-form-group">
					<view class="title">委托单号</view>
					<input name="input" v-model="weituodanhao"></input>
				</view>
				<!-- 			<view class="cu-form-group">
						<view class="title">类型</view>
						<input placeholder="常规" name="input" v-model="myFormData.username" disabled></input>
					</view> -->
				<view class="cu-form-group">
					<my-date style="padding: 0rpx;" v-model="beginTime" placeholder="请选择" fields="minute"
						label="期望完成时间"></my-date>
				</view>
			</uni-group>

<!-- 			<uni-link
				href="https://www.szjyxt.com/demo/reportJsp/pdfReport.jsp?access_token%20=%20999f19ea64f947ab83c13b0ef5e6677e&rpx=%E4%B8%AD%E6%B1%87%E7%91%9E%E5%BE%B7%E6%A3%80%E6%B5%8B%E4%B8%AD%E5%BF%83/08%E4%BB%AA%E5%99%A8%E8%AE%BE%E5%A4%87%E7%9A%84%E4%BD%BF%E7%94%A8%E3%80%81%E7%BB%B4%E6%8A%A4%E5%92%8C%E7%AE%A1%E7%90%86%E7%A8%8B%E5%BA%8F/GDYR-CX06-R06A%20%20%E4%BB%AA%E5%99%A8%E8%AE%BE%E5%A4%87%E7%BB%B4%E6%8A%A4%E4%BF%9D%E5%85%BB%E8%AE%B0%E5%BD%95%E8%A1%A8(%E6%9C%88).rpx&id_=948538515816185856"
				text="查阅报告"></uni-link>
			<uni-link
				href="
				https://www.szjyxt.com/demo/reportJsp/pdfReport.jsp?access_token%20=%20999f19ea64f947ab83c13b0ef5e6677e&rpx=%E4%B8%AD%E6%B1%87%E7%91%9E%E5%BE%B7%E6%A3%80%E6%B5%8B%E4%B8%AD%E5%BF%83/08%E4%BB%AA%E5%99%A8%E8%AE%BE%E5%A4%87%E7%9A%84%E4%BD%BF%E7%94%A8%E3%80%81%E7%BB%B4%E6%8A%A4%E5%92%8C%E7%AE%A1%E7%90%86%E7%A8%8B%E5%BA%8F/GDYR-CX06-R06A%20%20%E4%BB%AA%E5%99%A8%E8%AE%BE%E5%A4%87%E7%BB%B4%E6%8A%A4%E4%BF%9D%E5%85%BB%E8%AE%B0%E5%BD%95%E8%A1%A8(%E6%9C%88).rpx&id_=948538515816185856
				"
				text="超链"></uni-link> -->

<!-- 		<uni-section title="基本用法" type="line" padding>
			<uni-rate v-model="rateValue" @change="onChange" />
		</uni-section>
		<uni-section title="半星" subTitle="使用 allow-half 属性设置是否显示半星" type="line" padding>
			<uni-rate allow-half :value="3.5" />
		</uni-section> -->
			
			

			<uni-group mode="card" title="样品信息">
				<view class="cu-form-group margin-top">
					<view class="title" style="color: #888888">样品名称</view>
					<input placeholder="请输入样品名称" name="input"></input>
				</view>
				<view class="cu-form-group ">
					<view class="title" style="color: #888888">规格型号</view>
					<input placeholder="请输入规格型号" name="input"></input>
				</view>
				<view class="cu-form-group ">
					<view class="title" style="color: #888888">数量</view>
					<input placeholder="请输入数量" name="input"></input>
				</view>
				<view class="cu-form-group ">
					<view class="title" style="color: #888888">生产日期/批号</view>
					<input placeholder="请输入" name="input"></input>
				</view>
				<view class="cu-form-group ">


					<view class="title" style="color: #888888">样品处置</view>
					<app-select v-model="type2" placeholder="请选择处置方式" :dict="plan_type" space></app-select>
				</view>
				<view class="cu-form-group">
					<view class="title" style="color: #888888">检测类别</view>
					<app-select v-model="type1" placeholder="请选择检测类别" :dict="plan_type1" space></app-select>
				</view>
			</uni-group>

 <uni-group mode="card" >
			<uni-section v-bind:title="'检测对象/'+ leixing" type="line">
				<view class="example-body2 uni-px-5 uni-pb-5">
					<!-- <view class="text">{{sex[radio1].text}}</view> -->
					<uni-data-checkbox v-model="radio1" :localdata="sex" @change="change(sex[radio1].text)">
					</uni-data-checkbox>
				</view>



				<view class="example-body">
					<view v-for="(item,i) in canshu" :key="i" style="margin-bottom: 20rpx;margin-left: 25rpx;">
						<view class="tag-view">
							<uni-tag :circle="true" :inverted="!item.show" :text="item.text" type="primary"
								@click="setInverted(i)" ></uni-tag>
						</view>
					</view>
				</view>
				
				
				</uni-section>

</uni-group>


			<view class="">
				<uni-section title="" type="line" padding>
					<!-- 					<uni-title type="h5" title="项目参数"></uni-title>
					<view class="example-body" >	
						<view v-for="(item,i) in canshu" :key="i">
							   <view class="tag-view">
								<uni-tag  :circle="true" :inverted="!item.show"  :text="item.text" type="primary" @click="setInverted(i)" />
							   </view>		
						</view>			
					</view> -->

					<view class="cu-form-group">
						<view class="title">报告份数</view>
						<uni-number-box v-model="vModelValue" @blur="blur" @focus="focus" @change="changeValue" />
					</view>


					<view class="cu-form-group">
						<view class="title">是否出具意见和解释</view>
						<uni-data-checkbox v-model="radio2" :localdata="yijian" @change="change(yijian[radio2].text)">
						</uni-data-checkbox>

					</view>

					<view class="cu-form-group">
						<view class="title">检测结论</view>
						<uni-data-checkbox v-model="radio3" :localdata="jielun" @change="change(jielun[radio3].text)">
						</uni-data-checkbox>

					</view>

					<view class="cu-form-group">
						<view class="title">取报告方式</view>
						<uni-data-checkbox style="flex-wrap: nowrap;" v-model="radio4" :localdata="baogao"
							@change="change(baogao[radio4].text)"></uni-data-checkbox>

					</view>





					<uni-collapse-item title="声明" :open="open">
						<uni-card :is-shadow="false">
							<text class="uni-body" style="color: #DD514C;">1.送样单位须保证样品的真实性、代表性.
								2.本检验中心保证检测结果的公正性，对来样的检测数据负责；并对其样品及相关资料保密。
								3.委托方需对送检样品的安全性和缺陷负责，一旦因样品自身问题发生事故损失的，委托方需承担相应责任。</text>
						</uni-card>
					</uni-collapse-item>



				</uni-section>

			</view>


			<!-- v-model="value"   -->
			<!--    <uni-section title="检测对象" type="line">
      <uni-data-select 
		v-model="value"	 
        :localdata="range"
        @change="change(value)"
        :clear="false"
      ></uni-data-select> -->
			<!--    </uni-section>
			
		<uni-section title="基本用法" type="line">
			<view class="example-body2">
				<uni-combox :candidates="candidates" placeholder="请选择所在城市" v-model="city"></uni-combox>
				<view class="result-box">
					<text>所选城市为：{{city}}</text>
				</view>
			</view>
		</uni-section> 
			<view class="cu-form-group">
				<view class="title">检测类型</view>
				<input placeholder="请输入姓名" name="input" v-model="leixing"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">检测项目/参数</view>
				<input placeholder="请输入姓名" name="input" v-model="myFormData.realname"></input>
			</view>
			
			<view class="cu-form-group">
				<view class="title">检测方法</view>
				<input placeholder="请输入姓名" name="input" v-model="myFormData.realname"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">检测对象</view>
				<input placeholder="请输入姓名" name="input" v-model="myFormData.realname"></input>
			</view>
 -->



			<view class="padding flex flex-direction">
				<button class="cu-btn bg-blue lg" @click="onSubmit">提交</button>
			</view>
		</form>
	</view>
</template>

<script>
	const plan_type = [{
		text: '返回给委托人',
		value: '1'
	}, {
		text: '自取',
		value: '2'
	}, {
		text: '不取回',
		value: '3'
	}];
	const plan_type1 = [{
		text: '委托检测',
		value: '1'
	}, {
		text: '抽样检测',
		value: '2'
	}];
	import myDate from '@/components/my-componets/my-date.vue'
	import appSelect from '@/components/my-componets/appSelect.vue'
	import md5 from "@/common/util/md5.js"
	export default {
		components: {
			myDate,
			appSelect
		},

		data() {
			return {
				open:true,
				rateValue: 0,
				leixing: '等哈说',
				vModelValue: 1,
				radio1: -1,
				radio2: 1,
				radio3: 1,
				radio4: 0,
				sex: [{
					text: '金属零件',
					value: 0
				}, {
					text: '碳素钢和中低合金钢',
					value: 1
				}],
				yijian: [{
					text: '要',
					value: 0
				}, {
					text: '不要',
					value: 1
				}],
				jielun: [{
					text: '要',
					value: 0
				}, {
					text: '不要',
					value: 1
				}],
				baogao: [{
					text: '自取',
					value: 0
				}, {
					text: '邮件',
					value: 1
				}, {
					text: '其它',
					value: 2
				}],
				value: -1,
				range: [{
						value: 0,
						text: "金属零件"
					},
					{
						value: 1,
						text: "碳素钢和中低合金钢"
					}

				],
				canshu: [


				],
				candidates: ['北京', '南京', '东京', '武汉', '天津', '上海', '海口'],
				city: '',
				type: "default",
				inverted: false,
				leibie: "",
				weituodanhao: '',
				plan_type1,
				plan_type,
				type2: '',
				type1: '',
				beginTime: '',
				index: -1,
				leixing: '',
				switchC: true,
				imgList: [],
				uploadUrl: "/sys/common/upload",
				myFormData: {
					weituodanhao: '',
					avatar: '',
					realname: '',
					username: '',
					sex: 1,
					birthday: '',
					orgCode: '',
					workNo: '',
					phone: '',
					email: '',
					id: '',
				},
			};
		},
		onLoad: function(option) {

         //下单数据格式
		 let weituodandata=
         {
             "crmZhuangTai":"crm",
             "weiTuoZhuangTai":"待审核",
             "id":"",
             "weiTuoDanHaoZhuan":"",
             "yangPinBianHaoZhu":"",
             "shouLiBuMen":"检测室",
             "weiTuoFang":"外部委托",
             "jianCeWeiZhi":"",
             "shouLiShiJian":"2022-05-30",
             "dingDanHao":"",
             "dingDanLaiYuan":"客户直接下单",
             "baoJiaDan":"980832275937624064",
             "quDao":"961911156522352640",
             "xiaoShouRenYuan":"702117247933480960",
             "zongJinE":"400",
             "weiTuoDanHao":"GDYR-WT-20220530-04",
             "lianXiRen":"香香",
             "weiTuoDanWei":"5d61f11d33dc44898d4ef77a30211461",
             "lianXiFangShi":"12354578542",
             "qiWangWanChengShi":"2022-05-31",
             "tongXunDiZhi":"广东深圳",
             "gdyrqcyp":[
                 {
                     "yangPinMingCheng":"阿松大",
                     "guiGeXingHao":"UC615 -1060 RBφ38x38阿松大",
                     "shuLiang":"1",
                     "shengChanRiQiPiHa":"4512122"
                 }
             ],
             "yangPinChuZhi":"返回给委托人",
             "jianCeLeiBie":"委托检测",
             "nengLiFanWeiLeiXi":"碳素钢和中低合金钢",
             "jianCeLeiXingId":"阿萨",
             "jianCeXiangMu":"阿松大",
             "jianCeFangFa":"d41778b4252241b0bb39d391a65fe840,1e45eb75f0594cdab8a16e24839bbc11",
             "keHuYaoQiu":"无特殊要求",
             "jcxmcrm":[
                 {
                     "jianCeLeiXing":"",
                     "xiangMuCanShu":"",
                     "danJia":"",
                     "shuLiang":"",
                     "zheKou":"",
                     "zheHouJia":"",
                     "id":"",
                     "parentId":""
                 }
             ],
             "quBaoGaoFangShiJi":"自取",
             "baoGaoFenShu":1,
             "qiTaYaoQiu":"无特殊要求",
             "jianCeJieGuoZuoCh":"不要",
             "jianCeJieLun":"不要",
             "jianCeBaoGaoZhong":"不要",
             "hkfab":[
         
             ],
             "dingDanShenHeYiJi":"",
             "dingDanShenPiYiJi":"",
             "bianZhiRen":"702117247933480960",
             "guiGeXingHao":"UC615 -1060 RBφ38x38阿松大",
             "shengChanRiQiPiHa":"4512122",
             "yangPinMingCheng":"阿松大"
         }
		
        let jiancepara={
			"boCode":"gdyrqcwt",
			"version":0,
			"formKey":"ddfq",
			"pk":"",
			"data":JSON.stringify(this.weituodandata)
		}
        
		this.$http.post("ibps/business/v3/data/template/saveFormData/vo",jiancepara).then(res =>{
			if (res.data.state == 200) {
				console.log(res)
			}			
		})







			//委托单号
			let smsParams = {
				alias: "gzyrwtbh"
			};
			this.$http.post("/ibps/business/v3/jc/sys/getNextIdByAlias", smsParams).then(res => {
				if (res.data.state == 200) {
					console.log(res.data.data)
					this.weituodanhao = res.data.data

					//	this.$set(this.myFormData,"weituodanhao",res.data.data)
				}
			});
			//检测对象 https://www.szjyxt.com/ibps/business/v3/data/template/queryDataTable
			let param1 = {
				"parameters": [{
						"key": "response_data",
						"value": "{\"template_id\":\"958692267806162944\",\"template_type\":\"\",\"attrs\":\"\",\"result_columns\":[{\"label\":\"检测对象\",\"name\":\"jian_ce_dui_xiang\"}],\"sort_columns\":\"\",\"buttons\":\"\",\"export_columns\":\"\",\"datasetKey\":\"jianceduixiangv\",\"unique\":\"jian_ce_dui_xiang\",\"key\":\"jcdxzly\",\"dynamic_params\":{}}"
					},
					{
						"key": "filter_condition_key",
						"value": ""
					}
				]
			}
			this.$http.post("ibps/business/v3/data/template/queryDataTable", param1).then(res => {
				if (res.data.state == 200) {
					console.log(res.data.data)
					let data = res.data.data.dataResult
					console.log(data)
				}
			});

			//检测类型、检测
			//请求系统接口demo




			console.log("this.$Route.query", this.$Route.query);
			let query = this.$Route.query
			if (query) {
				this.myFormData = query;
				if (this.myFormData.sex == '女') {
					this.switchC = false
				} else if (this.myFormData.sex == '男') {
					this.switchC = true
				}
				if (this.myFormData.avatar) {
					this.imgList = [this.myFormData.avatar]
				}
				if (!this.myFormData.birthday) {
					this.myFormData.birthday = '无'
				}
				if (this.myFormData.identity == '普通成员') {
					this.myFormData.identity = 1
				} else if (this.myFormData.identity == '上级') {
					this.myFormData.identity = 2
				}
				if (this.myFormData.status == '正常') {
					this.myFormData.status = 1
				} else if (this.myFormData.status == '冻结') {
					this.myFormData.status = 2
				}
				this.Avatar = this.myFormData.avatar

				Object.keys(this.myFormData).map(key => {
					if (this.myFormData[key] == '无') {
						this.myFormData[key] = ''
					}
				})
				console.log("this.myFormData", this.myFormData)
			}
		},
		methods: {
			onChange(e) {
					console.log('rate发生改变:' + JSON.stringify(e))
					// console.log(this.rateValue);
				},
			onSubmit() {
				let myForm = this.myFormData
				let checkPhone = new RegExp(/^[1]([3-9])[0-9]{9}$/);
				let checkEmail = /^[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.[a-zA-Z0-9]{2,6}$/;
				console.log("myForm", myForm)
				if (!myForm.phone || myForm.phone.length == 0) {
					this.$tip.alert('请输入手机号');
					return false
				}
				if (!checkPhone.test(myForm.phone)) {
					this.$tip.alert('请输入正确的手机号');
					return false
				}
				if (!checkEmail.test(myForm.email)) {
					this.$tip.alert('请输入正确的邮箱地址');
					return false
				}
				this.myFormData.id = this.$store.getters.userid
				if (this.switchC) {
					this.myFormData.sex = 1
				} else {
					this.myFormData.sex = 2
				}
				console.log('myform', this.myFormData)
				this.$tip.loading();
				this.$http.put('/sys/user/appEdit', this.myFormData).then(res => {
					console.log(res)
					this.$tip.loaded();
					if (res.data.success) {
						this.$tip.toast('提交成功')
						this.$Router.replace({
							name: 'userdetail'
						})
						/* uni.navigateTo({
							url: '/pages/user/userdetail'
						}) */
					}
				}).catch(() => {
					this.$tip.loaded();
					this.$tip.error('提交失败')
				});
			},
			DateChange(e) {
				this.myFormData.birthday = e.detail.value
			},
			SwitchC(e) {
				this.switchC = e.detail.value
			},
			sig(sql) {
				let rul = (sql.length + 9) * 12 * 3 + 168
				let salt = "JinYuanXinTong"
				return md5(rul + '' + salt)
			},
			ChooseImage() {
				var that = this;
				uni.chooseImage({
					count: 4, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						that.$http.upload(that.$config.apiUrl + that.uploadUrl, {
								filePath: res.tempFilePaths[0],
								name: 'file'
							})
							.then(res => {
								that.myFormData.avatar = res.data.message;
							})
							.catch(err => {
								that.$tip.error(err.data.message)
							});
						this.imgList = res.tempFilePaths
					}
				});
			},
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				uni.showModal({
					title: '召唤师',
					content: '确定要删除这段回忆吗？',
					cancelText: '再看看',
					confirmText: '再见',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			change(text) {
				console.log(text)

				if (text == '金属零件' || text == '碳素钢和中低合金钢') {
					let data = '';
					if (text == '金属零件') {
						data = "select * from t_sysjtsjpz where jian_ce_dui_xiang = '金属零件' and shi_fou_shan_chu_ = '0'";
						this.leixing = "尺寸和形位公差测量"
					}
					if (text == '碳素钢和中低合金钢') {
						data =
							"select * from t_sysjtsjpz where jian_ce_dui_xiang = '碳素钢和中低合金钢' and shi_fou_shan_chu_ = '0'";
						this.leixing = "元素成分测定"
					}

					data = '{"sql":"' + data + '"}'
					let md5 = this.sig(data) //加密， 获取md5密文
					let requestData = data.slice(0, 1) + '"sig":"' + md5 + '",' + data.slice(1) //结果拼接
					this.$http.post("/ibps/business/v3/sys/universal/inputSqlSelectData", requestData).then(res => {
						if (res.data.state == 200) {
							let result = res.data.variables.data;
							console.log(result)
							let canshu = []
							for (let index in result) {
								let en = {}
								en.show = false,
									en.text = result[index].xiang_mu_can_shu_;
								canshu.push(en);
							}
							this.canshu = canshu;

							console.log(this.canshu)
						}
					});
				}

			},
			onChange(){},
			
			changeValue(value) {
				console.log('返回数值：', value);
			},
			focus(e) {
				console.log('focus:', e);
			},
			blur(e) {
				console.log('blur:', e);
			},
			setType() {
				let types = ["default", "primary", "success", "warning", "error"];
				let index = types.indexOf(this.type);
				types.splice(index, 1);
				let randomIndex = Math.floor(Math.random() * 4);
				this.type = types[randomIndex];
			},
			setInverted(index) {
				this.canshu[index].show = !this.canshu[index].show;
			},


		}
	}
</script>

<style>
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}

	.example-body {
		/* #ifndef APP-PLUS-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
		justify-content: flex-start;
		align-items: flex-end;
		flex-wrap: wrap;
	}

	.tag-view {
		margin-right: 10px;
	}

	.example-body2 {
		padding: 12px;
		background-color: #FFFFFF;
	}

	.result-box {
		text-align: center;
		padding: 20px 0px;
		font-size: 16px;
	}
</style>
