
var sp1component = {
	template: `
		<div>
			<div style="display: flex;">
				<el-input v-model="id_v" placeholder="序号" clearable style="width: 100px;" @change="input_change"></el-input>
				<el-input v-model="contract_id_v" placeholder="合同号" clearable style="width: 105px;" @change="input_change"></el-input>
  	            <!-- <el-input v-model="supplier_v" placeholder="供应商" clearable style="width: 105px;" @change="input_change"></el-input> -->
				<el-input v-model="applicant_v" placeholder="申请人" clearable style="width: 105px;" @change="input_change"></el-input>
				<el-input v-model="contract_name_v" placeholder="合同名称" clearable style="width: 105px;" @change="input_change"></el-input>
				<el-input v-model="rdm_v" placeholder="RDM" clearable style="width: 100px;" @change="input_change"></el-input>
				<!--<el-select clearable v-model="state_v" placeholder="审批状态" style="width: 105px;" @change="input_change">
					<el-option label="待审批" value="待审批"></el-option>
					<el-option label="已审批" value="已审批"></el-option>
				</el-select>
				-->
				<!--
				<el-select clearable filterable v-model="more_query_v" placeholder="更多查询"
					style="width: 110px;" @change="more_query_select">
				 <el-option-group
					   key="1"
					   label="">
					   <el-option label="采购人员" value="采购人员"></el-option>
				 </el-option-group>
				</el-select>
				<el-select v-if="more_query_v=='采购人员'" v-model="buyer_v" clearable filterable placeholder="请选择" style="width: 120px;" @change="input_change">
				  <el-option
					v-for="item in buyer_data"
					:key="item.value"
					:label="item.label"
					:value="item.value">
				  </el-option>
				</el-select>
				-->
				
				<el-checkbox style="margin: 0px;" v-model="checked" @change="if_fin_cahnge" border>已处理</el-checkbox>
				
				<el-button id ="bt_serach" plain type="primary" icon="el-icon-search" @click="get_sp_1()" style="padding-left: 10px;padding-right: 10px;">搜索</el-button>
				<!--<el-button id ="bt_add" plain type="primary" icon="el-icon-document-add" @click="importCsv()" style="margin-left: 0px;padding-left: 10px;padding-right: 10px;">导入</el-button>
				-->
				<el-button id ="bt_add" v-if='level==1' plain type="primary" icon="el-icon-circle-check" @click="mul_update_pp_plan_num()" style="margin-left: 0px;padding-left: 10px;padding-right: 10px;">批量审批</el-button>
			</div>
			
			<div>
				<el-progress v-if="if_show_process1" :percentage="percent_len1" ></el-progress>
			</div>
			
			<div >
				<div class="span">
					<el-table
					    :data="tableData"
					    style="font-size:14px"
					    :height="tHeight"
						:row-class-name="tableRowClassName"
						@selection-change="handleSelectionChange"
						border
						:row-style="selectedRowStyle"
						@cell-dblclick="celldblclick_1"
						:header-cell-style="tableHeaderColor"
						>
						
						<el-table-column
						  type="selection"
						  width="30"
						  >
						</el-table-column>
						
						<el-table-column
						  prop="id"
						  label="序号"
						  :width="flexColumnWidth('id',tableData,2)">
						</el-table-column>
						
						<el-table-column
						  prop="contract_id"
						  label="合同号"
						  :width="flexColumnWidth('contract_id',tableData,3)"
						  :show-overflow-tooltip="true">
						</el-table-column>
						
						// <el-table-column
						//   prop="supplier"
						//   label="供应商名称"
						//   width="160"
						//   :show-overflow-tooltip="true">
						// </el-table-column>
						
						<el-table-column
						  prop="applicant"
						  label="申请人"
						  :width="flexColumnWidth('applicant',tableData,3)"
						  :show-overflow-tooltip="true">
						</el-table-column>
						
						<el-table-column
						  prop="time"
						  label="申请日期"
						  width="80"
						  :show-overflow-tooltip="true">
						</el-table-column>
						
						<el-table-column
						  prop="contract_name"
						  label="草稿合同"
						  :width="flexColumnWidth('contract_name',tableData)*1.1"
						  :show-overflow-tooltip="true">
						  <template slot-scope="scope" >
							  <el-button  type="text" @click="down_file_22(scope.row)" >{{scope.row.contract_name}}</el-button>
						  </template>
						</el-table-column>
						
						<el-table-column
						  label="合同操作"
						  :width="tableData?160:80"
						  :show-overflow-tooltip="true">
						  <template slot-scope="scope">
							 <el-upload
							 	v-if='scope.row.if_modify'
							   class="upload-demo"
							   ref="upload"
							   action="/pp/upload_sp_1_file"
							   :on-change="handleChange_file"
							   :file-list="fileList_1"
							   :show-file-list="false"
							   :on-success="upload_file_success"
							   :on-error="upload_file_error"
							   :data="upload_param_2(scope.row)">
							   
								<el-button v-show='scope.row.contract_name==""' slot="trigger" size="medium" type="success"">上传</el-button>
								<el-button size="medium" type="success"  @click="del_contract_file(scope.row)">删除</el-button>
								</el-upload>
						  </template>
						</el-table-column>
						
						<el-table-column
						  
						  label="RDM"
						  :width="flexColumnWidth('RDM',tableData,3)"
						  :show-overflow-tooltip="true">
						  <template slot-scope="scope">
						  <div v-for="(item, index) in scope.row.rdm.split(/[,，、 ]+/)" :key="index">                      
                             <el-button :style="scope.row.redmine_color" @click="to_redmine_1(item)" type="text" size="medium">{{item}}</el-button>
                           </div>
							
						  </template>
						</el-table-column>
						
						<el-table-column
						  prop="amount"
						  label="金额"
						 :width="flexColumnWidth('amount',tableData,2)"
						 :show-overflow-tooltip="true">
						 <template slot-scope="scope">
							<div style="float: right;">{{convert(scope.row.amount)}}</div>
						 </template>
						</el-table-column>
						
						<el-table-column
					      prop="state"
						  label="审批状态"
						 :width="flexColumnWidth('state',tableData)"
						 :show-overflow-tooltip="true">
						 
						</el-table-column>
						
						<el-table-column
						      label="操作"
						      :width="tableData?80:40">
						      <template slot-scope="scope">
								  <el-button v-if='scope.row.if_modify' class="t_hover_button"  @click="show_update_dialog(scope.row)" type="text" size="medium" >修改</el-button>
								  <el-button v-if='scope.row.if_modify' style="margin-left: 3px;margin-right: 0px;"  @click="remove_ma_plan(scope.row)" type="text" size="medium" >删除</el-button>
						      </template>
						    </el-table-column>
					  </el-table>
				</div>
				<div class="block">
				    <span class="demonstration"></span>
				    <el-pagination
				      @size-change="handleSizeChange"
				      @current-change="handleCurrentChange"
				      :current-page="currentPage"
					  :page-sizes="[50,100, 200, 300]"
				      :page-size="pagesize"
					  :total="recordTotal"
				      layout="total, sizes, prev, pager, next, jumper"
				      >
				    </el-pagination>
				  </div>
			</div>
			
			<el-dialog
			 title="合同审批"
			 :visible.sync="updatedialogVisible_ex"
			 :lock-scroll ="false"
			 width="70%">
			 <el-form ref="authform_ex" :model="form" :rules="rules" label-width="160px" :inline="false" class="demo-form-inline" size="medium">
				  <el-row :gutter="10">
					  <el-col :span="8">
						  <el-form-item label="序号" prop="id" >
						  <el-input v-model="form.id" :disabled="true" ></el-input>
						  </el-form-item>
					  </el-col>
					  <el-col :span="8">
							<el-form-item label="供应商名称" prop="supplier">
							<el-input v-model="form.supplier" :disabled="false"></el-input>
							</el-form-item>
					  </el-col>
					  <el-col :span="8">
							<el-form-item label="申请人" prop="applicant">
							<el-input v-model="form.applicant" :disabled="true"></el-input>
							</el-form-item>
					  </el-col>
				  </el-row>
				  
				  <el-row :gutter="10">
					  <el-col :span="8">
						  <el-form-item label="RDM" prop="rdm" >
						  <el-input v-model="form.rdm" :disabled="false" ></el-input>
						  </el-form-item>
					  </el-col>
					  <el-col :span="8">
							<el-form-item label="金额" prop="amount">
							<el-input v-model="form.amount" :disabled="false"></el-input>
							</el-form-item>
					  </el-col>
					  <el-col :span="8" >
							<el-form-item label="审批状态" prop="state">
							<!--<el-input v-model="form.state" :disabled="!(level==1)"></el-input>-->
							<el-select :disabled="!(level==1)" clearable v-model="form.state" placeholder="审批状态" style="width: 105px;" @change="input_change">
							<el-option label="批准" value="批准"></el-option>
							<el-option label="拒绝" value="拒绝"></el-option>
					
							</el-select>
							</el-form-item>
					  </el-col>
				  </el-row>
				  
			 </el-form>
			 <span slot="footer" class="dialog-footer">
			 <el-button @click="updatedialogVisible_ex = false">取 消</el-button>
			 <el-button id ="bt_ok" plain type="primary" @click="update_ma_ex();">确 定</el-button>
			 </span>
			</el-dialog>
			
			<el-dialog
			 title="合同审核导入"
			 :visible.sync="importdialogVisible"
			 :lock-scroll ="false"
			 :before-close="importDialog_close"
			 width="55%">
				<div style="display: flex;">
					<el-upload
					 class="upload-demo"
					 action=""
					 :on-change="handleChange"
					 :file-list="fileListUpload"
					 :show-file-list="false"
					  accept=".csv"
					  :auto-upload="false">
					  <el-button id ="bt_upload" size="small" plain type="primary">点击上传（csv文件）</el-button>
					</el-upload>
					 <el-button id ="bt_import" size="small" plain type="primary" @click="importData" style="margin-left: 10px;">确认导入</el-button>
				<el-button id ="bt_download" size="small" plain type="primary" @click="download_template" style="margin-left: 10px;">下载导入模板文件</el-button>
				</div>
				<div>
					<el-progress v-if="if_show_process" :percentage="percent_len" :stroke-width="2"></el-progress>
				</div>
				<el-table
					    :data="importTableData"
					    style="font-size:14px;margin-top: 10px;width: 100%;"
						:row-class-name="tableRowClassName"
						stripe border>
						
						<el-table-column
						  prop="t_id"
						  label="序号"
						  width="70"
						  :show-overflow-tooltip="true">
						</el-table-column>
						<el-table-column
						  prop="supplier"
						  label="供应商名称"
						  width="160"
						  :show-overflow-tooltip="true">
						</el-table-column>
						
						<el-table-column
						  prop="applicant"
						  label="申请人"
						  width="100"
						  :show-overflow-tooltip="true">
						</el-table-column>
						
						<el-table-column
						  prop="rdm"
						  label="RDM"
						  width="100"
						  :show-overflow-tooltip="true">
						  <template slot-scope="scope">
							<el-button :style="scope.row.redmine_color" @click="to_redmine_1(scope.row.rdm)" type="text" size="medium">{{scope.row.rdm}}</el-button>
						  </template>
						</el-table-column>
						
						<el-table-column
						  prop="amount"
						  label="金额"
						 width="100"
						 :show-overflow-tooltip="true">
						</el-table-column>
						<!--
						<el-table-column
						  prop="code"
						  label="合同"
						  width="160"
						  :show-overflow-tooltip="true">
						</el-table-column>-->
					  </el-table>
			</el-dialog>
			
		</div>
		`,
	data() {
		// 获取当前屏幕的分辨率
		let screenW = window.screen.width;
		let screenH = window.innerHeight;
		console.log("screen width:", screenW);
		console.log("screen height:", screenH);
		return {
			tHeight: screenH - 40 - 232,
			tHeight_1: screenH - 80 - 34,
			tableData: Array(0),
			tableData1: Array(0),
			currentPage: 1,
			pagesize: 50,
			pagecnt: 1,
			recordTotal: 0,

			checked: false,
			id_v: '',
			contract_id_v: '',
			rdm_v: '',
			supplier_v: '',
			applicant_v: '',
			contract_name_v: '',
			state_v: '',

			updatedialogVisible_ex: false,
			form: {
				id: 0,
				supplier: '',
				applicant: '',
				rdm: '',
				amount: '',
				state: '',
			},
			rules: {
				product_id: [
					{ required: true, message: '六合编号不可为空', trigger: 'blur' }
				],
			},

			options: [],

			importdialogVisible: false,
			fileTemp: null,
			fileListUpload: [],
			importTableData: [],

			multipleSelection: [],

			if_show_processed: true,

			p_id_options: [],

			loading: false,
			percent_len: 0,
			if_show_process: false,
			interval: '',

			if_show_process1: false,
			percent_len1: 0,

			ma_users: [],
			disabled: false,

			if_do: true,

			show_child: false,
			pre_id: 0,
			child_data: [],

			row: '',
			dialogVisible: false,

			addplanVisible_1: false,
			maxid: -1,
			planform: {
				id: 0,
				payment_month: '',
				payment: '',
				payment_user: '',
			},
			plan_op_type: 0,

			if_paid_all: false,

			buyer_data: [],

			warning_dialogVisible: false,
			warning_data: [],
			warning_checked: false,

			more_query_v: '',

			buyer_v: '',

			fileList_1: [],

			level: 0,
		}
	},
	mounted() {
		var _this = this;

		var op_user = localStorage.getItem("online_user");
		this.$data.level = localStorage.getItem("level")
		var did = localStorage.getItem("did");

		this.get_sp_1();

		this.get_buyer();
	},
	methods: {
		convert(amount) {
			let numStr = (amount.replaceAll(",", "").trim() * 1).toFixed(2);
			let thousandSeparated = numStr.replace(/\d(?=(\d{3})+\.)/g, '$&,');
			return thousandSeparated;
		},
		del_contract_file(row) {
			var _this = this;

			var objs;
			axios.post('/pp/del_contract_file', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				data: row,
			})
				.then(function (response) {

					let r = response.data.r;
					let s = ""
					let errType = ""
					if (r == 0) {
						errType = "success"

						// 操作日志
						// _this.add_operation_log("删除合同：" + row.contract_name);
						
					} else {
						errType = "error"
					}

					if (r == 0) {
						s = "删除成功！";
					} else {
						s = "删除失败！";
					}

					_this.$message({
						message: s,
						type: errType,
						duration: 1500
					});

					_this.get_sp_1();
				})
				.catch(function (error) {
					console.log(error);
				});
		},

		down_file_22(row) {
			var downUrl = '/pp/download_sp_1_file' + "?id=" + row.id;
			downloadUrl(row.contract_name, downUrl);
			return;

			console.log(row)

			var index = row.contract_name.lastIndexOf(".")

			if (row.contract_name.slice(index) == ".pdf") {
				var downUrl = '/file/' + 'sp_1/' + row.contract_name;
				window.open(downUrl, '_blank');
			} else {
				var downUrl = '/pp/download_sp_1_file' + "?id=" + row.id;
				downloadUrl(row.contract_name, downUrl);
			}
		},

		upload_param_2(row) {
			console.log("---")
			return {
				id: row.id,
				file_type: "1"
			}
		},
		upload_file_error(response, file, fileList) {
			this.$message({
				message: "上传失败",
				type: "error",
				duration: 1500
			});
		},
		upload_file_success(response, file, fileList) {
			this.$message({
				message: "上传成功",
				type: "success",
				duration: 1500
			});
			this.get_sp_1();
			// 操作日志
			this.add_operation_log("上传合同：" + file.name);
		},
		handleChange_file(file, fileList) {
			console.log(file);
			this.fileList_1 = fileList.slice(-1);
		},

		more_query_select(value) {
			console.log(value);
			console.log(this.$data.more_query_v);
			if (value == "采购人员") {

			} else {
				this.$data.buyer_v = ''
			}

			console.log("更多查询", value)
			this.get_ma_plan();
		},

		down_qs_files(row) {
			var downUrl = '/pp/download_ds_file' + "?id=" + row.qs;
			downloadUrl(row.qs, downUrl);
		},

		get_warning() {
			var _this = this;
			var objs;
			axios.post('/pp/get_warning_plan', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
			})
				.then(function (response) {
					console.log(response.data);
					objs = response.data.data;
					_this.$data.warning_data = objs;

					if (_this.$data.warning_data.length > 0) {
						_this.warning_dialogVisible = true;
					}
				})
				.catch(function (error) {
					console.log(error);
				});
		},

		get_buyer() {
			var _this = this;
			var objs;
			axios.post('/pp/getUsers', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				index: 1,
				count: 1000
			})
				.then(function (response) {
					console.log(response.data);
					objs = response.data.data;
					rcnt = response.data.total;
					for (var i = 0; i < objs.length; ++i) {
						if (objs[i].if_buyer == 1) {
							var obj = {
								value: objs[i].username,
								label: objs[i].username,
							}

							_this.$data.buyer_data.push(obj);
						}
					}
				})
				.catch(function (error) {
					console.log(error);
				});

		},

		tableHeaderColor({ row, column, rowIndex, columnIndex }) {
			return;
			console.log(column);
			if (rowIndex === 0 && column.label == "RDM") {
				return 'background-color: #FAD355; ';//绿色
			} else if (rowIndex === 0 && column.label == "六合编号") {
				return 'background-color: #FAD355; ';//橙色
			} else if (rowIndex === 0 && column.label == "名称") {
				return 'background-color: #BACEFD; ';//橙色
			} else if (rowIndex === 0 && column.label == "规格") {
				return 'background-color: #BACEFD; ';//橙色
			} else if (rowIndex === 0 && column.label == "单位") {
				return 'background-color: #BACEFD; ';//橙色
			} else if (rowIndex === 0 && column.label == "数量") {
				return 'background-color: #FAD355; ';//橙色
			} else if (rowIndex === 0 && column.label == "单价") {
				return 'background-color: #BACEFD; ';//橙色
			} else if (rowIndex === 0 && column.label == "付款方式") {
				return 'background-color: #BACEFD; ';//橙色
			} else if (rowIndex === 0 && column.label == "交付日期") {
				return 'background-color: #FAD355; ';//橙色
			} else if (rowIndex === 0 && column.label == "采购周期") {
				return 'background-color: #BACEFD; ';//橙色
			} else {
				return 'background: #ffffff;';
			}
		},

		mul_update_pp_plan_num() {

			if (this.$data.multipleSelection.length == 0) {
				this.$message({
					message: "请选择计划",
					type: "warning",
					duration: 1500
				});
				return;
			}

			var _this = this;

			var objs;
			axios.post('/pp/mul_sp_1', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				data: _this.$data.multipleSelection,
			})
				.then(function (response) {

					let r = response.data.r;
					let s = ""
					let errType = ""
					if (r == 0) {
						errType = "success"

						// 操作日志
						var list = [];
						_this.$data.multipleSelection.forEach(element => {
							list.push(element.id);
						});
						_this.add_operation_log("序号：" + list.toString() + "合同审批");
					} else {
						errType = "error"
					}

					if (r == 0) {
						s = "修改成功！";
					} else {
						s = "修改失败！";
					}

					_this.$message({
						message: s,
						type: errType,
						duration: 1500
					});

					_this.get_sp_1();
				})
				.catch(function (error) {
					console.log(error);
				});
		},

		get_ma_user() {
			var _this = this;
			axios.post('/pp/get_ma_username', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
			})
				.then(function (response) {
					_this.$data.ma_users = [];
					console.log(response.data);

					objs = response.data.data;
					for (var i = 0; i < objs.length; ++i) {
						var obj = {
							value: objs[i],
							label: objs[i]
						}
						_this.$data.ma_users.push(obj);
					}
				})
				.catch(function (error) {
					console.log(error);
				});
		},

		get_single_pp(child_id) {
			var _this = this;
			var objs;
			axios.post('/pp/get_single_plan', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				id: child_id,
			})
				.then(function (response) {
					console.log(response.data);
					objs = response.data.data;
					//rcnt = response.data.total;
					_this.$data.child_data = objs;
				})
				.catch(function (error) {
					console.log(error);
				});
		},

		celldblclick_1(row, column, cell, event) {
			console.log("row0:", row);
			if (row.if_modify == false) {
				return;
			}
			if (row.flag == "1") {
				this.$data.pre_id = row.id;
				var _this = this;
				var objs;
				axios.post('/pp/get_single_plan', {
					opuser: localStorage.getItem("online_user"),
					opuser_uuid: localStorage.getItem("uuid"),
					id: row.cti,
				})
					.then(function (response) {
						console.log(response.data);
						objs = response.data.data;
						//rcnt = response.data.total;
						_this.$data.child_data = objs;
					})
					.catch(function (error) {
						console.log(error);
					});
				_this.$data.show_child = true;
			} else {
				this.$data.pre_id = 0;
				console.log("row:", row);
				this.show_update_dialog(row);
			}
		},
		to_redmine_1(rdm) {
			let id = parseInt(rdm);
			if (id < 10000) {
				return;
			}
			url = encodeURI("http://123.54.1.214:10010/redmine/issues/" + rdm);
			window.open(url, "");
		},

		input_change(value) {
			console.log(value);
			this.get_sp_1();
		},
		pid_selectChanged(value) {
			console.log("select change");
			this.loading = true;
			var _this = this;
			axios.post('/pp/get_p_name', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				p_id: value,
			})
				.then(function (response) {
					_this.$data.form.p_name = response.data.p_name;
				})
				.catch(function (error) {
					console.log(error);
				});
		},
		remoteMethod(query) {
			if (query !== '') {
				this.loading = true;
				setTimeout(() => {

					var _this = this;
					axios.post('/pp/get_p_id_options', {
						opuser: localStorage.getItem("online_user"),
						opuser_uuid: localStorage.getItem("uuid"),
						p_like_id: query,
					})
						.then(function (response) {
							_this.$data.p_id_options = [];
							console.log(response.data);
							objs = response.data.data;
							for (var i = 0; i < objs.length; ++i) {
								var obj = {
									value: objs[i],
									label: objs[i],
								}
								_this.$data.p_id_options.push(obj);
							}
							_this.$data.loading = false;
							console.log(_this.$data.loading)
						})
						.catch(function (error) {
							console.log(error);
							_this.$data.loading = false;
						});
				}, 200);
			} else {
				_this.$data.p_id_options = [];
			}
		},


		if_fin_cahnge(val) {
			if (val) {
				this.$data.if_do = false;
			} else {
				this.$data.if_do = true;
			}

			this.get_sp_1();
		},
		selectedRowStyle({ row, rowIndex }) {

			for (var i = 0; i < this.$data.multipleSelection.length; i++) {
				if (this.$data.multipleSelection[i].id == row.id) {
					let styleJson = {
						"background": "#134857",
						"color": "#FFFFFF",
					};
					return styleJson;
				}
			}
		},
		download_template() {
			document.getElementById("bt_download").blur();

			var downUrl = '/pp/download_file' + "?id=" + "合同审核导入.csv";
			downloadUrl("合同审核导入.csv", downUrl);
		},

		handleSelectionChange(val) {
			console.log("已选择");
			console.log(val);
			this.multipleSelection = val;
		},
		importData() {
			document.getElementById("bt_import").blur();
			if (this.$data.importTableData.length == 0) {
				this.$message({
					message: "请选择导入文件",
					type: "warning",
					duration: 1500
				});
				return;
			}

			this.$data.percent_len = 0;
			this.$data.if_show_process = true;
			this.$data.interval = setInterval(() => {
				if (this.$data.percent_len >= 99) {
					clearInterval(this.$data.interval);
					return;
				}
				this.$data.percent_len += 1
			}, 20)
			var _this = this;

			axios.post('/pp/import_sp_1', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				plan: this.$data.importTableData,
			})
				.then(function (response) {

					let r = response.data.r;
					console.log("r:", r);
					let s = ""
					let errType = ""
					if (r == 0) {
						let len = _this.$data.importTableData.length;
						_this.$data.percent_len = 100;
						_this.$data.if_show_process = false;

						errType = "success"
						s = "导入" + len + "采购计划成功！";
						_this.$message({
							message: s,
							type: errType,
							duration: 1500
						});
					} else if (r == 2) {
						errType = "error"
						s = response.data.context;
						console.log(s);
						clearInterval(_this.$data.interval);

						_this.$message({
							dangerouslyUseHTMLString: true,
							message: s,
							type: errType,
							duration: 3000
						});
					} else {
						errType = "error"
						s = "导入采购计划失败！";
						clearInterval(_this.$data.interval);

						_this.$message({
							message: s,
							type: errType,
							duration: 3000
						});
					}

					_this.$data.importdialogVisible = false;
					//更新页面
					_this.get_sp_1();

				})
				.catch(function (error) {
					console.log(error);
				});
		},
		importDialog_close(done) {
			console.log("关闭导入对话框");
			done();
		},
		handleChange(file, fileList) {
			document.getElementById("bt_upload").blur();

			this.fileTemp = file.raw
			console.log("filetype:", this.fileTemp);
			if (this.fileTemp) {
				console.log("begin ...")
				console.log(this.fileTemp.type);
				if ((this.fileTemp.type == 'text/csv') || (this.fileTemp.type == '.csv') || (this.fileTemp.type == 'application/vnd.ms-excel')) {
					let _this = this//如果需要点击事件结束之后对DOM进行操作使用)_this.xx=xx进行操作
					Papa.parse(_this.fileTemp, {
						encoding: 'gb2312',
						complete(results) {
							console.log(results)//这个是csv文件的数据
							let data = []
							//遍历csv文件中的数据，存放到data中 方法不唯一，可自己更改
							var cnt = 1
							for (let i = 0; i < results.data.length; ++i) {
								if (i == 0) {
									continue;
								}
								let obj = {}
								obj.supplier = results.data[i][0]
								if (obj.supplier == "" || obj.supplier == undefined) {
									continue;
								}
								obj.applicant = results.data[i][1]
								obj.rdm = results.data[i][2]
								obj.amount = results.data[i][3]

								obj.t_id = cnt
								cnt += 1
								data.push(obj)
							}
							//data.splice(0, 1)//将数组第一位的表格名称去除
							let num = 0
							console.log('data', data)
							_this.$data.importTableData = data;
						}
					})

				} else {
					this.$data.fileListUpload = [];
					this.$message({
						type: 'warning',
						message: '附件格式错误，请删除后重新上传！'
					})
				}
			} else {
				this.$message({
					type: 'warning',
					message: '请上传附件！'
				})
			}
		},
		importCsv() {
			this.$data.fileListUpload = [];
			this.$data.importTableData = [];
			this.$data.importdialogVisible = true;

			this.$data.if_show_process = false;
		},

		export_plan_1() {

			var _this = this;
			var objs;
			axios.post('/pp/export_plan', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				index: this.$data.currentPage,
				count: this.$data.pagesize,
				id: this.$data.id_v,
				rdm: this.$data.rdm_v,
				bt: this.$data.bt_v,
				et: this.$data.et_v,
				code: this.$data.msid_v,
				name: this.$data.pname_v,
				supplier: this.$data.supplier_v,
				if_done: this.$data.checked,
				state: this.$data.state_v,
			})
				.then(function (response) {

					var date = new Date();
					//年 getFullYear()：四位数字返回年份
					var year = date.getFullYear() % 2000; //getFullYear()代替getYear()
					console.log(year.toString());
					//月 getMonth()：0 ~ 11
					var month = date.getMonth() + 1;
					if (month < 10) {
						month = '0' + month
					}
					//日 getDate()：(1 ~ 31)
					var day = date.getDate();
					if (day < 10) {
						day = '0' + day;
					}
					//时 getHours()：(0 ~ 23)
					var hour = date.getHours();
					if (hour < 10) {
						hour = '0' + hour;
					}
					//分 getMinutes()： (0 ~ 59)
					var minute = date.getMinutes();
					if (minute < 10) {
						minute = '0' + minute;
					}
					//秒 getSeconds()：(0 ~ 59)
					var second = date.getSeconds();
					if (second < 10) {
						second = '0' + second;
					}

					var filename = year.toString() + month.toString() + day.toString() + " " + hour.toString() + minute.toString() + second.toString();
					filename = "采购计划 " + filename + ".csv"
					console.log(response.data);
					var fileid = response.data.fileId;

					var downUrl = '/pp/download_file' + "?id=" + fileid;
					downloadUrl(filename, downUrl);
				})
				.catch(function (error) {
					console.log(error);
				});
		},

		tableRowClassName({ row, rowIndex }) {
			if (row.cti != undefined && row.cti.length > 0) {
				return 'child-row';
			} else {
				/*var n = rowIndex%2;
				if (n == 1) {
					return 'success-row';
				}*/
			}
			return '';
		},
		show_update_dialog(row) {

			this.$data.form = {
				id: row.id,
				supplier: row.supplier,
				applicant: row.applicant,
				rdm: row.rdm,
				amount: row.amount,
				state: row.state,
			};

			console.log(this.$data.form)

			//this.get_ma_user();

			var op_user = localStorage.getItem("online_user");
			var level = localStorage.getItem("level");
			var did = localStorage.getItem("did");
			if (level == 1) {
				this.$data.disabled = false;
			} else {
				this.$data.disabled = true;
			}
			console.log(level, this.$data.disabled);
			this.$data.updatedialogVisible_ex = true;
		},

		update_ma_ex() {
			this.$refs['authform_ex'].validate((valid) => {
				if (valid) {
					var _this = this;
					axios.post('/pp/update_sp_1', {
						opuser: localStorage.getItem("online_user"),
						opuser_uuid: localStorage.getItem("uuid"),
						data: _this.form,
					})
						.then(function (response) {

							let r = response.data.r;
							let s = ""
							let errType = ""
							if (r == 0) {
								errType = "success"
								s = "修改成功！";

								// 操作日志
								_this.add_operation_log("修改序号："+ _this.form.id +"合同审批")
							} else {
								errType = "error"
								s = "修改失败！";
							}
							_this.$message({
								message: s,
								type: errType,
								duration: 1500
							});
							//更新页面

							if (r == 0) {
								_this.get_sp_1()
								_this.updatedialogVisible_ex = false;
							}
						})
						.catch(function (error) {
							console.log(error);
						});
				}
			});
		},
		remove_ma_plan(row) {

			this.$confirm('此操作将永久删除, 是否继续?', '提示', {
				confirmButtonText: '确定',
				cancelButtonText: '取消',
				type: 'warning'
			}).then(() => {
				var _this = this;
				axios.post('/pp/remove_sp_1', {
					opuser: localStorage.getItem("online_user"),
					opuser_uuid: localStorage.getItem("uuid"),
					id: row.id
				})
					.then(function (response) {

						let r = response.data.r;
						let s = ""
						let errType = ""
						if (r == 0) {
							errType = "success"
							s = "删除成功！";

							_this.get_sp_1()

							// 操作日志
							// _this.add_operation_log("删除序号：" + row.id + "合同审批")
						} else {
							errType = "error"
							s = "删除失败！";
						}
						_this.$message({
							message: s,
							type: errType,
							duration: 1500
						});
					})
					.catch(function (error) {
						console.log(error);
					});
			}).catch(() => {
			});
		},

		get_sp_1() {

			document.getElementById("bt_serach").blur();

			var _this = this;
			var objs;
			axios.post('/pp/get_sp_1', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				index: this.$data.currentPage,
				count: this.$data.pagesize,
				id: parseInt(this.$data.id_v),
				supplier: this.$data.supplier_v,
				applicant: this.$data.applicant_v,
				contract_name: this.$data.contract_name_v,
				rdm: this.$data.rdm_v,
				if_done: this.$data.checked,
			})
				.then(function (response) {
					console.log(response.data);
					objs = response.data.data;
					rcnt = response.data.total;
					_this.$data.tableData = objs;
					_this.$data.recordTotal = rcnt;
					//_this.$data.pagecnt = response.data.pagecnt;
				})
				.catch(function (error) {
					console.log(error);
				});
		},

		handleSizeChange(val) {
			//console.log(`每页 ${val} 条`);
			this.$data.pagesize = val;

			this.get_sp_1();
		},

		handleCurrentChange(val) {
			//console.log(`当前页: ${val}`);
			this.$data.currentPage = val;

			this.get_sp_1();
		},

		// 根据内容设置列表宽度
		flexColumnWidth(str, arr1, fontNum = 4, flag = 'max') {
			return window.flexColumnWidth(str, arr1, fontNum, flag);
		},

		// 操作日志
		add_operation_log(operation) {
			axios.post('/pp/add_operation_log', {
				opuser: localStorage.getItem("online_user"),
				opuser_uuid: localStorage.getItem("uuid"),
				operation: operation,
			}).then(function (response) {
				console.log(response);
			}).catch(function (error) {
				console.log(error);
			})

		}
	}
}
